Revert "FIX: TL0 users' messages to moderators were not being posted when flagging private messages"

This commit is contained in:
Neil Lalonde 2017-10-23 17:19:30 -04:00
parent dfdf12c92f
commit 4452d67a23
4 changed files with 50 additions and 96 deletions

View File

@ -292,10 +292,8 @@ class Guardian
(is_group || is_user) &&
# User is authenticated
authenticated? &&
# Have to be a basic level at least, or are contacting moderators
(@user.has_trust_level?(SiteSetting.min_trust_to_send_messages) ||
(target.is_a?(User) && target.moderator?) ||
(target.name == Group[:moderators].name)) &&
# Have to be a basic level at least
@user.has_trust_level?(SiteSetting.min_trust_to_send_messages) &&
# User disabled private message
(is_staff? || is_group || target.user_option.allow_private_messages) &&
# PMs are enabled

View File

@ -154,24 +154,11 @@ describe Guardian do
expect(Guardian.new(user).can_send_private_message?(user)).to be_truthy
end
context "when user is untrusted " do
before do
it "returns false when you are untrusted" do
user.trust_level = TrustLevel[0]
end
it "returns false to another user" do
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey
end
it "returns true to moderator user" do
expect(Guardian.new(user).can_send_private_message?(moderator)).to be_truthy
end
it "returns true to moderator group" do
expect(Guardian.new(user).can_send_private_message?(Group[:moderators])).to be_truthy
end
end
it "returns true to another user" do
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_truthy
end
@ -193,10 +180,6 @@ describe Guardian do
expect(Guardian.new(moderator).can_send_private_message?(another_user)).to be_truthy
expect(Guardian.new(admin).can_send_private_message?(another_user)).to be_truthy
end
it "returns false even to a moderator" do
expect(Guardian.new(trust_level_4).can_send_private_message?(moderator)).to be_falsey
end
end
context "target user is suspended" do

View File

@ -3,12 +3,11 @@ require 'rails_helper'
describe TopicCreator do
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:user2) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
let(:pm_valid_attrs) { { raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: user2.username } }
let(:pm_valid_attrs) { { raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username } }
let(:pm_to_email_valid_attrs) do
{

View File

@ -42,13 +42,10 @@ describe PostAction do
expect { PostAction.act(admin, post, PostActionType.types[:notify_user], message: "WAT") }.not_to raise_error
end
context "notify moderators integration test" do
let!(:mod) { moderator }
before { Group.refresh_automatic_groups! }
it "flag from TL1 user" do
it "notify moderators integration test" do
post = create_post
mod = moderator
Group.refresh_automatic_groups!
action = PostAction.act(codinghorror, post, PostActionType.types[:notify_moderators], message: "this is my special long message")
@ -103,29 +100,6 @@ describe PostAction do
expect(topic.posts.last.post_type).to eq(Post.types[:moderator_action])
end
it "flag from TL0 user" do
tl0_user = Fabricate(:user, trust_level: 0)
first_post = Fabricate(:post, user: Fabricate(:user, trust_level: 1))
pm_topic = Fabricate(:private_message_topic,
first_post: first_post,
topic_allowed_users: [
Fabricate.build(:topic_allowed_user, user: first_post.user),
Fabricate.build(:topic_allowed_user, user: tl0_user),
]
)
action = PostAction.act(tl0_user, first_post, PostActionType.types[:notify_moderators], message: 'my special message')
expect(action.related_post_id).to be_present
notify_moderators_post = action.related_post
expect(notify_moderators_post.topic&.subtype).to eq(TopicSubtype.notify_moderators)
expect(notify_moderators_post.raw).to include('my special message')
end
end
describe 'notify_moderators' do
before do
PostAction.stubs(:create)