From 13a1538eb9a3fbe363fa2537059080e834348cf9 Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 5 Sep 2023 12:38:25 -0400 Subject: [PATCH 01/46] DEV: Update compatibility for main branch --- .discourse-compatibility | 1 + 1 file changed, 1 insertion(+) diff --git a/.discourse-compatibility b/.discourse-compatibility index b53ff04d..556450b9 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,2 +1,3 @@ +3.1.0: 1f35b80f85e5fd1efb7f4851f0845700432febdc 2.7.99: e07a57e398b6b1676ab42a7e34467556fca5416b 2.5.1: bb85b3a0d2c0ab6b59bcb405731c39089ec6731c From 121d60330a87ec47791809d4b78b85b7060bc11b Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 5 Sep 2023 12:49:58 -0400 Subject: [PATCH 02/46] DEV: Pin plugin for Discourse 3.1 stable --- .discourse-compatibility | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.discourse-compatibility b/.discourse-compatibility index 556450b9..01ce2cde 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,3 @@ -3.1.0: 1f35b80f85e5fd1efb7f4851f0845700432febdc +3.1.999: 1f35b80f85e5fd1efb7f4851f0845700432febdc 2.7.99: e07a57e398b6b1676ab42a7e34467556fca5416b 2.5.1: bb85b3a0d2c0ab6b59bcb405731c39089ec6731c From 36d6f9bc6f94737e446f6a0bd5b95541e21d67cc Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 5 Sep 2023 12:52:11 -0400 Subject: [PATCH 03/46] bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 756154bb..ea56d174 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.18 +# version: 2.4.19 # 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 From 833281861692ec265ac94731716c186d213083c8 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 13:29:21 +0100 Subject: [PATCH 04/46] FEATURE: implement way to temporarily ignore redirect --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 70676bb0..16e4205a 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -22,6 +22,7 @@ export default { withPluginApi("0.8.36", (api) => { api.onAppEvent("page:changed", (data) => { const currentUser = api.getCurrentUser(); + const searchParams = new URLSearchParams(window.location.search); if (currentUser) { const redirectToWizard = currentUser.redirect_to_wizard; @@ -30,6 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && + !searchParams.has('ignore_redirect') && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; From 037132fb1a990b8b519f624b09a02d2d6ad7dabb Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 16:26:30 +0100 Subject: [PATCH 05/46] prettier --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 16e4205a..02f11a6d 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -31,7 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && - !searchParams.has('ignore_redirect') && + !searchParams.has("ignore_redirect") && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; From 8649ab22864682910e2e33a949c486537c2eac6a Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 6 Sep 2023 16:27:40 +0100 Subject: [PATCH 06/46] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 756154bb..ea56d174 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.18 +# version: 2.4.19 # 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 From 050a38a9d38250b43125490675031240d7445709 Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 8 Sep 2023 07:13:52 +0100 Subject: [PATCH 07/46] make code testable, add test --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 +- test/javascripts/acceptance/wizard-test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 02f11a6d..391340b7 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -31,7 +31,7 @@ export default { .concat(["loading"]); if ( redirectToWizard && - !searchParams.has("ignore_redirect") && + !data.url.includes("ignore_redirect") && data.currentRouteName !== "customWizardStep" && !excludedPaths.find((p) => { return data.currentRouteName.indexOf(p) > -1; diff --git a/test/javascripts/acceptance/wizard-test.js b/test/javascripts/acceptance/wizard-test.js index dd441649..0527cf0f 100644 --- a/test/javascripts/acceptance/wizard-test.js +++ b/test/javascripts/acceptance/wizard-test.js @@ -74,6 +74,15 @@ acceptance("Wizard | Redirect", function (needs) { "pending wizard routing works" ); }); + + test("Don't redirect to pending Wizard when ingore redirect param is supplied", async function (assert) { + sinon.stub(DiscourseURL, "routeTo"); + await visit("/latest?ignore_redirect=1"); + assert.notOk( + DiscourseURL.routeTo.calledWith("/w/wizard"), + "pending wizard routing blocked" + ); + }); }); acceptance("Wizard | Wizard", function (needs) { From ebc0f706e31c99d437dfb741690a643d3b5a472a Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 8 Sep 2023 07:18:31 +0100 Subject: [PATCH 08/46] remove redundant assignment --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 391340b7..c02f0f3d 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -22,7 +22,6 @@ export default { withPluginApi("0.8.36", (api) => { api.onAppEvent("page:changed", (data) => { const currentUser = api.getCurrentUser(); - const searchParams = new URLSearchParams(window.location.search); if (currentUser) { const redirectToWizard = currentUser.redirect_to_wizard; From 785bce228e762fddfba83b6ffd63abf5160c5d3b Mon Sep 17 00:00:00 2001 From: jumagura Date: Fri, 8 Sep 2023 10:02:12 -0400 Subject: [PATCH 09/46] bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index ea56d174..ef83b548 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.19 +# version: 2.4.20 # 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 From 31b2625a65ead9bfae52f7513be57727f5c649fb Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:05:55 +0100 Subject: [PATCH 10/46] add this to avoid deprecation --- .../components/wizard-custom-action.hbs | 106 +++++++++--------- .../components/wizard-mapper-input.hbs | 36 +++--- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index e6a4b703..80152674 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -14,7 +14,7 @@
{{wizard-subscription-selector - value=action.type + value=this.action.type feature="action" attribute="type" onChange=(action "changeType") @@ -31,9 +31,9 @@
{{combo-box - value=action.run_after + value=this.action.run_after content=runAfterContent - onChange=(action (mut action.run_after)) + onChange=(action (mut this.action.run_after)) }}
@@ -48,7 +48,7 @@
{{wizard-mapper - inputs=action.title + inputs=this.action.title property="title" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -67,10 +67,10 @@
{{combo-box - value=action.post + value=this.action.post content=wizardFields nameProperty="label" - onChange=(action (mut action.post)) + onChange=(action (mut this.action.post)) options=(hash none="admin.wizard.selector.placeholder.wizard_field" isDisabled=showPostBuilder @@ -84,7 +84,7 @@
- {{#if action.post_builder}} + {{#if this.action.post_builder}}
@@ -92,7 +92,7 @@
{{wizard-text-editor - value=action.post_template + value=this.action.post_template wizardFields=wizardFields }}
@@ -108,7 +108,7 @@
{{wizard-mapper - inputs=action.category + inputs=this.action.category property="category" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -131,7 +131,7 @@
{{wizard-mapper - inputs=action.tags + inputs=this.action.tags property="tags" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -153,7 +153,7 @@
{{wizard-mapper - inputs=action.visible + inputs=this.action.visible property="visible" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -171,7 +171,7 @@
{{wizard-mapper - inputs=action.add_event + inputs=this.action.add_event property="add_event" onUpdate=(action "mappedFieldUpdated") options=(hash wizardFieldSelection=true context="action") @@ -188,7 +188,7 @@
{{wizard-mapper - inputs=action.add_location + inputs=this.action.add_location property="add_location" onUpdate=(action "mappedFieldUpdated") options=(hash wizardFieldSelection=true context="action") @@ -206,7 +206,7 @@
{{wizard-mapper - inputs=action.recipient + inputs=this.action.recipient property="recipient" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -230,7 +230,7 @@
{{wizard-mapper - inputs=action.profile_updates + inputs=this.action.profile_updates property="profile_updates" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -254,11 +254,11 @@
{{combo-box - value=action.api + value=this.action.api content=availableApis - onChange=(action (mut action.api)) + onChange=(action (mut this.action.api)) options=(hash - isDisabled=action.custom_title_enabled + isDisabled=this.action.custom_title_enabled none="admin.wizard.action.send_to_api.select_an_api" ) }} @@ -272,9 +272,9 @@
{{combo-box - value=action.api_endpoint + value=this.action.api_endpoint content=availableEndpoints - onChange=(action (mut action.api_endpoint)) + onChange=(action (mut this.action.api_endpoint)) options=(hash isDisabled=apiEmpty none="admin.wizard.action.send_to_api.select_an_endpoint" @@ -290,7 +290,7 @@
{{wizard-text-editor - value=action.api_body + value=this.action.api_body previewEnabled=false barEnabled=false wizardFields=wizardFields @@ -308,7 +308,7 @@
{{wizard-mapper - inputs=action.group + inputs=this.action.group property="group" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -333,7 +333,7 @@
{{wizard-mapper - inputs=action.url + inputs=this.action.url property="url" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -357,7 +357,7 @@
{{wizard-mapper - inputs=action.categories + inputs=this.action.categories property="categories" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -381,7 +381,7 @@
{{wizard-mapper - inputs=action.mute_remainder + inputs=this.action.mute_remainder property="mute_remainder" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -402,11 +402,11 @@
{{combo-box - value=action.notification_level + value=this.action.notification_level content=availableNotificationLevels - onChange=(action (mut action.notification_level)) + onChange=(action (mut this.action.notification_level)) options=(hash - isDisabled=action.custom_title_enabled + isDisabled=this.action.custom_title_enabled none="admin.wizard.action.watch_x.select_a_notification_level" ) }} @@ -430,7 +430,7 @@
{{wizard-mapper - inputs=action.usernames + inputs=this.action.usernames property="usernames" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -452,7 +452,7 @@
{{wizard-mapper - inputs=action.tags + inputs=this.action.tags property="tags" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -476,11 +476,11 @@
{{combo-box - value=action.notification_level + value=this.action.notification_level content=availableNotificationLevels - onChange=(action (mut action.notification_level)) + onChange=(action (mut this.action.notification_level)) options=(hash - isDisabled=action.custom_title_enabled + isDisabled=this.action.custom_title_enabled none="admin.wizard.action.watch_x.select_a_notification_level" ) }} @@ -504,7 +504,7 @@
{{wizard-mapper - inputs=action.usernames + inputs=this.action.usernames property="usernames" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -526,7 +526,7 @@
{{wizard-mapper - inputs=action.name + inputs=this.action.name property="name" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -545,7 +545,7 @@
{{wizard-mapper - inputs=action.full_name + inputs=this.action.full_name property="full_name" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -564,7 +564,7 @@
{{wizard-mapper - inputs=action.title + inputs=this.action.title property="title" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -583,7 +583,7 @@
{{wizard-mapper - inputs=action.bio_raw + inputs=this.action.bio_raw property="bio_raw" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -602,7 +602,7 @@
{{wizard-mapper - inputs=action.owner_usernames + inputs=this.action.owner_usernames property="owner_usernames" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -622,7 +622,7 @@
{{wizard-mapper - inputs=action.usernames + inputs=this.action.usernames property="usernames" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -644,7 +644,7 @@
{{wizard-mapper - inputs=action.grant_trust_level + inputs=this.action.grant_trust_level property="grant_trust_level" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -665,7 +665,7 @@
{{wizard-mapper - inputs=action.mentionable_level + inputs=this.action.mentionable_level property="mentionable_level" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -686,7 +686,7 @@
{{wizard-mapper - inputs=action.messageable_level + inputs=this.action.messageable_level property="messageable_level" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -707,7 +707,7 @@
{{wizard-mapper - inputs=action.visibility_level + inputs=this.action.visibility_level property="visibility_level" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -728,7 +728,7 @@
{{wizard-mapper - inputs=action.members_visibility_level + inputs=this.action.members_visibility_level property="members_visibility_level" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -750,7 +750,7 @@
{{wizard-mapper - inputs=action.name + inputs=this.action.name property="name" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -770,7 +770,7 @@
{{wizard-mapper - inputs=action.slug + inputs=this.action.slug property="slug" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -790,7 +790,7 @@
{{wizard-mapper - inputs=action.color + inputs=this.action.color property="color" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -810,7 +810,7 @@
{{wizard-mapper - inputs=action.text_color + inputs=this.action.text_color property="text_color" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -832,7 +832,7 @@
{{wizard-mapper - inputs=action.parent_category_id + inputs=this.action.parent_category_id property="parent_category_id" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -853,7 +853,7 @@
{{wizard-mapper - inputs=action.permissions + inputs=this.action.permissions property="permissions" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -878,7 +878,7 @@
{{wizard-mapper - inputs=action.custom_fields + inputs=this.action.custom_fields property="custom_fields" onUpdate=(action "mappedFieldUpdated") options=(hash @@ -903,7 +903,7 @@
{{wizard-mapper - inputs=action.required + inputs=this.action.required property="required" onUpdate=(action "mappedFieldUpdated") options=(hash diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs index 4138a254..de1f1d1d 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs @@ -1,11 +1,11 @@ {{wizard-mapper-connector - connector=input.type - connectors=inputTypes + connector=this.input.type + connectors=this.inputTypes inputTypes=true - inputType=inputType + inputType=this.inputType connectorType="type" - options=options - onUpdate=onUpdate + options=this.options + onUpdate=this.onUpdate }} {{#if hasPairs}} @@ -14,10 +14,10 @@ {{wizard-mapper-pair pair=pair last=pair.last - inputType=inputType - options=options + inputType=this.inputType + options=this.options removePair=(action "removePair") - onUpdate=onUpdate + onUpdate=this.onUpdate }} {{/each}} @@ -32,23 +32,23 @@ {{#if hasOutput}} {{#if hasPairs}} {{wizard-mapper-connector - connector=input.output_connector - connectors=connectors + connector=this.input.output_connector + connectors=this.connectors connectorType="output" - inputType=inputType - options=options - onUpdate=onUpdate + inputType=this.inputType + options=this.options + onUpdate=this.onUpdate }} {{/if}}
{{wizard-mapper-selector selectorType="output" - inputType=input.type - value=input.output - activeType=input.output_type - options=options - onUpdate=onUpdate + inputType=this.input.type + value=this.input.output + activeType=this.input.output_type + options=this.options + onUpdate=this.onUpdate }}
{{/if}} From 6c0d7a671ee933ee0869640dcfb8a7d529a5bb8a Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:18:47 +0100 Subject: [PATCH 11/46] more this additions --- .../discourse/templates/components/wizard-mapper-input.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs index de1f1d1d..d21a90c0 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs @@ -10,7 +10,7 @@ {{#if hasPairs}}
- {{#each input.pairs as |pair|}} + {{#each this.input.pairs as |pair|}} {{wizard-mapper-pair pair=pair last=pair.last @@ -53,6 +53,6 @@
{{/if}} - + {{d-icon "times"}} \ No newline at end of file From 31f917ec80e9957a5e9936dac5df78e8f2e18b83 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:34:18 +0100 Subject: [PATCH 12/46] fix replaceWith calling style deprecation --- .../javascripts/discourse/routes/custom-wizard-index.js.es6 | 5 ++++- .../javascripts/discourse/routes/custom-wizard-step.js.es6 | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 index 5ffe83c6..d024a0de 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 @@ -1,11 +1,14 @@ import { getCachedWizard } from "../models/custom-wizard"; import Route from "@ember/routing/route"; +import { inject as service } from '@ember/service'; export default Route.extend({ + router: service(), + beforeModel() { const wizard = getCachedWizard(); if (wizard && wizard.permitted && !wizard.completed && wizard.start) { - this.replaceWith("customWizardStep", wizard.start); + this.router.replaceWith("customWizardStep", wizard.start); } }, diff --git a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 index a882340b..c7ba1cf6 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 @@ -3,14 +3,17 @@ import { getCachedWizard } from "../models/custom-wizard"; import Route from "@ember/routing/route"; import { scrollTop } from "discourse/mixins/scroll-top"; import { action } from "@ember/object"; +import { inject as service } from '@ember/service'; export default Route.extend({ + router: service(), + beforeModel() { const wizard = getCachedWizard(); this.set("wizard", wizard); if (!wizard || !wizard.permitted || wizard.completed) { - this.replaceWith("customWizard"); + this.router.replaceWith("customWizard"); } }, From e6f44b7dfcf5ec73e07944559b2cbe2880eba59a Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:42:12 +0100 Subject: [PATCH 13/46] resolve a batch of router deprecations --- .../discourse/routes/admin-wizards-api-show.js.es6 | 5 ++++- .../discourse/routes/admin-wizards-api.js.es6 | 9 ++++++--- .../discourse/routes/admin-wizards-logs-show.js.es6 | 5 ++++- .../discourse/routes/admin-wizards-logs.js.es6 | 5 ++++- .../routes/admin-wizards-submissions-show.js.es6 | 5 ++++- .../discourse/routes/admin-wizards-submissions.js.es6 | 5 ++++- .../discourse/routes/admin-wizards-wizard-show.js.es6 | 5 ++++- .../discourse/routes/admin-wizards-wizard.js.es6 | 11 +++++++---- .../javascripts/discourse/routes/admin-wizards.js.es6 | 5 ++++- .../discourse/routes/custom-wizard-step.js.es6 | 2 +- 10 files changed, 42 insertions(+), 15 deletions(-) diff --git a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 index bfe90f72..b405cf95 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 @@ -1,7 +1,10 @@ import CustomWizardApi from "../models/custom-wizard-api"; import DiscourseRoute from "discourse/routes/discourse"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model(params) { if (params.name === "create") { return CustomWizardApi.create({ isNew: true }); @@ -12,7 +15,7 @@ export default DiscourseRoute.extend({ afterModel(model) { if (model === null) { - return this.transitionTo("adminWizardsApi"); + return this.router.transitionTo("adminWizardsApi"); } }, diff --git a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 index 541ab028..e96160a6 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 @@ -1,7 +1,10 @@ import DiscourseRoute from "discourse/routes/discourse"; import CustomWizardApi from "../models/custom-wizard-api"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model() { return CustomWizardApi.list(); }, @@ -25,11 +28,11 @@ export default DiscourseRoute.extend({ actions: { changeApi(apiName) { this.controllerFor("adminWizardsApi").set("apiName", apiName); - this.transitionTo("adminWizardsApiShow", apiName); + this.router.transitionTo("adminWizardsApiShow", apiName); }, afterDestroy() { - this.transitionTo("adminWizardsApi").then(() => this.refresh()); + this.router.transitionTo("adminWizardsApi").then(() => this.refresh()); }, afterSave(apiName) { @@ -38,7 +41,7 @@ export default DiscourseRoute.extend({ createApi() { this.controllerFor("adminWizardsApi").set("apiName", "create"); - this.transitionTo("adminWizardsApiShow", "create"); + this.router.transitionTo("adminWizardsApiShow", "create"); }, }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 index e1f53c8f..497f66cf 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 @@ -1,15 +1,18 @@ import CustomWizardLogs from "../models/custom-wizard-logs"; import DiscourseRoute from "discourse/routes/discourse"; import { A } from "@ember/array"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model(params) { return CustomWizardLogs.list(params.wizardId); }, afterModel(model) { if (model === null) { - return this.transitionTo("adminWizardsLogs"); + return this.router.transitionTo("adminWizardsLogs"); } }, diff --git a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 index a1575050..414dc87c 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 @@ -1,7 +1,10 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model() { return ajax(`/admin/wizards/wizard`); }, @@ -18,7 +21,7 @@ export default DiscourseRoute.extend({ actions: { changeWizard(wizardId) { this.controllerFor("adminWizardsLogs").set("wizardId", wizardId); - this.transitionTo("adminWizardsLogsShow", wizardId); + this.router.transitionTo("adminWizardsLogsShow", wizardId); }, }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 index b9dbd90f..4f267b49 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -2,15 +2,18 @@ import { A } from "@ember/array"; import CustomWizardAdmin from "../models/custom-wizard-admin"; import DiscourseRoute from "discourse/routes/discourse"; import { formatModel } from "../lib/wizard-submission"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model(params) { return CustomWizardAdmin.submissions(params.wizardId); }, afterModel(model) { if (model === null) { - return this.transitionTo("adminWizardsSubmissions"); + return this.router.transitionTo("adminWizardsSubmissions"); } }, diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 index 9ecb183d..3229bd8c 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 @@ -1,7 +1,10 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model() { return ajax(`/admin/wizards/wizard`); }, @@ -18,7 +21,7 @@ export default DiscourseRoute.extend({ actions: { changeWizard(wizardId) { this.controllerFor("adminWizardsSubmissions").set("wizardId", wizardId); - this.transitionTo("adminWizardsSubmissionsShow", wizardId); + this.router.transitionTo("adminWizardsSubmissionsShow", wizardId); }, }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 index f55ff19e..2dde4788 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -2,8 +2,11 @@ import CustomWizardAdmin from "../models/custom-wizard-admin"; import { ajax } from "discourse/lib/ajax"; import DiscourseRoute from "discourse/routes/discourse"; import I18n from "I18n"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model(params) { if (params.wizardId === "create") { return { create: true }; @@ -14,7 +17,7 @@ export default DiscourseRoute.extend({ afterModel(model) { if (model.none) { - return this.transitionTo("adminWizardsWizard"); + return this.router.transitionTo("adminWizardsWizard"); } }, diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 index b23b63f6..6c984b48 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 @@ -4,8 +4,11 @@ import EmberObject, { set } from "@ember/object"; import { A } from "@ember/array"; import { all } from "rsvp"; import { ajax } from "discourse/lib/ajax"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model() { return ajax("/admin/wizards/wizard"); }, @@ -80,14 +83,14 @@ export default DiscourseRoute.extend({ this.controllerFor("adminWizardsWizard").set("wizardId", wizardId); if (wizardId) { - this.transitionTo("adminWizardsWizardShow", wizardId); + this.router.transitionTo("adminWizardsWizardShow", wizardId); } else { - this.transitionTo("adminWizardsWizard"); + this.router.transitionTo("adminWizardsWizard"); } }, afterDestroy() { - this.transitionTo("adminWizardsWizard").then(() => this.refresh()); + this.router.transitionTo("adminWizardsWizard").then(() => this.refresh()); }, afterSave(wizardId) { @@ -96,7 +99,7 @@ export default DiscourseRoute.extend({ createWizard() { this.controllerFor("adminWizardsWizard").set("wizardId", "create"); - this.transitionTo("adminWizardsWizardShow", "create"); + this.router.transitionTo("adminWizardsWizardShow", "create"); }, }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index 1fa786d3..b29fccec 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -1,7 +1,10 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; +import { inject as service } from '@ember/service'; export default DiscourseRoute.extend({ + router: service(), + model() { return ajax("/admin/wizards"); }, @@ -17,7 +20,7 @@ export default DiscourseRoute.extend({ afterModel(model, transition) { if (transition.targetName === "adminWizards.index") { - this.transitionTo("adminWizardsWizard"); + this.router.transitionTo("adminWizardsWizard"); } }, }); diff --git a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 index c7ba1cf6..1ad41fbf 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 @@ -30,7 +30,7 @@ export default Route.extend({ afterModel(model) { if (model.completed) { - return this.transitionTo("wizard.index"); + return this.router.transitionTo("wizard.index"); } return model.set("wizardId", this.wizard.id); }, From 33a320021f4a746d722c85bd348328d89b26a428 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:47:52 +0100 Subject: [PATCH 14/46] linting --- .../javascripts/discourse/routes/admin-wizards-api-show.js.es6 | 2 +- assets/javascripts/discourse/routes/admin-wizards-api.js.es6 | 2 +- .../javascripts/discourse/routes/admin-wizards-logs-show.js.es6 | 2 +- assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 | 2 +- .../discourse/routes/admin-wizards-submissions-show.js.es6 | 2 +- .../discourse/routes/admin-wizards-submissions.js.es6 | 2 +- .../discourse/routes/admin-wizards-wizard-show.js.es6 | 2 +- assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 | 2 +- assets/javascripts/discourse/routes/admin-wizards.js.es6 | 2 +- assets/javascripts/discourse/routes/custom-wizard-index.js.es6 | 2 +- assets/javascripts/discourse/routes/custom-wizard-step.js.es6 | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 index b405cf95..a431e9ae 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 @@ -1,6 +1,6 @@ import CustomWizardApi from "../models/custom-wizard-api"; import DiscourseRoute from "discourse/routes/discourse"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 index e96160a6..2b108460 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; import CustomWizardApi from "../models/custom-wizard-api"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 index 497f66cf..9c096a1e 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-logs-show.js.es6 @@ -1,7 +1,7 @@ import CustomWizardLogs from "../models/custom-wizard-logs"; import DiscourseRoute from "discourse/routes/discourse"; import { A } from "@ember/array"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 index 414dc87c..6bb5864b 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 index 4f267b49..e9bad625 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -2,7 +2,7 @@ import { A } from "@ember/array"; import CustomWizardAdmin from "../models/custom-wizard-admin"; import DiscourseRoute from "discourse/routes/discourse"; import { formatModel } from "../lib/wizard-submission"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 index 3229bd8c..dc0ef5e0 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 index 2dde4788..2ed2627f 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -2,7 +2,7 @@ import CustomWizardAdmin from "../models/custom-wizard-admin"; import { ajax } from "discourse/lib/ajax"; import DiscourseRoute from "discourse/routes/discourse"; import I18n from "I18n"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 index 6c984b48..6ae31e82 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 @@ -4,7 +4,7 @@ import EmberObject, { set } from "@ember/object"; import { A } from "@ember/array"; import { all } from "rsvp"; import { ajax } from "discourse/lib/ajax"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index b29fccec..ff8a949a 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; import { ajax } from "discourse/lib/ajax"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 index d024a0de..78495607 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-index.js.es6 @@ -1,6 +1,6 @@ import { getCachedWizard } from "../models/custom-wizard"; import Route from "@ember/routing/route"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default Route.extend({ router: service(), diff --git a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 index 1ad41fbf..963307e7 100644 --- a/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/routes/custom-wizard-step.js.es6 @@ -3,7 +3,7 @@ import { getCachedWizard } from "../models/custom-wizard"; import Route from "@ember/routing/route"; import { scrollTop } from "discourse/mixins/scroll-top"; import { action } from "@ember/object"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default Route.extend({ router: service(), From 742239b0233b34ffc95d615fa34e163dac2e6046 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:58:34 +0100 Subject: [PATCH 15/46] add router service to controllers to avoid deprecation --- .../discourse/controllers/admin-wizards-api-show.js.es6 | 5 ++++- .../discourse/controllers/custom-wizard-step.js.es6 | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 index c08e820c..66b62da2 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 @@ -7,8 +7,11 @@ import { selectKitContent } from "../lib/wizard"; import { underscore } from "@ember/string"; import Controller from "@ember/controller"; import I18n from "I18n"; +import { inject as service } from '@ember/service'; export default Controller.extend({ + router: service(), + queryParams: ["refresh_list"], loadingSubscriptions: false, notAuthorized: not("api.authorized"), @@ -248,7 +251,7 @@ export default Controller.extend({ .catch(popupAjaxError) .then((result) => { if (result.success) { - this.transitionToRoute("adminWizardsApis").then(() => { + this.router.transitionToRoute("adminWizardsApis").then(() => { this.send("refreshModel"); }); } diff --git a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 index 2dca2e70..7efd9782 100644 --- a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 @@ -1,7 +1,9 @@ import Controller from "@ember/controller"; import getUrl from "discourse-common/lib/get-url"; +import { inject as service } from '@ember/service'; export default Controller.extend({ + router: service(), wizard: null, step: null, @@ -15,12 +17,12 @@ export default Controller.extend({ const wizardId = this.get("wizard.id"); window.location.href = getUrl(`/w/${wizardId}/steps/${nextStepId}`); } else { - this.transitionToRoute("customWizardStep", nextStepId); + this.router.transitionToRoute("customWizardStep", nextStepId); } }, goBack() { - this.transitionToRoute("customWizardStep", this.get("step.previous")); + this.router.transitionToRoute("customWizardStep", this.get("step.previous")); }, showMessage(message) { From 3c17ef574ec978d22bde7c3ab7d07f5b62029b47 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 14:59:22 +0100 Subject: [PATCH 16/46] linting --- .../discourse/controllers/admin-wizards-api-show.js.es6 | 2 +- .../javascripts/discourse/controllers/custom-wizard-step.js.es6 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 index 66b62da2..f847422e 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 @@ -7,7 +7,7 @@ import { selectKitContent } from "../lib/wizard"; import { underscore } from "@ember/string"; import Controller from "@ember/controller"; import I18n from "I18n"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default Controller.extend({ router: service(), diff --git a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 index 7efd9782..7b248474 100644 --- a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 @@ -1,6 +1,6 @@ import Controller from "@ember/controller"; import getUrl from "discourse-common/lib/get-url"; -import { inject as service } from '@ember/service'; +import { inject as service } from "@ember/service"; export default Controller.extend({ router: service(), From 27596a1624b36a036b57c5865b537783efacfda4 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 15:03:15 +0100 Subject: [PATCH 17/46] linting --- .../discourse/controllers/custom-wizard-step.js.es6 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 index 7b248474..f38747d1 100644 --- a/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/controllers/custom-wizard-step.js.es6 @@ -22,7 +22,10 @@ export default Controller.extend({ }, goBack() { - this.router.transitionToRoute("customWizardStep", this.get("step.previous")); + this.router.transitionToRoute( + "customWizardStep", + this.get("step.previous") + ); }, showMessage(message) { From d71d9976b81594c7d2ef97817845f87b9313f0e0 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 15:05:54 +0100 Subject: [PATCH 18/46] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index ef83b548..40b30334 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.20 +# version: 2.4.21 # 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 From 6572b32706961bf45bdfe343dba2318704c2da06 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 19:14:44 +0100 Subject: [PATCH 19/46] move modals to glimmer components --- .../modal/admin-wizards-columns.hbs | 35 +++++++++++++++++++ .../components/modal/admin-wizards-columns.js | 14 ++++++++ .../modal/next-session-scheduled.hbs | 20 +++++++++++ .../modal/next-session-scheduled.js | 29 +++++++++++++++ .../controllers/admin-wizards-columns.js.es6 | 14 -------- .../admin-wizards-submissions-show.js.es6 | 6 ++-- .../admin-wizards-wizard-show.js.es6 | 8 +++-- .../controllers/next-session-scheduled.js.es6 | 30 ---------------- .../templates/modal/admin-wizards-columns.hbs | 35 ------------------- .../modal/next-session-scheduled.hbs | 17 --------- 10 files changed, 107 insertions(+), 101 deletions(-) create mode 100644 assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs create mode 100644 assets/javascripts/discourse/components/modal/admin-wizards-columns.js create mode 100644 assets/javascripts/discourse/components/modal/next-session-scheduled.hbs create mode 100644 assets/javascripts/discourse/components/modal/next-session-scheduled.js delete mode 100644 assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 delete mode 100644 assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 delete mode 100644 assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs delete mode 100644 assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs new file mode 100644 index 00000000..f83a92a0 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs @@ -0,0 +1,35 @@ + + {{#if loading}} + + {{else}} +
+ {{#each this.args.model.columns as |column|}} +
+
+ +
+
+ {{/each}} +
+ {{/if}} + +
+ diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.js b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js new file mode 100644 index 00000000..87c6673f --- /dev/null +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js @@ -0,0 +1,14 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; + +export default class AdminWizardsColumnComponent extends Component { + title = I18n.t("admin.wizard.edit_columns"); + + @action save() { + this.args.closeModal(); + } + + @action resetToDefault() { + this.args.model.reset(); + } +} diff --git a/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs b/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs new file mode 100644 index 00000000..62d291f2 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/assets/javascripts/discourse/components/modal/next-session-scheduled.js b/assets/javascripts/discourse/components/modal/next-session-scheduled.js new file mode 100644 index 00000000..890ecc73 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/next-session-scheduled.js @@ -0,0 +1,29 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; + +export default class NextSessionScheduledComponent extends Component { + @tracked bufferedDateTime; + title = I18n.t("admin.wizard.after_time_modal.title"); + + constructor() { + super(...arguments); + this.bufferedDateTime = this.args.model.dateTime + ? moment(this.args.model.dateTime) + : moment(Date.now()); + } + + get submitDisabled() { + return moment().isAfter(this.bufferedDateTime); + } + + @action submit() { + const dateTime = this.bufferedDateTime; + this.args.model.update(moment(dateTime).utc().toISOString()); + this.args.closeModal(); + } + + @action dateTimeChanged(dateTime) { + this.bufferedDateTime = dateTime; + } +} diff --git a/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 deleted file mode 100644 index 4754c577..00000000 --- a/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 +++ /dev/null @@ -1,14 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default Controller.extend(ModalFunctionality, { - actions: { - save() { - this.send("closeModal"); - }, - - resetToDefault() { - this.get("model.reset")(); - }, - }, -}); diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 41dabbb4..dfcf3b7e 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -2,11 +2,13 @@ import Controller from "@ember/controller"; import { empty } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; import { fmt } from "discourse/lib/computed"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; +import AdminWizardsColumnsModal from "../components/modal/admin-wizards-columns"; import CustomWizardAdmin from "../models/custom-wizard-admin"; import { formatModel } from "../lib/wizard-submission"; export default Controller.extend({ + modal: service(), downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), noResults: empty("submissions"), page: 0, @@ -57,7 +59,7 @@ export default Controller.extend({ }, showEditColumnsModal() { - return showModal("admin-wizards-columns", { + return this.modal.show(AdminWizardsColumnsModal, { model: { columns: this.get("fields"), reset: () => { diff --git a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 index 75ea0ff7..6fa38b0b 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 @@ -3,7 +3,8 @@ import { observes, } from "discourse-common/utils/decorators"; import { notEmpty } from "@ember/object/computed"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; +import NextSessionScheduledModal from "../components/modal/next-session-scheduled"; import { generateId, wizardFieldList } from "../lib/wizard"; import { dasherize } from "@ember/string"; import { later, scheduleOnce } from "@ember/runloop"; @@ -13,6 +14,7 @@ import I18n from "I18n"; import { filterValues } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; export default Controller.extend({ + modal: service(), hasName: notEmpty("wizard.name"), @observes("currentStep") @@ -126,7 +128,7 @@ export default Controller.extend({ }, setNextSessionScheduled() { - let controller = showModal("next-session-scheduled", { + this.modal.show(NextSessionScheduledModal, { model: { dateTime: this.wizard.after_time_scheduled, update: (dateTime) => @@ -134,7 +136,7 @@ export default Controller.extend({ }, }); - controller.setup(); + // controller.setup(); }, copyUrl() { diff --git a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 deleted file mode 100644 index b8f51d1f..00000000 --- a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 +++ /dev/null @@ -1,30 +0,0 @@ -import { default as discourseComputed } from "discourse-common/utils/decorators"; -import Controller from "@ember/controller"; - -export default Controller.extend({ - title: "admin.wizard.after_time_modal.title", - - setup() { - this.set( - "bufferedDateTime", - this.model.dateTime ? moment(this.model.dateTime) : moment(Date.now()) - ); - }, - - @discourseComputed("bufferedDateTime") - submitDisabled(dateTime) { - return moment().isAfter(dateTime); - }, - - actions: { - submit() { - const dateTime = this.get("bufferedDateTime"); - this.get("model.update")(moment(dateTime).utc().toISOString()); - this.send("closeModal"); - }, - - dateTimeChanged(dateTime) { - this.set("bufferedDateTime", dateTime); - }, - }, -}); diff --git a/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs deleted file mode 100644 index b37a92bf..00000000 --- a/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs +++ /dev/null @@ -1,35 +0,0 @@ -{{#d-modal-body title="admin.wizard.edit_columns"}} - {{#if loading}} - {{loading-spinner size="large"}} - {{else}} -
- {{#each model.columns as |column|}} -
-
- -
-
- {{/each}} -
- {{/if}} -{{/d-modal-body}} - - \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs b/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs deleted file mode 100644 index c7e52a56..00000000 --- a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs +++ /dev/null @@ -1,17 +0,0 @@ -{{#d-modal-body class="next-session-time-modal" title=title}} - {{date-time-input - date=bufferedDateTime - onChange=(action "dateTimeChanged") - showTime=true - clearable=true - }} -{{/d-modal-body}} - - \ No newline at end of file From 76c359be3b3905d23834fe723b9de548bf5e6b2f Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 19:16:59 +0100 Subject: [PATCH 20/46] linting --- .../discourse/components/modal/admin-wizards-columns.hbs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs index f83a92a0..1a8f7fbb 100644 --- a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs @@ -31,5 +31,4 @@ @action={{action "resetToDefault"}} />
- - + \ No newline at end of file From 794b7c9d5c6ec5f36e3a597935c140b3fb68fb43 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 19:19:20 +0100 Subject: [PATCH 21/46] add missing I18n imports --- .../discourse/components/modal/admin-wizards-columns.js | 1 + .../discourse/components/modal/next-session-scheduled.js | 1 + 2 files changed, 2 insertions(+) diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.js b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js index 87c6673f..d4da771e 100644 --- a/assets/javascripts/discourse/components/modal/admin-wizards-columns.js +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; +import I18n from "I18n"; export default class AdminWizardsColumnComponent extends Component { title = I18n.t("admin.wizard.edit_columns"); diff --git a/assets/javascripts/discourse/components/modal/next-session-scheduled.js b/assets/javascripts/discourse/components/modal/next-session-scheduled.js index 890ecc73..446237f0 100644 --- a/assets/javascripts/discourse/components/modal/next-session-scheduled.js +++ b/assets/javascripts/discourse/components/modal/next-session-scheduled.js @@ -1,6 +1,7 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; +import I18n from "I18n"; export default class NextSessionScheduledComponent extends Component { @tracked bufferedDateTime; From a786b5956beaca47b6b43e83467ec337a88bc7bd Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 19:21:10 +0100 Subject: [PATCH 22/46] linting --- .../discourse/components/modal/admin-wizards-columns.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs index 1a8f7fbb..5e3829da 100644 --- a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs @@ -3,7 +3,7 @@ {{else}}
- {{#each this.args.model.columns as |column|}} + {{#each @model.columns as |column|}}
\ No newline at end of file From 2460685e65e4db8b356a31f653a472a6248d9693 Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 15 Sep 2023 07:04:17 +0100 Subject: [PATCH 29/46] remove unintentional comment --- .../discourse/controllers/admin-wizards-wizard-show.js.es6 | 2 -- 1 file changed, 2 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 index 6fa38b0b..7ae48709 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 @@ -135,8 +135,6 @@ export default Controller.extend({ this.set("wizard.after_time_scheduled", dateTime), }, }); - - // controller.setup(); }, copyUrl() { From 43cd090b17538e1bbc8e3be7f700c51523e9289a Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 15 Sep 2023 16:15:31 +0100 Subject: [PATCH 30/46] FIX: avoid page limit on downloads --- app/controllers/custom_wizard/admin/submissions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/custom_wizard/admin/submissions.rb b/app/controllers/custom_wizard/admin/submissions.rb index 72f0961a..d5994c96 100644 --- a/app/controllers/custom_wizard/admin/submissions.rb +++ b/app/controllers/custom_wizard/admin/submissions.rb @@ -23,7 +23,7 @@ class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController def download content = ActiveModel::ArraySerializer.new( - submission_list.submissions, + CustomWizard::Submission.list(@wizard).submissions, each_serializer: CustomWizard::SubmissionSerializer ) From 16109b01e755c7697350b38ecf202dc0e803d8de Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 15 Sep 2023 16:19:09 +0100 Subject: [PATCH 31/46] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 40b30334..0634ef8c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.21 +# version: 2.4.22 # 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 From f2d1437cff98e697bb24469c3867fb832e6f6f2f Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:35:38 -0400 Subject: [PATCH 32/46] DEV: Implement wizard replacement validation in Topic Creation --- config/locales/server.en.yml | 2 ++ .../extensions/topic_extension.rb | 23 +++++++++++++++++++ plugin.rb | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 lib/custom_wizard/extensions/topic_extension.rb diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index e8ceb44b..4056d885 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -55,6 +55,8 @@ en: liquid_syntax_error: "Liquid syntax error in %{attribute}: %{message}" subscription: "%{type} %{property} usage is not supported on your subscription" not_permitted_for_guests: "%{object_id} is not permitted when guests can access the wizard" + error_messages: + wizard_replacing_composer: "A wizard is set to replace the composer in this category. You cannot create a topic here." site_settings: custom_wizard_enabled: "Enable custom wizards." diff --git a/lib/custom_wizard/extensions/topic_extension.rb b/lib/custom_wizard/extensions/topic_extension.rb new file mode 100644 index 00000000..395a58cc --- /dev/null +++ b/lib/custom_wizard/extensions/topic_extension.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module CustomWizardTopicExtension + extend ActiveSupport::Concern + + included { before_validation :check_wizard_replacement, on: :create } + + def check_wizard_replacement + if wizard_replacing_composer?(self.category_id) + self.errors.add( + :base, + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) + end + end + + def wizard_replacing_composer?(category_id) + return false unless category_id + + category = Category.find(category_id) + category.custom_fields['create_topic_wizard'].present? + end +end diff --git a/plugin.rb b/plugin.rb index 0634ef8c..a2df919b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -91,6 +91,7 @@ after_initialize do ../lib/custom_wizard/extensions/invites_controller.rb ../lib/custom_wizard/extensions/users_controller.rb ../lib/custom_wizard/extensions/guardian.rb + ../lib/custom_wizard/extensions/topic_extension.rb ../lib/custom_wizard/extensions/custom_field/preloader.rb ../lib/custom_wizard/extensions/custom_field/serializer.rb ../lib/custom_wizard/extensions/custom_field/extension.rb @@ -200,6 +201,7 @@ after_initialize do ::InvitesController.prepend InvitesControllerCustomWizard ::UsersController.prepend CustomWizardUsersController ::Guardian.prepend CustomWizardGuardian + ::Topic.include CustomWizardTopicExtension full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss" if Stylesheet::Importer.respond_to?(:plugin_assets) From 29d7818a4a4b5fdfd6245b7cfbd91d24d0bb028c Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:36:21 -0400 Subject: [PATCH 33/46] DEV: Add spec for validation --- spec/extensions/topic_extension_spec.rb | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/extensions/topic_extension_spec.rb diff --git a/spec/extensions/topic_extension_spec.rb b/spec/extensions/topic_extension_spec.rb new file mode 100644 index 00000000..e4fabfea --- /dev/null +++ b/spec/extensions/topic_extension_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class DummyTopic < Topic + include CustomWizardTopicExtension +end + +describe DummyTopic, type: :model do + fab!(:category_with_wizard) do + Fabricate(:category, custom_fields: { create_topic_wizard: 'true' }) + end + fab!(:category_without_wizard) { Fabricate(:category) } + fab!(:user) { Fabricate(:user) } + + context 'when the category has a create_topic_wizard custom field' do + it 'does not allow creating a topic directly' do + topic = DummyTopic.new(user: user, category: category_with_wizard) + topic.valid? + expect(topic.errors[:base]).to include( + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) + end + end + + context 'when the category does not have a create_topic_wizard custom field' do + it 'allows creating a topic directly' do + topic = + DummyTopic.new( + user: user, + category: category_without_wizard, + title: 'A valid topic title' + ) + is_valid = topic.valid? + puts topic.errors.full_messages unless is_valid + expect(is_valid).to be_truthy + end + end +end From de03cbd15ae87e20280736ecdabd5c425f982c32 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:39:50 -0400 Subject: [PATCH 34/46] DEV: Implement control to hide category from composer dropdown in specified categories --- .../custom-wizard-category-settings.hbs | 11 +++++++++++ .../custom-wizard-category-settings.js.es6 | 11 +++++++++++ config/locales/client.en.yml | 1 + 3 files changed, 23 insertions(+) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs index 2c6a6975..1d316fe2 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs @@ -12,4 +12,15 @@ options=(hash none="admin.wizard.select") }}
+ +
+ +
\ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 index 7004c317..552ee193 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 @@ -13,6 +13,10 @@ export default { "wizardListVal", attrs?.category?.custom_fields?.create_topic_wizard ); + component.set( + "hideFromComposer", + attrs?.category?.custom_fields?.custom_wizard_hide_from_composer + ); }, actions: { @@ -20,5 +24,12 @@ export default { this.set("wizardListVal", wizard); this.set("category.custom_fields.create_topic_wizard", wizard); }, + toggleHideFromComposer() { + this.toggleProperty("hideFromComposer"); + this.set( + "category.custom_fields.custom_wizard_hide_from_composer", + this.hideFromComposer + ); + }, }, }; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 98519335..1fd9f158 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -133,6 +133,7 @@ en: custom_wizard: title: "Custom Wizard" create_topic_wizard: "Select a wizard to replace the new topic composer in this category." + hide_from_composer: "Exclude category from composer dropdown" message: wizard: From b365b5dd4ffb5c847e4c2fcfdb0e83e9fa6734e7 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:40:07 -0400 Subject: [PATCH 35/46] DEV: Add custom_field --- plugin.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.rb b/plugin.rb index a2df919b..6559e469 100644 --- a/plugin.rb +++ b/plugin.rb @@ -105,6 +105,7 @@ after_initialize do # preloaded category custom fields %w[ create_topic_wizard + custom_wizard_hide_from_composer ].each do |custom_field| Site.preloaded_category_custom_fields << custom_field end From 61309fd3205aff693783d1862b082248abda5f6c Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:40:44 -0400 Subject: [PATCH 36/46] DEV: Add initializer logic to filter categories --- .../discourse/initializers/custom-wizard-edits.js.es6 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index c974fafb..fa1b753c 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -2,6 +2,7 @@ import DiscourseURL from "discourse/lib/url"; import { withPluginApi } from "discourse/lib/plugin-api"; import getUrl from "discourse-common/lib/get-url"; import { observes } from "discourse-common/utils/decorators"; +import Category from "discourse/models/category"; export default { name: "custom-wizard-edits", @@ -83,6 +84,16 @@ export default { } }, }); + + api.modifyClass("component:category-chooser", { + categoriesByScope(options = {}) { + let categories = this._super(options); + + return categories.filter((category) => { + return !category.custom_fields?.custom_wizard_hide_from_composer; + }); + }, + }); }); }, }; From bb3f0c62528b664c5792b1a041d4990fd1f35d13 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:41:24 -0400 Subject: [PATCH 37/46] DEV: Add acceptance tests for category filtering --- .../category-chooser-initializer-test.js | 21 +++++++++++++++++++ test/javascripts/fixtures/categories.js.es6 | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 test/javascripts/acceptance/category-chooser-initializer-test.js diff --git a/test/javascripts/acceptance/category-chooser-initializer-test.js b/test/javascripts/acceptance/category-chooser-initializer-test.js new file mode 100644 index 00000000..a5ca3b2a --- /dev/null +++ b/test/javascripts/acceptance/category-chooser-initializer-test.js @@ -0,0 +1,21 @@ +import { click, visit } from "@ember/test-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import selectKit from "discourse/tests/helpers/select-kit-helper"; +import { test } from "qunit"; + +acceptance("CategoryChooser", function (needs) { + needs.user(); + needs.settings({ + allow_uncategorized_topics: false, + }); + + test("does not display category with custom_wizard_hide_from_composer set to 't'", async function (assert) { + const categoryChooser = selectKit(".category-chooser"); + + await visit("/"); + await click("#create-topic"); + await categoryChooser.expand(); + + assert.ok(categoryChooser.rowByIndex(4).name() !== "Custom Categories"); + }); +}); diff --git a/test/javascripts/fixtures/categories.js.es6 b/test/javascripts/fixtures/categories.js.es6 index e553f860..432a1b77 100644 --- a/test/javascripts/fixtures/categories.js.es6 +++ b/test/javascripts/fixtures/categories.js.es6 @@ -33,6 +33,7 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, + custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -77,6 +78,7 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, + custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -121,6 +123,7 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, + custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -165,6 +168,7 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, + custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -206,6 +210,7 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, + custom_wizard_hide_from_composer: "t", }, allowed_tags: [], allowed_tag_groups: [], From de9dccf23391a86e19e720f3bcc4fa2fd9cbe419 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:46:41 -0400 Subject: [PATCH 38/46] bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 6559e469..af82879b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.4.22 +# version: 2.4.23 # 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 From 2ab15aaf8649697ab19c17adea43f1dd9670007b Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 18:06:52 -0400 Subject: [PATCH 39/46] FIX: linting error --- .../category-custom-settings/custom-wizard-category-settings.hbs | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs index 1d316fe2..8af4d974 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs @@ -22,5 +22,4 @@ /> {{i18n "admin.wizard.category_settings.custom_wizard.hide_from_composer"}} - \ No newline at end of file From bdd290f4e680e3e41936661bc73022ca97482787 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 18:07:27 -0400 Subject: [PATCH 40/46] FIX: Linting error --- .../custom-wizard-category-settings.hbs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs index 8af4d974..f548e93f 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs @@ -14,12 +14,12 @@
- +
\ No newline at end of file From 03ef41f7f05e2df8283d18bd768fc181dd52fb4c Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 18:11:20 -0400 Subject: [PATCH 41/46] FIX: Linting error --- .../discourse/initializers/custom-wizard-edits.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index fa1b753c..5019ef83 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -2,7 +2,6 @@ import DiscourseURL from "discourse/lib/url"; import { withPluginApi } from "discourse/lib/plugin-api"; import getUrl from "discourse-common/lib/get-url"; import { observes } from "discourse-common/utils/decorators"; -import Category from "discourse/models/category"; export default { name: "custom-wizard-edits", From bb81c5700ab08214e928826b578ae3b6d4439b35 Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 19 Sep 2023 13:57:11 -0400 Subject: [PATCH 42/46] DEV: Use Discourse Events instead of topic model --- config/locales/server.en.yml | 2 +- .../extensions/topic_extension.rb | 27 +++------- plugin.rb | 3 +- spec/extensions/topic_extension_spec.rb | 50 +++++++++++-------- 4 files changed, 37 insertions(+), 45 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 4056d885..9fa23d53 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -56,7 +56,7 @@ en: subscription: "%{type} %{property} usage is not supported on your subscription" not_permitted_for_guests: "%{object_id} is not permitted when guests can access the wizard" error_messages: - wizard_replacing_composer: "A wizard is set to replace the composer in this category. You cannot create a topic here." + wizard_replacing_composer: "Category not allowed for topic creation." site_settings: custom_wizard_enabled: "Enable custom wizards." diff --git a/lib/custom_wizard/extensions/topic_extension.rb b/lib/custom_wizard/extensions/topic_extension.rb index 395a58cc..e890f9df 100644 --- a/lib/custom_wizard/extensions/topic_extension.rb +++ b/lib/custom_wizard/extensions/topic_extension.rb @@ -1,23 +1,8 @@ -# frozen_string_literal: true - -module CustomWizardTopicExtension - extend ActiveSupport::Concern - - included { before_validation :check_wizard_replacement, on: :create } - - def check_wizard_replacement - if wizard_replacing_composer?(self.category_id) - self.errors.add( - :base, - I18n.t('wizard.error_messages.wizard_replacing_composer') - ) - end - end - - def wizard_replacing_composer?(category_id) - return false unless category_id - - category = Category.find(category_id) - category.custom_fields['create_topic_wizard'].present? +DiscourseEvent.on(:before_create_topic) do |topic_params, user| + category = topic_params.category + if category&.custom_fields&.[]('create_topic_wizard').present? + raise Discourse::InvalidParameters.new( + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) end end diff --git a/plugin.rb b/plugin.rb index af82879b..a16d47d1 100644 --- a/plugin.rb +++ b/plugin.rb @@ -202,8 +202,7 @@ after_initialize do ::InvitesController.prepend InvitesControllerCustomWizard ::UsersController.prepend CustomWizardUsersController ::Guardian.prepend CustomWizardGuardian - ::Topic.include CustomWizardTopicExtension - + full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss" if Stylesheet::Importer.respond_to?(:plugin_assets) Stylesheet::Importer.plugin_assets['wizard_custom'] = Set[full_path] diff --git a/spec/extensions/topic_extension_spec.rb b/spec/extensions/topic_extension_spec.rb index e4fabfea..da4f416e 100644 --- a/spec/extensions/topic_extension_spec.rb +++ b/spec/extensions/topic_extension_spec.rb @@ -1,37 +1,45 @@ # frozen_string_literal: true -class DummyTopic < Topic - include CustomWizardTopicExtension -end - -describe DummyTopic, type: :model do +describe Topic, type: :model do fab!(:category_with_wizard) do Fabricate(:category, custom_fields: { create_topic_wizard: 'true' }) end fab!(:category_without_wizard) { Fabricate(:category) } fab!(:user) { Fabricate(:user) } + let(:valid_attrs) { Fabricate.attributes_for(:topic) } - context 'when the category has a create_topic_wizard custom field' do - it 'does not allow creating a topic directly' do - topic = DummyTopic.new(user: user, category: category_with_wizard) - topic.valid? - expect(topic.errors[:base]).to include( - I18n.t('wizard.error_messages.wizard_replacing_composer') + context 'with a create_topic_wizard custom field in the category' do + it 'will not allow creating a topic directly' do + expect do + TopicCreator.create( + user, + Guardian.new(user), + valid_attrs.merge( + title: 'A valid and sufficiently long title for testing', + category: category_with_wizard.id, + raw: 'hello this is a test topic with category with custom fields' + ) + ) + end.to raise_error( + Discourse::InvalidParameters, + 'Category not allowed for topic creation.' ) end end - context 'when the category does not have a create_topic_wizard custom field' do - it 'allows creating a topic directly' do - topic = - DummyTopic.new( - user: user, - category: category_without_wizard, - title: 'A valid topic title' + context 'without a create_topic_wizard custom field in the category' do + it 'will allow creating a topic directly' do + expect do + TopicCreator.create( + user, + Guardian.new(user), + valid_attrs.merge( + category: category_without_wizard.id, + title: 'Another valid and sufficiently long title for testing', + raw: 'This is the body of a valid topic' + ) ) - is_valid = topic.valid? - puts topic.errors.full_messages unless is_valid - expect(is_valid).to be_truthy + end.not_to raise_error end end end From 10609f33e258513f6e2e2f56db384b53bb59aac8 Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 19 Sep 2023 14:00:04 -0400 Subject: [PATCH 43/46] FIX: linting error --- lib/custom_wizard/extensions/topic_extension.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/custom_wizard/extensions/topic_extension.rb b/lib/custom_wizard/extensions/topic_extension.rb index e890f9df..7ee442ed 100644 --- a/lib/custom_wizard/extensions/topic_extension.rb +++ b/lib/custom_wizard/extensions/topic_extension.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + DiscourseEvent.on(:before_create_topic) do |topic_params, user| category = topic_params.category if category&.custom_fields&.[]('create_topic_wizard').present? From 0992e9601cf9dc76c226f26a4b453e6de7572797 Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 19 Sep 2023 14:17:06 -0400 Subject: [PATCH 44/46] DEV: Make hide category default when custom wizard is selected --- .../custom-wizard-category-settings.hbs | 10 ---------- .../custom-wizard-category-settings.js.es6 | 11 ----------- .../discourse/initializers/custom-wizard-edits.js.es6 | 2 +- config/locales/client.en.yml | 1 - plugin.rb | 3 +-- test/javascripts/fixtures/categories.js.es6 | 5 ----- 6 files changed, 2 insertions(+), 30 deletions(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs index f548e93f..2c6a6975 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs @@ -12,14 +12,4 @@ options=(hash none="admin.wizard.select") }}
- -
-
\ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 index 552ee193..7004c317 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 @@ -13,10 +13,6 @@ export default { "wizardListVal", attrs?.category?.custom_fields?.create_topic_wizard ); - component.set( - "hideFromComposer", - attrs?.category?.custom_fields?.custom_wizard_hide_from_composer - ); }, actions: { @@ -24,12 +20,5 @@ export default { this.set("wizardListVal", wizard); this.set("category.custom_fields.create_topic_wizard", wizard); }, - toggleHideFromComposer() { - this.toggleProperty("hideFromComposer"); - this.set( - "category.custom_fields.custom_wizard_hide_from_composer", - this.hideFromComposer - ); - }, }, }; diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 5019ef83..bd3c3d2d 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -89,7 +89,7 @@ export default { let categories = this._super(options); return categories.filter((category) => { - return !category.custom_fields?.custom_wizard_hide_from_composer; + return !category.custom_fields?.create_topic_wizard; }); }, }); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1fd9f158..98519335 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -133,7 +133,6 @@ en: custom_wizard: title: "Custom Wizard" create_topic_wizard: "Select a wizard to replace the new topic composer in this category." - hide_from_composer: "Exclude category from composer dropdown" message: wizard: diff --git a/plugin.rb b/plugin.rb index a16d47d1..d5eed12b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -105,7 +105,6 @@ after_initialize do # preloaded category custom fields %w[ create_topic_wizard - custom_wizard_hide_from_composer ].each do |custom_field| Site.preloaded_category_custom_fields << custom_field end @@ -202,7 +201,7 @@ after_initialize do ::InvitesController.prepend InvitesControllerCustomWizard ::UsersController.prepend CustomWizardUsersController ::Guardian.prepend CustomWizardGuardian - + full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss" if Stylesheet::Importer.respond_to?(:plugin_assets) Stylesheet::Importer.plugin_assets['wizard_custom'] = Set[full_path] diff --git a/test/javascripts/fixtures/categories.js.es6 b/test/javascripts/fixtures/categories.js.es6 index 432a1b77..e553f860 100644 --- a/test/javascripts/fixtures/categories.js.es6 +++ b/test/javascripts/fixtures/categories.js.es6 @@ -33,7 +33,6 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, - custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -78,7 +77,6 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, - custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -123,7 +121,6 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, - custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -168,7 +165,6 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, - custom_wizard_hide_from_composer: null, }, allowed_tags: [], allowed_tag_groups: [], @@ -210,7 +206,6 @@ export default { navigate_to_first_post_after_read: false, custom_fields: { create_topic_wizard: null, - custom_wizard_hide_from_composer: "t", }, allowed_tags: [], allowed_tag_groups: [], From 0eb6fb1ae0c7105295c7d792903ede4585c012ae Mon Sep 17 00:00:00 2001 From: jumagura Date: Tue, 19 Sep 2023 20:46:42 -0400 Subject: [PATCH 45/46] REFACTOR: Move before_create_topic event handler to plugin.rb --- lib/custom_wizard/extensions/topic_extension.rb | 10 ---------- plugin.rb | 10 +++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 lib/custom_wizard/extensions/topic_extension.rb diff --git a/lib/custom_wizard/extensions/topic_extension.rb b/lib/custom_wizard/extensions/topic_extension.rb deleted file mode 100644 index 7ee442ed..00000000 --- a/lib/custom_wizard/extensions/topic_extension.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -DiscourseEvent.on(:before_create_topic) do |topic_params, user| - category = topic_params.category - if category&.custom_fields&.[]('create_topic_wizard').present? - raise Discourse::InvalidParameters.new( - I18n.t('wizard.error_messages.wizard_replacing_composer') - ) - end -end diff --git a/plugin.rb b/plugin.rb index d5eed12b..7d3f7679 100644 --- a/plugin.rb +++ b/plugin.rb @@ -91,7 +91,6 @@ after_initialize do ../lib/custom_wizard/extensions/invites_controller.rb ../lib/custom_wizard/extensions/users_controller.rb ../lib/custom_wizard/extensions/guardian.rb - ../lib/custom_wizard/extensions/topic_extension.rb ../lib/custom_wizard/extensions/custom_field/preloader.rb ../lib/custom_wizard/extensions/custom_field/serializer.rb ../lib/custom_wizard/extensions/custom_field/extension.rb @@ -237,4 +236,13 @@ after_initialize do end DiscourseEvent.trigger(:custom_wizard_ready) + + on(:before_create_topic) do |topic_params, user| + category = topic_params.category + if category&.custom_fields&.[]('create_topic_wizard').present? + raise Discourse::InvalidParameters.new( + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) + end + end end From 3d104406fded4f6fc2fdb5246a30f2ae55c15d12 Mon Sep 17 00:00:00 2001 From: jumagura Date: Wed, 20 Sep 2023 03:55:32 -0400 Subject: [PATCH 46/46] REFACTOR: Improve test for category chooser when there is a create_topic_wizard customfield --- .../category-chooser-initializer-test.js | 67 ++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/test/javascripts/acceptance/category-chooser-initializer-test.js b/test/javascripts/acceptance/category-chooser-initializer-test.js index a5ca3b2a..f7e02bb8 100644 --- a/test/javascripts/acceptance/category-chooser-initializer-test.js +++ b/test/javascripts/acceptance/category-chooser-initializer-test.js @@ -3,19 +3,80 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import { test } from "qunit"; -acceptance("CategoryChooser", function (needs) { +acceptance("Category Chooser Initializer", function (needs) { needs.user(); needs.settings({ allow_uncategorized_topics: false, }); + needs.site({ + can_tag_topics: true, + categories: [ + { + id: 1, + name: "General", + slug: "general", + permission: 1, + topic_template: null, + }, + { + id: 2, + name: "Category with custom field", + slug: "category-custom-field", + permission: 1, + topic_template: "", + custom_fields: { + create_topic_wizard: "21", + }, + }, + { + id: 3, + name: "Category 1", + slug: "category-1", + permission: 1, + topic_template: "", + }, + { + id: 4, + name: "Category 2", + slug: "category-2", + permission: 1, + topic_template: "", + }, + ], + }); - test("does not display category with custom_wizard_hide_from_composer set to 't'", async function (assert) { + test("does not display category with create_topic_wizard custom field", async function (assert) { const categoryChooser = selectKit(".category-chooser"); await visit("/"); await click("#create-topic"); await categoryChooser.expand(); + let categories = Array.from( + document.querySelectorAll(".category-chooser .category-row") + ).filter((category) => category.getAttribute("data-name")); // Filter elements with a data-name attribute + assert.equal( + categories.length, + 3, + "Correct number of categories are displayed" + ); + const categoryNames = ["General", "Category 1", "Category 2"]; - assert.ok(categoryChooser.rowByIndex(4).name() !== "Custom Categories"); + categoryNames.forEach((categoryName) => { + assert.ok( + categories.some( + (category) => category.getAttribute("data-name") === categoryName + ), + `Category '${categoryName}' is displayed` + ); + }); + + const categoryNameWithCustomField = "Category with custom field"; + assert.notOk( + categories.some( + (category) => + category.getAttribute("data-name") === categoryNameWithCustomField + ), + `Category '${categoryNameWithCustomField}' is not displayed` + ); }); });