diff --git a/client/js/controllers/comments_controller.js b/client/js/controllers/comments_controller.js index e6c3ccb..1758393 100644 --- a/client/js/controllers/comments_controller.js +++ b/client/js/controllers/comments_controller.js @@ -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'); diff --git a/client/js/controllers/post_controller.js b/client/js/controllers/post_controller.js index e11027e..ac569eb 100644 --- a/client/js/controllers/post_controller.js +++ b/client/js/controllers/post_controller.js @@ -13,6 +13,12 @@ const EmptyView = require('../views/empty_view.js'); class PostController { constructor(id, editMode, ctx) { + if (!api.hasPrivilege('posts:view')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view posts.'); + return; + } + topNavigation.activate('posts'); topNavigation.setTitle('Post #' + id.toString()); diff --git a/client/js/controllers/post_list_controller.js b/client/js/controllers/post_list_controller.js index cbe014f..d76e3f4 100644 --- a/client/js/controllers/post_list_controller.js +++ b/client/js/controllers/post_list_controller.js @@ -8,6 +8,7 @@ const topNavigation = require('../models/top_navigation.js'); const PageController = require('../controllers/page_controller.js'); const PostsHeaderView = require('../views/posts_header_view.js'); const PostsPageView = require('../views/posts_page_view.js'); +const EmptyView = require('../views/empty_view.js'); const fields = [ 'id', 'thumbnailUrl', 'type', @@ -15,6 +16,12 @@ const fields = [ class PostListController { constructor(ctx) { + if (!api.hasPrivilege('posts:list')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view posts.'); + return; + } + topNavigation.activate('posts'); topNavigation.setTitle('Listing posts'); diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index aec34d5..ae4f497 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -1,13 +1,21 @@ 'use strict'; +const api = require('../api.js'); const router = require('../router.js'); const misc = require('../util/misc.js'); const topNavigation = require('../models/top_navigation.js'); const Post = require('../models/post.js'); const PostUploadView = require('../views/post_upload_view.js'); +const EmptyView = require('../views/empty_view.js'); class PostUploadController { constructor() { + if (!api.hasPrivilege('posts:create')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to upload posts.'); + return; + } + topNavigation.activate('upload'); topNavigation.setTitle('Upload'); this._view = new PostUploadView(); diff --git a/client/js/controllers/snapshots_controller.js b/client/js/controllers/snapshots_controller.js index e1f67bd..1cc853d 100644 --- a/client/js/controllers/snapshots_controller.js +++ b/client/js/controllers/snapshots_controller.js @@ -6,9 +6,16 @@ const SnapshotList = require('../models/snapshot_list.js'); const PageController = require('../controllers/page_controller.js'); const topNavigation = require('../models/top_navigation.js'); const SnapshotsPageView = require('../views/snapshots_page_view.js'); +const EmptyView = require('../views/empty_view.js'); class SnapshotsController { constructor(ctx) { + if (!api.hasPrivilege('snapshots:list')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view history.'); + return; + } + topNavigation.activate(''); topNavigation.setTitle('History'); diff --git a/client/js/controllers/tag_categories_controller.js b/client/js/controllers/tag_categories_controller.js index f7b8655..e13c79e 100644 --- a/client/js/controllers/tag_categories_controller.js +++ b/client/js/controllers/tag_categories_controller.js @@ -9,6 +9,13 @@ const EmptyView = require('../views/empty_view.js'); class TagCategoriesController { constructor() { + if (!api.hasPrivilege('tagCategories:list')) { + this._view = new EmptyView(); + this._view.showError( + 'You don\'t have privileges to view tag categories.'); + return; + } + topNavigation.activate('tags'); topNavigation.setTitle('Listing tags'); TagCategoryList.get().then(response => { diff --git a/client/js/controllers/tag_controller.js b/client/js/controllers/tag_controller.js index 9071593..e0e8feb 100644 --- a/client/js/controllers/tag_controller.js +++ b/client/js/controllers/tag_controller.js @@ -11,6 +11,12 @@ const EmptyView = require('../views/empty_view.js'); class TagController { constructor(ctx, section) { + if (!api.hasPrivilege('tags:view')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view tags.'); + return; + } + Tag.get(ctx.parameters.name).then(tag => { topNavigation.activate('tags'); topNavigation.setTitle('Tag #' + tag.names[0]); diff --git a/client/js/controllers/tag_list_controller.js b/client/js/controllers/tag_list_controller.js index 823469f..6c03220 100644 --- a/client/js/controllers/tag_list_controller.js +++ b/client/js/controllers/tag_list_controller.js @@ -7,12 +7,19 @@ const topNavigation = require('../models/top_navigation.js'); const PageController = require('../controllers/page_controller.js'); const TagsHeaderView = require('../views/tags_header_view.js'); const TagsPageView = require('../views/tags_page_view.js'); +const EmptyView = require('../views/empty_view.js'); const fields = [ 'names', 'suggestions', 'implications', 'lastEditTime', 'usages']; class TagListController { constructor(ctx) { + if (!api.hasPrivilege('tags:list')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view tags.'); + return; + } + topNavigation.activate('tags'); topNavigation.setTitle('Listing tags'); diff --git a/client/js/controllers/user_controller.js b/client/js/controllers/user_controller.js index 7c34eb8..0e2b961 100644 --- a/client/js/controllers/user_controller.js +++ b/client/js/controllers/user_controller.js @@ -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 ? diff --git a/client/js/controllers/user_list_controller.js b/client/js/controllers/user_list_controller.js index 0df1eae..9cdd0a1 100644 --- a/client/js/controllers/user_list_controller.js +++ b/client/js/controllers/user_list_controller.js @@ -7,9 +7,16 @@ const topNavigation = require('../models/top_navigation.js'); const PageController = require('../controllers/page_controller.js'); const UsersHeaderView = require('../views/users_header_view.js'); const UsersPageView = require('../views/users_page_view.js'); +const EmptyView = require('../views/empty_view.js'); class UserListController { constructor(ctx) { + if (!api.hasPrivilege('users:list')) { + this._view = new EmptyView(); + this._view.showError('You don\'t have privileges to view users.'); + return; + } + topNavigation.activate('users'); topNavigation.setTitle('Listing users'); diff --git a/client/js/controllers/user_registration_controller.js b/client/js/controllers/user_registration_controller.js index a456bb7..2a64def 100644 --- a/client/js/controllers/user_registration_controller.js +++ b/client/js/controllers/user_registration_controller.js @@ -5,9 +5,16 @@ const api = require('../api.js'); const User = require('../models/user.js'); const topNavigation = require('../models/top_navigation.js'); const RegistrationView = require('../views/registration_view.js'); +const EmptyView = require('../views/empty_view.js'); class UserRegistrationController { constructor() { + if (!api.hasPrivilege('users:create')) { + this._view = new EmptyView(); + this._view.showError('Registration is closed.'); + return; + } + topNavigation.activate('register'); topNavigation.setTitle('Registration'); this._view = new RegistrationView();