FIX: don't show the option to notify yourself in the flag dialog

This commit is contained in:
Neil Lalonde 2014-07-25 16:36:57 -04:00
parent 6ba5f715f3
commit fcaeb885e5
2 changed files with 9 additions and 0 deletions

View file

@ -158,6 +158,10 @@ class PostSerializer < BasicPostSerializer
hidden: (sym == :vote), hidden: (sym == :vote),
can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)} can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}
if sym == :notify_user && scope.current_user.present? && scope.current_user == object.user
action_summary[:can_act] = false # Don't send a pm to yourself about your own post, silly
end
# The following only applies if you're logged in # The following only applies if you're logged in
if action_summary[:can_act] && scope.current_user.present? if action_summary[:can_act] && scope.current_user.present?
action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id) action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id)

View file

@ -36,6 +36,11 @@ describe PostSerializer do
visible_actions_for(admin).sort.should == [:like,:notify_user,:spam,:vote] visible_actions_for(admin).sort.should == [:like,:notify_user,:spam,:vote]
end end
it "can't flag your own post to notify yourself" do
serializer = PostSerializer.new(post, scope: Guardian.new(post.user), root: false)
notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
notify_user_action[:can_act].should == false
end
end end
context "a post by a nuked user" do context "a post by a nuked user" do