mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 17:02:45 +08:00
FIX: invite users with sufficient trust level
This commit is contained in:
parent
281bf0b345
commit
fab67fafc1
|
@ -1815,6 +1815,7 @@ en:
|
|||
min_trust_to_post_embedded_media: "The minimum trust level required to embed media items in a post"
|
||||
min_trust_level_to_allow_profile_background: "The minimum trust level required to upload a profile background"
|
||||
min_trust_level_to_allow_user_card_background: "The minimum trust level required to upload a user card background"
|
||||
min_trust_level_to_allow_invite: "The minimum trust level required to allow invite"
|
||||
allowed_link_domains: "Domains that users may link to even if they don't have the appropriate trust level to post links"
|
||||
|
||||
newuser_max_links: "How many links a new user can add to a post."
|
||||
|
|
|
@ -1403,6 +1403,10 @@ trust:
|
|||
default: 0
|
||||
client: true
|
||||
enum: "TrustLevelSetting"
|
||||
min_trust_level_to_allow_invite:
|
||||
default: 2
|
||||
client: true
|
||||
enum: "TrustLevelSetting"
|
||||
allow_flagging_staff: true
|
||||
send_tl1_welcome_message: true
|
||||
send_tl2_promotion_message: true
|
||||
|
|
|
@ -353,7 +353,7 @@ class Guardian
|
|||
!SiteSetting.enable_sso &&
|
||||
SiteSetting.enable_local_logins &&
|
||||
(
|
||||
(!SiteSetting.must_approve_users? && @user.has_trust_level?(TrustLevel[2])) ||
|
||||
(!SiteSetting.must_approve_users? && @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)) ||
|
||||
is_staff?
|
||||
) &&
|
||||
(groups.blank? || is_admin? || groups.all? { |g| can_edit_group?(g) })
|
||||
|
@ -383,7 +383,7 @@ class Guardian
|
|||
end
|
||||
end
|
||||
|
||||
user.has_trust_level?(TrustLevel[2])
|
||||
user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)
|
||||
end
|
||||
|
||||
def can_invite_via_email?(object)
|
||||
|
|
|
@ -477,6 +477,17 @@ describe Guardian do
|
|||
let(:user) { Fabricate.build(:user) }
|
||||
let(:moderator) { Fabricate.build(:moderator) }
|
||||
|
||||
it 'returns true if user has sufficient trust level' do
|
||||
SiteSetting.min_trust_level_to_allow_invite = 2
|
||||
expect(Guardian.new(trust_level_2).can_invite_to_forum?).to be_truthy
|
||||
expect(Guardian.new(moderator).can_invite_to_forum?).to be_truthy
|
||||
end
|
||||
|
||||
it 'returns false if user trust level does not have sufficient trust level' do
|
||||
SiteSetting.min_trust_level_to_allow_invite = 2
|
||||
expect(Guardian.new(trust_level_1).can_invite_to_forum?).to be_falsey
|
||||
end
|
||||
|
||||
it "doesn't allow anonymous users to invite" do
|
||||
expect(Guardian.new.can_invite_to_forum?).to be_falsey
|
||||
end
|
||||
|
@ -532,6 +543,10 @@ describe Guardian do
|
|||
describe 'can_invite_to?' do
|
||||
|
||||
describe "regular topics" do
|
||||
before do
|
||||
SiteSetting.min_trust_level_to_allow_invite = 2
|
||||
user.update!(trust_level: SiteSetting.min_trust_level_to_allow_invite)
|
||||
end
|
||||
fab!(:category) { Fabricate(:category, read_restricted: true) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:private_topic) { Fabricate(:topic, category: category) }
|
||||
|
@ -544,7 +559,7 @@ describe Guardian do
|
|||
expect(Guardian.new(nil).can_invite_to?(topic)).to be_falsey
|
||||
expect(Guardian.new(moderator).can_invite_to?(nil)).to be_falsey
|
||||
expect(Guardian.new(moderator).can_invite_to?(topic)).to be_truthy
|
||||
expect(Guardian.new(user).can_invite_to?(topic)).to be_falsey
|
||||
expect(Guardian.new(trust_level_1).can_invite_to?(topic)).to be_falsey
|
||||
|
||||
SiteSetting.max_invites_per_day = 0
|
||||
|
||||
|
@ -610,7 +625,8 @@ describe Guardian do
|
|||
end
|
||||
|
||||
describe "private messages" do
|
||||
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
|
||||
SiteSetting.min_trust_level_to_allow_invite = 2
|
||||
fab!(:user) { Fabricate(:user, trust_level: SiteSetting.min_trust_level_to_allow_invite) }
|
||||
fab!(:pm) { Fabricate(:private_message_topic, user: user) }
|
||||
|
||||
context "when private messages are disabled" do
|
||||
|
@ -631,6 +647,21 @@ describe Guardian do
|
|||
end
|
||||
end
|
||||
|
||||
context "when private messages are enabled" do
|
||||
before do
|
||||
SiteSetting.enable_personal_messages = true
|
||||
end
|
||||
|
||||
it "returns true if user has sufficient trust level" do
|
||||
expect(Guardian.new(user).can_invite_to?(pm)).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if user has sufficient trust level" do
|
||||
user.trust_level = 1
|
||||
expect(Guardian.new(user).can_invite_to?(pm)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "when PM has receached the maximum number of recipients" do
|
||||
before do
|
||||
SiteSetting.max_allowed_message_recipients = 2
|
||||
|
|
Loading…
Reference in New Issue
Block a user