client/auth: show errors early in controllers

In other words, verify the privileges client-side before issuing an
request to the server. This commit focuses on routing (e.g. clicking a
link while not logged in), rather than DOM element visibility that
should be already taken care of.
This commit is contained in:
rr-
2016-08-23 21:18:03 +02:00
parent 803a1350fa
commit 08c6c2c145
11 changed files with 81 additions and 3 deletions

View File

@ -12,12 +12,20 @@ const EmptyView = require('../views/empty_view.js');
class UserController {
constructor(ctx, section) {
topNavigation.setTitle('User ' + ctx.parameters.name);
User.get(ctx.parameters.name).then(user => {
const userName = ctx.parameters.name;
if (!api.hasPrivilege('users:view') &&
!api.isLoggedIn({name: userName})) {
this._view = new EmptyView();
this._view.showError('You don\'t have privileges to view users.');
return;
}
topNavigation.setTitle('User ' + userName);
User.get(userName).then(user => {
const isLoggedIn = api.isLoggedIn(user);
const infix = isLoggedIn ? 'self' : 'any';
this._name = ctx.parameters.name;
this._name = userName;
user.addEventListener('change', e => this._evtSaved(e));
const myRankIndex = api.user ?