0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 01:10:28 +01:00

DEV: Ensure admins are excluded from set_user_redirect

Dieser Commit ist enthalten in:
Angus McLeod 2024-10-03 11:34:13 +02:00
Ursprung c9d76848dc
Commit d4d27c0bf3
3 geänderte Dateien mit 35 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -384,7 +384,7 @@ class CustomWizard::Wizard
def self.set_user_redirect(wizard_id, user) def self.set_user_redirect(wizard_id, user)
wizard = self.create(wizard_id, user) wizard = self.create(wizard_id, user)
if wizard.permitted? if wizard.permitted?(always_allow_admin: false)
user.custom_fields['redirect_to_wizard'] = wizard_id user.custom_fields['redirect_to_wizard'] = wizard_id
user.save_custom_fields(true) user.save_custom_fields(true)
else else

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-custom-wizard # name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.8.4 # version: 2.8.5
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech # contact_emails: development@pavilion.tech

Datei anzeigen

@ -2,30 +2,52 @@
describe Jobs::SetAfterTimeWizard do describe Jobs::SetAfterTimeWizard do
fab!(:user1) { Fabricate(:user) } fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) } fab!(:user2) { Fabricate(:user, trust_level: TrustLevel[3]) }
fab!(:user3) { Fabricate(:user) } fab!(:user3) { Fabricate(:user, admin: true) }
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
before do
@after_time_template = template.dup
@after_time_template["after_time"] = true
@after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601
CustomWizard::Template.save(@after_time_template)
end
it "sets wizard redirect for all users " do it "sets wizard redirect for all users " do
after_time_template = template.dup
after_time_template["after_time"] = true
after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601
CustomWizard::Template.save(after_time_template)
messages = MessageBus.track_publish("/redirect_to_wizard") do messages = MessageBus.track_publish("/redirect_to_wizard") do
described_class.new.execute(wizard_id: 'super_mega_fun_wizard') described_class.new.execute(wizard_id: 'super_mega_fun_wizard')
end end
expect(messages.first.data).to eq("super_mega_fun_wizard")
expect(messages.first.user_ids).to match_array([user1.id, user2.id, user3.id])
expect( expect(
UserCustomField.where( UserCustomField.where(
name: 'redirect_to_wizard', name: 'redirect_to_wizard',
value: 'super_mega_fun_wizard' value: 'super_mega_fun_wizard'
).length ).length
).to eq(3) ).to eq(3)
end
expect(messages.first.data).to eq("super_mega_fun_wizard") context "when permitted is set" do
expect(messages.first.user_ids).to match_array([user1.id, user2.id, user3.id]) before do
enable_subscription("business")
@after_time_template["permitted"] = permitted_json["permitted"]
CustomWizard::Template.save(@after_time_template.as_json)
end
it "only redirects users in the group" do
messages = MessageBus.track_publish("/redirect_to_wizard") do
described_class.new.execute(wizard_id: 'super_mega_fun_wizard')
end
expect(messages.first.data).to eq("super_mega_fun_wizard")
expect(messages.first.user_ids).to match_array([user2.id])
expect(
UserCustomField.where(
name: 'redirect_to_wizard',
value: 'super_mega_fun_wizard'
).length
).to eq(1)
end
end end
end end