Skip to content

Commit

Permalink
Merge branch 'main' into N21-1918-external-tool-thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Jul 29, 2024
2 parents f2bc033 + e2c4e14 commit be7d575
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
99 changes: 61 additions & 38 deletions controllers/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SCHOOL_FEATURES = [
'rocketChat',
'videoconference',
'messenger',
'studentVisibility',
// 'studentVisibility', // is now handled instead with env vars / permission in school combination
'messengerSchoolRoom',
'oauthProvisioningEnabled',
'showOutdatedUsers',
Expand Down Expand Up @@ -161,55 +161,78 @@ const getCreateHandler = (service) => {
};

const getUpdateHandler = (service) => {
return function (req, res, next) {
// parse school features
req.body.features = [];
for (let feature of SCHOOL_FEATURES) {
let key = 'hasFeature_' + feature;
if (req.body[key]) {
req.body.features.push(feature);
return async function (req, res, next) {
try {
const configuration = await api(req, {version: 'v3'}).get(`/config/public`);

if (configuration.TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE) {
await api(req, {version: 'v3'}).patch(`/school/${req.params.id}`, {
json: {
permissions: {
teacher: {
STUDENT_LIST: !!req.body.hasFeature_studentVisibility
}
}
},
})
}
}

api(req)
.patch('/' + service + '/' + req.params.id, {
// parse school features
req.body.features = [];
for (let feature of SCHOOL_FEATURES) {
let key = 'hasFeature_' + feature;
if (req.body[key]) {
req.body.features.push(feature);
}
}

await api(req).patch('/' + service + '/' + req.params.id, {
// TODO: sanitize
json: req.body,
})
.then((data) => {
res.redirect(req.header('Referer'));
})
.catch((err) => {
next(err);
});

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

const getDetailHandler = (service) => {
return function (req, res, next) {
api(req)
.get('/' + service + '/' + req.params.id)
.then((data) => {
// parse school features
for (let feature of SCHOOL_FEATURES) {
let key = 'hasFeature_' + feature;
if (data.features) {
data[key] = data.features.indexOf(feature) !== -1;
} else {
data[key] = false;
}
return async function (req, res, next) {
try {
const configuration = await api(req, { version: 'v3' }).get(`/config/public`);
const data = await api(req).get('/' + service + '/' + req.params.id)

// parse school features
for (let feature of SCHOOL_FEATURES) {
let key = 'hasFeature_' + feature;
if (data.features) {
data[key] = data.features.indexOf(feature) !== -1;
} else {
data[key] = false;
}
}

if (data.county && data.county.name && data.county._id) {
data.county = data.county._id;
}
if (!configuration.TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE) {
data.hasFeature_studentVisibility_disabled = true;
}

res.json(data);
})
.catch((err) => {
next(err);
});
};
data.hasFeature_studentVisibility = !!configuration.TEACHER_STUDENT_VISIBILITY__IS_ENABLED_BY_DEFAULT;

if (data.permissions && data.permissions.teacher && data.permissions.teacher.STUDENT_LIST !== undefined) {
data.hasFeature_studentVisibility = data.permissions.teacher.STUDENT_LIST;
}

if (data.county && data.county.name && data.county._id) {
data.county = data.county._id;
}

res.json(data);
} catch (err) {
next(err);
}
}
};

const getDeleteHandler = (service) => {
Expand Down
4 changes: 3 additions & 1 deletion static/scripts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function updateQueryStringParameter(uri, key, value) {
}

function populateModalForm(modal, data) {

var $title = modal.find('.modal-title');
var $btnSubmit = modal.find('.btn-submit');
var $btnClose = modal.find('.btn-close');
Expand Down Expand Up @@ -59,6 +58,9 @@ function populateModalForm(modal, data) {
} else {
$(this).removeAttr("checked");
}
if (data.fields[$(this).attr('name') + "_disabled"] ){
$(this).attr("disabled", true);
}
});
break;
case "datetime-local":
Expand Down

0 comments on commit be7d575

Please sign in to comment.