A platform for community discussion. Free, open, simple.
FIX: Send workflow variables import as a JSON body (#45003)
Osama Sayegh04db89f871be
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjsindex ffd978892d2..824a63992cb 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs@@ -1460,7 +1460,11 @@ export default class WorkflowsEditor extends Component {try {const response = await ajax(`/admin/plugins/discourse-workflows/workflows/${this.args.workflow.id}/variables/import.json`,- { type: "POST", data: { variables } }+ {+ type: "POST",+ contentType: "application/json",+ data: JSON.stringify({ variables }),+ });this.replaceWorkflow(response.workflow);diff --git a/plugins/discourse-workflows/spec/requests/discourse_workflows/workflow_variables_controller_spec.rb b/plugins/discourse-workflows/spec/requests/discourse_workflows/workflow_variables_controller_spec.rbindex 86f9889379f..7cdad6310ee 100644--- a/plugins/discourse-workflows/spec/requests/discourse_workflows/workflow_variables_controller_spec.rb+++ b/plugins/discourse-workflows/spec/requests/discourse_workflows/workflow_variables_controller_spec.rb@@ -195,7 +195,8 @@ RSpec.describe DiscourseWorkflows::WorkflowVariablesController do{ key: "priority", variable_type: "string" },{ key: "notify_categories", variable_type: "category_list" },],- }+ },+ as: :json}.to change { workflow.reload.version_counter }.by(1)expect(response).to have_http_status(:ok)@@ -205,6 +206,23 @@ RSpec.describe DiscourseWorkflows::WorkflowVariablesController doexpect(workflow.variables.pluck(:key)).to contain_exactly("priority", "notify_categories")end+ it "keeps nested type options from the JSON body" do+ post "/admin/plugins/discourse-workflows/workflows/#{workflow.id}/variables/import.json",+ params: {+ variables: [+ { key: "plain", variable_type: "boolean", type_options: {} },+ { key: "priority", variable_type: "enum", type_options: { choices: %w[low high] } },+ ],+ },+ as: :json++ expect(response).to have_http_status(:ok)+ expect(response.parsed_body["imported_count"]).to eq(2)+ expect(workflow.variables.find_by(key: "priority").type_options).to eq(+ "choices" => %w[low high],+ )+ end+it "skips variables whose key already exists on the workflow" doFabricate(:discourse_workflows_workflow_variable,@@ -219,7 +237,8 @@ RSpec.describe DiscourseWorkflows::WorkflowVariablesController dopost "/admin/plugins/discourse-workflows/workflows/#{workflow.id}/variables/import.json",params: {variables: [{ key: "priority", variable_type: "string" }],- }+ },+ as: :jsonexpect(response).to have_http_status(:ok)json = response.parsed_body@@ -232,7 +251,8 @@ RSpec.describe DiscourseWorkflows::WorkflowVariablesController dopost "/admin/plugins/discourse-workflows/workflows/-1/variables/import.json",params: {variables: [{ key: "priority", variable_type: "string" }],- }+ },+ as: :jsonexpect(response).to have_http_status(:not_found)endend