From c9453a0bdd76027194e31953265555c2feb11c93 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 4 Oct 2021 14:40:17 +0100 Subject: [PATCH 01/41] API: remove GET method from API options --- .../discourse/controllers/admin-wizards-api-show.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5dba2d7f..7d3c1084 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 @@ -11,7 +11,7 @@ export default Controller.extend({ queryParams: ["refresh_list"], loadingSubscriptions: false, notAuthorized: not("api.authorized"), - endpointMethods: selectKitContent(["GET", "PUT", "POST", "PATCH", "DELETE"]), + endpointMethods: selectKitContent(["PUT", "POST", "PATCH", "DELETE"]), showRemove: not("isNew"), showRedirectUri: and("threeLeggedOauth", "api.name"), responseIcon: null, From a2ebd5c463f09e7bf9801f76a30d0853e113a11c Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 4 Oct 2021 18:51:47 +0100 Subject: [PATCH 02/41] API: don't present an API menu entry if not subscribed --- assets/javascripts/discourse/templates/admin-wizards.hbs | 2 +- controllers/custom_wizard/admin/admin.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index 5ab666c7..a9169d66 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -2,7 +2,7 @@ {{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}} {{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}} {{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}} - {{#if siteSettings.wizard_apis_enabled}} + {{#if subscribed}} {{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}} {{/if}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index ff01ddac..63f148b9 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -4,6 +4,7 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( + subscribed: CustomWizard::Subscription.subscribed?, notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer From 6056351b7c7da031b80a0e580d39b45c66733957 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 5 Oct 2021 10:06:15 +0100 Subject: [PATCH 03/41] API: fix request call --- lib/custom_wizard/api/endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/api/endpoint.rb b/lib/custom_wizard/api/endpoint.rb index 9dbbc590..b82dd39a 100644 --- a/lib/custom_wizard/api/endpoint.rb +++ b/lib/custom_wizard/api/endpoint.rb @@ -74,7 +74,7 @@ class CustomWizard::Api::Endpoint headers["Authorization"] = auth_string if auth_string headers["Content-Type"] = content_type if content_type - connection = Excon.new(UrlHelper.encode_and_parse(endpoint.url), headers: headers) + connection = Excon.new(URI.encode(endpoint.url), headers: headers) params = { method: endpoint.method } From 5a424e8e3dfdd00202a5dcd07da4dca96e8fc4df Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 5 Oct 2021 10:07:20 +0100 Subject: [PATCH 04/41] API: add mocked request spec --- spec/components/custom_wizard/action_spec.rb | 27 +++++++++++++++++++ spec/fixtures/api/no_authorization.json | 3 +++ spec/fixtures/endpoints/test_endpoint.json | 5 ++++ .../endpoints/test_endpoint_body.json | 3 +++ spec/plugin_helper.rb | 1 + 5 files changed, 39 insertions(+) create mode 100644 spec/fixtures/api/no_authorization.json create mode 100644 spec/fixtures/endpoints/test_endpoint.json create mode 100644 spec/fixtures/endpoints/test_endpoint_body.json diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index e34dd861..f5296a54 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -13,6 +13,9 @@ describe CustomWizard::Action do let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } + let(:api_test_endpoint) { get_wizard_fixture("endpoints/test_endpoint") } + let(:api_test_endpoint_body) { get_wizard_fixture("endpoints/test_endpoint_body")} + let(:api_test_no_authorization) { get_wizard_fixture("api/no_authorization")} def update_template(template) CustomWizard::Template.save(template, skip_jobs: true) @@ -265,5 +268,29 @@ describe CustomWizard::Action do expect(group.users.first.username).to eq('angus') end + + it '#send_to_api' do + stub_request(:put, "https://myexternalapi.com/update"). + with( + body: "some_body", + headers: { + 'Host'=>'myexternalapi.com' + }). + to_return(status: 200, body: "success", headers: {}) + + new_api = CustomWizard::Api.new("my_api") + CustomWizard::Api.set("my_api", title: "Mocked external api") + CustomWizard::Api::Authorization.set("my_api", api_test_no_authorization) + CustomWizard::Api::Endpoint.new("my_api") + CustomWizard::Api::Endpoint.set("my_api", api_test_endpoint) + endpoint_id = CustomWizard::Api::Endpoint.list("my_api").first.id + + result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body") + log_entry = CustomWizard::Api::LogEntry.list("my_api").first + byebug + expect(result).to eq('success') + expect(log_entry.status).to eq('SUCCESS') + end end end + diff --git a/spec/fixtures/api/no_authorization.json b/spec/fixtures/api/no_authorization.json new file mode 100644 index 00000000..b1c6506e --- /dev/null +++ b/spec/fixtures/api/no_authorization.json @@ -0,0 +1,3 @@ +{ + "auth_type": "none" +} \ No newline at end of file diff --git a/spec/fixtures/endpoints/test_endpoint.json b/spec/fixtures/endpoints/test_endpoint.json new file mode 100644 index 00000000..ba979064 --- /dev/null +++ b/spec/fixtures/endpoints/test_endpoint.json @@ -0,0 +1,5 @@ +{ + "method": "PUT", + "url": "https://myexternalapi.com/update", + "success_codes": [200] +} \ No newline at end of file diff --git a/spec/fixtures/endpoints/test_endpoint_body.json b/spec/fixtures/endpoints/test_endpoint_body.json new file mode 100644 index 00000000..837e7c72 --- /dev/null +++ b/spec/fixtures/endpoints/test_endpoint_body.json @@ -0,0 +1,3 @@ +{ + "data": "some_data" +} \ No newline at end of file diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index d47c47c1..e72fe355 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -15,6 +15,7 @@ require 'oj' Oj.default_options = Oj.default_options.merge(cache_str: -1) require 'rails_helper' +require 'webmock/rspec' def get_wizard_fixture(path) JSON.parse( From 31e275668cd9d9d509876e28930fae20def9956d Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 5 Oct 2021 10:19:47 +0100 Subject: [PATCH 05/41] API: remove byebug --- spec/components/custom_wizard/action_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index f5296a54..4bd626ad 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -287,7 +287,7 @@ describe CustomWizard::Action do result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body") log_entry = CustomWizard::Api::LogEntry.list("my_api").first - byebug + expect(result).to eq('success') expect(log_entry.status).to eq('SUCCESS') end From 1f939c1ca039778daa88ba6f179fdd6986af8cda Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 5 Oct 2021 10:20:36 +0100 Subject: [PATCH 06/41] API: only show API menu on business sub --- assets/javascripts/discourse/templates/admin-wizards.hbs | 2 +- config/settings.yml | 3 --- controllers/custom_wizard/admin/admin.rb | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index a9169d66..b72f5a7b 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -2,7 +2,7 @@ {{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}} {{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}} {{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}} - {{#if subscribed}} + {{#if api_subscription}} {{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}} {{/if}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} diff --git a/config/settings.yml b/config/settings.yml index 0d93524d..d88dbaf5 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -15,6 +15,3 @@ plugins: refresh: true type: list list_type: compact - wizard_apis_enabled: - client: true - default: false \ No newline at end of file diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index 63f148b9..df11d25c 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -4,7 +4,8 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( - subscribed: CustomWizard::Subscription.subscribed?, + #TODO replace with appropriate static? + api_subscription: ["business"].includes?(CustomWizard::Subscription.type), notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer From 14e7e9c0db9718b259e5446065a81e4b83377370 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 09:54:52 +0100 Subject: [PATCH 07/41] improve api section switch --- assets/javascripts/discourse/routes/admin-wizards.js.es6 | 1 + assets/javascripts/discourse/templates/admin-wizards.hbs | 2 +- controllers/custom_wizard/admin/admin.rb | 2 +- lib/custom_wizard/subscription.rb | 8 ++++++++ lib/custom_wizard/subscription/subscription.rb | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index da184d93..4e4e3c40 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -9,6 +9,7 @@ export default DiscourseRoute.extend({ setupController(controller, model) { controller.set('notices', A(model.notices)); + controller.set('api_section', model.api_section); }, afterModel(model, transition) { diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index b72f5a7b..aa3b2cf5 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -2,7 +2,7 @@ {{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}} {{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}} {{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}} - {{#if api_subscription}} + {{#if api_section}} {{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}} {{/if}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index df11d25c..8a3b69ac 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -5,7 +5,7 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( #TODO replace with appropriate static? - api_subscription: ["business"].includes?(CustomWizard::Subscription.type), + api_section: ["business"].include?(CustomWizard::Subscription.type), notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 11e6d4d3..6c535602 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -27,6 +27,10 @@ class CustomWizard::Subscription "stripe" end + def type + @subscription.type + end + def client_name "custom-wizard" end @@ -119,6 +123,10 @@ class CustomWizard::Subscription self.new.subscribed? end + def self.type + self.new.type + end + def self.authorized? self.new.authorized? end diff --git a/lib/custom_wizard/subscription/subscription.rb b/lib/custom_wizard/subscription/subscription.rb index 129f993a..b2ddf744 100644 --- a/lib/custom_wizard/subscription/subscription.rb +++ b/lib/custom_wizard/subscription/subscription.rb @@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription end def types - %w(community business) + %w(core advanced business) end def active? From 67cfeb6ed95663809d0768e1adab3bb481bbbfed Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 12:51:38 +0100 Subject: [PATCH 08/41] Distinguish actions which require additional subscription --- .../components/wizard-custom-action.js.es6 | 23 ++++++++-------- .../discourse/lib/wizard-schema.js.es6 | 27 +++++++++++++------ .../routes/admin-wizards-wizard-show.js.es6 | 1 + .../templates/admin-wizards-wizard-show.hbs | 3 ++- controllers/custom_wizard/admin/wizard.rb | 3 ++- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index ffe5b514..39c84fa2 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,5 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; -import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; +import wizardSchema, { + actionsAvailableWithAdditionalSubscription, +} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; import { notificationLevels, selectKitContent } from "../lib/wizard"; import { computed } from "@ember/object"; @@ -94,17 +96,16 @@ export default Component.extend(UndoChanges, { return apis.find((a) => a.name === api).endpoints; }, - @discourseComputed("subscribed") - actionTypes(subscribed) { + @discourseComputed("subscribed", "subscription") + actionTypes(subscribed, subscription) { + let unsubscribedActions = + actionsAvailableWithAdditionalSubscription(subscription); return Object.keys(wizardSchema.action.types).reduce((result, type) => { - let subscription = wizardSchema.action.subscriptionTypes.includes(type); - if (subscribed || !subscription) { - result.push({ - id: type, - name: I18n.t(`admin.wizard.action.${type}.label`), - subscription, - }); - } + result.push({ + id: type, + name: I18n.t(`admin.wizard.action.${type}.label`), + subscribed: unsubscribedActions.includes(type), + }); return result; }, []); }, diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 5d876ed0..f36110da 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -200,14 +200,10 @@ const action = { "create_group", "send_to_api", ], - required: ["id", "type"], - proTypes: [ - "send_message", - "add_to_group", - "create_category", - "create_group", - "send_to_api", - ], + actionTypesWithSubscription: { + advanced: ["send_message", "add_to_group", "watch_categories"], + business: ["create_category", "create_group", "send_to_api"], + }, dependent: {}, objectArrays: {}, }; @@ -219,6 +215,21 @@ const wizardSchema = { action, }; +export function actionsAvailableWithAdditionalSubscription( + currentSubscription +) { + switch (currentSubscription) { + case "business": + return []; + case "advanced": + return action.actionTypesWithSubscription["business"]; + case "community": + return action.actionTypesWithSubscription["advanced"].concat( + action.actionTypesWithSubscription["business"] + ); + } +} + export function buildFieldTypes(types) { wizardSchema.field.types = types; } 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 046fc6d4..d6263471 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -40,6 +40,7 @@ export default DiscourseRoute.extend({ currentAction: wizard.actions[0], creating: model.create, subscribed: parentModel.subscribed, + subscription: parentModel.subscription, }; controller.setProperties(props); diff --git a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs index 3966a50c..abf06ba9 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs @@ -178,7 +178,8 @@ apis=apis removeAction="removeAction" wizardFields=wizardFields - subscribed=subscribed}} + subscribed=subscribed + subscription=subscription}} {{/each}}
diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index fdf338bf..e6ea684a 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -11,7 +11,8 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController field_types: CustomWizard::Field.types, realtime_validations: CustomWizard::RealtimeValidation.types, custom_fields: custom_field_list, - subscribed: CustomWizard::Subscription.subscribed? + subscribed: CustomWizard::Subscription.subscribed?, + subscription: CustomWizard::Subscription.type ) end From d4e489456e61e39359c79d77834e094b371b2b70 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 13:01:39 +0100 Subject: [PATCH 09/41] rename functional levels --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 4 ++-- lib/custom_wizard/subscription/subscription.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index f36110da..34df21d2 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -219,11 +219,11 @@ export function actionsAvailableWithAdditionalSubscription( currentSubscription ) { switch (currentSubscription) { - case "business": + case "complete": return []; case "advanced": return action.actionTypesWithSubscription["business"]; - case "community": + case "core": return action.actionTypesWithSubscription["advanced"].concat( action.actionTypesWithSubscription["business"] ); diff --git a/lib/custom_wizard/subscription/subscription.rb b/lib/custom_wizard/subscription/subscription.rb index b2ddf744..84d21c9d 100644 --- a/lib/custom_wizard/subscription/subscription.rb +++ b/lib/custom_wizard/subscription/subscription.rb @@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription end def types - %w(core advanced business) + %w(core advanced complete) end def active? From 3e2907abc22a30a9181e39644011c3edae1b01cc Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 14:37:36 +0100 Subject: [PATCH 10/41] show api for complete sub --- controllers/custom_wizard/admin/admin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index 8a3b69ac..9f48e632 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -5,7 +5,7 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( #TODO replace with appropriate static? - api_section: ["business"].include?(CustomWizard::Subscription.type), + api_section: ["complete"].include?(CustomWizard::Subscription.type), notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer From e5fbc408f52be36cad318c1a595cde04f17657c2 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 14:49:09 +0100 Subject: [PATCH 11/41] Add failing API call test --- spec/components/custom_wizard/action_spec.rb | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 4bd626ad..8c8e2d31 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -269,7 +269,7 @@ describe CustomWizard::Action do expect(group.users.first.username).to eq('angus') end - it '#send_to_api' do + it '#send_to_api successful' do stub_request(:put, "https://myexternalapi.com/update"). with( body: "some_body", @@ -291,6 +291,29 @@ describe CustomWizard::Action do expect(result).to eq('success') expect(log_entry.status).to eq('SUCCESS') end + + it '#send_to_api failure' do + stub_request(:put, "https://myexternalapi.com/update"). + with( + body: "some_body", + headers: { + 'Host'=>'myexternalapi.com' + }). + to_return(status: 500, body: "failure", headers: {}) + + new_api = CustomWizard::Api.new("my_api") + CustomWizard::Api.set("my_api", title: "Mocked external api") + CustomWizard::Api::Authorization.set("my_api", api_test_no_authorization) + CustomWizard::Api::Endpoint.new("my_api") + CustomWizard::Api::Endpoint.set("my_api", api_test_endpoint) + endpoint_id = CustomWizard::Api::Endpoint.list("my_api").first.id + + result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body") + log_entry = CustomWizard::Api::LogEntry.list("my_api").first + + expect(result).to eq('failure') + expect(log_entry.status).to eq('FAILURE') + end end end From a42e23d352434059acf5c396c0435f03d6c72527 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Oct 2021 13:41:24 +0100 Subject: [PATCH 12/41] Show but differentiate unsubbed action options --- .../components/wizard-custom-action.js.es6 | 8 ++++- .../wizard-subscription-selector-row.js.es6 | 19 +++++++++++- .../discourse/lib/wizard-schema.js.es6 | 30 ++++++++++++++----- .../wizard-subscription-selector-row.hbs | 8 ++++- assets/stylesheets/admin/admin.scss | 4 +++ config/locales/client.en.yml | 1 + controllers/custom_wizard/admin/admin.rb | 2 +- .../subscription/subscription.rb | 2 +- 8 files changed, 61 insertions(+), 13 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 39c84fa2..915e83aa 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,6 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; import wizardSchema, { actionsAvailableWithAdditionalSubscription, + actionsAvailableWithCurrentSubscription } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; import { notificationLevels, selectKitContent } from "../lib/wizard"; @@ -100,11 +101,16 @@ export default Component.extend(UndoChanges, { actionTypes(subscribed, subscription) { let unsubscribedActions = actionsAvailableWithAdditionalSubscription(subscription); + let subscribedActions = actionsAvailableWithCurrentSubscription(subscription); return Object.keys(wizardSchema.action.types).reduce((result, type) => { + let subscriptionLabel = (subscribedActions.includes(type) || unsubscribedActions.includes(type)); + let disabled = unsubscribedActions.includes(type); + console.log(subscriptionLabel, disabled); result.push({ id: type, name: I18n.t(`admin.wizard.action.${type}.label`), - subscribed: unsubscribedActions.includes(type), + subscription: subscriptionLabel, + disabled: disabled, }); return result; }, []); diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 index 23034ac1..11dd314a 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 @@ -1,3 +1,20 @@ import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row"; +import { default as discourseComputed } from "discourse-common/utils/decorators"; -export default SelectKitRowComponent.extend(); +export default SelectKitRowComponent.extend({ + classNameBindings: ["isDisabled:disabled"], + + @discourseComputed("item") + isDisabled() { + return this.item.disabled; + }, + + click(event) { + event.preventDefault(); + event.stopPropagation(); + if (!this.item.disabled) { + this.selectKit.select(this.rowValue, this.item); + } + return false; + } +}); diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 34df21d2..3559c98d 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -201,8 +201,8 @@ const action = { "send_to_api", ], actionTypesWithSubscription: { - advanced: ["send_message", "add_to_group", "watch_categories"], - business: ["create_category", "create_group", "send_to_api"], + basic: ["send_message", "add_to_group", "watch_categories"], + advanced: ["create_category", "create_group", "send_to_api"], }, dependent: {}, objectArrays: {}, @@ -219,17 +219,31 @@ export function actionsAvailableWithAdditionalSubscription( currentSubscription ) { switch (currentSubscription) { - case "complete": - return []; case "advanced": - return action.actionTypesWithSubscription["business"]; - case "core": - return action.actionTypesWithSubscription["advanced"].concat( - action.actionTypesWithSubscription["business"] + return []; + case "basic": + return action.actionTypesWithSubscription["advanced"]; + case "none", "": + return action.actionTypesWithSubscription["basic"].concat( + action.actionTypesWithSubscription["advanced"] ); } } +export function actionsAvailableWithCurrentSubscription( + currentSubscription +) { + switch (currentSubscription) { + case "advanced": + return action.actionTypesWithSubscription["advanced"].concat( + action.actionTypesWithSubscription["basic"]); + case "basic": + return action.actionTypesWithSubscription["basic"]; + case "none", "": + return []; + } +} + export function buildFieldTypes(types) { wizardSchema.field.types = types; } diff --git a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs index e2650408..92cb2750 100644 --- a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs @@ -10,6 +10,12 @@
{{html-safe label}} {{#if item.subscription}} - {{i18n "admin.wizard.subscription.label"}} + + {{#if item.disabled}} + {{i18n "admin.wizard.subscription.additional_label"}} + {{else}} + {{i18n "admin.wizard.subscription.label"}} + {{/if}} + {{/if}}
diff --git a/assets/stylesheets/admin/admin.scss b/assets/stylesheets/admin/admin.scss index 862f6761..8a8c7239 100644 --- a/assets/stylesheets/admin/admin.scss +++ b/assets/stylesheets/admin/admin.scss @@ -427,6 +427,10 @@ margin-bottom: 0; } + .wizard-custom-action .select-kit-row.disabled { + background: var(--primary-low); + } + .select-box-kit-header { height: initial; } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 61e8274c..ced433ce 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -467,6 +467,7 @@ en: subscription: nav_label: Subscription label: Subscription + additional_label: "Add subscription" title: Custom Wizard Subscription authorize: Authorize authorized: Authorized diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index 9f48e632..2bd5c86e 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -5,7 +5,7 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( #TODO replace with appropriate static? - api_section: ["complete"].include?(CustomWizard::Subscription.type), + api_section: ["advanced"].include?(CustomWizard::Subscription.type), notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer diff --git a/lib/custom_wizard/subscription/subscription.rb b/lib/custom_wizard/subscription/subscription.rb index 84d21c9d..4c804513 100644 --- a/lib/custom_wizard/subscription/subscription.rb +++ b/lib/custom_wizard/subscription/subscription.rb @@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription end def types - %w(core advanced complete) + %w(none basic advanced) end def active? From deb4460d2ccfb9fddb225eaed331b8b72d1eca62 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Oct 2021 13:53:58 +0100 Subject: [PATCH 13/41] modify dropdown sub text slightly --- config/locales/client.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ced433ce..0b318922 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -466,7 +466,7 @@ en: subscription: nav_label: Subscription - label: Subscription + label: In subscription additional_label: "Add subscription" title: Custom Wizard Subscription authorize: Authorize From 487ad3c46d5f9e083f3f5d69916195d543617b2b Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 19 Oct 2021 13:09:11 +0100 Subject: [PATCH 14/41] Fix test --- spec/components/custom_wizard/action_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 8c8e2d31..230a1760 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -311,7 +311,7 @@ describe CustomWizard::Action do result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body") log_entry = CustomWizard::Api::LogEntry.list("my_api").first - expect(result).to eq('failure') + expect(result).to eq({:error=>"API request failed"}) expect(log_entry.status).to eq('FAILURE') end end From b616adaf7147227f8e7f215d94150c7c93121c4e Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 19 Oct 2021 13:13:32 +0100 Subject: [PATCH 15/41] fix linting --- .../discourse/components/wizard-custom-action.js.es6 | 1 - assets/javascripts/discourse/lib/wizard-schema.js.es6 | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 915e83aa..f9d90a8c 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -105,7 +105,6 @@ export default Component.extend(UndoChanges, { return Object.keys(wizardSchema.action.types).reduce((result, type) => { let subscriptionLabel = (subscribedActions.includes(type) || unsubscribedActions.includes(type)); let disabled = unsubscribedActions.includes(type); - console.log(subscriptionLabel, disabled); result.push({ id: type, name: I18n.t(`admin.wizard.action.${type}.label`), diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 3559c98d..14970334 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -223,7 +223,7 @@ export function actionsAvailableWithAdditionalSubscription( return []; case "basic": return action.actionTypesWithSubscription["advanced"]; - case "none", "": + case "none": return action.actionTypesWithSubscription["basic"].concat( action.actionTypesWithSubscription["advanced"] ); @@ -239,7 +239,7 @@ export function actionsAvailableWithCurrentSubscription( action.actionTypesWithSubscription["basic"]); case "basic": return action.actionTypesWithSubscription["basic"]; - case "none", "": + case "none": return []; } } From b4f463778db7b127c384839e0affe383dcee3c68 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 19 Oct 2021 13:49:06 +0100 Subject: [PATCH 16/41] fix linting issues --- .../components/subscription-container.js.es6 | 20 ++++++----- .../components/wizard-custom-action.js.es6 | 14 +++++--- .../discourse/components/wizard-notice.js.es6 | 36 +++++++++++-------- .../wizard-subscription-selector.js.es6 | 3 +- .../wizard-subscription-selector-row.js.es6 | 2 +- .../components/wizard-subscription.js.es6 | 4 ++- .../custom-wizard-important-notice.js.es6 | 10 +++--- .../controllers/admin-wizards.js.es6 | 10 +++--- .../initializers/custom-wizard-edits.js.es6 | 26 +++++++++----- .../discourse/lib/wizard-schema.js.es6 | 7 ++-- .../models/custom-wizard-notice.js.es6 | 20 ++++++----- .../discourse/routes/admin-wizards.js.es6 | 8 ++--- assets/stylesheets/admin/admin.scss | 10 +++--- 13 files changed, 99 insertions(+), 71 deletions(-) diff --git a/assets/javascripts/discourse/components/subscription-container.js.es6 b/assets/javascripts/discourse/components/subscription-container.js.es6 index 620c6d88..a12b8949 100644 --- a/assets/javascripts/discourse/components/subscription-container.js.es6 +++ b/assets/javascripts/discourse/components/subscription-container.js.es6 @@ -4,18 +4,22 @@ import discourseComputed from "discourse-common/utils/decorators"; export default Component.extend({ classNameBindings: [":subscription-container", "subscribed"], - @discourseComputed('subscribed') + @discourseComputed("subscribed") subscribedIcon(subscribed) { - return subscribed ? 'check' : 'dash'; + return subscribed ? "check" : "dash"; }, - @discourseComputed('subscribed') + @discourseComputed("subscribed") subscribedLabel(subscribed) { - return `admin.wizard.subscription_container.${subscribed ? 'subscribed' : 'not_subscribed'}.label`; + return `admin.wizard.subscription_container.${ + subscribed ? "subscribed" : "not_subscribed" + }.label`; }, - @discourseComputed('subscribed') + @discourseComputed("subscribed") subscribedTitle(subscribed) { - return `admin.wizard.subscription_container.${subscribed ? 'subscribed' : 'not_subscribed'}.title`; - } -}); \ No newline at end of file + return `admin.wizard.subscription_container.${ + subscribed ? "subscribed" : "not_subscribed" + }.title`; + }, +}); diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index f9d90a8c..4ee28d17 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,7 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; import wizardSchema, { actionsAvailableWithAdditionalSubscription, - actionsAvailableWithCurrentSubscription + actionsAvailableWithCurrentSubscription, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; import { notificationLevels, selectKitContent } from "../lib/wizard"; @@ -99,11 +99,15 @@ export default Component.extend(UndoChanges, { @discourseComputed("subscribed", "subscription") actionTypes(subscribed, subscription) { - let unsubscribedActions = - actionsAvailableWithAdditionalSubscription(subscription); - let subscribedActions = actionsAvailableWithCurrentSubscription(subscription); + let unsubscribedActions = actionsAvailableWithAdditionalSubscription( + subscription + ); + let subscribedActions = actionsAvailableWithCurrentSubscription( + subscription + ); return Object.keys(wizardSchema.action.types).reduce((result, type) => { - let subscriptionLabel = (subscribedActions.includes(type) || unsubscribedActions.includes(type)); + let subscriptionLabel = + subscribedActions.includes(type) || unsubscribedActions.includes(type); let disabled = unsubscribedActions.includes(type); result.push({ id: type, diff --git a/assets/javascripts/discourse/components/wizard-notice.js.es6 b/assets/javascripts/discourse/components/wizard-notice.js.es6 index 15da3f35..fcd77606 100644 --- a/assets/javascripts/discourse/components/wizard-notice.js.es6 +++ b/assets/javascripts/discourse/components/wizard-notice.js.es6 @@ -4,33 +4,39 @@ import { not, notEmpty } from "@ember/object/computed"; import I18n from "I18n"; export default Component.extend({ - classNameBindings: [':wizard-notice', 'notice.type', 'dismissed', 'expired', 'resolved'], + classNameBindings: [ + ":wizard-notice", + "notice.type", + "dismissed", + "expired", + "resolved", + ], showFull: false, - resolved: notEmpty('notice.expired_at'), - dismissed: notEmpty('notice.dismissed_at'), - canDismiss: not('dismissed'), + resolved: notEmpty("notice.expired_at"), + dismissed: notEmpty("notice.dismissed_at"), + canDismiss: not("dismissed"), - @discourseComputed('notice.type') + @discourseComputed("notice.type") title(type) { return I18n.t(`admin.wizard.notice.title.${type}`); }, - @discourseComputed('notice.type') + @discourseComputed("notice.type") icon(type) { return { - plugin_status_warning: 'exclamation-circle', - plugin_status_connection_error: 'bolt', - subscription_messages_connection_error: 'bolt', - info: 'info-circle' + plugin_status_warning: "exclamation-circle", + plugin_status_connection_error: "bolt", + subscription_messages_connection_error: "bolt", + info: "info-circle", }[type]; }, actions: { dismiss() { - this.set('dismissing', true); + this.set("dismissing", true); this.notice.dismiss().then(() => { - this.set('dismissing', false); + this.set("dismissing", false); }); - } - } -}); \ No newline at end of file + }, + }, +}); diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 index ec94bce5..ea1aa5d9 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 @@ -7,7 +7,8 @@ export default SingleSelectComponent.extend({ autoFilterable: false, filterable: false, showFullTitle: true, - headerComponent: "wizard-subscription-selector/wizard-subscription-selector-header", + headerComponent: + "wizard-subscription-selector/wizard-subscription-selector-header", caretUpIcon: "caret-up", caretDownIcon: "caret-down", }, diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 index 11dd314a..1d43047a 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 @@ -16,5 +16,5 @@ export default SelectKitRowComponent.extend({ this.selectKit.select(this.rowValue, this.item); } return false; - } + }, }); diff --git a/assets/javascripts/discourse/components/wizard-subscription.js.es6 b/assets/javascripts/discourse/components/wizard-subscription.js.es6 index 0d839a5f..29e47bc2 100644 --- a/assets/javascripts/discourse/components/wizard-subscription.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription.js.es6 @@ -25,7 +25,9 @@ export default Component.extend({ @discourseComputed("stateClass") stateLabel(stateClass) { - return I18n.t(`admin.wizard.subscription.subscription.status.${stateClass}`); + return I18n.t( + `admin.wizard.subscription.subscription.status.${stateClass}` + ); }, actions: { diff --git a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-important-notice.js.es6 b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-important-notice.js.es6 index 43a2152b..5962f255 100644 --- a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-important-notice.js.es6 +++ b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-important-notice.js.es6 @@ -6,11 +6,11 @@ export default { }, setupComponent() { - const controller = getOwner(this).lookup('controller:admin-dashboard'); - const importantNotice = controller.get('customWizardImportantNotice'); + const controller = getOwner(this).lookup("controller:admin-dashboard"); + const importantNotice = controller.get("customWizardImportantNotice"); if (importantNotice) { - this.set('importantNotice', importantNotice); + this.set("importantNotice", importantNotice); } - } -}; \ No newline at end of file + }, +}; diff --git a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 index a94222c1..d128d851 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 @@ -8,13 +8,13 @@ export default Controller.extend({ ajax(`/admin/wizards/notice/${this.id}`, { type: "DELETE", }) - .then(result => { + .then((result) => { if (result.success) { const notices = this.notices; - notices.removeObject(notices.findBy('id', noticeId)); + notices.removeObject(notices.findBy("id", noticeId)); } }) .catch(popupAjaxError); - } - } -}); \ No newline at end of file + }, + }, +}); diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index f53dc2cd..21a9d745 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -21,27 +21,37 @@ export default { }; withPluginApi("0.8.36", (api) => { - api.modifyClass('route:admin-dashboard', { + api.modifyClass("route:admin-dashboard", { afterModel() { - return CustomWizardNotice.list().then(result => { + return CustomWizardNotice.list().then((result) => { if (result && result.length) { - this.set('notices', A(result.map(n => CustomWizardNotice.create(n)))); + this.set( + "notices", + A(result.map((n) => CustomWizardNotice.create(n))) + ); } - }); + }); }, setupController(controller) { if (this.notices) { - let pluginStatusConnectionError = this.notices.filter(n => n.type === 'plugin_status_connection_error')[0]; - let pluginStatusWarning = this.notices.filter(n => n.type === 'plugin_status_warning')[0]; + let pluginStatusConnectionError = this.notices.filter( + (n) => n.type === "plugin_status_connection_error" + )[0]; + let pluginStatusWarning = this.notices.filter( + (n) => n.type === "plugin_status_warning" + )[0]; if (pluginStatusConnectionError || pluginStatusWarning) { - controller.set('customWizardImportantNotice', pluginStatusConnectionError || pluginStatusWarning); + controller.set( + "customWizardImportantNotice", + pluginStatusConnectionError || pluginStatusWarning + ); } } this._super(...arguments); - } + }, }); }); }, diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 14970334..76943e2b 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -230,13 +230,12 @@ export function actionsAvailableWithAdditionalSubscription( } } -export function actionsAvailableWithCurrentSubscription( - currentSubscription -) { +export function actionsAvailableWithCurrentSubscription(currentSubscription) { switch (currentSubscription) { case "advanced": return action.actionTypesWithSubscription["advanced"].concat( - action.actionTypesWithSubscription["basic"]); + action.actionTypesWithSubscription["basic"] + ); case "basic": return action.actionTypesWithSubscription["basic"]; case "none": diff --git a/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 index a6b47c40..1eb21e73 100644 --- a/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 @@ -6,18 +6,20 @@ const CustomWizardNotice = EmberObject.extend(); CustomWizardNotice.reopen({ dismiss() { - return ajax(`/admin/wizards/notice/${this.id}`, { type: 'PUT' }).then(result => { - if (result.success) { - this.set('dismissed_at', result.dismissed_at); - } - }).catch(popupAjaxError); - } + return ajax(`/admin/wizards/notice/${this.id}`, { type: "PUT" }) + .then((result) => { + if (result.success) { + this.set("dismissed_at", result.dismissed_at); + } + }) + .catch(popupAjaxError); + }, }); CustomWizardNotice.reopenClass({ list() { - return ajax('/admin/wizards/notice').catch(popupAjaxError); - } + return ajax("/admin/wizards/notice").catch(popupAjaxError); + }, }); -export default CustomWizardNotice; \ No newline at end of file +export default CustomWizardNotice; diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index 4e4e3c40..de67a8b9 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -4,17 +4,17 @@ import { A } from "@ember/array"; export default DiscourseRoute.extend({ model() { - return ajax('/admin/wizards'); + return ajax("/admin/wizards"); }, setupController(controller, model) { - controller.set('notices', A(model.notices)); - controller.set('api_section', model.api_section); + controller.set("notices", A(model.notices)); + controller.set("api_section", model.api_section); }, afterModel(model, transition) { if (transition.targetName === "adminWizards.index") { this.transitionTo("adminWizardsWizard"); } - } + }, }); diff --git a/assets/stylesheets/admin/admin.scss b/assets/stylesheets/admin/admin.scss index 8a8c7239..5973a1e7 100644 --- a/assets/stylesheets/admin/admin.scss +++ b/assets/stylesheets/admin/admin.scss @@ -928,7 +928,7 @@ } .d-icon { - margin-right: .4em; + margin-right: 0.4em; } .notice-header { @@ -939,9 +939,9 @@ border: 1px solid var(--primary); display: inline-flex; align-items: center; - padding: 0 .5em; + padding: 0 0.5em; margin-right: 1em; - font-size: .9em; + font-size: 0.9em; line-height: 25px; min-height: 25px; box-sizing: border-box; @@ -967,12 +967,12 @@ .notice-issued, .notice-resolved { - margin-right: .3em; + margin-right: 0.3em; } .notice-message { p { - margin: .5em 0; + margin: 0.5em 0; } p:last-of-type { From 30fe73570a437c268c9a794d902ed51c3831eefe Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 15:38:38 +0100 Subject: [PATCH 17/41] remove triple curlies --- .../discourse/templates/components/wizard-notice.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-notice.hbs b/assets/javascripts/discourse/templates/components/wizard-notice.hbs index 6a7d0afb..89bbf5d4 100644 --- a/assets/javascripts/discourse/templates/components/wizard-notice.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-notice.hbs @@ -33,7 +33,7 @@
- {{{notice.message}}} + {{html-safe notice.message}}
{{#if importantOnDashboard}} From 0b8fced879373e699f6d5d2ac8fcb42f270b49da Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 19:04:37 +0100 Subject: [PATCH 18/41] rubocop changes --- spec/components/custom_wizard/action_spec.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 230a1760..94192aa7 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -14,8 +14,8 @@ describe CustomWizard::Action do let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } let(:api_test_endpoint) { get_wizard_fixture("endpoints/test_endpoint") } - let(:api_test_endpoint_body) { get_wizard_fixture("endpoints/test_endpoint_body")} - let(:api_test_no_authorization) { get_wizard_fixture("api/no_authorization")} + let(:api_test_endpoint_body) { get_wizard_fixture("endpoints/test_endpoint_body") } + let(:api_test_no_authorization) { get_wizard_fixture("api/no_authorization") } def update_template(template) CustomWizard::Template.save(template, skip_jobs: true) @@ -271,12 +271,12 @@ describe CustomWizard::Action do it '#send_to_api successful' do stub_request(:put, "https://myexternalapi.com/update"). - with( + with( body: "some_body", headers: { - 'Host'=>'myexternalapi.com' + 'Host' => 'myexternalapi.com' }). - to_return(status: 200, body: "success", headers: {}) + to_return(status: 200, body: "success", headers: {}) new_api = CustomWizard::Api.new("my_api") CustomWizard::Api.set("my_api", title: "Mocked external api") @@ -294,12 +294,12 @@ describe CustomWizard::Action do it '#send_to_api failure' do stub_request(:put, "https://myexternalapi.com/update"). - with( + with( body: "some_body", headers: { - 'Host'=>'myexternalapi.com' + 'Host' => 'myexternalapi.com' }). - to_return(status: 500, body: "failure", headers: {}) + to_return(status: 500, body: "failure", headers: {}) new_api = CustomWizard::Api.new("my_api") CustomWizard::Api.set("my_api", title: "Mocked external api") @@ -311,9 +311,8 @@ describe CustomWizard::Action do result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body") log_entry = CustomWizard::Api::LogEntry.list("my_api").first - expect(result).to eq({:error=>"API request failed"}) + expect(result).to eq({ error: "API request failed" }) expect(log_entry.status).to eq('FAILURE') end end end - From 50176b400d6c068674b57e01de5b4654804b0b9a Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 19:07:45 +0100 Subject: [PATCH 19/41] more rubocop --- lib/custom_wizard/api/endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/api/endpoint.rb b/lib/custom_wizard/api/endpoint.rb index b82dd39a..38000106 100644 --- a/lib/custom_wizard/api/endpoint.rb +++ b/lib/custom_wizard/api/endpoint.rb @@ -74,7 +74,7 @@ class CustomWizard::Api::Endpoint headers["Authorization"] = auth_string if auth_string headers["Content-Type"] = content_type if content_type - connection = Excon.new(URI.encode(endpoint.url), headers: headers) + connection = Excon.new(CGI.escape(endpoint.url), headers: headers) params = { method: endpoint.method } From 41e0f13b255441409988889549715a36fcb59bcf Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 19:24:28 +0100 Subject: [PATCH 20/41] update subscription types --- controllers/custom_wizard/admin/admin.rb | 2 +- lib/custom_wizard/subscription/subscription.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/custom_wizard/admin/admin.rb b/controllers/custom_wizard/admin/admin.rb index 2bd5c86e..8a3b69ac 100644 --- a/controllers/custom_wizard/admin/admin.rb +++ b/controllers/custom_wizard/admin/admin.rb @@ -5,7 +5,7 @@ class CustomWizard::AdminController < ::Admin::AdminController def index render_json_dump( #TODO replace with appropriate static? - api_section: ["advanced"].include?(CustomWizard::Subscription.type), + api_section: ["business"].include?(CustomWizard::Subscription.type), notices: ActiveModel::ArraySerializer.new( CustomWizard::Notice.list, each_serializer: CustomWizard::NoticeSerializer diff --git a/lib/custom_wizard/subscription/subscription.rb b/lib/custom_wizard/subscription/subscription.rb index 4c804513..0b3bb84d 100644 --- a/lib/custom_wizard/subscription/subscription.rb +++ b/lib/custom_wizard/subscription/subscription.rb @@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription end def types - %w(none basic advanced) + %w(none standard business) end def active? From fbab8d89a52adc600e3f2e55b01de21b15e4d82f Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 19:56:00 +0100 Subject: [PATCH 21/41] Update action dropdown behaviour to show sub level --- .../components/wizard-custom-action.js.es6 | 13 ++----- .../discourse/lib/wizard-schema.js.es6 | 37 +++++++++---------- .../wizard-subscription-selector-row.hbs | 6 +-- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 4ee28d17..9024b401 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,7 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; import wizardSchema, { - actionsAvailableWithAdditionalSubscription, - actionsAvailableWithCurrentSubscription, + actionsRequiringAdditionalSubscription, + actionSubscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; import { notificationLevels, selectKitContent } from "../lib/wizard"; @@ -99,20 +99,15 @@ export default Component.extend(UndoChanges, { @discourseComputed("subscribed", "subscription") actionTypes(subscribed, subscription) { - let unsubscribedActions = actionsAvailableWithAdditionalSubscription( - subscription - ); - let subscribedActions = actionsAvailableWithCurrentSubscription( + let unsubscribedActions = actionsRequiringAdditionalSubscription( subscription ); return Object.keys(wizardSchema.action.types).reduce((result, type) => { - let subscriptionLabel = - subscribedActions.includes(type) || unsubscribedActions.includes(type); let disabled = unsubscribedActions.includes(type); result.push({ id: type, name: I18n.t(`admin.wizard.action.${type}.label`), - subscription: subscriptionLabel, + subscription: actionSubscriptionLevel(type), disabled: disabled, }); return result; diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 76943e2b..e55e8a44 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -201,8 +201,8 @@ const action = { "send_to_api", ], actionTypesWithSubscription: { - basic: ["send_message", "add_to_group", "watch_categories"], - advanced: ["create_category", "create_group", "send_to_api"], + standard: ["send_message", "add_to_group", "watch_categories"], + business: ["create_category", "create_group", "send_to_api"], }, dependent: {}, objectArrays: {}, @@ -215,31 +215,30 @@ const wizardSchema = { action, }; -export function actionsAvailableWithAdditionalSubscription( +export function actionsRequiringAdditionalSubscription( currentSubscription ) { switch (currentSubscription) { - case "advanced": + case "business": return []; - case "basic": - return action.actionTypesWithSubscription["advanced"]; - case "none": - return action.actionTypesWithSubscription["basic"].concat( - action.actionTypesWithSubscription["advanced"] + case "standard": + return action.actionTypesWithSubscription["business"]; + default: + return action.actionTypesWithSubscription["standard"].concat( + action.actionTypesWithSubscription["business"] ); } } -export function actionsAvailableWithCurrentSubscription(currentSubscription) { - switch (currentSubscription) { - case "advanced": - return action.actionTypesWithSubscription["advanced"].concat( - action.actionTypesWithSubscription["basic"] - ); - case "basic": - return action.actionTypesWithSubscription["basic"]; - case "none": - return []; +export function actionSubscriptionLevel(type) { + if (action.actionTypesWithSubscription["business"].includes(type)) { + return "business" + } else { + if (action.actionTypesWithSubscription["standard"].includes(type)) { + return "standard" + } else { + return "" + } } } diff --git a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs index 92cb2750..87f2a1e1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs @@ -11,11 +11,7 @@ {{html-safe label}} {{#if item.subscription}} - {{#if item.disabled}} - {{i18n "admin.wizard.subscription.additional_label"}} - {{else}} - {{i18n "admin.wizard.subscription.label"}} - {{/if}} + {{item.subscription}} {{/if}} From 5334d12f10555fbcb78fd33f9f8108f92f85afdb Mon Sep 17 00:00:00 2001 From: merefield Date: Fri, 22 Oct 2021 19:57:16 +0100 Subject: [PATCH 22/41] format code --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index e55e8a44..250df371 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -232,7 +232,7 @@ export function actionsRequiringAdditionalSubscription( export function actionSubscriptionLevel(type) { if (action.actionTypesWithSubscription["business"].includes(type)) { - return "business" + return "business" } else { if (action.actionTypesWithSubscription["standard"].includes(type)) { return "standard" From a806e14c64e097987e6a175255b1cda229ccb23c Mon Sep 17 00:00:00 2001 From: merefield Date: Sat, 23 Oct 2021 13:06:12 +0100 Subject: [PATCH 23/41] Admin custom fields subscription differentiation --- .../components/custom-field-input.js.es6 | 83 +++++++++++-------- .../discourse/lib/wizard-schema.js.es6 | 66 +++++++++++++++ .../routes/admin-wizards-custom-fields.js.es6 | 2 + .../templates/admin-wizards-custom-fields.hbs | 3 +- .../components/custom-field-input.hbs | 4 +- assets/stylesheets/admin/admin.scss | 22 +++-- .../custom_wizard/admin/custom_fields.rb | 3 +- 7 files changed, 132 insertions(+), 51 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index a673112b..bd6c78a1 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -4,27 +4,12 @@ import { alias, equal, or } from "@ember/object/computed"; import { computed } from "@ember/object"; import I18n from "I18n"; -const klasses = ["topic", "post", "group", "category"]; -const types = ["string", "boolean", "integer", "json"]; -const subscriptionTypes = { - klass: ["group", "category"], - type: ["json"], -}; - -const generateContent = function (array, type, subscribed = false) { - return array.reduce((result, key) => { - let subArr = subscriptionTypes[type]; - let subscription = subArr && subArr.includes(key); - if (!subscription || subscribed) { - result.push({ - id: key, - name: I18n.t(`admin.wizard.custom_field.${type}.${key}`), - subscription, - }); - } - return result; - }, []); -}; +import wizardSchema, { + customFieldsKlassesRequiringAdditionalSubscription, + customFieldsKlassSubscriptionLevel, + customFieldsTypesRequiringAdditionalSubscription, + customFieldsTypeSubscriptionLevel, +} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; export default Component.extend({ tagName: "tr", @@ -32,12 +17,6 @@ export default Component.extend({ postSerializers: ["post"], groupSerializers: ["basic_group"], categorySerializers: ["basic_category"], - klassContent: computed("subscribed", function () { - return generateContent(klasses, "klass", this.subscribed); - }), - typeContent: computed("subscribed", function () { - return generateContent(types, "type", this.subscribed); - }), showInputs: or("field.new", "field.edit"), classNames: ["custom-field-input"], loading: or("saving", "destroying"), @@ -49,15 +28,49 @@ export default Component.extend({ this.set("originalField", JSON.parse(JSON.stringify(this.field))); }, - @discourseComputed("field.klass") - serializerContent(klass) { - const serializers = this.get(`${klass}Serializers`); + // @discourseComputed("field.klass") + // serializerContent(klass) { + // const serializers = this.get(`${klass}Serializers`); - if (serializers) { - return generateContent(serializers, "serializers", this.subscribed); - } else { - return []; - } + // if (serializers) { + // return generateContent(serializers, "serializers", this.subscribed); + // } else { + // return []; + // } + // }, + + @discourseComputed("subscription") + customFieldTypes(subscription) { + let unsubscribedCustomFields = customFieldsTypesRequiringAdditionalSubscription( + subscription + ); + return wizardSchema.custom_field.types.reduce((result, type) => { + let disabled = unsubscribedCustomFields.includes(type); + result.push({ + id: type, + name: I18n.t(`admin.wizard.custom_field.type.${type}`), + subscription: customFieldsTypeSubscriptionLevel(type), + disabled: disabled, + }); + return result; + }, []); + }, + + @discourseComputed("subscription") + customFieldKlasses(subscription) { + let unsubscribedCustomFields = customFieldsKlassesRequiringAdditionalSubscription( + subscription + ); + return wizardSchema.custom_field.klasses.reduce((result, klass) => { + let disabled = unsubscribedCustomFields.includes(klass); + result.push({ + id: klass, + name: I18n.t(`admin.wizard.custom_field.klass.${klass}`), + subscription: customFieldsKlassSubscriptionLevel(klass), + disabled: disabled, + }); + return result; + }, []); }, @observes("field.klass") diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 250df371..a49dec14 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -208,10 +208,24 @@ const action = { objectArrays: {}, }; +const custom_field = { + klasses: ["topic", "post", "group", "category"], + types: ["string", "boolean", "integer", "json"], + customFieldKlassWithSubscription: { + standard: [], + business: ["group", "category"], + }, + customFieldTypeWithSubscription: { + standard: ["json"], + business: [], + }, +} + const wizardSchema = { wizard, step, field, + custom_field, action, }; @@ -242,6 +256,58 @@ export function actionSubscriptionLevel(type) { } } + + +export function customFieldsKlassesRequiringAdditionalSubscription( + currentSubscription +) { + switch (currentSubscription) { + case "business": + return []; + case "standard": + return custom_field.customFieldKlassWithSubscription["business"]; + default: + return custom_field.customFieldKlassWithSubscription["business"].concat(custom_field.customFieldKlassWithSubscription["standard"]); + } +} + +export function customFieldsKlassSubscriptionLevel(type) { + if (custom_field.customFieldKlassWithSubscription["business"].includes(type)) { + return "business" + } else { + if (custom_field.customFieldKlassWithSubscription["standard"].includes(type)) { + return "standard" + } else { + return "" + } + } +} + +export function customFieldsTypesRequiringAdditionalSubscription( + currentSubscription +) { + switch (currentSubscription) { + case "business": + return []; + case "standard": + return custom_field.customFieldTypeWithSubscription["business"]; + default: + return custom_field.customFieldTypeWithSubscription["business"].concat(custom_field.customFieldTypeWithSubscription["standard"]); + } +} + +export function customFieldsTypeSubscriptionLevel(type) { + if (custom_field.customFieldTypeWithSubscription["business"].includes(type)) { + return "business" + } else { + if (custom_field.customFieldTypeWithSubscription["standard"].includes(type)) { + return "standard" + } else { + return "" + } + } +} + export function buildFieldTypes(types) { wizardSchema.field.types = types; } diff --git a/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 index ca9c4c40..4992f92d 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 @@ -10,10 +10,12 @@ export default DiscourseRoute.extend({ setupController(controller, model) { const customFields = A(model.custom_fields || []); const subscribed = model.subscribed; + const subscription = model.subscription; controller.setProperties({ customFields, subscribed, + subscription, }); }, }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs b/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs index 361d2d44..dceed458 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs @@ -33,7 +33,8 @@ field=field removeField=(action "removeField") saveField=(action "saveField") - subscribed=subscribed}} + subscribed=subscribed + subscription=subscription}} {{/each}} diff --git a/assets/javascripts/discourse/templates/components/custom-field-input.hbs b/assets/javascripts/discourse/templates/components/custom-field-input.hbs index ac7e8689..b4ddcc81 100644 --- a/assets/javascripts/discourse/templates/components/custom-field-input.hbs +++ b/assets/javascripts/discourse/templates/components/custom-field-input.hbs @@ -2,14 +2,14 @@ {{wizard-subscription-selector value=field.klass - content=klassContent + content=customFieldKlasses none="admin.wizard.custom_field.klass.select" onChange=(action (mut field.klass))}} {{wizard-subscription-selector value=field.type - content=typeContent + content=customFieldTypes none="admin.wizard.custom_field.type.select" onChange=(action (mut field.type))}} diff --git a/assets/stylesheets/admin/admin.scss b/assets/stylesheets/admin/admin.scss index 5973a1e7..94fe6839 100644 --- a/assets/stylesheets/admin/admin.scss +++ b/assets/stylesheets/admin/admin.scss @@ -427,10 +427,6 @@ margin-bottom: 0; } - .wizard-custom-action .select-kit-row.disabled { - background: var(--primary-low); - } - .select-box-kit-header { height: initial; } @@ -792,11 +788,6 @@ vertical-align: middle; } -.subscription-label { - color: var(--tertiary); - font-size: 0.75em; -} - .admin-wizards-subscription { .admin-wizard-controls { h3, @@ -857,14 +848,21 @@ } .wizard-subscription-selector.select-kit.single-select { - .select-kit-row .texts { - display: flex; - align-items: center; + .select-kit-row { + .texts { + display: flex; + align-items: center; + } + &.disabled { + background: var(--primary-low); + } } .subscription-label { margin-left: 0.75em; padding-top: 0.25em; + color: var(--tertiary); + font-size: 0.75em; } } diff --git a/controllers/custom_wizard/admin/custom_fields.rb b/controllers/custom_wizard/admin/custom_fields.rb index d10f82ed..1cd20f5d 100644 --- a/controllers/custom_wizard/admin/custom_fields.rb +++ b/controllers/custom_wizard/admin/custom_fields.rb @@ -3,7 +3,8 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController def index render_json_dump( custom_fields: custom_field_list, - subscribed: CustomWizard::Subscription.subscribed? + subscribed: CustomWizard::Subscription.subscribed?, + subscription: CustomWizard::Subscription.type ) end From 7b129debacdf174e9b390e788ea8c43d74f72451 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 25 Oct 2021 15:31:44 +0100 Subject: [PATCH 24/41] partial generalisation of subscription logic --- .../components/wizard-custom-action.js.es6 | 5 +- .../discourse/lib/wizard-schema.js.es6 | 64 ++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 9024b401..122df003 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,6 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; import wizardSchema, { actionsRequiringAdditionalSubscription, + requiringAdditionalSubscription, actionSubscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; @@ -99,7 +100,9 @@ export default Component.extend(UndoChanges, { @discourseComputed("subscribed", "subscription") actionTypes(subscribed, subscription) { - let unsubscribedActions = actionsRequiringAdditionalSubscription( + let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions"); + debugger; + let unsubscribedActionslong = actionsRequiringAdditionalSubscription( subscription ); return Object.keys(wizardSchema.action.types).reduce((result, type) => { diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index a49dec14..d8befe97 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -221,13 +221,75 @@ const custom_field = { }, } +const subscription_levels = { + standard: { + actions: ["send_message", "add_to_group", "watch_categories"], + custom_fields: { + klasses: [], + types: ["json"] + } + }, + + business: { + actions: ["create_category", "create_group", "send_to_api"], + custom_fields: { + klasses: ["group", "category"], + types: [] + } + } +} + const wizardSchema = { wizard, step, field, custom_field, action, -}; + subscription_levels +} + +export function requiringAdditionalSubscription( + currentSubscription, category +) { + switch (currentSubscription) { + case "business": + return []; + case "standard": + return subscription_levels["business"].[category]; + default: + return subscription_levels["standard"].[category].concat( + subscription_levels["business"].[category] + ); + } +} + + +export function SubscriptionLevel(category, type, subCategory) { + switch (category) { + case "actions": + if (subscription_levels.["business"].actions.includes(type)) { + return "business" + } else { + if (subscription_levels.["standard"].actions.includes(type)) { + return "standard" + } else { + return "" + } + } + case "custom_fields": + if (subscription_levels.["business"].custom_fields[subCategory].includes(type)) { + return "business" + } else { + if (subscription_levels.["standard"].custom_fields[subCategory].includes(type)) { + return "standard" + } else { + return "" + } + } + default: + return ""; + } +} export function actionsRequiringAdditionalSubscription( currentSubscription From 9350db5424e2043d2ad2fa13c8f27baf65766714 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 25 Oct 2021 18:55:28 +0100 Subject: [PATCH 25/41] REFACTOR: abstract subscription logic to reduce code --- .../components/custom-field-input.js.es6 | 18 ++- .../components/wizard-custom-action.js.es6 | 15 +- .../discourse/lib/wizard-schema.js.es6 | 134 ++++-------------- 3 files changed, 39 insertions(+), 128 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index bd6c78a1..51064974 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -5,10 +5,8 @@ import { computed } from "@ember/object"; import I18n from "I18n"; import wizardSchema, { - customFieldsKlassesRequiringAdditionalSubscription, - customFieldsKlassSubscriptionLevel, - customFieldsTypesRequiringAdditionalSubscription, - customFieldsTypeSubscriptionLevel, + requiringAdditionalSubscription, + subscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; export default Component.extend({ @@ -41,15 +39,15 @@ export default Component.extend({ @discourseComputed("subscription") customFieldTypes(subscription) { - let unsubscribedCustomFields = customFieldsTypesRequiringAdditionalSubscription( - subscription + let unsubscribedCustomFields = requiringAdditionalSubscription( + subscription, "custom_fields", "types" ); return wizardSchema.custom_field.types.reduce((result, type) => { let disabled = unsubscribedCustomFields.includes(type); result.push({ id: type, name: I18n.t(`admin.wizard.custom_field.type.${type}`), - subscription: customFieldsTypeSubscriptionLevel(type), + subscription: subscriptionLevel(type, "custom_fields", "types"), disabled: disabled, }); return result; @@ -58,15 +56,15 @@ export default Component.extend({ @discourseComputed("subscription") customFieldKlasses(subscription) { - let unsubscribedCustomFields = customFieldsKlassesRequiringAdditionalSubscription( - subscription + let unsubscribedCustomFields = requiringAdditionalSubscription( + subscription, "custom_fields", "klasses" ); return wizardSchema.custom_field.klasses.reduce((result, klass) => { let disabled = unsubscribedCustomFields.includes(klass); result.push({ id: klass, name: I18n.t(`admin.wizard.custom_field.klass.${klass}`), - subscription: customFieldsKlassSubscriptionLevel(klass), + subscription: subscriptionLevel(klass, "custom_fields", "klasses"), disabled: disabled, }); return result; diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 122df003..31d2099f 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,8 +1,7 @@ import { default as discourseComputed } from "discourse-common/utils/decorators"; import wizardSchema, { - actionsRequiringAdditionalSubscription, requiringAdditionalSubscription, - actionSubscriptionLevel, + subscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { empty, equal, or } from "@ember/object/computed"; import { notificationLevels, selectKitContent } from "../lib/wizard"; @@ -98,19 +97,15 @@ export default Component.extend(UndoChanges, { return apis.find((a) => a.name === api).endpoints; }, - @discourseComputed("subscribed", "subscription") - actionTypes(subscribed, subscription) { - let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions"); - debugger; - let unsubscribedActionslong = actionsRequiringAdditionalSubscription( - subscription - ); + @discourseComputed("subscription") + actionTypes(subscription) { + let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions", ""); return Object.keys(wizardSchema.action.types).reduce((result, type) => { let disabled = unsubscribedActions.includes(type); result.push({ id: type, name: I18n.t(`admin.wizard.action.${type}.label`), - subscription: actionSubscriptionLevel(type), + subscription: subscriptionLevel(type, "actions", ""), disabled: disabled, }); return result; diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index d8befe97..d62a2df8 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -193,17 +193,6 @@ const action = { "members_visibility_level", ], required: ["id", "type"], - subscriptionTypes: [ - "send_message", - "add_to_group", - "create_category", - "create_group", - "send_to_api", - ], - actionTypesWithSubscription: { - standard: ["send_message", "add_to_group", "watch_categories"], - business: ["create_category", "create_group", "send_to_api"], - }, dependent: {}, objectArrays: {}, }; @@ -211,14 +200,6 @@ const action = { const custom_field = { klasses: ["topic", "post", "group", "category"], types: ["string", "boolean", "integer", "json"], - customFieldKlassWithSubscription: { - standard: [], - business: ["group", "category"], - }, - customFieldTypeWithSubscription: { - standard: ["json"], - business: [], - }, } const subscription_levels = { @@ -249,22 +230,38 @@ const wizardSchema = { } export function requiringAdditionalSubscription( - currentSubscription, category + currentSubscription, category, subCategory ) { - switch (currentSubscription) { - case "business": - return []; - case "standard": - return subscription_levels["business"].[category]; + switch (category) { + case "actions": + switch (currentSubscription) { + case "business": + return []; + case "standard": + return subscription_levels["business"].[category]; + default: + return subscription_levels["standard"].[category].concat( + subscription_levels["business"].[category] + ); + } + case "custom_fields": + switch (currentSubscription) { + case "business": + return []; + case "standard": + return subscription_levels["business"].[category].[subCategory]; + default: + return subscription_levels["standard"].[category].[subCategory].concat( + subscription_levels["business"].[category].[subCategory] + ); + } default: - return subscription_levels["standard"].[category].concat( - subscription_levels["business"].[category] - ); + return []; } } -export function SubscriptionLevel(category, type, subCategory) { +export function subscriptionLevel(type, category, subCategory) { switch (category) { case "actions": if (subscription_levels.["business"].actions.includes(type)) { @@ -291,85 +288,6 @@ export function SubscriptionLevel(category, type, subCategory) { } } -export function actionsRequiringAdditionalSubscription( - currentSubscription -) { - switch (currentSubscription) { - case "business": - return []; - case "standard": - return action.actionTypesWithSubscription["business"]; - default: - return action.actionTypesWithSubscription["standard"].concat( - action.actionTypesWithSubscription["business"] - ); - } -} - -export function actionSubscriptionLevel(type) { - if (action.actionTypesWithSubscription["business"].includes(type)) { - return "business" - } else { - if (action.actionTypesWithSubscription["standard"].includes(type)) { - return "standard" - } else { - return "" - } - } -} - - - -export function customFieldsKlassesRequiringAdditionalSubscription( - currentSubscription -) { - switch (currentSubscription) { - case "business": - return []; - case "standard": - return custom_field.customFieldKlassWithSubscription["business"]; - default: - return custom_field.customFieldKlassWithSubscription["business"].concat(custom_field.customFieldKlassWithSubscription["standard"]); - } -} - -export function customFieldsKlassSubscriptionLevel(type) { - if (custom_field.customFieldKlassWithSubscription["business"].includes(type)) { - return "business" - } else { - if (custom_field.customFieldKlassWithSubscription["standard"].includes(type)) { - return "standard" - } else { - return "" - } - } -} - -export function customFieldsTypesRequiringAdditionalSubscription( - currentSubscription -) { - switch (currentSubscription) { - case "business": - return []; - case "standard": - return custom_field.customFieldTypeWithSubscription["business"]; - default: - return custom_field.customFieldTypeWithSubscription["business"].concat(custom_field.customFieldTypeWithSubscription["standard"]); - } -} - -export function customFieldsTypeSubscriptionLevel(type) { - if (custom_field.customFieldTypeWithSubscription["business"].includes(type)) { - return "business" - } else { - if (custom_field.customFieldTypeWithSubscription["standard"].includes(type)) { - return "standard" - } else { - return "" - } - } -} - export function buildFieldTypes(types) { wizardSchema.field.types = types; } From 36257fbdfeac4bf5284e8475215719a2d1d9de5b Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 13:59:50 +0100 Subject: [PATCH 26/41] fix excon call --- lib/custom_wizard/api/endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/api/endpoint.rb b/lib/custom_wizard/api/endpoint.rb index 38000106..97fc1127 100644 --- a/lib/custom_wizard/api/endpoint.rb +++ b/lib/custom_wizard/api/endpoint.rb @@ -74,7 +74,7 @@ class CustomWizard::Api::Endpoint headers["Authorization"] = auth_string if auth_string headers["Content-Type"] = content_type if content_type - connection = Excon.new(CGI.escape(endpoint.url), headers: headers) + connection = Excon.new(endpoint.url, headers: headers) params = { method: endpoint.method } From 791eab6c470d32952d1b9de8925baa75f2581a79 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 14:02:21 +0100 Subject: [PATCH 27/41] Fix action spec example --- spec/components/custom_wizard/action_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 94192aa7..0c677300 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -312,7 +312,7 @@ describe CustomWizard::Action do log_entry = CustomWizard::Api::LogEntry.list("my_api").first expect(result).to eq({ error: "API request failed" }) - expect(log_entry.status).to eq('FAILURE') + expect(log_entry.status).to eq('FAIL') end end end From 0752f8068a492cfbec9b8682313943a6865986e3 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 14:09:34 +0100 Subject: [PATCH 28/41] fix subscription spec --- .../subscription/subscription_serializer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/serializers/custom_wizard/subscription/subscription_serializer_spec.rb b/spec/serializers/custom_wizard/subscription/subscription_serializer_spec.rb index 63caf363..91dc59b1 100644 --- a/spec/serializers/custom_wizard/subscription/subscription_serializer_spec.rb +++ b/spec/serializers/custom_wizard/subscription/subscription_serializer_spec.rb @@ -4,11 +4,11 @@ require_relative '../../../plugin_helper' describe CustomWizard::Subscription::SubscriptionSerializer do it 'should return subscription attributes' do - sub = CustomWizard::Subscription::Subscription.new(OpenStruct.new(type: 'community', updated_at: Time.now)) + sub = CustomWizard::Subscription::Subscription.new(OpenStruct.new(type: 'standard', updated_at: Time.now)) serialized = described_class.new(sub, root: false).as_json expect(serialized[:active]).to eq(true) - expect(serialized[:type]).to eq('community') + expect(serialized[:type]).to eq('standard') expect(serialized[:updated_at]).to eq(sub.updated_at) end end From 0c9acb9b200de60766d46f4f2d26ccacb7337696 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 14:31:24 +0100 Subject: [PATCH 29/41] Update subscription titles --- config/locales/client.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0b318922..7c3b449b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -475,7 +475,7 @@ en: not_subscribed: You're not currently subscribed subscription: title: - community: Community Subscription + standard: Standard Subscription business: Business Subscription status: active: Active From 31b4663b3f66533a31de08fa14caf2efb0557fc5 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 14:41:49 +0100 Subject: [PATCH 30/41] Fix linting errors --- .../javascripts/discourse/lib/wizard-schema.js.es6 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index d62a2df8..3dd69be0 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -238,10 +238,10 @@ export function requiringAdditionalSubscription( case "business": return []; case "standard": - return subscription_levels["business"].[category]; + return subscription_levels["business"][category]; default: - return subscription_levels["standard"].[category].concat( - subscription_levels["business"].[category] + return subscription_levels["standard"][category].concat( + subscription_levels["business"][category] ); } case "custom_fields": @@ -249,10 +249,10 @@ export function requiringAdditionalSubscription( case "business": return []; case "standard": - return subscription_levels["business"].[category].[subCategory]; + return subscription_levels["business"][category][subCategory]; default: - return subscription_levels["standard"].[category].[subCategory].concat( - subscription_levels["business"].[category].[subCategory] + return subscription_levels["standard"][category][subCategory].concat( + subscription_levels["business"][category][subCategory] ); } default: From 60388b7dab2e0fc1f208d4208aa2f36606810959 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 14:52:22 +0100 Subject: [PATCH 31/41] fix more linting errors --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 3dd69be0..b482ca2b 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -264,20 +264,20 @@ export function requiringAdditionalSubscription( export function subscriptionLevel(type, category, subCategory) { switch (category) { case "actions": - if (subscription_levels.["business"].actions.includes(type)) { + if (subscription_levels["business"].actions.includes(type)) { return "business" } else { - if (subscription_levels.["standard"].actions.includes(type)) { + if (subscription_levels["standard"].actions.includes(type)) { return "standard" } else { return "" } } case "custom_fields": - if (subscription_levels.["business"].custom_fields[subCategory].includes(type)) { + if (subscription_levels["business"].custom_fields[subCategory].includes(type)) { return "business" } else { - if (subscription_levels.["standard"].custom_fields[subCategory].includes(type)) { + if (subscription_levels["standard"].custom_fields[subCategory].includes(type)) { return "standard" } else { return "" From 203876e9271d10d7b20a2f6cfb576b376916cfe5 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 15:01:29 +0100 Subject: [PATCH 32/41] linting fixes --- .../components/custom-field-input.js.es6 | 5 ++--- .../components/wizard-custom-action.js.es6 | 2 +- .../discourse/lib/wizard-schema.js.es6 | 19 +++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index 51064974..6d4c6366 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -1,7 +1,6 @@ import Component from "@ember/component"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; import { alias, equal, or } from "@ember/object/computed"; -import { computed } from "@ember/object"; import I18n from "I18n"; import wizardSchema, { @@ -48,7 +47,7 @@ export default Component.extend({ id: type, name: I18n.t(`admin.wizard.custom_field.type.${type}`), subscription: subscriptionLevel(type, "custom_fields", "types"), - disabled: disabled, + disabled, }); return result; }, []); @@ -65,7 +64,7 @@ export default Component.extend({ id: klass, name: I18n.t(`admin.wizard.custom_field.klass.${klass}`), subscription: subscriptionLevel(klass, "custom_fields", "klasses"), - disabled: disabled, + disabled, }); return result; }, []); diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 31d2099f..53d79098 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -106,7 +106,7 @@ export default Component.extend(UndoChanges, { id: type, name: I18n.t(`admin.wizard.action.${type}.label`), subscription: subscriptionLevel(type, "actions", ""), - disabled: disabled, + disabled, }); return result; }, []); diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index b482ca2b..65e003a8 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -200,7 +200,7 @@ const action = { const custom_field = { klasses: ["topic", "post", "group", "category"], types: ["string", "boolean", "integer", "json"], -} +}; const subscription_levels = { standard: { @@ -218,7 +218,7 @@ const subscription_levels = { types: [] } } -} +}; const wizardSchema = { wizard, @@ -227,7 +227,7 @@ const wizardSchema = { custom_field, action, subscription_levels -} +}; export function requiringAdditionalSubscription( currentSubscription, category, subCategory @@ -258,8 +258,7 @@ export function requiringAdditionalSubscription( default: return []; } -} - +}; export function subscriptionLevel(type, category, subCategory) { switch (category) { @@ -286,15 +285,15 @@ export function subscriptionLevel(type, category, subCategory) { default: return ""; } -} +}; export function buildFieldTypes(types) { wizardSchema.field.types = types; -} +}; export function buildFieldValidations(validations) { wizardSchema.field.validations = validations; -} +}; const siteSettings = getOwner(this).lookup("site-settings:main"); if (siteSettings.wizard_apis_enabled) { @@ -303,7 +302,7 @@ if (siteSettings.wizard_apis_enabled) { api_endpoint: null, api_body: null, }; -} +}; export function setWizardDefaults(obj, itemType) { const objSchema = wizardSchema[itemType]; @@ -329,6 +328,6 @@ export function setWizardDefaults(obj, itemType) { } return obj; -} +}; export default wizardSchema; From a3d59caee81917398ddd8eb402e6e3fbc237dbbd Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 27 Oct 2021 15:05:09 +0100 Subject: [PATCH 33/41] yet more linting fixes --- .../javascripts/discourse/lib/wizard-schema.js.es6 | 12 ++++++------ assets/javascripts/wizard/lib/text-lite.js.es6 | 2 +- assets/javascripts/wizard/lib/user-search.js.es6 | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 65e003a8..fcdd37b4 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -264,22 +264,22 @@ export function subscriptionLevel(type, category, subCategory) { switch (category) { case "actions": if (subscription_levels["business"].actions.includes(type)) { - return "business" + return "business"; } else { if (subscription_levels["standard"].actions.includes(type)) { - return "standard" + return "standard"; } else { - return "" + return ""; } } case "custom_fields": if (subscription_levels["business"].custom_fields[subCategory].includes(type)) { - return "business" + return "business"; } else { if (subscription_levels["standard"].custom_fields[subCategory].includes(type)) { - return "standard" + return "standard"; } else { - return "" + return ""; } } default: diff --git a/assets/javascripts/wizard/lib/text-lite.js.es6 b/assets/javascripts/wizard/lib/text-lite.js.es6 index c93f6708..cc161426 100644 --- a/assets/javascripts/wizard/lib/text-lite.js.es6 +++ b/assets/javascripts/wizard/lib/text-lite.js.es6 @@ -7,7 +7,7 @@ import { getOwner } from "discourse-common/lib/get-owner"; export function cook(text, options) { if (!options) { options = buildOptions({ - getURL: getURL, + getURL, siteSettings: getOwner(this).lookup("site-settings:main"), }); } diff --git a/assets/javascripts/wizard/lib/user-search.js.es6 b/assets/javascripts/wizard/lib/user-search.js.es6 index 8ef96266..e7171f18 100644 --- a/assets/javascripts/wizard/lib/user-search.js.es6 +++ b/assets/javascripts/wizard/lib/user-search.js.es6 @@ -27,12 +27,12 @@ function performSearch( // need to be able to cancel this oldSearch = $.ajax(getUrl("/u/search/users"), { data: { - term: term, + term, topic_id: topicId, include_groups: includeGroups, include_mentionable_groups: includeMentionableGroups, include_messageable_groups: includeMessageableGroups, - group: group, + group, topic_allowed_users: allowedUsers, }, }); From bd5edaffe99027385df62ebc79903150b4b6f647 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 2 Nov 2021 08:58:15 +0000 Subject: [PATCH 34/41] custom field input: further make generic, fix serializers dropdown --- .../components/custom-field-input.js.es6 | 66 +++++++++---------- .../discourse/lib/wizard-schema.js.es6 | 12 ++-- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index 6d4c6366..f60052c9 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -8,6 +8,22 @@ import wizardSchema, { subscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; +const generateContent = function (kategory, subscription) { + let unsubscribedCustomFields = requiringAdditionalSubscription( + subscription, "custom_fields", kategory + ); + return wizardSchema.custom_field[kategory].reduce((result, item) => { + let disabled = unsubscribedCustomFields.includes(item); + result.push({ + id: item, + name: I18n.t(`admin.wizard.custom_field.${kategory}.${item}`), + subscription: subscriptionLevel(item, "custom_fields", kategory), + disabled, + }); + return result; + }, []); +}; + export default Component.extend({ tagName: "tr", topicSerializers: ["topic_view", "topic_list_item"], @@ -25,49 +41,29 @@ export default Component.extend({ this.set("originalField", JSON.parse(JSON.stringify(this.field))); }, - // @discourseComputed("field.klass") - // serializerContent(klass) { - // const serializers = this.get(`${klass}Serializers`); + @discourseComputed("field.klass") + serializerContent(klass) { + const serializers = this.get(`${klass}Serializers`); - // if (serializers) { - // return generateContent(serializers, "serializers", this.subscribed); - // } else { - // return []; - // } - // }, + if (serializers) { + return serializers.reduce((result, key) => { + result.push({ + id: key, + name: I18n.t(`admin.wizard.custom_field.serializers.${key}`), + }); + return result; + }, []); + } + }, @discourseComputed("subscription") customFieldTypes(subscription) { - let unsubscribedCustomFields = requiringAdditionalSubscription( - subscription, "custom_fields", "types" - ); - return wizardSchema.custom_field.types.reduce((result, type) => { - let disabled = unsubscribedCustomFields.includes(type); - result.push({ - id: type, - name: I18n.t(`admin.wizard.custom_field.type.${type}`), - subscription: subscriptionLevel(type, "custom_fields", "types"), - disabled, - }); - return result; - }, []); + return generateContent("type", this.subscription); }, @discourseComputed("subscription") customFieldKlasses(subscription) { - let unsubscribedCustomFields = requiringAdditionalSubscription( - subscription, "custom_fields", "klasses" - ); - return wizardSchema.custom_field.klasses.reduce((result, klass) => { - let disabled = unsubscribedCustomFields.includes(klass); - result.push({ - id: klass, - name: I18n.t(`admin.wizard.custom_field.klass.${klass}`), - subscription: subscriptionLevel(klass, "custom_fields", "klasses"), - disabled, - }); - return result; - }, []); + return generateContent("klass", this.subscription); }, @observes("field.klass") diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index fcdd37b4..fb2e697d 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -198,24 +198,24 @@ const action = { }; const custom_field = { - klasses: ["topic", "post", "group", "category"], - types: ["string", "boolean", "integer", "json"], + klass: ["topic", "post", "group", "category"], + type: ["string", "boolean", "integer", "json"], }; const subscription_levels = { standard: { actions: ["send_message", "add_to_group", "watch_categories"], custom_fields: { - klasses: [], - types: ["json"] + klass: [], + type: ["json"] } }, business: { actions: ["create_category", "create_group", "send_to_api"], custom_fields: { - klasses: ["group", "category"], - types: [] + klass: ["group", "category"], + type: [] } } }; From 8cbc8745b90efe66375117df6128478631580734 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 2 Nov 2021 09:06:00 +0000 Subject: [PATCH 35/41] prettier --- .../components/custom-field-input.js.es6 | 4 +- .../components/wizard-custom-action.js.es6 | 6 ++- .../discourse/lib/wizard-schema.js.es6 | 40 ++++++++++++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index f60052c9..83f668d0 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -10,7 +10,9 @@ import wizardSchema, { const generateContent = function (kategory, subscription) { let unsubscribedCustomFields = requiringAdditionalSubscription( - subscription, "custom_fields", kategory + subscription, + "custom_fields", + kategory ); return wizardSchema.custom_field[kategory].reduce((result, item) => { let disabled = unsubscribedCustomFields.includes(item); diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 53d79098..6cf22942 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -99,7 +99,11 @@ export default Component.extend(UndoChanges, { @discourseComputed("subscription") actionTypes(subscription) { - let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions", ""); + let unsubscribedActions = requiringAdditionalSubscription( + subscription, + "actions", + "" + ); return Object.keys(wizardSchema.action.types).reduce((result, type) => { let disabled = unsubscribedActions.includes(type); result.push({ diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index fb2e697d..af4fa758 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -207,17 +207,17 @@ const subscription_levels = { actions: ["send_message", "add_to_group", "watch_categories"], custom_fields: { klass: [], - type: ["json"] - } + type: ["json"], + }, }, business: { actions: ["create_category", "create_group", "send_to_api"], custom_fields: { klass: ["group", "category"], - type: [] - } - } + type: [], + }, + }, }; const wizardSchema = { @@ -226,11 +226,13 @@ const wizardSchema = { field, custom_field, action, - subscription_levels + subscription_levels, }; export function requiringAdditionalSubscription( - currentSubscription, category, subCategory + currentSubscription, + category, + subCategory ) { switch (category) { case "actions": @@ -258,7 +260,7 @@ export function requiringAdditionalSubscription( default: return []; } -}; +} export function subscriptionLevel(type, category, subCategory) { switch (category) { @@ -273,10 +275,18 @@ export function subscriptionLevel(type, category, subCategory) { } } case "custom_fields": - if (subscription_levels["business"].custom_fields[subCategory].includes(type)) { + if ( + subscription_levels["business"].custom_fields[subCategory].includes( + type + ) + ) { return "business"; } else { - if (subscription_levels["standard"].custom_fields[subCategory].includes(type)) { + if ( + subscription_levels["standard"].custom_fields[subCategory].includes( + type + ) + ) { return "standard"; } else { return ""; @@ -285,15 +295,15 @@ export function subscriptionLevel(type, category, subCategory) { default: return ""; } -}; +} export function buildFieldTypes(types) { wizardSchema.field.types = types; -}; +} export function buildFieldValidations(validations) { wizardSchema.field.validations = validations; -}; +} const siteSettings = getOwner(this).lookup("site-settings:main"); if (siteSettings.wizard_apis_enabled) { @@ -302,7 +312,7 @@ if (siteSettings.wizard_apis_enabled) { api_endpoint: null, api_body: null, }; -}; +} export function setWizardDefaults(obj, itemType) { const objSchema = wizardSchema[itemType]; @@ -328,6 +338,6 @@ export function setWizardDefaults(obj, itemType) { } return obj; -}; +} export default wizardSchema; From 3add43e81b312137383c226b3bcd236b0233c31c Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 2 Nov 2021 09:09:06 +0000 Subject: [PATCH 36/41] eslint --- .../discourse/components/custom-field-input.js.es6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index 83f668d0..7ee70716 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -60,12 +60,12 @@ export default Component.extend({ @discourseComputed("subscription") customFieldTypes(subscription) { - return generateContent("type", this.subscription); + return generateContent("type", subscription); }, @discourseComputed("subscription") customFieldKlasses(subscription) { - return generateContent("klass", this.subscription); + return generateContent("klass", subscription); }, @observes("field.klass") From 14a337e00c20c07387d020019c42d5dce16a4874 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 2 Nov 2021 09:11:30 +0000 Subject: [PATCH 37/41] template lint --- .../wizard-subscription-selector-row.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs index 87f2a1e1..ecd77cb1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-subscription-selector/wizard-subscription-selector-row.hbs @@ -11,7 +11,7 @@ {{html-safe label}} {{#if item.subscription}} - {{item.subscription}} + {{item.subscription}} {{/if}} From c6b8e08e38e516d3da13b84ae635deb23c5992a4 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 9 Nov 2021 14:57:33 +0000 Subject: [PATCH 38/41] Add subscription level logic to back-end validation --- lib/custom_wizard/custom_field.rb | 8 ++-- lib/custom_wizard/subscription.rb | 46 +++++++++++++++++++ spec/components/custom_wizard/action_spec.rb | 2 +- spec/components/custom_wizard/builder_spec.rb | 12 ++--- .../custom_wizard/custom_field_spec.rb | 2 +- spec/components/custom_wizard/mapper_spec.rb | 2 +- .../custom_wizard/template_validator_spec.rb | 2 +- .../custom_field_extensions_spec.rb | 2 +- spec/plugin_helper.rb | 4 +- .../custom_field_extensions_spec.rb | 3 +- .../custom_wizard/steps_controller_spec.rb | 2 +- .../wizard_step_serializer_spec.rb | 2 +- 12 files changed, 66 insertions(+), 21 deletions(-) diff --git a/lib/custom_wizard/custom_field.rb b/lib/custom_wizard/custom_field.rb index eb93e292..99dcfbbb 100644 --- a/lib/custom_wizard/custom_field.rb +++ b/lib/custom_wizard/custom_field.rb @@ -17,9 +17,8 @@ class ::CustomWizard::CustomField category: ["basic_category"], post: ["post"] } - SUBSCRIPTION_CLASSES ||= ['category', 'group'] + TYPES ||= ["string", "boolean", "integer", "json"] - SUBSCRIPTION_TYPES ||= ["json"] LIST_CACHE_KEY ||= 'custom_field_list' def self.serializers @@ -84,8 +83,7 @@ class ::CustomWizard::CustomField add_error(I18n.t("#{i18n_key}.unsupported_class", class: value)) next end - - if attr == 'klass' && SUBSCRIPTION_CLASSES.include?(value) && !@subscription.subscribed? + if attr == 'klass' && @subscription.requires_additional_subscription("custom_fields", "klass").include?(value) add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value)) end @@ -100,7 +98,7 @@ class ::CustomWizard::CustomField add_error(I18n.t("#{i18n_key}.unsupported_type", type: value)) end - if attr == 'type' && SUBSCRIPTION_TYPES.include?(value) && !@subscription.subscribed? + if attr == 'type' && @subscription.requires_additional_subscription("custom_fields", "type").include?(value) add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value)) end diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 6c535602..7d94eb89 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -6,6 +6,23 @@ class CustomWizard::Subscription attr_accessor :authentication, :subscription + SUBSCRIPTION_LEVELS = { + standard: { + actions: ["send_message", "add_to_group", "watch_categories"], + custom_fields: { + klass: [], + type: ["json"], + }, + }, + business: { + actions: ["create_category", "create_group", "send_to_api"], + custom_fields: { + klass: ["group", "category"], + type: [], + }, + }, + } + def initialize @authentication = CustomWizard::Subscription::Authentication.new(get_authentication) @subscription = CustomWizard::Subscription::Subscription.new(get_subscription) @@ -39,6 +56,31 @@ class CustomWizard::Subscription "discourse-subscription-server:user_subscription" end + def requires_additional_subscription(kategory, sub_kategory) + case kategory + when "actions" + case self.type + when "business" + return [] + when "standard" + return SUBSCRIPTION_LEVELS[:business][kategory.to_sym] + else + return SUBSCRIPTION_LEVELS[:standard][kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym] + end + when "custom_fields" + case self.type + when "business" + return [] + when "standard" + return SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym]; + else + return SUBSCRIPTION_LEVELS[:standard][kategory.to_sym][sub_kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym] + end + else + return [] + end + end + def update if @authentication.active? response = Excon.get( @@ -127,6 +169,10 @@ class CustomWizard::Subscription self.new.type end + def self.requires_additional_subscription(kategory, sub_kategory) + self.new.requires_additional_subscription(kategory, sub_kategory) + end + def self.authorized? self.new.authorized? end diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 0c677300..284f63d3 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -179,7 +179,7 @@ describe CustomWizard::Action do context "subscription actions" do before do - enable_subscription + enable_subscription("standard") end it '#send_message' do diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index 28880409..f4a6d2fc 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -176,7 +176,7 @@ describe CustomWizard::Builder do context "restart is enabled" do before do - enable_subscription + enable_subscription("standard") @template[:restart_on_revisit] = true CustomWizard::Template.save(@template.as_json) end @@ -205,7 +205,7 @@ describe CustomWizard::Builder do context 'with required data' do before do - enable_subscription + enable_subscription("standard") @template[:steps][0][:required_data] = required_data_json['required_data'] @template[:steps][0][:required_data_message] = required_data_json['required_data_message'] CustomWizard::Template.save(@template.as_json) @@ -241,7 +241,7 @@ describe CustomWizard::Builder do context "with permitted params" do before do - enable_subscription + enable_subscription("standard") @template[:steps][0][:permitted_params] = permitted_param_json['permitted_params'] CustomWizard::Template.save(@template.as_json) end @@ -256,7 +256,7 @@ describe CustomWizard::Builder do context "with condition" do before do - enable_subscription + enable_subscription("standard") @template[:steps][0][:condition] = user_condition_json['condition'] CustomWizard::Template.save(@template.as_json) end @@ -295,7 +295,7 @@ describe CustomWizard::Builder do context "with condition" do before do - enable_subscription + enable_subscription("standard") @template[:steps][0][:fields][0][:condition] = user_condition_json['condition'] CustomWizard::Template.save(@template.as_json) end @@ -327,7 +327,7 @@ describe CustomWizard::Builder do context 'save submissions disabled' do before do - enable_subscription + enable_subscription("standard") @template[:save_submissions] = false CustomWizard::Template.save(@template.as_json) @wizard = CustomWizard::Builder.new(@template[:id], user).build diff --git a/spec/components/custom_wizard/custom_field_spec.rb b/spec/components/custom_wizard/custom_field_spec.rb index a30ec02b..fd0fa4fc 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -217,7 +217,7 @@ describe CustomWizard::CustomField do context "with a subscription" do before do - enable_subscription + enable_subscription("business") end it "saves subscription field types" do diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index 1ac945d0..71c1e7de 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -359,7 +359,7 @@ describe CustomWizard::Mapper do context "with a subscription" do before do - enable_subscription + enable_subscription("standard") end it "treats replaced values as string literals" do diff --git a/spec/components/custom_wizard/template_validator_spec.rb b/spec/components/custom_wizard/template_validator_spec.rb index e8b8af28..14214e4d 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -75,7 +75,7 @@ describe CustomWizard::TemplateValidator do context "with subscription" do before do - enable_subscription + enable_subscription("standard") end it "validates wizard attributes" do diff --git a/spec/extensions/custom_field_extensions_spec.rb b/spec/extensions/custom_field_extensions_spec.rb index 7bba27a0..3660644b 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -74,7 +74,7 @@ describe "custom field extensions" do context "subscription custom fields" do before do - enable_subscription + enable_subscription("business") subscription_custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index e72fe355..232a2411 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -29,8 +29,10 @@ def authenticate_subscription CustomWizard::Subscription::Authentication.any_instance.stubs(:active?).returns(true) end -def enable_subscription +def enable_subscription(type) + # CustomWizard::Subscription.new CustomWizard::Subscription.any_instance.stubs(:subscribed?).returns(true) + CustomWizard::Subscription.any_instance.stubs(:type).returns(type) end def disable_subscription diff --git a/spec/requests/custom_wizard/custom_field_extensions_spec.rb b/spec/requests/custom_wizard/custom_field_extensions_spec.rb index 775e3ee0..19a8417a 100644 --- a/spec/requests/custom_wizard/custom_field_extensions_spec.rb +++ b/spec/requests/custom_wizard/custom_field_extensions_spec.rb @@ -40,8 +40,7 @@ describe "custom field extensions" do context "with a subscription" do before do - enable_subscription - + enable_subscription("business") subscription_custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) custom_field.save diff --git a/spec/requests/custom_wizard/steps_controller_spec.rb b/spec/requests/custom_wizard/steps_controller_spec.rb index 8396135c..b55de419 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -121,7 +121,7 @@ describe CustomWizard::StepsController do context "subscription" do before do - enable_subscription + enable_subscription("standard") end it "raises an error when user cant see the step due to conditions" do diff --git a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb index 0a9f7e89..f0128765 100644 --- a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb @@ -34,7 +34,7 @@ describe CustomWizard::StepSerializer do context 'with required data' do before do - enable_subscription + enable_subscription("standard") wizard_template['steps'][0]['required_data'] = required_data_json['required_data'] wizard_template['steps'][0]['required_data_message'] = required_data_json['required_data_message'] CustomWizard::Template.save(wizard_template) From 584ee6d24edb0937d7a8846dc0bfb0d0bf4496e2 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 9 Nov 2021 15:01:17 +0000 Subject: [PATCH 39/41] remove redundant returns --- lib/custom_wizard/subscription.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 7d94eb89..1ab53dc9 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -61,23 +61,23 @@ class CustomWizard::Subscription when "actions" case self.type when "business" - return [] + [] when "standard" - return SUBSCRIPTION_LEVELS[:business][kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym] else - return SUBSCRIPTION_LEVELS[:standard][kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym] + SUBSCRIPTION_LEVELS[:standard][kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym] end when "custom_fields" case self.type when "business" - return [] + [] when "standard" - return SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym]; + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym]; else - return SUBSCRIPTION_LEVELS[:standard][kategory.to_sym][sub_kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym] + SUBSCRIPTION_LEVELS[:standard][kategory.to_sym][sub_kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym] end else - return [] + [] end end From e37b2a6e852544e71622366a24fcacfe31736ff7 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 9 Nov 2021 15:04:04 +0000 Subject: [PATCH 40/41] Remove semi colon! --- lib/custom_wizard/subscription.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 1ab53dc9..7bac7f59 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -72,7 +72,7 @@ class CustomWizard::Subscription when "business" [] when "standard" - SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym]; + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym] else SUBSCRIPTION_LEVELS[:standard][kategory.to_sym][sub_kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym][sub_kategory.to_sym] end From 457463f7c76fc79accff00b8509165f4d7df70c4 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 10 Nov 2021 22:25:42 +0800 Subject: [PATCH 41/41] Add blankspace --- lib/custom_wizard/custom_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/custom_wizard/custom_field.rb b/lib/custom_wizard/custom_field.rb index 99dcfbbb..ed0c9594 100644 --- a/lib/custom_wizard/custom_field.rb +++ b/lib/custom_wizard/custom_field.rb @@ -83,6 +83,7 @@ class ::CustomWizard::CustomField add_error(I18n.t("#{i18n_key}.unsupported_class", class: value)) next end + if attr == 'klass' && @subscription.requires_additional_subscription("custom_fields", "klass").include?(value) add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value)) end