mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: error when sending a private message to a group in some cases
This commit is contained in:
@ -42,6 +42,7 @@ class Group < ActiveRecord::Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
AUTO_GROUP_IDS = Hash[*AUTO_GROUPS.to_a.flatten.reverse]
|
AUTO_GROUP_IDS = Hash[*AUTO_GROUPS.to_a.flatten.reverse]
|
||||||
|
STAFF_GROUPS = [:admins, :moderators, :staff]
|
||||||
|
|
||||||
ALIAS_LEVELS = {
|
ALIAS_LEVELS = {
|
||||||
:nobody => 0,
|
:nobody => 0,
|
||||||
@ -370,6 +371,10 @@ class Group < ActiveRecord::Base
|
|||||||
Group.mentionable(user).where(id: group_id).exists?
|
Group.mentionable(user).where(id: group_id).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def staff?
|
||||||
|
STAFF_GROUPS.include?(self.name.to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def name_format_validator
|
def name_format_validator
|
||||||
|
@ -202,6 +202,14 @@ describe Guardian do
|
|||||||
it "returns false if target is not staff" do
|
it "returns false if target is not staff" do
|
||||||
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey
|
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns true if target is a staff group" do
|
||||||
|
Group::STAFF_GROUPS.each do |name|
|
||||||
|
g = Group[name]
|
||||||
|
g.alias_level = Group::ALIAS_LEVELS[:everyone]
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(g)).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user