Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…client into BC-6708-remove-course-share
  • Loading branch information
odalys-dataport committed Mar 13, 2024
2 parents a378912 + 0148ea0 commit 13b5903
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 107 deletions.
109 changes: 51 additions & 58 deletions controllers/administration.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const sendMailHandler = (user, req, res, internalReturn) => {
req.session.notification = {
type: 'success',
message:
res.$t('administration.controller.text.userCreatedSuccessfullyAndRegistration'),
res.$t('administration.controller.text.userCreatedSuccessfullyAndRegistration'),
};
return redirectHelper.safeBackRedirect(req, res);
})
Expand Down Expand Up @@ -337,10 +337,10 @@ const getUserCreateHandler = (internalReturn) => function userCreate(req, res, n
return redirectHelper.safeBackRedirect(req, res);

/*
createEventsForData(data, service, req, res).then(_ => {
next();
});
*/
createEventsForData(data, service, req, res).then(_ => {
next();
});
*/
})
.catch((err) => {
if (internalReturn) return false;
Expand Down Expand Up @@ -1822,7 +1822,7 @@ router.get(
age: CONSENT_WITHOUT_PARENTS_MIN_AGE_YEARS,
}),
content:
res.$t('administration.controller.text.passTheRegistrationLinkDirectly')
res.$t('administration.controller.text.passTheRegistrationLinkDirectly')
+ res.$t('administration.controller.text.theStepsForTheParentsAreOmitted'),
},
{
Expand Down Expand Up @@ -2240,7 +2240,7 @@ router.get(
// ONLY useable with ADMIN_VIEW !

/*
COURSES
COURSES
*/

const getCourseCreateHandler = () => function coruseCreateHandler(req, res, next) {
Expand All @@ -2258,76 +2258,68 @@ const getCourseCreateHandler = () => function coruseCreateHandler(req, res, next
});
};

const updateSchoolFeatures = async (req, currentFeatures, features) => {
const pushValues = Object.keys(features)
.filter((feature) => features[feature] && !currentFeatures.includes(feature));
const pullValues = Object.keys(features)
.filter((feature) => !features[feature] && currentFeatures.includes(feature));
const schoolUpdateHandler = async (req, res, next) => {
const defaultLogoName = 'logo.png';
const {
name,
language,
logo_dataUrl,
} = req.body;

const requests = [];
if (pushValues.length > 0) {
requests.push(api(req)
.patch(`/schools/${req.params.id}`, { json: { $push: { features: { $each: pushValues } } } }));
}
if (pullValues.length > 0) {
requests.push(api(req)
.patch(`/schools/${req.params.id}`, { json: { $pull: { features: { $in: pullValues } } } }));
let logo;
if (logo_dataUrl) {
logo = {
dataUrl: logo_dataUrl,
name: defaultLogoName,
};
}
await Promise.all(requests);
};

const schoolFeatureUpdateHandler = async (req, res, next) => {
const requestBody = {
name,
language,
permissions: {
student: { LERNSTORE_VIEW: false },
teacher: { STUDENT_LIST: false },
},
features: [],
logo,
};

try {
// Toggle teacher's studentVisibility permission
if (Configuration.get('TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE')) {
await api(req)
.patch('school/teacher/studentvisibility', {
json: {
permission: {
isEnabled: !!req.body.studentVisibility,
},
},
});
requestBody.permissions.teacher.STUDENT_LIST = !!req.body.studentVisibility;
}

delete req.body.studentVisibility;

// Toggle sudent lernstore view permission
const studentLernstoreFeature = Configuration.get('FEATURE_ADMIN_TOGGLE_STUDENT_LERNSTORE_VIEW_ENABLED');
if (studentLernstoreFeature) {
await api(req)
.patch('school/student/studentlernstorevisibility', {
json: {
permission: {
isEnabled: !!req.body.studentlernstorevisibility,
},
},
});
requestBody.permissions.student.LERNSTORE_VIEW = !!req.body.studentlernstorevisibility;
}

delete req.body.studentlernstorevisibility;

const currentFeatures = res.locals.currentSchoolData.features;

// Update school features
const possibleSchoolFeatures = [
'messenger', 'messengerSchoolRoom', 'messengerStudentRoomCreate', 'rocketChat', 'videoconference',
];
const featuresToSet = {};

for (const feature of possibleSchoolFeatures) {
featuresToSet[feature] = req.body[feature] === 'true';
if (req.body[feature] === 'true') {
requestBody.features.push(feature);
}
}
await updateSchoolFeatures(req, currentFeatures, featuresToSet);

await api(req, { version: 'v3' }).patch(`/school/${res.locals.currentSchool}`, {
json: requestBody,
});

res.redirect(req.header('Referer'));
} catch (err) {
next(err);
}

// update other school properties
return getUpdateHandler('schools')(req, res, next);
};

router.use(permissionsHelper.permissionsChecker('ADMIN_VIEW'));
router.patch('/schools/:id', schoolFeatureUpdateHandler);
router.patch('/schools/:id', schoolUpdateHandler);
router.post('/schools/:id/bucket', createBucket);
router.post('/schools/policy', updatePolicy);
router.post('/courses/', mapTimeProps, getCourseCreateHandler());
Expand Down Expand Up @@ -2508,7 +2500,7 @@ const getTeamFlags = (team, res) => {
};

const enableStudentUpdateHandler = async function enableStudentUpdate(req, res, next) {
await api(req).patch(`/schools/${req.params.id}`, {
await api(req, { version: 'v3' }).patch(`/school/${req.params.id}`, {
json: {
enableStudentTeamCreation: req.body.enablestudentteamcreation === 'true',
},
Expand Down Expand Up @@ -2544,7 +2536,7 @@ router.all('/teams', async (req, res, next) => {
query = Object.assign(query, filterQuery);
// TODO: mapping sort
/*
'Mitglieder': 'members',
'Mitglieder': 'members',
'Schule(n)': 'schoolIds',
'Erstellt am': 'createdAt',
*/
Expand Down Expand Up @@ -2685,13 +2677,14 @@ router.all('/teams', async (req, res, next) => {

users.sort((a, b) => (
compare(a.lastName.toLowerCase(), b.lastName.toLowerCase())
|| compare(a.firstName.toLowerCase(), b.firstName.toLowerCase())
|| compare(a.firstName.toLowerCase(), b.firstName.toLowerCase())
));

users = users.filter((user) => !isUserHidden(user, res.locals.currentSchoolData));

const school = res.locals.currentSchoolData;
const isTeamCreationByStudentsEnabled = school.features.includes('isTeamCreationByStudentsEnabled');
const isTeamCreationByStudentsEnabled = school.instanceFeatures
.includes('isTeamCreationByStudentsEnabled');

res.render('administration/teams', {
title: res.$t('administration.dashboard.headline.manageTeams'),
Expand Down Expand Up @@ -2762,7 +2755,7 @@ router.delete('/teams/:id', (req, res, next) => {
});

/*
SCHOOL / SYSTEMS / RSS
SCHOOL / SYSTEMS / RSS
*/

router.post('/systems/', createSystemHandler);
Expand Down Expand Up @@ -3129,7 +3122,7 @@ router.get('/startldapschoolyear', async (req, res) => {
});

/*
LDAP SYSTEMS
LDAP SYSTEMS
*/

router.post(
Expand Down
81 changes: 61 additions & 20 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ const markSelected = (options, values = []) => options.map((option) => {
return option;
});

// checks for user's 'STUDENT_LIST' permission and filters checked students
const filterStudents = (ctx, s) => (
!ctx.locals.currentUser.permissions.includes('STUDENT_LIST')
? s.filter(({ selected }) => selected) : s
);

const selectedElementIdsToString = (arr = []) => {
const txt = arr.filter((obj) => obj.selected).map((obj) => (obj.id !== undefined ? obj.id : obj._id)).join(',');
return txt;
};

const getSyncedElementIds = (
course,
classesAndGroups,
classAndGroupIdsOfCourse,
teachers,
substitutions,
students,
res,
) => {
const startDate = course.startDate ? timesHelper.formatDate(course.startDate, 'DD.MM.YYYY') : undefined;
const untilDate = course.untilDate ? timesHelper.formatDate(course.untilDate, 'DD.MM.YYYY') : undefined;

const selectedElements = {
teachersSelected: selectedElementIdsToString(markSelected(teachers, course.teacherIds)),
substitutionSelected: selectedElementIdsToString(markSelected(substitutions, course.substitutionIds)),
classesAndGroupsSelected: selectedElementIdsToString(markSelected(classesAndGroups, classAndGroupIdsOfCourse)),
studentsSelected: selectedElementIdsToString(filterStudents(res, markSelected(students, course.userIds))),
startDate,
untilDate,
};

return selectedElements;
};

const getDefaultRedirectUrl = (courseId) => `/rooms/${courseId}`;

/**
Expand Down Expand Up @@ -241,14 +276,18 @@ const editCourseHandler = (req, res, next) => {
'#795548',
];

// checks for user's 'STUDENT_LIST' permission and filters checked students
const filterStudents = (ctx, s) => (
!ctx.locals.currentUser.permissions.includes('STUDENT_LIST')
? s.filter(({ selected }) => selected) : s
);

const classAndGroupIdsOfCourse = [...(course.classIds || []), ...(course.groupIds || [])];

const syncedElementIds = course.syncedWithGroup ? getSyncedElementIds(
course,
classesAndGroups,
classAndGroupIdsOfCourse,
teachers,
substitutions,
students,
res,
) : {};

if (req.params.courseId) {
if (!_scopePermissions.includes('COURSE_EDIT')) return next(new Error(res.$t('global.text.403')));
return res.render('courses/edit-course', {
Expand All @@ -260,17 +299,12 @@ const editCourseHandler = (req, res, next) => {
course,
colors,
classesAndGroups: markSelected(classesAndGroups, classAndGroupIdsOfCourse),
teachers: markSelected(
teachers,
course.teacherIds,
),
substitutions: markSelected(
substitutions,
course.substitutionIds,
),
teachers: markSelected(teachers, course.teacherIds),
substitutions: markSelected(substitutions, course.substitutionIds),
students: filterStudents(res, markSelected(students, course.userIds)),
scopePermissions: _scopePermissions,
schoolData: res.locals.currentSchoolData,
...syncedElementIds,
});
}
return res.render('courses/create-course', {
Expand Down Expand Up @@ -379,12 +413,6 @@ const copyCourseHandler = (req, res, next) => {

course.isArchived = false;

// checks for user's 'STUDENT_LIST' permission and filters checked students
const filterStudents = (ctx, s) => (
!ctx.locals.currentUser.permissions.includes('STUDENT_LIST')
? s.filter(({ selected }) => selected) : s
);

res.render('courses/edit-course', {
action,
method,
Expand Down Expand Up @@ -764,6 +792,19 @@ router.patch('/:courseId', async (req, res, next) => {
req.body.substitutionIds = [];
}

if (typeof req.body.teacherIds === 'string') {
req.body.teacherIds = req.body.teacherIds.split(',');
}
if (typeof req.body.substitutionIds === 'string') {
req.body.substitutionIds = req.body.substitutionIds.split(',');
}
if (typeof req.body.classIds === 'string') {
req.body.classIds = req.body.classIds.split(',');
}
if (typeof req.body.userIds === 'string') {
req.body.userIds = req.body.userIds.split(',');
}

const startDate = timesHelper.dateStringToMoment(req.body.startDate);
const untilDate = timesHelper.dateStringToMoment(req.body.untilDate);

Expand Down
4 changes: 2 additions & 2 deletions controllers/homework.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,11 @@ router.get('/:assignmentId', (req, res, next) => {
}

const submissionFilesStorageData = _.clone(filesStorage);
submissionFilesStorageData.files = filesStorage.files.filter((file) => submitters.has(file.creatorId));
submissionFilesStorageData.files = filesStorage.files.filter((file) => !file.creatorId || submitters.has(file.creatorId));
submissionFilesStorageData.readonly = readonly || (!isCreator && isTeacher);

const gradeFilesStorageData = _.clone(filesStorage);
gradeFilesStorageData.files = filesStorage.files.filter((file) => teachers.has(file.creatorId));
gradeFilesStorageData.files = filesStorage.files.filter((file) => !file.creatorId || teachers.has(file.creatorId));
gradeFilesStorageData.readonly = !isTeacher;

submission.submissionFiles = { filesStorage: submissionFilesStorageData };
Expand Down
6 changes: 4 additions & 2 deletions controllers/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ const checkIfUserCanCreateTeam = (res) => {
if (roleNames.includes('administrator') || roleNames.includes('teacher') || roleNames.includes('student')) {
allowedCreateTeam = true;
const currentSchool = res.locals.currentSchoolData;
if (roleNames.includes('student') && !currentSchool.features.includes('isTeamCreationByStudentsEnabled')) {
if (roleNames.includes('student')
&& !currentSchool.instanceFeatures.includes('isTeamCreationByStudentsEnabled')
) {
allowedCreateTeam = false;
}
}
Expand Down Expand Up @@ -1140,7 +1142,7 @@ router.get('/:teamId/members', async (req, res, next) => {
const { _id: studentRoleId } = roles.find((role) => role.name === 'student');
return res.locals.currentUser.permissions.includes('STUDENT_LIST')
|| !user.roles.includes(studentRoleId)
|| res.locals.currentSchoolData.features.includes('isTeamCreationByStudentsEnabled');
|| res.locals.currentSchoolData.instanceFeatures.includes('isTeamCreationByStudentsEnabled');
});

body.sort((a, b) => {
Expand Down
10 changes: 3 additions & 7 deletions controllers/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const editTopicHandler = (req, res, next) => {
action = `/${context}/${context === 'courses' ? req.params.courseId : req.params.teamId}`
+ `/topics/${req.params.topicId}${req.query.courseGroup ? `?courseGroup=${req.query.courseGroup}` : ''}`;
method = 'patch';
lessonPromise = api(req).get(`/lessons/${req.params.topicId}`);
lessonPromise = api(req, { version: 'v3' }).get(`/lessons/${req.params.topicId}`);
} else {
action = `/${context}/${context === 'courses' ? req.params.courseId : req.params.teamId}`
+ `/topics${req.query.courseGroup ? `?courseGroup=${req.query.courseGroup}` : ''}`;
Expand Down Expand Up @@ -296,7 +296,7 @@ router.post('/', async (req, res, next) => {

router.post('/:id/share', (req, res, next) => {
// if lesson already has shareToken, do not generate a new one
api(req).get(`/lessons/${req.params.id}`).then((topic) => {
api(req, { version: 'v3' }).get(`/lessons/${req.params.id}`).then((topic) => {
topic.shareToken = topic.shareToken || shortId.generate();
api(req).patch(`/lessons/${req.params.id}`, { json: topic })
.then((result) => res.json(result))
Expand All @@ -309,11 +309,7 @@ router.get('/:topicId', (req, res, next) => {
const context = req.originalUrl.split('/')[1];
Promise.all([
api(req).get(`/${context}/${req.params.courseId}`),
api(req).get(`/lessons/${req.params.topicId}`, {
qs: {
$populate: ['materialIds'],
},
}).then((lesson) => {
api(req, { version: 'v3' }).get(`/lessons/${req.params.topicId}`).then((lesson) => {
const etherpadPads = [];
if (typeof lesson.contents !== 'undefined') {
lesson.contents.forEach((element) => {
Expand Down
Loading

0 comments on commit 13b5903

Please sign in to comment.