Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
Encode each query param seperately using Addressable
Dieser Commit ist enthalten in:
Ursprung
1962388501
Commit
909f82095f
3 geänderte Dateien mit 64 neuen und 16 gelöschten Zeilen
|
@ -269,8 +269,8 @@ class CustomWizard::Action
|
||||||
params = basic_topic_params
|
params = basic_topic_params
|
||||||
|
|
||||||
if params[:title].present? && params[:raw].present?
|
if params[:title].present? && params[:raw].present?
|
||||||
url = "/new-topic?title=#{params[:title]}"
|
url = "/new-topic?title=#{encode_query_param(params[:title])}"
|
||||||
url += "&body=#{params[:raw]}"
|
url += "&body=#{encode_query_param(params[:raw])}"
|
||||||
|
|
||||||
if category_id = action_category
|
if category_id = action_category
|
||||||
if category = Category.find_by(id: category_id)
|
if category = Category.find_by(id: category_id)
|
||||||
|
@ -282,10 +282,10 @@ class CustomWizard::Action
|
||||||
url += "&tags=#{tags.join(',')}"
|
url += "&tags=#{tags.join(',')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
route_to = Discourse.base_uri + UrlHelper.encode(url)
|
route_to = Discourse.base_uri + url
|
||||||
data['route_to'] = route_to
|
@result.output = data['route_to'] = route_to
|
||||||
|
|
||||||
log_info("route: #{route_to}")
|
log_success("route: #{route_to}")
|
||||||
else
|
else
|
||||||
log_error("invalid composer params", "title: #{params[:title]}; post: #{params[:raw]}")
|
log_error("invalid composer params", "title: #{params[:title]}; post: #{params[:raw]}")
|
||||||
end
|
end
|
||||||
|
@ -691,6 +691,10 @@ class CustomWizard::Action
|
||||||
user.user_avatar.save!
|
user.user_avatar.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def encode_query_param(param)
|
||||||
|
Addressable::URI.encode_component(param, Addressable::URI::CharacterClasses::UNRESERVED)
|
||||||
|
end
|
||||||
|
|
||||||
def log_success(message, detail = nil)
|
def log_success(message, detail = nil)
|
||||||
@log.push("success: #{message} - #{detail}")
|
@log.push("success: #{message} - #{detail}")
|
||||||
@result.success = true
|
@result.success = true
|
||||||
|
|
|
@ -5,6 +5,12 @@ describe CustomWizard::Action do
|
||||||
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
|
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
|
||||||
fab!(:group) { Fabricate(:group) }
|
fab!(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
|
let(:open_composer) {
|
||||||
|
JSON.parse(File.open(
|
||||||
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/actions/open_composer.json"
|
||||||
|
).read)
|
||||||
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Group.refresh_automatic_group!(:trust_level_2)
|
Group.refresh_automatic_group!(:trust_level_2)
|
||||||
CustomWizard::Template.save(
|
CustomWizard::Template.save(
|
||||||
|
@ -99,7 +105,8 @@ describe CustomWizard::Action do
|
||||||
expect(user.profile_background_upload.id).to eq(upload.id)
|
expect(user.profile_background_upload.id).to eq(upload.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'opens a composer' do
|
context "open composer" do
|
||||||
|
it 'works' do
|
||||||
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
||||||
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
||||||
|
|
||||||
|
@ -109,10 +116,33 @@ describe CustomWizard::Action do
|
||||||
category = Category.find_by(id: wizard.current_submission['action_8'])
|
category = Category.find_by(id: wizard.current_submission['action_8'])
|
||||||
|
|
||||||
expect(updater.result[:redirect_on_next]).to eq(
|
expect(updater.result[:redirect_on_next]).to eq(
|
||||||
"/new-topic?title=Title%20of%20the%20composer%20topic&body=I%20am%20interpolating%20some%20user%20fields%20Angus%20angus%20angus@email.com&category=#{category.slug}/#{category.id}&tags=tag1"
|
"/new-topic?title=Title%20of%20the%20composer%20topic&body=I%20am%20interpolating%20some%20user%20fields%20Angus%20angus%20angus%40email.com&category=#{category.slug}/#{category.id}&tags=tag1"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'encodes special characters in the title and body' do
|
||||||
|
open_composer['title'][0]['output'] = "Title that's special $"
|
||||||
|
open_composer['post_template'] = "Body & more body & more body"
|
||||||
|
|
||||||
|
wizard = CustomWizard::Wizard.new(@template, user)
|
||||||
|
|
||||||
|
action = CustomWizard::Action.new(
|
||||||
|
wizard: wizard,
|
||||||
|
action: open_composer,
|
||||||
|
user: user,
|
||||||
|
data: {}
|
||||||
|
)
|
||||||
|
action.perform
|
||||||
|
|
||||||
|
expect(action.result.success?).to eq(true)
|
||||||
|
|
||||||
|
decoded_output = CGI.parse(URI.parse(action.result.output).query)
|
||||||
|
|
||||||
|
expect(decoded_output['title'][0]).to eq("Title that's special $")
|
||||||
|
expect(decoded_output['body'][0]).to eq("Body & more body & more body")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a category' do
|
it 'creates a category' do
|
||||||
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
||||||
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
||||||
|
|
14
spec/fixtures/actions/open_composer.json
gevendort
Normale Datei
14
spec/fixtures/actions/open_composer.json
gevendort
Normale Datei
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"id": "open_composer_action",
|
||||||
|
"type": "open_composer",
|
||||||
|
"title": [
|
||||||
|
{
|
||||||
|
"type": "assignment",
|
||||||
|
"output": "Title content",
|
||||||
|
"output_type": "text",
|
||||||
|
"output_connector": "set"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"post_builder": true,
|
||||||
|
"post_template": "Post content"
|
||||||
|
}
|
Laden …
In neuem Issue referenzieren