From 0a489ba7fb3eed1a65b2c02d4d7f0e7de2cc1cd6 Mon Sep 17 00:00:00 2001 From: Malte Berg Date: Wed, 4 Oct 2023 16:19:23 +0200 Subject: [PATCH 01/14] add feature flag --- config/default.schema.json | 5 +++++ config/global.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/config/default.schema.json b/config/default.schema.json index 671afe11fa..89af3aa34a 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -597,6 +597,11 @@ "type": "boolean", "default": false, "description": "Enables the new class list view" + }, + "FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED": { + "type": "boolean", + "default": false, + "description": "Enables to get groups of type class" } }, "allOf": [ diff --git a/config/global.js b/config/global.js index 0b47c56e7d..7e3d8f4801 100644 --- a/config/global.js +++ b/config/global.js @@ -40,6 +40,7 @@ const { FEATURE_ALERTS_ON_HOMEPAGE_ENABLED, FEATURE_BUTTONS_ON_LOGINPAGE_ENABLED, FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED, + FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED, } = process.env; const exp = { @@ -82,6 +83,7 @@ const exp = { FEATURE_ALERTS_ON_HOMEPAGE_ENABLED, FEATURE_BUTTONS_ON_LOGINPAGE_ENABLED, FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED, + FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED, }; // eslint-disable-next-line no-console From 5433690403b5354c4fd93588efbad87c9e25e551 Mon Sep 17 00:00:00 2001 From: Malte Berg Date: Wed, 4 Oct 2023 16:20:09 +0200 Subject: [PATCH 02/14] adjust class component --- views/courses/create-course.hbs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/views/courses/create-course.hbs b/views/courses/create-course.hbs index c49294e86d..dcc60c7574 100644 --- a/views/courses/create-course.hbs +++ b/views/courses/create-course.hbs @@ -185,12 +185,29 @@ From 87a7a70a6c4ac8ecb767bda4792a60f479ab9483 Mon Sep 17 00:00:00 2001 From: Malte Berg Date: Wed, 4 Oct 2023 16:20:35 +0200 Subject: [PATCH 03/14] adjust class component --- views/courses/edit-course.hbs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/views/courses/edit-course.hbs b/views/courses/edit-course.hbs index cc9cd73139..39657c8cab 100644 --- a/views/courses/edit-course.hbs +++ b/views/courses/edit-course.hbs @@ -167,17 +167,28 @@ From d7f3cc26f3420b86148b6429bd93f2cb6f78e92a Mon Sep 17 00:00:00 2001 From: Malte Berg Date: Wed, 4 Oct 2023 16:23:21 +0200 Subject: [PATCH 04/14] add v3 endpoint --- controllers/courses.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/controllers/courses.js b/controllers/courses.js index 4f55c1db5b..d665925c46 100644 --- a/controllers/courses.js +++ b/controllers/courses.js @@ -17,6 +17,7 @@ const { logger, formatError } = require('../helpers'); const timesHelper = require('../helpers/timesHelper'); const OPTIONAL_COURSE_FEATURES = ['messenger', 'videoconference']; +const FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED = Configuration.get('FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED'); const router = express.Router(); const { HOST } = require('../config/global'); @@ -27,7 +28,8 @@ const getSelectOptions = (req, service, query) => api(req).get(`/${service}`, { }).then((data) => data.data); const markSelected = (options, values = []) => options.map((option) => { - option.selected = values.includes(option._id); + const optionId = option.id !== undefined ? option.id : option._id; + option.selected = values.includes(optionId); return option; }); @@ -124,16 +126,22 @@ const editCourseHandler = (req, res, next) => { action += `?redirectUrl=${req.query.redirectUrl}`; } - const classesPromise = api(req) - .get('/classes', { - qs: { - schoolId: res.locals.currentSchool, - $populate: ['year'], - $limit: -1, - $sort: { year: -1, displayName: 1 }, - }, - }); - // .then(data => data.data); needed when pagination is not disabled + let classesPromise; + if (FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED) { + classesPromise = api(req, { version: 'v3' }) + .get('/groups/class'); + } else { + classesPromise = api(req) + .get('/classes', { + qs: { + schoolId: res.locals.currentSchool, + $populate: ['year'], + $limit: -1, + $sort: { year: -1, displayName: 1 }, + }, + }); + } + const teachersPromise = getSelectOptions(req, 'users', { roles: ['teacher'], $limit: false, @@ -159,7 +167,7 @@ const editCourseHandler = (req, res, next) => { scopePermissions, ]).then(([course, _classes, _teachers, _students, _scopePermissions]) => { // these 3 might not change anything because hooks allow just ownSchool results by now, but to be sure: - const classes = _classes.filter( + const classes = FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED ? _classes.data : _classes.filter( (c) => c.schoolId === res.locals.currentSchool, ).sort(); const teachers = _teachers.filter( @@ -784,6 +792,11 @@ router.patch('/:courseId', async (req, res, next) => { } await deleteEventsForCourse(req, res, courseId); + // if(FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED){ + // // TODO: V3 save course + // } else { + // + // } await api(req).patch(`/courses/${courseId}`, { json: req.body, }); From 715f2006649db9ce0f479bf14fe160bd58c32805 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 5 Oct 2023 15:01:06 +0200 Subject: [PATCH 05/14] N21-939 change feature flag --- config/default.schema.json | 2 +- config/global.js | 4 ++-- controllers/courses.js | 2 +- views/courses/create-course.hbs | 2 +- views/courses/edit-course.hbs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/default.schema.json b/config/default.schema.json index 89af3aa34a..1229f530ef 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -598,7 +598,7 @@ "default": false, "description": "Enables the new class list view" }, - "FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED": { + "FEATURE_GROUPS_IN_COURSE_ENABLED": { "type": "boolean", "default": false, "description": "Enables to get groups of type class" diff --git a/config/global.js b/config/global.js index 7e3d8f4801..738efbfe1a 100644 --- a/config/global.js +++ b/config/global.js @@ -40,7 +40,7 @@ const { FEATURE_ALERTS_ON_HOMEPAGE_ENABLED, FEATURE_BUTTONS_ON_LOGINPAGE_ENABLED, FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED, - FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED, + FEATURE_GROUPS_IN_COURSE_ENABLED, } = process.env; const exp = { @@ -83,7 +83,7 @@ const exp = { FEATURE_ALERTS_ON_HOMEPAGE_ENABLED, FEATURE_BUTTONS_ON_LOGINPAGE_ENABLED, FEATURE_SHOW_NEW_CLASS_VIEW_ENABLED, - FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED, + FEATURE_GROUPS_IN_COURSE_ENABLED, }; // eslint-disable-next-line no-console diff --git a/controllers/courses.js b/controllers/courses.js index d665925c46..570899042a 100644 --- a/controllers/courses.js +++ b/controllers/courses.js @@ -17,7 +17,7 @@ const { logger, formatError } = require('../helpers'); const timesHelper = require('../helpers/timesHelper'); const OPTIONAL_COURSE_FEATURES = ['messenger', 'videoconference']; -const FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED = Configuration.get('FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED'); +const FEATURE_GROUPS_IN_COURSE_ENABLED = Configuration.get('FEATURE_GROUPS_IN_COURSE_ENABLED'); const router = express.Router(); const { HOST } = require('../config/global'); diff --git a/views/courses/create-course.hbs b/views/courses/create-course.hbs index dcc60c7574..d2cb67be91 100644 --- a/views/courses/create-course.hbs +++ b/views/courses/create-course.hbs @@ -186,7 +186,7 @@ {{#each ../classes}}