Skip to content

Commit

Permalink
partial sync
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Oct 29, 2024
1 parent 86383ca commit 5f44b41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const getSyncedElements = (
startDate,
untilDate,
syncedWithGroup,
syncExcludedFields: course.syncExcludedFields.join(','),
};

return selectedElements;
Expand Down Expand Up @@ -305,7 +306,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.syncExcludedFields = ['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 +589,7 @@ router.post('/', (req, res, next) => {
req.body.untilDate = untilDate.toDate();
}

const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds'];
const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds', 'syncExcludedFields'];
req.body = strToPropsArray(req.body, keys);

req.body.features = [];
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="syncExcludedFields" name="syncExcludedFields" value="{{syncExcludedFields}}">
{{/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="syncExcludedFields" name="syncExcludedFields" value="{{syncExcludedFields}}">
{{/if}}

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

0 comments on commit 5f44b41

Please sign in to comment.