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-8182 - shd creating schools fix #273

Merged
merged 2 commits into from
Dec 19, 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
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
Loading