Skip to content

Commit

Permalink
N21-2136 show buttons only to moin.schule users
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Nov 3, 2024
1 parent ffc9338 commit 6195d8d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
17 changes: 16 additions & 1 deletion helpers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const clearCookie = async (req, res, options = { destroySession: false }) => {
});
});
}

res.clearCookie('jwt');
// this is deprecated and only used for cookie removal from now on,
// and can be removed after one month (max cookie lifetime from life systems)
Expand Down Expand Up @@ -101,12 +101,27 @@ const isAuthenticated = (req) => {
};

const populateCurrentUser = async (req, res) => {
async function setExternalSystemFromJwt(decodedJwt) {
if (!("systemId" in decodedJwt) && !decodedJwt.systemId) {
return;
}

try {
const response = await api(req, { version: 'v3' }).get(`/systems/public/${decodedJwt.systemId}`);
res.locals.externalSystem = response.alias;
} catch (err) {
const metadata = { error: err.toString() };
logger.error('Unable to find out the external login system used by user', metadata);
}
}

let payload = {};
if (isJWT(req)) {
try {
// eslint-disable-next-line prefer-destructuring
payload = (jwt.decode(req.cookies.jwt, { complete: true }) || {}).payload;
res.locals.currentPayload = payload;
await setExternalSystemFromJwt(payload);
} catch (err) {
logger.error('Broken JWT / JWT decoding failed', formatError(err));
return clearCookie(req, res, { destroySession: true })
Expand Down
4 changes: 2 additions & 2 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2440,9 +2440,9 @@
"tab_label": {
"settings": "Einstellungen",
"signOut": "Logout",
"n21": {
"sanis": {
"signOut": "Logout Bildungscloud",
"signOutWithMoinSchule": "Logout Bildungscloud & moin.schule"
"externalSignOut": "Logout Bildungscloud & moin.schule"
}
},
"text": {
Expand Down
4 changes: 2 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2440,9 +2440,9 @@
"tab_label": {
"settings": "Settings",
"signOut": "Sign out",
"n21": {
"sanis": {
"signOut": "Logout Bildungscloud",
"signOutWithMoinSchule": "Logout Bildungscloud & moin.schule"
"externalSignOut": "Logout Bildungscloud & moin.schule"
}
},
"text": {
Expand Down
4 changes: 2 additions & 2 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2440,9 +2440,9 @@
"tab_label": {
"settings": "Configuración",
"signOut": "Cerrar sesión",
"n21": {
"sanis": {
"signOut": "Cerrar sesión Bildungscloud",
"signOutWithMoinSchule": "Cerrar sesión Bildungscloud & moin.schule"
"externalSignOut": "Cerrar sesión Bildungscloud & moin.schule"
}
},
"text": {
Expand Down
4 changes: 2 additions & 2 deletions locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -2608,9 +2608,9 @@
"tab_label": {
"settings": "Налаштування",
"signOut": "Вийти з системи",
"n21": {
"sanis": {
"signOut": "Вийти з системи Bildungscloud",
"signOutWithMoinSchule": "Вийти з системи Bildungscloud & moin.schule"
"externalSignOut": "Вийти з системи Bildungscloud & moin.schule"
}
},
"text": {
Expand Down
15 changes: 8 additions & 7 deletions views/lib/topbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@
<hr>
{{> "user/forms/language" language=@root.userLanguage }}
<li><a class="dropdown-item" data-testid="settings" href="/account/" role="menuitem" aria-label="{{$t 'lib.loggedin.tab_label.settings' }}">{{$t "lib.loggedin.tab_label.settings" }}</a></li>
{{#ifeq @root.theme.name "n21"}}
<li><a class="dropdown-item localstorageclear" data-testid="logout-external" href="/logout/external/" role="menuitem" aria-label="{{$t 'lib.loggedin.tab_label.n21.signOutWithMoinSchule'}}">{{$t "lib.loggedin.tab_label.n21.signOutWithMoinSchule"}}</a></li>
{{/ifeq}}
<li><a class="dropdown-item localstorageclear"
{{#ifeq externalSystem "SANIS"}}
<li><a class="dropdown-item localstorageclear" data-testid="logout-external" href="/logout/external/" role="menuitem" aria-label="{{$t 'lib.loggedin.tab_label.sanis.signOut'}}">{{$t "lib.loggedin.tab_label.sanis.externalSignOut"}}</a></li>
<li><a class="dropdown-item localstorageclear" data-testid="logout" href= {{#hasConfig "OAUTH2_LOGOUT_URI"}} {{getConfig "OAUTH2_LOGOUT_URI"}} {{else}} "/logout/" {{/hasConfig}} role="menuitem" aria-label="{{$t 'lib.loggedin.tab_label.sanis.signOut'}}">{{$t 'lib.loggedin.tab_label.sanis.signOut'}}</a></li>
{{else}}
<li><a class="dropdown-item localstorageclear"
data-testid="logout"
href= {{#hasConfig "OAUTH2_LOGOUT_URI"}} {{getConfig "OAUTH2_LOGOUT_URI"}} {{else}} "/logout/" {{/hasConfig}} role="menuitem"
aria-label="{{#ifeq @root.theme.name "n21"}} {{$t 'lib.loggedin.tab_label.n21.signOut'}} {{else}} {{$t 'lib.loggedin.tab_label.signOut'}} {{/ifeq}}">
{{#ifeq @root.theme.name "n21"}} {{$t 'lib.loggedin.tab_label.n21.signOut'}} {{else}} {{$t 'lib.loggedin.tab_label.signOut'}} {{/ifeq}}
</a></li>
aria-label="{{$t 'lib.loggedin.tab_label.signOut'}}">
{{$t 'lib.loggedin.tab_label.signOut'}}</a></li>
{{/ifeq}}
</ul>
</div>
</li>
Expand Down

0 comments on commit 6195d8d

Please sign in to comment.