Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-24 10:20:28 +01:00
FIX: return user matching guest_email if exists
Dieser Commit ist enthalten in:
Ursprung
4e7587ea3a
Commit
83320e227c
3 geänderte Dateien mit 42 neuen und 13 gelöschten Zeilen
|
@ -381,7 +381,7 @@ class CustomWizard::Action
|
||||||
|
|
||||||
group_map = group_map.flatten.compact
|
group_map = group_map.flatten.compact
|
||||||
|
|
||||||
unless group_map.present?
|
if group_map.blank?
|
||||||
log_error("invalid group map")
|
log_error("invalid group map")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -415,7 +415,7 @@ class CustomWizard::Action
|
||||||
end
|
end
|
||||||
|
|
||||||
def route_to
|
def route_to
|
||||||
return unless (url_input = action['url']).present?
|
return if (url_input = action['url']).blank?
|
||||||
|
|
||||||
if url_input.is_a?(String)
|
if url_input.is_a?(String)
|
||||||
url = mapper.interpolate(url_input)
|
url = mapper.interpolate(url_input)
|
||||||
|
@ -510,7 +510,7 @@ class CustomWizard::Action
|
||||||
user: user
|
user: user
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
return false unless output.present?
|
return false if output.blank?
|
||||||
|
|
||||||
if output.is_a?(Array)
|
if output.is_a?(Array)
|
||||||
output.first
|
output.first
|
||||||
|
@ -528,7 +528,7 @@ class CustomWizard::Action
|
||||||
user: user,
|
user: user,
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
return false unless output.present?
|
return false if output.blank?
|
||||||
|
|
||||||
if output.is_a?(Array)
|
if output.is_a?(Array)
|
||||||
output.flatten
|
output.flatten
|
||||||
|
@ -682,12 +682,16 @@ class CustomWizard::Action
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
if email&.match(/@/)
|
if email&.match(/@/)
|
||||||
User.create!(
|
if user = User.find_by_email(email)
|
||||||
email: email,
|
user
|
||||||
username: UserNameSuggester.suggest(email),
|
else
|
||||||
name: User.suggest_name(email),
|
User.create!(
|
||||||
staged: true,
|
email: email,
|
||||||
)
|
username: UserNameSuggester.suggest(email),
|
||||||
|
name: User.suggest_name(email),
|
||||||
|
staged: true,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.1
|
# version: 2.8.2
|
||||||
# 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
|
||||||
|
|
|
@ -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!(: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!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
|
||||||
fab!(:tag) { Fabricate(:tag, name: 'tag1') }
|
fab!(:tag) { Fabricate(:tag, name: 'tag1') }
|
||||||
fab!(:group) { Fabricate(:group) }
|
fab!(:group)
|
||||||
|
|
||||||
let(:wizard_template) { get_wizard_fixture("wizard") }
|
let(:wizard_template) { get_wizard_fixture("wizard") }
|
||||||
let(:open_composer) { get_wizard_fixture("actions/open_composer") }
|
let(:open_composer) { get_wizard_fixture("actions/open_composer") }
|
||||||
|
@ -373,7 +373,7 @@ describe CustomWizard::Action do
|
||||||
|
|
||||||
context "with a guest" do
|
context "with a guest" do
|
||||||
describe "#create_topic" do
|
describe "#create_topic" do
|
||||||
it "creates a staged guest poster if guest_email is set" do
|
before do
|
||||||
Jobs.run_immediately!
|
Jobs.run_immediately!
|
||||||
|
|
||||||
wizard_template["permitted"] = guests_permitted["permitted"]
|
wizard_template["permitted"] = guests_permitted["permitted"]
|
||||||
|
@ -404,7 +404,9 @@ describe CustomWizard::Action do
|
||||||
wizard_template[:actions] = [create_topic]
|
wizard_template[:actions] = [create_topic]
|
||||||
|
|
||||||
update_template(wizard_template)
|
update_template(wizard_template)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a staged guest poster if guest_email is set" do
|
||||||
wizard = CustomWizard::Builder.new(
|
wizard = CustomWizard::Builder.new(
|
||||||
@template[:id],
|
@template[:id],
|
||||||
nil,
|
nil,
|
||||||
|
@ -424,6 +426,29 @@ describe CustomWizard::Action do
|
||||||
expect(topic.posts.first.user.staged).to eq(true)
|
expect(topic.posts.first.user.staged).to eq(true)
|
||||||
expect(topic.posts.first.user.primary_email.email).to eq('guest@email.com')
|
expect(topic.posts.first.user.primary_email.email).to eq('guest@email.com')
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#send_message" do
|
describe "#send_message" do
|
||||||
|
|
Laden …
In neuem Issue referenzieren