Skip to content

Commit

Permalink
BC-7522 - use env vars for student visibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Jul 25, 2024
1 parent ee3ae6e commit 5ef2554
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 52 deletions.
110 changes: 59 additions & 51 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,70 +161,78 @@ const getCreateHandler = (service) => {
};

const getUpdateHandler = (service) => {
return function (req, res, next) {
return async function (req, res, next) {
try {
const configuration = await api(req, {version: 'v3'}).get(`/config/publicx`);

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
}
}
},
})
}

// 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);
// 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);
}
}
}

Promise.all([
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, {
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;
}
}

data.hasFeature_studentVisibility = false;
if (data.permissions && data.permissions.teacher && data.permissions.teacher.STUDENT_LIST) {
data.hasFeature_studentVisibility = true;
}
if (!configuration.TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE) {
data.hasFeature_studentVisibility_disabled = true;
}

if (data.county && data.county.name && data.county._id) {
data.county = data.county._id;
}
data.hasFeature_studentVisibility = !!configuration.TEACHER_STUDENT_VISIBILITY__IS_ENABLED_BY_DEFAULT;

res.json(data);
})
.catch((err) => {
next(err);
});
};
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
6 changes: 5 additions & 1 deletion static/scripts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function updateQueryStringParameter(uri, key, value) {
}

function populateModalForm(modal, data) {

console.log(data);
var $title = modal.find('.modal-title');
var $btnSubmit = modal.find('.btn-submit');
var $btnClose = modal.find('.btn-close');
Expand Down Expand Up @@ -54,11 +54,15 @@ function populateModalForm(modal, data) {
case "radio":
case "checkbox":
$(this).each(function () {
console.log($(this).attr('name'), $(this).prop('name'), value);
if (($(this).attr('name') == $(this).prop('name')) && value) {
$(this).attr("checked", value);
} 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 5ef2554

Please sign in to comment.