From 133f4c4a6b4691bfed3e3a36d839014169075309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= <103562092+MarvinOehlerkingCap@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:30:18 +0100 Subject: [PATCH] N21-2151 Partial course sync (#3534) add partial sync --- controllers/courses.js | 18 ++++++++++++++---- views/courses/create-course.hbs | 4 ++++ views/courses/edit-course.hbs | 3 +++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/controllers/courses.js b/controllers/courses.js index a646f8c4c5..6ab16c6d23 100644 --- a/controllers/courses.js +++ b/controllers/courses.js @@ -80,8 +80,8 @@ const getSyncedElements = ( startDate, untilDate, syncedWithGroup, + excludeFromSync: course.excludeFromSync?.join(','), }; - return selectedElements; }; @@ -305,7 +305,17 @@ const editCourseHandler = (req, res, next) => { if (syncedGroupId && group) { course.name = group.name; - course.teacherIds = getUserIdsByRole(group.users, 'teacher'); + + const teacherIds = getUserIdsByRole(group.users, 'teacher'); + const isTeacherInGroup = teacherIds.some((tid) => tid === res.locals.currentUser._id); + const isTeacher = res.locals.currentUser.roles.map((role) => role.name).includes('teacher'); + if (!isTeacherInGroup && isTeacher) { + course.excludeFromSync = ['teachers']; + course.teacherIds = [res.locals.currentUser._id]; + } else { + course.teacherIds = teacherIds; + } + course.userIds = getUserIdsByRole(group.users, 'student'); if (group.validPeriod) { @@ -578,7 +588,7 @@ router.post('/', (req, res, next) => { req.body.untilDate = untilDate.toDate(); } - const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds']; + const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds', 'excludeFromSync']; req.body = strToPropsArray(req.body, keys); req.body.features = []; @@ -843,7 +853,7 @@ router.patch('/:courseId', async (req, res, next) => { req.body.substitutionIds = []; } - const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds']; + const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds', 'excludeFromSync']; req.body = strToPropsArray(req.body, keys); const startDate = timesHelper.dateTimeStringToMoment(req.body.startDate).utc(); diff --git a/views/courses/create-course.hbs b/views/courses/create-course.hbs index bc4e619dd9..ed96190856 100644 --- a/views/courses/create-course.hbs +++ b/views/courses/create-course.hbs @@ -188,6 +188,10 @@ + {{#if syncedWithGroup}} + + {{/if}} +
diff --git a/views/courses/edit-course.hbs b/views/courses/edit-course.hbs index 10eed025c6..acae64f5cf 100644 --- a/views/courses/edit-course.hbs +++ b/views/courses/edit-course.hbs @@ -300,6 +300,9 @@ + {{#if course.syncedWithGroup}} + + {{/if}} {{#unless @root.course.isArchived}}