From 7b129debacdf174e9b390e788ea8c43d74f72451 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 25 Oct 2021 15:31:44 +0100 Subject: [PATCH] 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