Skip to content

Commit

Permalink
BC-8182 - shd creating schools fix (#273)
Browse files Browse the repository at this point in the history
* remove non-existing school feature matrix-messenger
* fix feature checkbox handling when newly creating schools
  • Loading branch information
hoeppner-dataport authored Dec 19, 2024
1 parent 28684ba commit 8fefabc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
47 changes: 30 additions & 17 deletions controllers/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,33 @@ const sortSchools = (schools, sortCriteria) => {
});
};

const collectSchoolFeatures = (data) => {
const features = [];
for (let feature of SCHOOL_FEATURES) {
let key = "hasFeature_" + feature;
if (data[key]) {
features.push(feature);
}
}
return features;
}

const separateSchoolFeatures = (data) => {
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 data;
}

const getCreateHandler = (service) => {
return function (req, res, next) {
req.body.features = collectSchoolFeatures(req.body);

api(req)
.post('/' + service + '/', {
// TODO: sanitize
Expand All @@ -165,6 +190,8 @@ const getUpdateHandler = (service) => {
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: {
Expand All @@ -176,15 +203,8 @@ const getUpdateHandler = (service) => {
},
})
}

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

req.body.features = collectSchoolFeatures(req.body);

await api(req).patch('/' + service + '/' + req.params.id, {
// TODO: sanitize
Expand All @@ -205,14 +225,7 @@ const getDetailHandler = (service) => {
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;
}
}
separateSchoolFeatures(data);

if (!configuration.TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE) {
data.hasFeature_studentVisibility_disabled = true;
Expand Down
22 changes: 0 additions & 22 deletions views/schools/forms/add-school.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,6 @@
</select>
</div>

<div class="form-group">
<label>
<input
type="checkbox"
name="hasFeature_messenger"
value="true"
/>
Matrix Messenger Chatfunktion aktivieren
</label>
</div>

<div class="form-group">
<label>
<input
type="checkbox"
name="hasFeature_messengerSchoolRoom"
value="true"
/>
Matrix Messenger Chatraum für Ankündigungen an die gesamte Schule anlegen
</label>
</div>

<div class="form-group">
<label>
<input
Expand Down

0 comments on commit 8fefabc

Please sign in to comment.