From 67cfeb6ed95663809d0768e1adab3bb481bbbfed Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 12 Oct 2021 12:51:38 +0100 Subject: [PATCH] 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