bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/learning-dashboard/service.js
Ramón Souza 7514066fc3
fix: Client can't load in certain cases (#20336)
* move settings

* remove meteor cache files
2024-05-29 09:26:11 -04:00

57 lines
1.7 KiB
JavaScript

import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import Meetings from '/imports/api/meetings';
const isModerator = () => {
const ROLE_MODERATOR = window.meetingClientSettings.public.user.role_moderator;
const user = Users.findOne(
{
meetingId: Auth.meetingID,
userId: Auth.userID,
},
{ fields: { role: 1 } },
);
if (user && user.role === ROLE_MODERATOR) {
return true;
}
return false;
};
const getLearningDashboardAccessToken = () => ((
Meetings.findOne(
{ meetingId: Auth.meetingID },
{
fields: { 'learningDashboard.learningDashboardAccessToken': 1 },
},
) || {})?.learningDashboard?.learningDashboardAccessToken || null);
const setLearningDashboardCookie = () => {
const learningDashboardAccessToken = getLearningDashboardAccessToken();
if (learningDashboardAccessToken !== null) {
const lifetime = new Date();
lifetime.setTime(lifetime.getTime() + (3600000)); // 1h (extends 7d when open Dashboard)
document.cookie = `ld-${Auth.meetingID}=${getLearningDashboardAccessToken()}; expires=${lifetime.toGMTString()}; path=/`;
return true;
}
return false;
};
const openLearningDashboardUrl = (lang) => {
const APP = window.meetingClientSettings.public.app;
if (getLearningDashboardAccessToken() && setLearningDashboardCookie()) {
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&lang=${lang}`, '_blank');
} else {
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&sessionToken=${Auth.sessionToken}&lang=${lang}`, '_blank');
}
};
export default {
isModerator,
getLearningDashboardAccessToken,
setLearningDashboardCookie,
openLearningDashboardUrl,
};