post_disapprovals/index: don't show usernames to other users.

* Don't show who disapproved the post to other users. Only show the
  creator to mods or to the disapprover themselves.
* Let unprivileged users see the /post_disapprovals index.
This commit is contained in:
evazion
2020-02-16 20:25:01 -06:00
parent ff8bfee9eb
commit 9ef80d7344
3 changed files with 16 additions and 9 deletions

View File

@@ -39,12 +39,6 @@ class PostDisapproval < ApplicationRecord
end
end
def create_downvote
if %w(breaks_rules poor_quality).include?(reason)
PostVote.create(:score => -1, :post_id => post_id)
end
end
concerning :SearchMethods do
class_methods do
def search(params)
@@ -71,4 +65,14 @@ class PostDisapproval < ApplicationRecord
def self.available_includes
[:user, :post]
end
def can_view_creator?(user)
user.is_moderator? || user_id == user.id
end
def api_attributes
attributes = super
attributes -= [:creator_id] unless can_view_creator?(CurrentUser.user)
attributes
end
end