Skip to content

Commit

Permalink
Merge branch 'main' into BC-4900-red-line-shows-when-removing-task
Browse files Browse the repository at this point in the history
  • Loading branch information
davwas authored Sep 22, 2023
2 parents f96d5a2 + 8b7754f commit 3c8d4c9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 33 deletions.
94 changes: 62 additions & 32 deletions controllers/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const getVersion = () => {
const VERSION = getVersion();

router.get('/login', csrfProtection, (req, res, next) => api(req, { version: VERSION })
.get(`/oauth2/loginRequest/${req.query.login_challenge}`).then((loginRequest) => {
.get(`/oauth2/loginRequest/${req.query.login_challenge}`)
.then((loginRequest) => {
req.session.login_challenge = req.query.login_challenge;
if (loginRequest.skip) {
return res.redirect('/oauth2/login/success');
}
return res.redirect(Configuration.get('NOT_AUTHENTICATED_REDIRECT_URL'));
}).catch(next));
})
.catch(next));

router.get('/login/success', csrfProtection, auth.authChecker, (req, res, next) => {
if (!req.session.login_challenge) res.redirect('/dashboard/');
Expand All @@ -38,23 +40,28 @@ router.get('/login/success', csrfProtection, auth.authChecker, (req, res, next)
.patch(
`/oauth2/loginRequest/${req.session.login_challenge}/?accept=1`,
{ body },
).then((loginRequest) => {
)
.then((loginRequest) => {
delete (req.session.login_challenge);
return res.redirect(loginRequest.redirect_to);
}).catch(next);
})
.catch(next);
});

router.all('/logout', csrfProtection, auth.authChecker, (req) => {
api(req, { version: VERSION }).get('/oauth2/logoutRequest');
api(req, { version: VERSION })
.get('/oauth2/logoutRequest');
});

router.all('/logout/redirect', csrfProtection, auth.authChecker, (req, res, next) => {
const body = {
redirect_to: '',
};

return api(req, { version: VERSION }).patch(`/oauth2/logoutRequest/${req.query.logout_challenge}`, { body })
.then((logoutRequest) => res.redirect(logoutRequest.redirect_to)).catch(next);
return api(req, { version: VERSION })
.patch(`/oauth2/logoutRequest/${req.query.logout_challenge}`, { body })
.then((logoutRequest) => res.redirect(logoutRequest.redirect_to))
.catch(next);
});

const acceptConsent = (r, w, challenge, grantScopes, remember = false) => {
Expand All @@ -64,7 +71,8 @@ const acceptConsent = (r, w, challenge, grantScopes, remember = false) => {
remember_for: 60 * 60 * 24 * 30,
};

return api(r, { version: VERSION }).patch(`/oauth2/consentRequest/${challenge}/?accept=1`, { body })
return api(r, { version: VERSION })
.patch(`/oauth2/consentRequest/${challenge}/?accept=1`, { body })
.then((consentRequest) => w.redirect(consentRequest.redirect_to));
};

Expand All @@ -87,7 +95,8 @@ router.get('/consent', csrfProtection, auth.authChecker, (req, res, next) => {
// An error occurred (at hydra)
return res.send(`${req.query.error}<br />${req.query.error_description}`);
}
return api(req, { version: VERSION }).get(`/oauth2/consentRequest/${req.query.consent_challenge}`)
return api(req, { version: VERSION })
.get(`/oauth2/consentRequest/${req.query.consent_challenge}`)
.then(async (consentRequest) => {
let skipConsent = consentRequest.context?.skipConsent;

Expand All @@ -101,7 +110,8 @@ router.get('/consent', csrfProtection, auth.authChecker, (req, res, next) => {
({ skipConsent } = tools.data[0]);
} else {
throw new Error(
`Unable to find a singular LtiTool with client_id ${consentRequest.client.client_id} for consent request`,
`Unable to find a singular LtiTool with client_id
${consentRequest.client.client_id} for consent request`,
);
}
}
Expand All @@ -124,26 +134,43 @@ router.get('/consent', csrfProtection, auth.authChecker, (req, res, next) => {
value: scope,
})),
});
}).catch(next);
})
.catch(next);
});

router.post('/consent', auth.authChecker, (r, w) => acceptConsent(r, w, r.query.challenge, r.body.grantScopes, true));

