Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-7522 - fix SHD student visibility #259

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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