2021-07-16 08:23:16 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
2021-10-20 04:35:39 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2021-07-16 08:23:16 +08:00
|
|
|
|
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
|
|
|
const isModerator = () => {
|
|
|
|
const user = Users.findOne(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
},
|
|
|
|
{ fields: { role: 1 } },
|
|
|
|
);
|
|
|
|
|
|
|
|
if (user && user.role === ROLE_MODERATOR) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2021-10-15 01:00:25 +08:00
|
|
|
const getLearningDashboardAccessToken = () => ((
|
|
|
|
Meetings.findOne(
|
|
|
|
{ meetingId: Auth.meetingID, learningDashboardAccessToken: { $exists: true } },
|
|
|
|
{
|
|
|
|
fields: { learningDashboardAccessToken: 1 },
|
2021-07-20 01:02:32 +08:00
|
|
|
},
|
2021-10-15 01:00:25 +08:00
|
|
|
) || {}).learningDashboardAccessToken || null);
|
|
|
|
|
|
|
|
const setLearningDashboardCookie = () => {
|
|
|
|
const learningDashboardAccessToken = getLearningDashboardAccessToken();
|
|
|
|
if (learningDashboardAccessToken !== null) {
|
2021-12-15 21:35:14 +08:00
|
|
|
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=/`;
|
2021-10-15 01:00:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2021-07-16 08:23:16 +08:00
|
|
|
|
2021-08-27 02:04:06 +08:00
|
|
|
const openLearningDashboardUrl = (lang) => {
|
2021-11-19 05:52:20 +08:00
|
|
|
const APP = Meteor.settings.public.app;
|
2021-10-15 01:00:25 +08:00
|
|
|
if (getLearningDashboardAccessToken() && setLearningDashboardCookie()) {
|
2021-11-19 05:52:20 +08:00
|
|
|
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&lang=${lang}`, '_blank');
|
2021-10-15 01:00:25 +08:00
|
|
|
} else {
|
2021-11-19 05:52:20 +08:00
|
|
|
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&sessionToken=${Auth.sessionToken}&lang=${lang}`, '_blank');
|
2021-10-15 01:00:25 +08:00
|
|
|
}
|
2021-07-16 08:23:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
isModerator,
|
2021-08-25 22:38:35 +08:00
|
|
|
getLearningDashboardAccessToken,
|
2021-10-15 01:00:25 +08:00
|
|
|
setLearningDashboardCookie,
|
2021-08-25 22:38:35 +08:00
|
|
|
openLearningDashboardUrl,
|
2021-07-16 08:23:16 +08:00
|
|
|
};
|