router.get('/username/:pseudonym', (req, res, next) => {
router.get('/username/:pseudonym', async (req, res, next) => {
if (req.cookies.jwt) {
return api(req).get('/pseudonym', {
qs: {
pseudonym: req.params.pseudonym,
},
}).then((pseudonym) => {
let shortName;
let completeName;
const anonymousName = '???';
completeName = anonymousName;
shortName = completeName;
if (pseudonym.data.length) {
completeName = `${pseudonym.data[0].user.firstName} ${pseudonym.data[0].user.lastName}`;
shortName = `${pseudonym.data[0].user.firstName} ${pseudonym.data[0].user.lastName.charAt(0)}.`;
try {
let shortName = '???';
let completeName = '???';

if (Configuration.get('FEATURE_CTL_TOOLS_TAB_ENABLED')) {
const pseudonymResponse = await api(req, { version: 'v3' })
.get(`/pseudonyms/${req.params.pseudonym}`);
const userResponse = await api(req)
.get('/users', {
qs: { _id: pseudonymResponse.userId },
$limit: 1,
});
if (userResponse.data.length) {
completeName = `${userResponse.data[0].firstName} ${userResponse.data[0].lastName}`;
shortName = `${userResponse.data[0].firstName} ${userResponse.data[0].lastName.charAt(0)}.`;
}
} else {
const feathersPseudonymResponse = await api(req)
.get('/pseudonym', {
qs: {
pseudonym: req.params.pseudonym,
},
});
if (feathersPseudonymResponse.data.length) {
// eslint-disable-next-line max-len
completeName = `${feathersPseudonymResponse.data[0].user.firstName} ${feathersPseudonymResponse.data[0].user.lastName}`;
// eslint-disable-next-line max-len
shortName = `${feathersPseudonymResponse.data[0].user.firstName} ${feathersPseudonymResponse.data[0].user.lastName.charAt(0)}.`;
}
}
return res.render('oauth2/username', {
depseudonymized: true,
Expand All @@ -153,14 +180,17 @@ router.get('/username/:pseudonym', (req, res, next) => {
shortTitle: res.locals.theme.short_title,
}),
});
}).catch(next);
} catch (error) {
return next(error);
}
} else {
return res.render('oauth2/username', {
depseudonymized: false,
completeName: res.$t('login.oauth2.label.showName'),
shortName: res.$t('login.oauth2.label.showName'),
infoText: '',
});
}
return res.render('oauth2/username', {
depseudonymized: false,
completeName: res.$t('login.oauth2.label.showName'),
shortName: res.$t('login.oauth2.label.showName'),
infoText: '',
});
});

module.exports = router;
1 change: 1 addition & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
"afterTheTransferPhaseEnded": "Nach Beenden der Transferphase",
"allStudentsVisibility": "Die Aktivierung dieser Option hat datenschutzrechtlich eine hohe Schwelle. Um die Sichtbarkeit aller Schüler:innen der Schule für jede Lehrkraft zu aktivieren, ist es erforderlich, dass jede/r Schüler:in wirksam in diese Datenverarbeitung eingewilligt hat.",
"allStudentsVisibilityBrandenburg": "Die Aktivierung dieser Option schaltet die Sichtbarkeit aller Schüler:innen der Schule für jede Lehrkraft an.",
"allStudentsVisibilityNiedersachsen" : "Wenn diese Option nicht aktiviert ist, können die Lehrkräfte ausschließlich die Klassen sowie deren Schülerinnen und Schüler sehen, in denen sie Mitglied sind.",
"authentication": "Authentifizierung",
"newPage": "Zur neuen Admin-Seite",
"changeOfClasses": "Änderung von Klassen/neue Klassen",
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
"afterTheTransferPhaseEnded": "After the transfer phase has ended",
"allStudentsVisibility": "Activating this option has a high threshold under data protection law. In order to activate the visibility of all students in the school for each teacher, it is necessary that each student has effectively consented to this data processing.",
"allStudentsVisibilityBrandenburg": "Enabling this option turns on the visibility of all students of this school for each teacher.",
"allStudentsVisibilityNiedersachsen" : "If this option is not enabled, teachers can only see the classes and their students in which they are members.",
"authentication": "Authentication",
"newPage": "To the new admin page",
"changeOfClasses": "Change of classes / new classes",
Expand Down
1 change: 1 addition & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
"afterTheTransferPhaseEnded": "Una vez finalizada la fase de transferencia",
"allStudentsVisibility": "La activación de esta opción tiene un nivel alto según la ley de protección de datos. Para activar la visibilidad de todos los alumnos de la escuela para cada profesor, es necesario que cada alumno haya dado su consentimiento de manera efectiva para este tratamiento de datos.",
"allStudentsVisibilityBrandenburg": "Activando esta opción se activa la visibilidad de todos los alumnos de esta escuela para cada profesor.",
"allStudentsVisibilityNiedersachsen" : "Si esta opción no está activada, los profesores sólo podrán ver las clases y sus alumnos de las que son miembros.",
"authentication": "Autenticación",
"newPage": "A la nueva página de administración",
"changeOfClasses": "Cambio de clases / nuevas clases",
Expand Down
1 change: 1 addition & 0 deletions locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@
"afterTheTransferPhaseEnded": "Після завершення фази переходу",
"allStudentsVisibility": "Активація цієї опції має високе граничне значення згідно із законодавством про захист даних. Щоб активувати видимість усіх учнів у школі для кожного викладача, необхідно, щоб кожен учень надав свою фактичну згоду на таку обробку даних.",
"allStudentsVisibilityBrandenburg": "Увімкнення цієї опції вмикає видимість всіх учнів цієї школи для кожного вчителя.",
"allStudentsVisibilityNiedersachsen" : "Якщо цю опцію не ввімкнено, вчителі бачитимуть лише ті класи та учнів, учасниками яких вони є.",
"authentication": "Аутентифікація",
"changeOfClasses": "Зміна класів / нові класи",
"changeOfUserData": "Зміна даних користувача / нові користувачі",
Expand Down
6 changes: 5 additions & 1 deletion views/administration/school.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@
{{#ifeq @root.theme.name "brb"}}
{{$t "administration.school.label.allStudentsVisibilityBrandenburg" }}
{{else}}
{{$t "administration.school.label.allStudentsVisibility" }}
{{#ifeq @root.theme.name "n21"}}
{{$t "administration.school.label.allStudentsVisibilityNiedersachsen"}}
{{else}}
{{$t "administration.school.label.allStudentsVisibility" }}
{{/ifeq}}
{{/ifeq}}
</p>
</label>
Expand Down

0 comments on commit 3c8d4c9

Please sign in to comment.