mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Don't display option for users to flag and notify a bot.
This commit is contained in:
@@ -251,7 +251,12 @@ class PostSerializer < BasicPostSerializer
|
|||||||
summary[:can_act] = true
|
summary[:can_act] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if sym == :notify_user && scope.current_user.present? && scope.current_user == object.user
|
if sym == :notify_user &&
|
||||||
|
(
|
||||||
|
(scope.current_user.present? && scope.current_user == object.user) ||
|
||||||
|
(object.user && object.user.bot?)
|
||||||
|
)
|
||||||
|
|
||||||
summary.delete(:can_act)
|
summary.delete(:can_act)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -4,9 +4,9 @@ require 'rails_helper'
|
|||||||
require_dependency 'post_action'
|
require_dependency 'post_action'
|
||||||
|
|
||||||
describe PostSerializer do
|
describe PostSerializer do
|
||||||
|
fab!(:post) { Fabricate(:post) }
|
||||||
|
|
||||||
context "a post with lots of actions" do
|
context "a post with lots of actions" do
|
||||||
fab!(:post) { Fabricate(:post) }
|
|
||||||
fab!(:actor) { Fabricate(:user) }
|
fab!(:actor) { Fabricate(:user) }
|
||||||
fab!(:admin) { Fabricate(:admin) }
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
let(:acted_ids) {
|
let(:acted_ids) {
|
||||||
@@ -42,10 +42,24 @@ describe PostSerializer do
|
|||||||
notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
||||||
expect(notify_user_action).to be_blank
|
expect(notify_user_action).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not allow user to flag post and notify non human user" do
|
||||||
|
post.update!(user: Discourse.system_user)
|
||||||
|
|
||||||
|
serializer = PostSerializer.new(post,
|
||||||
|
scope: Guardian.new(actor),
|
||||||
|
root: false
|
||||||
|
)
|
||||||
|
|
||||||
|
notify_user_action = serializer.actions_summary.find do |a|
|
||||||
|
a[:id] == PostActionType.types[:notify_user]
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(notify_user_action).to eq(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "a post with reviewable content" do
|
context "a post with reviewable content" do
|
||||||
let!(:post) { Fabricate(:post, user: Fabricate(:user)) }
|
|
||||||
let!(:reviewable) { PostActionCreator.spam(Fabricate(:user), post).reviewable }
|
let!(:reviewable) { PostActionCreator.spam(Fabricate(:user), post).reviewable }
|
||||||
|
|
||||||
it "includes the reviewable data" do
|
it "includes the reviewable data" do
|
||||||
@@ -57,11 +71,11 @@ describe PostSerializer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "a post by a nuked user" do
|
context "a post by a nuked user" do
|
||||||
let!(:post) { Fabricate(:post, user: Fabricate(:user), deleted_at: Time.zone.now) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
post.user_id = nil
|
post.update!(
|
||||||
post.save!
|
user_id: nil,
|
||||||
|
deleted_at: Time.zone.now
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { PostSerializer.new(post, scope: Guardian.new(Fabricate(:admin)), root: false).as_json }
|
subject { PostSerializer.new(post, scope: Guardian.new(Fabricate(:admin)), root: false).as_json }
|
||||||
@@ -77,8 +91,7 @@ describe PostSerializer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "display_username" do
|
context "display_username" do
|
||||||
let(:user) { Fabricate.build(:user) }
|
let(:user) { post.user }
|
||||||
let(:post) { Fabricate.build(:post, user: user) }
|
|
||||||
let(:serializer) { PostSerializer.new(post, scope: Guardian.new, root: false) }
|
let(:serializer) { PostSerializer.new(post, scope: Guardian.new, root: false) }
|
||||||
let(:json) { serializer.as_json }
|
let(:json) { serializer.as_json }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user