Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-2151 Partial course sync #3534

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading