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

@ -6,11 +6,19 @@ const PostList = require('../models/post_list.js');
const topNavigation = require('../models/top_navigation.js');
const PageController = require('../controllers/page_controller.js');
const CommentsPageView = require('../views/comments_page_view.js');
const EmptyView = require('../views/empty_view.js');
const fields = ['id', 'comments', 'commentCount', 'thumbnailUrl'];
class CommentsController {
constructor(ctx) {
if (!api.hasPrivilege('comments:list')) {
this._view = new EmptyView();
this._view.showError(
'You don\'t have privileges to view comments.');
return;
}
topNavigation.activate('comments');
topNavigation.setTitle('Listing comments');