Skip to content

Commit

Permalink
Merge pull request #90 from UKHomeOffice/refactor/user-permissions
Browse files Browse the repository at this point in the history
WIP: Load establishment from user profile
  • Loading branch information
joefitter committed Aug 1, 2018
2 parents f5311bd + 81fd204 commit d2ecc5d
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 109 deletions.
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
realm: process.env.KEYCLOAK_REALM,
url: process.env.KEYCLOAK_URL,
client: process.env.KEYCLOAK_CLIENT,
secret: process.env.KEYCLOAK_SECRET
secret: process.env.KEYCLOAK_SECRET,
profile: process.env.API_URL
}
};
14 changes: 9 additions & 5 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ module.exports = settings => {
next();
});

app.use(urls.establishment.dashboard, (req, res, next) => {
const establishment = req.user.get('establishment');
if (establishment) {
req.establishment = establishment;
return next();
app.use('/', (req, res, next) => {
if (req.user.profile) {
const establishments = req.user.profile.establishments || [];
const establishment = establishments.find(e => e.id === req.query.establishment) || establishments.find(e => e.id === req.session.establishment) || establishments[0];
if (establishment) {
req.establishment = establishment.id;
req.session.establishment = req.establishment;
return next();
}
}
const err = new Error('Not found');
err.status = 404;
Expand Down

0 comments on commit d2ecc5d

Please sign in to comment.