FIX: only show agreed abd deferred flags on user's profile

This commit is contained in:
Régis Hanol 2014-10-09 16:10:16 +02:00
parent f834a5fe4e
commit 7e8c4b63f4
3 changed files with 51 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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