Skip to content

Commit

Permalink
N21-2192 Configure teachers in partial sync (#3540)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Richter <93926487+IgorCapCoder@users.noreply.github.com>
  • Loading branch information
MarvinOehlerkingCap and IgorCapCoder authored Nov 12, 2024
1 parent fde330d commit f628561
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const router = express.Router();
const { HOST } = require('../config/global');
const { isUserHidden } = require('../helpers/users');

const SYNC_ATTRIBUTE = Object.freeze({
TEACHERS: 'teachers',
});

const getSelectOptions = (req, service, query) => api(req).get(`/${service}`, {
qs: query,
}).then((data) => data.data);
Expand Down Expand Up @@ -81,6 +85,7 @@ const getSyncedElements = (
untilDate,
syncedWithGroup,
excludeFromSync: course.excludeFromSync?.join(','),
areTeachersSynced: !course.excludeFromSync?.includes(SYNC_ATTRIBUTE.TEACHERS),
};
return selectedElements;
};
Expand Down Expand Up @@ -310,7 +315,7 @@ const editCourseHandler = (req, res, next) => {
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.excludeFromSync = [SYNC_ATTRIBUTE.TEACHERS];
course.teacherIds = [res.locals.currentUser._id];
} else {
course.teacherIds = teacherIds;
Expand Down
4 changes: 2 additions & 2 deletions views/courses/create-course.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<div class="form-group col-md-6" data-testid="teachers_container">
<label for="courseTeacher">{{$t "administration.global.label.teachingTeacher"}}</label>
<select id="courseTeacher" name="teacherIds[]" required multiple data-placeholder="{{$t "courses.global.input.chooseTeacher"}}" data-testid="teachersearch" autocomplete="off"
aria-describedby="courseTeacherErr" {{#if syncedWithGroup}}disabled{{/if}}>
aria-describedby="courseTeacherErr" {{#if areTeachersSynced}}disabled{{/if}}>
{{#each teachers}}
<option data-testid="teacher" value="{{this._id}}" {{#if this.selected}}selected{{/if}} {{#if this.isHidden}}hidden{{/if}}>
{{#if this.displayName}}
Expand All @@ -120,7 +120,7 @@
</option>
{{/each}}
</select>
{{#if syncedWithGroup}}
{{#if areTeachersSynced}}
<input type="hidden" id="courseTeacherSync" name="teacherIds" value="{{teachersSelected}}">
{{/if}}
<span class="small course-validation-error" id="courseTeacherErr">
Expand Down
4 changes: 2 additions & 2 deletions views/courses/edit-course.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@
<div class="form-group">
<label for="teacherId">{{$t "administration.global.label.teachingTeacher"}}</label>
<select id="teacherId" name="teacherIds[]" data-testid="teachersearch" required multiple data-placeholder="{{$t "courses.global.input.chooseTeacher"}}"
{{#ifCond course.isArchived '||' course.syncedWithGroup}}disabled{{/ifCond}}>
{{#ifCond course.isArchived '||' areTeachersSynced}}disabled{{/ifCond}}>
{{#each teachers}}
<option value="{{this._id}}" {{#if this.selected}}selected{{/if}} {{#if this.isHidden}}hidden{{/if}}>
{{this.lastName}}, {{this.firstName}}{{#if this.outdatedSince}} ~~{{/if}}
</option>
{{/each}}
</select>
{{#if course.syncedWithGroup}}
{{#if areTeachersSynced}}
<input type="hidden" id="teacherIdSync" name="teacherIds" value="{{teachersSelected}}">
{{/if}}
<span class="small course-validation-error" id="courseTeacherErr">
Expand Down

0 comments on commit f628561

Please sign in to comment.