From 736c0a66ff107fd05993e0fe45c0121d0e8259de Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 22 Nov 2014 12:56:44 +0100 Subject: [PATCH] Fixed comments disregarding viewUsers privilege --- public_html/index.html | 2 +- ...stPresenter.js => CommentListPresenter.js} | 22 +++++++++++-------- .../Presenters/GlobalCommentListPresenter.js | 2 +- public_html/js/Presenters/PostPresenter.js | 6 ++--- public_html/templates/comment-list-item.tpl | 8 +++---- ...post-comment-list.tpl => comment-list.tpl} | 0 6 files changed, 22 insertions(+), 18 deletions(-) rename public_html/js/Presenters/{PostCommentListPresenter.js => CommentListPresenter.js} (85%) rename public_html/templates/{post-comment-list.tpl => comment-list.tpl} (100%) diff --git a/public_html/index.html b/public_html/index.html index 4104bf5a..23701840 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -138,7 +138,7 @@ - + diff --git a/public_html/js/Presenters/PostCommentListPresenter.js b/public_html/js/Presenters/CommentListPresenter.js similarity index 85% rename from public_html/js/Presenters/PostCommentListPresenter.js rename to public_html/js/Presenters/CommentListPresenter.js index eaeb5da7..82ea5f16 100644 --- a/public_html/js/Presenters/PostCommentListPresenter.js +++ b/public_html/js/Presenters/CommentListPresenter.js @@ -1,7 +1,7 @@ var App = App || {}; App.Presenters = App.Presenters || {}; -App.Presenters.PostCommentListPresenter = function( +App.Presenters.CommentListPresenter = function( _, jQuery, util, @@ -26,14 +26,16 @@ App.Presenters.PostCommentListPresenter = function( privileges = { canListComments: auth.hasPrivilege(auth.privileges.listComments), canAddComments: auth.hasPrivilege(auth.privileges.addComments), - editOwnComments: auth.hasPrivilege(auth.privileges.editOwnComments), - editAllComments: auth.hasPrivilege(auth.privileges.editAllComments), - deleteOwnComments: auth.hasPrivilege(auth.privileges.deleteOwnComments), - deleteAllComments: auth.hasPrivilege(auth.privileges.deleteAllComments), + canEditOwnComments: auth.hasPrivilege(auth.privileges.editOwnComments), + canEditAllComments: auth.hasPrivilege(auth.privileges.editAllComments), + canDeleteOwnComments: auth.hasPrivilege(auth.privileges.deleteOwnComments), + canDeleteAllComments: auth.hasPrivilege(auth.privileges.deleteAllComments), + canViewUsers: auth.hasPrivilege(auth.privileges.viewUsers), + canViewPosts: auth.hasPrivilege(auth.privileges.viewPosts), }; promise.wait( - util.promiseTemplate('post-comment-list'), + util.promiseTemplate('comment-list'), util.promiseTemplate('comment-list-item'), util.promiseTemplate('comment-form')) .then(function( @@ -103,8 +105,10 @@ App.Presenters.PostCommentListPresenter = function( formatRelativeTime: util.formatRelativeTime, formatMarkdown: util.formatMarkdown, canVote: auth.isLoggedIn(), - canEditComment: auth.isLoggedIn(comment.user.name) ? privileges.editOwnComments : privileges.editAllComments, - canDeleteComment: auth.isLoggedIn(comment.user.name) ? privileges.deleteOwnComments : privileges.deleteAllComments, + canEditComment: auth.isLoggedIn(comment.user.name) ? privileges.canEditOwnComments : privileges.canEditAllComments, + canDeleteComment: auth.isLoggedIn(comment.user.name) ? privileges.canDeleteOwnComments : privileges.canDeleteAllComments, + canViewUsers: privileges.canViewUsers, + canViewPosts: privileges.canViewPosts, }) + ''); util.loadImagesNicely($item.find('img')); $targetList.append($item); @@ -227,4 +231,4 @@ App.Presenters.PostCommentListPresenter = function( }; -App.DI.register('postCommentListPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostCommentListPresenter); +App.DI.register('commentListPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.CommentListPresenter); diff --git a/public_html/js/Presenters/GlobalCommentListPresenter.js b/public_html/js/Presenters/GlobalCommentListPresenter.js index 40da71c2..73d79874 100644 --- a/public_html/js/Presenters/GlobalCommentListPresenter.js +++ b/public_html/js/Presenters/GlobalCommentListPresenter.js @@ -72,7 +72,7 @@ App.Presenters.GlobalCommentListPresenter = function( }) + ''); util.loadImagesNicely($post.find('img')); - var presenter = App.DI.get('postCommentListPresenter'); + var presenter = App.DI.get('commentListPresenter'); presenter.init({ post: post, diff --git a/public_html/js/Presenters/PostPresenter.js b/public_html/js/Presenters/PostPresenter.js index 0cc95758..98c5095b 100644 --- a/public_html/js/Presenters/PostPresenter.js +++ b/public_html/js/Presenters/PostPresenter.js @@ -14,7 +14,7 @@ App.Presenters.PostPresenter = function( postsAroundCalculator, postEditPresenter, postContentPresenter, - postCommentListPresenter, + commentListPresenter, topNavigationPresenter, messagePresenter) { @@ -70,7 +70,7 @@ App.Presenters.PostPresenter = function( presenterManager.initPresenters([ [postContentPresenter, {post: post, $target: $el.find('#post-content-target')}], [postEditPresenter, {post: post, $target: $el.find('#post-edit-target'), updateCallback: postEdited}], - [postCommentListPresenter, {post: post, $target: $el.find('#post-comments-target')}]], + [commentListPresenter, {post: post, $target: $el.find('#post-comments-target')}]], function() { }); }).fail(function() { @@ -333,7 +333,7 @@ App.DI.register('postPresenter', [ 'postsAroundCalculator', 'postEditPresenter', 'postContentPresenter', - 'postCommentListPresenter', + 'commentListPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostPresenter); diff --git a/public_html/templates/comment-list-item.tpl b/public_html/templates/comment-list-item.tpl index f1fa6753..80102058 100644 --- a/public_html/templates/comment-list-item.tpl +++ b/public_html/templates/comment-list-item.tpl @@ -1,6 +1,6 @@
@@ -16,13 +16,13 @@
- <% if (comment.user.name) { %> + <% if (comment.user.name && canViewUsers) { %> <% } %> <%= comment.user.name || 'Anonymous user' %> - <% if (comment.user.name) { %> + <% if (comment.user.name && canViewUsers) { %> <% } %> diff --git a/public_html/templates/post-comment-list.tpl b/public_html/templates/comment-list.tpl similarity index 100% rename from public_html/templates/post-comment-list.tpl rename to public_html/templates/comment-list.tpl