diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index 7ddadfb2c..921341cf4 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -158,6 +158,10 @@ class PostSerializer < BasicPostSerializer hidden: (sym == :vote), 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 if action_summary[:can_act] && scope.current_user.present? action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id) diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index ad955de03..e37a8fccc 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -36,6 +36,11 @@ describe PostSerializer do visible_actions_for(admin).sort.should == [:like,:notify_user,:spam,:vote] 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 context "a post by a nuked user" do