diff --git a/app/models/group.rb b/app/models/group.rb index af2573e50f4..3acf120e7dc 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -42,6 +42,7 @@ class Group < ActiveRecord::Base } AUTO_GROUP_IDS = Hash[*AUTO_GROUPS.to_a.flatten.reverse] + STAFF_GROUPS = [:admins, :moderators, :staff] ALIAS_LEVELS = { :nobody => 0, @@ -370,6 +371,10 @@ class Group < ActiveRecord::Base Group.mentionable(user).where(id: group_id).exists? end + def staff? + STAFF_GROUPS.include?(self.name.to_sym) + end + protected def name_format_validator diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 59dd7bdc215..8f5ef5ae10e 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -202,6 +202,14 @@ describe Guardian do it "returns false if target is not staff" do expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey 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