1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

Closes #96 -- user re-auth on permissions change

This commit is contained in:
Harvey Kandola 2017-04-27 12:49:10 +01:00
parent be02ad2726
commit 831dfce3cb
2 changed files with 31 additions and 2 deletions

View file

@ -33,5 +33,21 @@ export default AjaxService.extend({
return headers;
}
})
}),
handleResponse(status, headers /*, payload*/) {
try {
let user = this.get('session.session.content.authenticated.user');
let userUpdate = headers['x-documize-status'];
if (is.not.empty(userUpdate)) {
let latest = JSON.parse(userUpdate);
if (!latest.active || user.editor !== latest.editor || user.admin !== latest.admin) {
window.location.href = 'auth/login';
}
}
} catch(e){} // eslint-disable-line no-empty
return this._super(...arguments);
}
});

View file

@ -211,12 +211,25 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
context.Administrator = user.Admin
context.Editor = user.Editor
context.Global = user.Global
var state struct {
Active bool `json:"active"`
Admin bool `json:"admin"`
Editor bool `json:"editor"`
}
state.Active = user.Active
state.Admin = user.Admin
state.Editor = user.Editor
sb, err := json.Marshal(state)
w.Header().Add("X-Documize-Status", string(sb))
}
request.SetContext(r, context)
p = request.GetPersister(r)
// Middleware moves on if we say 'yes' -- autheticated or allow anon access.
// Middleware moves on if we say 'yes' -- authenticated or allow anon access.
authenticated = context.Authenticated || org.AllowAnonymousAccess
}