DEV: Admins and mods are already members of staff (#404)

This hack is no longer necessary because fabricated admins and mods are already members of the staff group.
This commit is contained in:
Bianca Nenciu 2022-12-20 16:24:21 +02:00 committed by GitHub
parent 212a12d709
commit eeccf78c1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 14 deletions

View File

@ -17,8 +17,8 @@ RSpec.describe Assigner do
let(:topic) { post.topic } let(:topic) { post.topic }
let(:secure_category) { Fabricate(:private_category, group: Fabricate(:group)) } let(:secure_category) { Fabricate(:private_category, group: Fabricate(:group)) }
let(:secure_topic) { Fabricate(:post).topic.tap { |t| t.update(category: secure_category) } } let(:secure_topic) { Fabricate(:post).topic.tap { |t| t.update(category: secure_category) } }
let(:moderator) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator) { Fabricate(:moderator) }
let(:moderator_2) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator_2) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) } let(:admin) { Fabricate(:admin) }
let(:assigner) { described_class.new(topic, moderator_2) } let(:assigner) { described_class.new(topic, moderator_2) }
let(:assigner_self) { described_class.new(topic, moderator) } let(:assigner_self) { described_class.new(topic, moderator) }
@ -145,7 +145,7 @@ RSpec.describe Assigner do
context "when assigns_by_staff_mention is set to true" do context "when assigns_by_staff_mention is set to true" do
let(:system_user) { Discourse.system_user } let(:system_user) { Discourse.system_user }
let(:moderator) { Fabricate(:admin, username: "modi", groups: [assign_allowed_group]) } let(:moderator) { Fabricate(:admin, username: "modi") }
let(:post) { Fabricate(:post, raw: "Hey you @system, stay unassigned", user: moderator) } let(:post) { Fabricate(:post, raw: "Hey you @system, stay unassigned", user: moderator) }
let(:topic) { post.topic } let(:topic) { post.topic }
@ -170,7 +170,7 @@ RSpec.describe Assigner do
it "doesn't assign the same user more than once" do it "doesn't assign the same user more than once" do
SiteSetting.assign_mailer = AssignMailer.levels[:always] SiteSetting.assign_mailer = AssignMailer.levels[:always]
another_mod = Fabricate(:moderator, groups: [assign_allowed_group]) another_mod = Fabricate(:moderator)
Email::Sender.any_instance.expects(:send).once Email::Sender.any_instance.expects(:send).once
expect(assigned_to?(moderator)).to eq(true) expect(assigned_to?(moderator)).to eq(true)
@ -193,7 +193,7 @@ RSpec.describe Assigner do
# Assign many posts to reach the limit # Assign many posts to reach the limit
1.upto(described_class::ASSIGNMENTS_PER_TOPIC_LIMIT) do 1.upto(described_class::ASSIGNMENTS_PER_TOPIC_LIMIT) do
other_post = Fabricate(:post, topic: topic) other_post = Fabricate(:post, topic: topic)
user = Fabricate(:moderator, groups: [assign_allowed_group]) user = Fabricate(:moderator)
status = described_class.new(other_post, admin).assign(user) status = described_class.new(other_post, admin).assign(user)
expect(status[:success]).to eq(true) expect(status[:success]).to eq(true)
end end
@ -556,7 +556,7 @@ RSpec.describe Assigner do
context "unassign_on_close" do context "unassign_on_close" do
let(:post) { Fabricate(:post) } let(:post) { Fabricate(:post) }
let(:topic) { post.topic } let(:topic) { post.topic }
let(:moderator) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator) { Fabricate(:moderator) }
context "topic" do context "topic" do
let(:assigner) { described_class.new(topic, moderator) } let(:assigner) { described_class.new(topic, moderator) }
@ -653,7 +653,7 @@ RSpec.describe Assigner do
context "reassign_on_open" do context "reassign_on_open" do
let(:post) { Fabricate(:post) } let(:post) { Fabricate(:post) }
let(:topic) { post.topic } let(:topic) { post.topic }
let(:moderator) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator) { Fabricate(:moderator) }
context "topic" do context "topic" do
let(:assigner) { described_class.new(topic, moderator) } let(:assigner) { described_class.new(topic, moderator) }
@ -705,8 +705,8 @@ RSpec.describe Assigner do
context "assign_emailer" do context "assign_emailer" do
let(:post) { Fabricate(:post) } let(:post) { Fabricate(:post) }
let(:topic) { post.topic } let(:topic) { post.topic }
let(:moderator) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator) { Fabricate(:moderator) }
let(:moderator_2) { Fabricate(:moderator, groups: [assign_allowed_group]) } let(:moderator_2) { Fabricate(:moderator) }
it "send an email if set to 'always'" do it "send an email if set to 'always'" do
SiteSetting.assign_mailer = AssignMailer.levels[:always] SiteSetting.assign_mailer = AssignMailer.levels[:always]

View File

@ -7,9 +7,7 @@ RSpec.describe DiscourseAssign::AssignController do
before { SiteSetting.assign_enabled = true } before { SiteSetting.assign_enabled = true }
fab!(:default_allowed_group) { Group.find_by(name: "staff") } fab!(:default_allowed_group) { Group.find_by(name: "staff") }
let(:user) do let(:user) { Fabricate(:admin, name: "Robin Ward", username: "eviltrout") }
Fabricate(:admin, groups: [default_allowed_group], name: "Robin Ward", username: "eviltrout")
end
fab!(:post) { Fabricate(:post) } fab!(:post) { Fabricate(:post) }
fab!(:user2) do fab!(:user2) do
Fabricate(:active_user, name: "David Taylor", username: "david", groups: [default_allowed_group]) Fabricate(:active_user, name: "David Taylor", username: "david", groups: [default_allowed_group])
@ -127,7 +125,7 @@ RSpec.describe DiscourseAssign::AssignController do
it "excludes other users from the suggestions when they already reached the max assigns limit" do it "excludes other users from the suggestions when they already reached the max assigns limit" do
SiteSetting.max_assigned_topics = 1 SiteSetting.max_assigned_topics = 1
another_admin = Fabricate(:admin, groups: [default_allowed_group]) another_admin = Fabricate(:admin)
Assigner.new(post.topic, user).assign(another_admin) Assigner.new(post.topic, user).assign(another_admin)
get "/assign/suggestions.json" get "/assign/suggestions.json"

View File

@ -80,7 +80,7 @@ RSpec.describe TopicListSerializer do
end end
describe "as a staff" do describe "as a staff" do
let(:admin) { Fabricate(:admin, groups: [Group.find_by(name: "staff")]) } let(:admin) { Fabricate(:admin) }
let(:guardian) { Guardian.new(admin) } let(:guardian) { Guardian.new(admin) }
it "should include the right attribute" do it "should include the right attribute" do