From 7e8c4b63f43037abf5454627346aa2cab849a36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 9 Oct 2014 16:10:16 +0200 Subject: [PATCH] FIX: only show agreed abd deferred flags on user's profile --- app/controllers/posts_controller.rb | 5 +-- app/serializers/user_serializer.rb | 8 ++--- spec/controllers/posts_controller_spec.rb | 44 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1812d5978..a64ec3e4b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -280,8 +280,8 @@ class PostsController < ApplicationController limit = [(params[:limit] || 60).to_i, 100].min posts = user_posts(user.id, offset, limit) - .where(id: PostAction.with_deleted - .where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(disagreed_at: nil) .select(:post_id)) render_serialized(posts, AdminPostSerializer) @@ -298,6 +298,7 @@ class PostsController < ApplicationController posts = user_posts(user.id, offset, limit) .where(user_deleted: false) .where.not(deleted_by_id: user.id) + .where.not(deleted_at: nil) render_serialized(posts, AdminPostSerializer) end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 38ae31e6b..96f43569a 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -179,21 +179,21 @@ class UserSerializer < BasicUserSerializer .where(user_id: object.id) .where(user_deleted: false) .where.not(deleted_by_id: object.id) + .where.not(deleted_at: nil) .count end def number_of_flagged_posts Post.with_deleted .where(user_id: object.id) - .where(id: PostAction.with_deleted - .where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(disagreed_at: nil) .select(:post_id)) .count end def number_of_flags_given - PostAction.with_deleted - .where(user_id: object.id) + PostAction.where(user_id: object.id) .where(post_action_type_id: PostActionType.notify_flag_type_ids) .count end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 4c3faf7ee..04690e023 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -697,6 +697,29 @@ describe PostsController do response.should be_success end + it "only shows agreed and deferred flags" do + user = Fabricate(:user) + post_agreed = create_post(user: user) + post_deferred = create_post(user: user) + post_disagreed = create_post(user: user) + + moderator = Fabricate(:moderator) + PostAction.act(moderator, post_agreed, PostActionType.types[:spam]) + PostAction.act(moderator, post_deferred, PostActionType.types[:off_topic]) + PostAction.act(moderator, post_disagreed, PostActionType.types[:inappropriate]) + + admin = Fabricate(:admin) + PostAction.agree_flags!(post_agreed, admin) + PostAction.defer_flags!(post_deferred, admin) + PostAction.clear_flags!(post_disagreed, admin) + + Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true) + xhr :get, :flagged_posts, username: user.username + response.should be_success + + JSON.parse(response.body).length.should == 2 + end + end end @@ -720,6 +743,27 @@ describe PostsController do response.should be_success end + it "only shows posts deleted by other users" do + user = Fabricate(:user) + admin = Fabricate(:admin) + + post_not_deleted = create_post(user: user) + post_deleted_by_user = create_post(user: user) + post_deleted_by_admin = create_post(user: user) + + PostDestroyer.new(user, post_deleted_by_user).destroy + PostDestroyer.new(admin, post_deleted_by_admin).destroy + + Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true) + xhr :get, :deleted_posts, username: user.username + response.should be_success + + data = JSON.parse(response.body) + data.length.should == 1 + data[0]["id"].should == post_deleted_by_admin.id + data[0]["deleted_by"]["id"].should == admin.id + end + end end