DEV: Remove usages of enable_personal_messages (#18437)
cf. e62e93f83a
This PR also makes it so `bot` (negative ID) and `system` users are always allowed
to send PMs, since the old conditional was just based on `enable_personal_messages`
This commit is contained in:
parent
2d391565e4
commit
f5194aadd3
|
@ -50,6 +50,9 @@ class Guardian
|
|||
def is_system_user?
|
||||
false
|
||||
end
|
||||
def bot?
|
||||
false
|
||||
end
|
||||
def secure_category_ids
|
||||
[]
|
||||
end
|
||||
|
@ -402,9 +405,7 @@ class Guardian
|
|||
if object.private_message?
|
||||
return true if is_admin?
|
||||
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
if !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) ||
|
||||
!SiteSetting.enable_personal_messages
|
||||
if !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
return false
|
||||
end
|
||||
return false if object.reached_recipients_limit? && !is_staff?
|
||||
|
@ -451,6 +452,7 @@ class Guardian
|
|||
is_user = target.is_a?(User)
|
||||
is_group = target.is_a?(Group)
|
||||
from_system = @user.is_system_user?
|
||||
from_bot = @user.bot?
|
||||
|
||||
(is_group || is_user) &&
|
||||
# User is authenticated
|
||||
|
@ -458,8 +460,7 @@ class Guardian
|
|||
# User disabled private message
|
||||
(is_staff? || is_group || target.user_option.allow_private_messages) &&
|
||||
# User can send PMs, this can be covered by trust levels as well via AUTO_GROUPS
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
(is_staff? || (@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) || SiteSetting.enable_personal_messages) || notify_moderators) &&
|
||||
(is_staff? || from_bot || from_system || (@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)) || notify_moderators) &&
|
||||
# Can't send PMs to suspended users
|
||||
(is_staff? || is_group || !target.suspended?) &&
|
||||
# Check group messageable level
|
||||
|
@ -474,8 +475,7 @@ class Guardian
|
|||
# User is authenticated
|
||||
return false if !authenticated?
|
||||
# User is trusted enough
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
(@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) || SiteSetting.enable_personal_messages) &&
|
||||
@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) &&
|
||||
@user.has_trust_level_or_staff?(SiteSetting.min_trust_to_send_email_messages)
|
||||
end
|
||||
|
||||
|
|
|
@ -35,9 +35,7 @@ module GroupGuardian
|
|||
return true if is_moderator? && group.id == Group::AUTO_GROUPS[:moderators]
|
||||
return false if user.blank?
|
||||
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
(SiteSetting.enable_personal_messages ||
|
||||
user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)) &&
|
||||
user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) &&
|
||||
group.users.include?(user)
|
||||
end
|
||||
|
||||
|
|
|
@ -50,10 +50,7 @@ module PostGuardian
|
|||
(!SiteSetting.allow_flagging_staff?) &&
|
||||
post&.user&.staff?
|
||||
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
if action_key == :notify_user &&
|
||||
(!@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) ||
|
||||
!SiteSetting.enable_personal_messages)
|
||||
if action_key == :notify_user && !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
@ -183,8 +183,7 @@ module TopicGuardian
|
|||
end
|
||||
|
||||
def can_convert_topic?(topic)
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
return false unless SiteSetting.enable_personal_messages? || @user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
return false unless @user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
return false if topic.blank?
|
||||
return false if topic.trashed?
|
||||
return false if topic.is_category_topic?
|
||||
|
|
|
@ -173,8 +173,7 @@ class TopicQuery
|
|||
return if !topic.private_message?
|
||||
return if @user.blank?
|
||||
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
if !SiteSetting.enable_personal_messages || !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
if !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -201,13 +200,10 @@ class TopicQuery
|
|||
# Return a list of suggested topics for a topic
|
||||
def list_suggested_for(topic, pm_params: nil)
|
||||
|
||||
# TODO (martin) Remove enable_personal_messages here once plugins have been changed.
|
||||
# Don't suggest messages unless we have a user, and private messages are
|
||||
# enabled.
|
||||
if topic.private_message? && (
|
||||
@user.blank? ||
|
||||
!@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) ||
|
||||
!SiteSetting.enable_personal_messages
|
||||
@user.blank? || !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
|
@ -117,6 +117,7 @@ RSpec.describe WatchedWord do
|
|||
end
|
||||
|
||||
it "doesn't need approval in a private message" do
|
||||
Group.refresh_automatic_groups!
|
||||
manager = NewPostManager.new(
|
||||
tl2_user,
|
||||
raw: "Want some #{require_approval_word.word} for cheap?",
|
||||
|
|
|
@ -179,7 +179,6 @@ RSpec.describe Guardian do
|
|||
|
||||
it "returns false for notify_user if user is not in any group that can send personal messages" do
|
||||
user = Fabricate(:user)
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
||||
user.change_trust_level!(1)
|
||||
expect(Guardian.new(user).post_can_act?(post, :notify_user)).to be_falsey
|
||||
|
@ -267,7 +266,6 @@ RSpec.describe Guardian do
|
|||
end
|
||||
|
||||
it "returns false when you are untrusted" do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_2]
|
||||
user.update!(trust_level: TrustLevel[0])
|
||||
Group.user_trust_level_change!(user.id, TrustLevel[0])
|
||||
|
@ -279,7 +277,6 @@ RSpec.describe Guardian do
|
|||
end
|
||||
|
||||
it "disallows pms to other users if trust level is not met" do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_2]
|
||||
user.update!(trust_level: TrustLevel[1])
|
||||
Group.user_trust_level_change!(user.id, TrustLevel[1])
|
||||
|
@ -290,7 +287,6 @@ RSpec.describe Guardian do
|
|||
let(:group) { Fabricate(:group) }
|
||||
before do
|
||||
SiteSetting.personal_message_enabled_groups = group.id
|
||||
SiteSetting.enable_personal_messages = false
|
||||
end
|
||||
|
||||
it "returns false if user is not staff member" do
|
||||
|
@ -304,6 +300,14 @@ RSpec.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 true for bot user" do
|
||||
expect(Guardian.new(Fabricate(:user, id: -19876)).can_send_private_message?(another_user)).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true for system user" do
|
||||
expect(Guardian.new(Discourse.system_user).can_send_private_message?(another_user)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context "when target user is suspended" do
|
||||
|
@ -356,7 +360,6 @@ RSpec.describe Guardian do
|
|||
|
||||
it "allows TL0 to message group with messageable_level = everyone" do
|
||||
group.update!(messageable_level: Group::ALIAS_LEVELS[:everyone])
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_0]
|
||||
expect(Guardian.new(trust_level_0).can_send_private_message?(group)).to eq(true)
|
||||
expect(Guardian.new(user).can_send_private_message?(group)).to eq(true)
|
||||
|
@ -369,11 +372,11 @@ RSpec.describe Guardian do
|
|||
group.add(user)
|
||||
expect(Guardian.new(user).can_send_private_message?(group)).to eq(true)
|
||||
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_0]
|
||||
expect(Guardian.new(trust_level_0).can_send_private_message?(group)).to eq(false)
|
||||
|
||||
# group membership trumps min_trust_to_send_messages setting
|
||||
# user must have both a group from personal_message_enabled_groups to send messages in general,
|
||||
# and be a member of this group to send the message to this group for this messageable_level
|
||||
group.add(trust_level_0)
|
||||
expect(Guardian.new(trust_level_0).can_send_private_message?(group)).to eq(true)
|
||||
end
|
||||
|
@ -644,7 +647,6 @@ RSpec.describe Guardian do
|
|||
|
||||
context "when user does not belong to personal_message_enabled_groups" do
|
||||
before do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
||||
end
|
||||
|
||||
|
@ -1323,7 +1325,6 @@ RSpec.describe Guardian do
|
|||
end
|
||||
|
||||
it 'returns false when user is not in personal_message_enabled_groups' do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]
|
||||
expect(Guardian.new(user).can_convert_topic?(topic)).to be_falsey
|
||||
end
|
||||
|
|
|
@ -22,6 +22,7 @@ RSpec.describe NewPostManager do
|
|||
fab!(:other_user) { Fabricate(:user) }
|
||||
|
||||
it "doesn't enqueue private messages" do
|
||||
Group.refresh_automatic_groups!
|
||||
SiteSetting.approve_unless_trust_level = 4
|
||||
|
||||
manager = NewPostManager.new(user,
|
||||
|
|
|
@ -965,6 +965,7 @@ RSpec.describe PostCreator do
|
|||
fab!(:target_user2) { Fabricate(:moderator) }
|
||||
fab!(:unrelated_user) { Fabricate(:user) }
|
||||
let(:post) do
|
||||
Group.refresh_automatic_groups!
|
||||
PostCreator.create!(user,
|
||||
title: 'hi there welcome to my topic',
|
||||
raw: "this is my awesome message @#{unrelated_user.username_lower}",
|
||||
|
@ -1063,6 +1064,7 @@ RSpec.describe PostCreator do
|
|||
|
||||
1.upto(3) do |i|
|
||||
user = Fabricate(:user)
|
||||
Group.refresh_automatic_groups!
|
||||
topic.invite(topic.user, user.username)
|
||||
topic.reload
|
||||
expect(topic.posts_count).to eq(1)
|
||||
|
@ -1091,6 +1093,7 @@ RSpec.describe PostCreator do
|
|||
end
|
||||
|
||||
it "works as expected" do
|
||||
Group.refresh_automatic_groups!
|
||||
# Invalid archetype
|
||||
creator = PostCreator.new(user, base_args)
|
||||
creator.create
|
||||
|
@ -1159,9 +1162,9 @@ RSpec.describe PostCreator do
|
|||
end
|
||||
|
||||
describe 'private message to group' do
|
||||
let(:target_user1) { coding_horror }
|
||||
fab!(:target_user1) { coding_horror }
|
||||
fab!(:target_user2) { Fabricate(:moderator) }
|
||||
let(:group) do
|
||||
let!(:group) do
|
||||
g = Fabricate.build(:group, messageable_level: Group::ALIAS_LEVELS[:everyone])
|
||||
g.add(target_user1)
|
||||
g.add(target_user2)
|
||||
|
@ -1170,6 +1173,7 @@ RSpec.describe PostCreator do
|
|||
end
|
||||
fab!(:unrelated) { Fabricate(:user) }
|
||||
let(:post) do
|
||||
Group.refresh_automatic_groups!
|
||||
PostCreator.create!(user,
|
||||
title: 'hi there welcome to my topic',
|
||||
raw: "this is my awesome message @#{unrelated.username_lower}",
|
||||
|
|
|
@ -583,10 +583,10 @@ RSpec.describe Search do
|
|||
end
|
||||
|
||||
context 'with personal-direct and group_messages flags' do
|
||||
let(:current) { Fabricate(:user, admin: true, username: "current_user") }
|
||||
let(:participant) { Fabricate(:user, username: "participant_1") }
|
||||
let(:participant_2) { Fabricate(:user, username: "participant_2") }
|
||||
let(:non_participant) { Fabricate(:user, username: "non_participant") }
|
||||
let!(:current) { Fabricate(:user, admin: true, username: "current_user") }
|
||||
let!(:participant) { Fabricate(:user, username: "participant_1") }
|
||||
let!(:participant_2) { Fabricate(:user, username: "participant_2") }
|
||||
let!(:non_participant) { Fabricate(:user, username: "non_participant") }
|
||||
|
||||
let(:group) do
|
||||
group = Fabricate(:group, has_messages: true)
|
||||
|
@ -596,6 +596,7 @@ RSpec.describe Search do
|
|||
end
|
||||
|
||||
def create_pm(users:, group: nil)
|
||||
Group.refresh_automatic_groups!
|
||||
pm = Fabricate(:private_message_post_one_user, user: users.first).topic
|
||||
users[1..-1].each do |u|
|
||||
pm.invite(users.first, u.username)
|
||||
|
|
|
@ -410,6 +410,7 @@ RSpec.describe TopicCreator do
|
|||
TopicCreator.any_instance.expects(:watch_topic).returns(true)
|
||||
SiteSetting.allow_duplicate_topic_titles = true
|
||||
SiteSetting.enable_staged_users = true
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it "should be possible for a regular user to send private message" do
|
||||
|
@ -442,7 +443,6 @@ RSpec.describe TopicCreator do
|
|||
end
|
||||
|
||||
it "personal_message_enabled_groups setting should be checked when sending private message" do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]
|
||||
|
||||
expect do
|
||||
|
@ -452,6 +452,10 @@ RSpec.describe TopicCreator do
|
|||
end
|
||||
|
||||
context 'with to emails' do
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it 'works for staff' do
|
||||
SiteSetting.min_trust_to_send_email_messages = 'staff'
|
||||
expect(TopicCreator.create(admin, Guardian.new(admin), pm_to_email_valid_attrs)).to be_valid
|
||||
|
|
|
@ -7,6 +7,10 @@ RSpec.describe TopicQuery::PrivateMessageLists do
|
|||
fab!(:user_3) { Fabricate(:user) }
|
||||
fab!(:user_4) { Fabricate(:user) }
|
||||
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user_2)
|
||||
|
@ -167,6 +171,10 @@ RSpec.describe TopicQuery::PrivateMessageLists do
|
|||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:pm) do
|
||||
create_post(
|
||||
user: user,
|
||||
|
@ -210,6 +218,10 @@ RSpec.describe TopicQuery::PrivateMessageLists do
|
|||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:pm) do
|
||||
create_post(
|
||||
user: user,
|
||||
|
|
|
@ -1261,9 +1261,9 @@ RSpec.describe TopicQuery do
|
|||
expect(suggested_topics).to match_array([private_group_topic.id, private_message.id])
|
||||
end
|
||||
|
||||
context "when enable_personal_messages is false" do
|
||||
context "when user is not in personal_message_enabled_groups" do
|
||||
before do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]
|
||||
end
|
||||
|
||||
it 'should not return topics by the group user' do
|
||||
|
|
|
@ -4,6 +4,10 @@ RSpec.describe GroupArchivedMessage do
|
|||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user_2)
|
||||
|
|
|
@ -4,6 +4,10 @@ RSpec.describe PrivateMessageTopicTrackingState do
|
|||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user_2)
|
||||
|
|
|
@ -725,6 +725,7 @@ RSpec.describe Topic do
|
|||
before do
|
||||
SiteSetting.max_topic_invitations_per_day = 1
|
||||
RateLimiter.enable
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -779,6 +780,10 @@ RSpec.describe Topic do
|
|||
fab!(:user) { trust_level_2 }
|
||||
fab!(:topic) { Fabricate(:private_message_topic, user: trust_level_2) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
describe 'by username' do
|
||||
it 'should be able to invite a user' do
|
||||
expect(topic.invite(user, user1.username)).to eq(true)
|
||||
|
@ -831,7 +836,6 @@ RSpec.describe Topic do
|
|||
context "when PMs are enabled for TL3 or higher only" do
|
||||
before do
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]
|
||||
SiteSetting.enable_personal_messages = false
|
||||
end
|
||||
|
||||
it 'should raise error' do
|
||||
|
@ -1029,9 +1033,11 @@ RSpec.describe Topic do
|
|||
end
|
||||
|
||||
describe 'private message' do
|
||||
fab!(:pm_user) { Fabricate(:user) }
|
||||
fab!(:topic) do
|
||||
Group.refresh_automatic_groups!
|
||||
PostCreator.new(
|
||||
Fabricate(:user),
|
||||
pm_user,
|
||||
title: "This is a private message",
|
||||
raw: "This is my message to you-ou-ou",
|
||||
archetype: Archetype.private_message,
|
||||
|
@ -2470,6 +2476,7 @@ RSpec.describe Topic do
|
|||
end
|
||||
|
||||
it "limits according to max_personal_messages_per_day" do
|
||||
Group.refresh_automatic_groups!
|
||||
create_post(user: user, archetype: 'private_message', target_usernames: [user1.username, user2.username])
|
||||
expect {
|
||||
create_post(user: user, archetype: 'private_message', target_usernames: [user1.username, user2.username])
|
||||
|
|
|
@ -392,6 +392,7 @@ RSpec.describe TopicUser do
|
|||
new_user.user_option.update!(auto_track_topics_after_msecs: 0)
|
||||
|
||||
another_user = Fabricate(:user)
|
||||
Group.refresh_automatic_groups!
|
||||
pm = Fabricate(:private_message_topic, user: another_user)
|
||||
pm.invite(another_user, new_user.username)
|
||||
|
||||
|
|
|
@ -424,6 +424,7 @@ RSpec.describe TrustLevel3Requirements do
|
|||
let(:recent_post1) { create_post(topic: topic, user: user, created_at: 1.hour.ago) }
|
||||
let(:recent_post2) { create_post(topic: topic, user: user, created_at: 10.days.ago) }
|
||||
let(:private_post) do
|
||||
Group.refresh_automatic_groups!
|
||||
create_post(
|
||||
user: user,
|
||||
archetype: Archetype.private_message,
|
||||
|
|
|
@ -193,6 +193,7 @@ RSpec.describe UserSearch do
|
|||
search_for("", topic_id: pm_topic.id, searching_user: mr_b)
|
||||
end.to raise_error(Discourse::InvalidAccess)
|
||||
|
||||
Group.refresh_automatic_groups!
|
||||
pm_topic.invite(pm_topic.user, mr_b.username)
|
||||
|
||||
results = search_for("", topic_id: pm_topic.id, searching_user: mr_b)
|
||||
|
|
|
@ -1601,6 +1601,8 @@ RSpec.describe User do
|
|||
fab!(:unactivated_old_with_post) { Fabricate(:user, active: false, created_at: 1.month.ago) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
|
||||
PostCreator.new(Discourse.system_user,
|
||||
title: "Welcome to our Discourse",
|
||||
raw: "This is a welcome message",
|
||||
|
|
|
@ -635,7 +635,6 @@ RSpec.describe GroupsController do
|
|||
expect(body["messageable"]).to eq(true)
|
||||
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
||||
SiteSetting.enable_personal_messages = false
|
||||
|
||||
get "/groups/#{group.name}/messageable.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
|
|
@ -197,7 +197,6 @@ RSpec.describe ListController do
|
|||
before do
|
||||
group.add(user)
|
||||
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
||||
SiteSetting.enable_personal_messages = false
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
|
@ -239,6 +238,7 @@ RSpec.describe ListController do
|
|||
group.add(user)
|
||||
sign_in(user)
|
||||
SiteSetting.unicode_usernames = false
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it 'should return the right response when user does not belong to group' do
|
||||
|
@ -266,6 +266,7 @@ RSpec.describe ListController do
|
|||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.unicode_usernames = true
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it 'Returns a 200 with unicode group name' do
|
||||
|
|
|
@ -1067,6 +1067,7 @@ RSpec.describe PostsController do
|
|||
end
|
||||
|
||||
it "can send a message to a group" do
|
||||
Group.refresh_automatic_groups!
|
||||
group = Group.create(name: 'test_group', messageable_level: Group::ALIAS_LEVELS[:nobody])
|
||||
user1 = user
|
||||
group.add(user1)
|
||||
|
@ -1100,6 +1101,7 @@ RSpec.describe PostsController do
|
|||
end
|
||||
|
||||
it "can send a message to a group with caps" do
|
||||
Group.refresh_automatic_groups!
|
||||
group = Group.create(name: 'Test_group', messageable_level: Group::ALIAS_LEVELS[:nobody])
|
||||
user1 = user
|
||||
group.add(user1)
|
||||
|
@ -1303,6 +1305,7 @@ RSpec.describe PostsController do
|
|||
user_4 = Fabricate(:user, username: "Iyi_Iyi")
|
||||
user_4.update_attribute(:username, "İyi_İyi")
|
||||
user_4.update_attribute(:username_lower, "İyi_İyi".downcase)
|
||||
Group.refresh_automatic_groups!
|
||||
|
||||
post "/posts.json", params: {
|
||||
raw: 'this is the test content',
|
||||
|
@ -1462,6 +1465,10 @@ RSpec.describe PostsController do
|
|||
describe 'warnings' do
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
context 'as a staff user' do
|
||||
before do
|
||||
sign_in(admin)
|
||||
|
@ -1898,6 +1905,10 @@ RSpec.describe PostsController do
|
|||
include_examples "action requires login", :get, "/posts/system/deleted.json"
|
||||
|
||||
describe "when logged in" do
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it "raises an error if the user doesn't have permission to see the deleted posts" do
|
||||
sign_in(user)
|
||||
get "/posts/system/deleted.json"
|
||||
|
|
|
@ -3136,6 +3136,10 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context "with private message" do
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user_2)
|
||||
|
@ -3647,6 +3651,10 @@ RSpec.describe TopicsController do
|
|||
fab!(:topic) { Fabricate(:topic, user: user) }
|
||||
fab!(:post) { Fabricate(:post, user: user, topic: topic) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
sign_in(user)
|
||||
put "/t/#{topic.id}/convert-topic/private.json"
|
||||
|
@ -3673,6 +3681,10 @@ RSpec.describe TopicsController do
|
|||
fab!(:topic) { Fabricate(:private_message_topic, user: user) }
|
||||
fab!(:post) { Fabricate(:post, user: post_author1, topic: topic) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
sign_in(user)
|
||||
put "/t/#{topic.id}/convert-topic/public.json"
|
||||
|
@ -4490,6 +4502,10 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#private_message_reset_new' do
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user_2)
|
||||
|
@ -4634,6 +4650,10 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#archive_message' do
|
||||
before_all do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
fab!(:group) do
|
||||
Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone]).tap do |g|
|
||||
g.add(user)
|
||||
|
|
|
@ -5535,6 +5535,7 @@ RSpec.describe UsersController do
|
|||
fab!(:user_2) { Fabricate(:user) }
|
||||
|
||||
fab!(:private_message) do
|
||||
Group.refresh_automatic_groups!
|
||||
create_post(
|
||||
user: user1,
|
||||
target_usernames: [user_2.username],
|
||||
|
|
|
@ -41,10 +41,15 @@ RSpec.describe BasicGroupSerializer do
|
|||
describe '#has_messages' do
|
||||
fab!(:group) { Fabricate(:group, has_messages: true) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
describe 'for a staff user' do
|
||||
let(:guardian) { Guardian.new(Fabricate(:moderator)) }
|
||||
|
||||
it 'should be present' do
|
||||
Group.refresh_automatic_groups!
|
||||
expect(subject.as_json[:has_messages]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,7 +98,6 @@ RSpec.describe TopicViewSerializer do
|
|||
|
||||
describe '#suggested_topics' do
|
||||
before do
|
||||
SiteSetting.enable_personal_messages = false
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
|
@ -133,7 +132,6 @@ RSpec.describe TopicViewSerializer do
|
|||
|
||||
describe 'with private messages' do
|
||||
before do
|
||||
SiteSetting.enable_personal_messages = true
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
|
||||
|
|
|
@ -54,7 +54,9 @@ module Helpers
|
|||
args[:title] ||= "This is my title #{Helpers.next_seq}"
|
||||
args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}"
|
||||
args[:topic_id] = args[:topic].id if args[:topic]
|
||||
automated_group_refresh_required = args[:user].blank?
|
||||
user = args.delete(:user) || Fabricate(:user)
|
||||
Group.refresh_automatic_groups! if automated_group_refresh_required
|
||||
args[:category] = args[:category].id if args[:category].is_a?(Category)
|
||||
creator = PostCreator.new(user, args)
|
||||
post = creator.create
|
||||
|
|
Loading…
Reference in New Issue