Skip to content

Commit

Permalink
Merge branch 'main' into N21-2136-moin-schule-logout-in-svs
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap authored Nov 8, 2024
2 parents cb282a2 + 133f4c4 commit 2bc23fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
18 changes: 14 additions & 4 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ const getSyncedElements = (
startDate,
untilDate,
syncedWithGroup,
excludeFromSync: course.excludeFromSync?.join(','),
};

return selectedElements;
};

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions views/courses/create-course.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
</div>
</div>

{{#if syncedWithGroup}}
<input type="hidden" id="excludeFromSync" name="excludeFromSync" value="{{excludeFromSync}}">
{{/if}}

</section>

<section data-panel="section-2" data-testid="section-2-area" class="submit-page course-submit-page">
Expand Down
3 changes: 3 additions & 0 deletions views/courses/edit-course.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@
</button>
</div>

{{#if course.syncedWithGroup}}
<input type="hidden" id="excludeFromSync" name="excludeFromSync" value="{{excludeFromSync}}">
{{/if}}

{{#unless @root.course.isArchived}}
<div class="modal-footer">
Expand Down

0 comments on commit 2bc23fa

Please sign in to comment.