0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-21 17:00:29 +01:00

FIX: return user matching guest_email if exists

Dieser Commit ist enthalten in:
Angus McLeod 2024-08-05 12:18:19 +08:00
Ursprung 4e7587ea3a
Commit 83320e227c
3 geänderte Dateien mit 42 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -381,7 +381,7 @@ class CustomWizard::Action
group_map = group_map.flatten.compact
unless group_map.present?
if group_map.blank?
log_error("invalid group map")
return
end
@ -415,7 +415,7 @@ class CustomWizard::Action
end
def route_to
return unless (url_input = action['url']).present?
return if (url_input = action['url']).blank?
if url_input.is_a?(String)
url = mapper.interpolate(url_input)
@ -510,7 +510,7 @@ class CustomWizard::Action
user: user
).perform
return false unless output.present?
return false if output.blank?
if output.is_a?(Array)
output.first
@ -528,7 +528,7 @@ class CustomWizard::Action
user: user,
).perform
return false unless output.present?
return false if output.blank?
if output.is_a?(Array)
output.flatten
@ -682,12 +682,16 @@ class CustomWizard::Action
).perform
if email&.match(/@/)
User.create!(
email: email,
username: UserNameSuggester.suggest(email),
name: User.suggest_name(email),
staged: true,
)
if user = User.find_by_email(email)
user
else
User.create!(
email: email,
username: UserNameSuggester.suggest(email),
name: User.suggest_name(email),
staged: true,
)
end
end
end
end

Datei anzeigen

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

Datei anzeigen

@ -5,7 +5,7 @@ describe CustomWizard::Action do
fab!(:user1) { Fabricate(:user, name: "Angus One", username: 'angus1', email: "angus_one@email.com", trust_level: TrustLevel[2]) }
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
fab!(:tag) { Fabricate(:tag, name: 'tag1') }
fab!(:group) { Fabricate(:group) }
fab!(:group)
let(:wizard_template) { get_wizard_fixture("wizard") }
let(:open_composer) { get_wizard_fixture("actions/open_composer") }
@ -373,7 +373,7 @@ describe CustomWizard::Action do
context "with a guest" do
describe "#create_topic" do
it "creates a staged guest poster if guest_email is set" do
before do
Jobs.run_immediately!
wizard_template["permitted"] = guests_permitted["permitted"]
@ -404,7 +404,9 @@ describe CustomWizard::Action do
wizard_template[:actions] = [create_topic]
update_template(wizard_template)
end
it "creates a staged guest poster if guest_email is set" do
wizard = CustomWizard::Builder.new(
@template[:id],
nil,
@ -424,6 +426,29 @@ describe CustomWizard::Action do
expect(topic.posts.first.user.staged).to eq(true)
expect(topic.posts.first.user.primary_email.email).to eq('guest@email.com')
end
it "returns an existing user with the same email" do
existing = Fabricate(:user, email: 'guest@email.com')
wizard = CustomWizard::Builder.new(
@template[:id],
nil,
CustomWizard::Wizard.generate_guest_id
).build
wizard.create_updater(
wizard.steps.first.id,
step_1_field_5: "guest@email.com"
).update
wizard.create_updater(wizard.steps.second.id, {}).update
wizard.create_updater(wizard.steps.last.id,
step_3_field_3: category.id
).update
topic = Topic.where(category_id: category.id).first
expect(topic.present?).to eq(true)
expect(topic.posts.first.user.staged).to eq(false)
expect(topic.posts.first.user.primary_email.email).to eq('guest@email.com')
end
end
describe "#send_message" do