1
0
Fork 0

partial generalisation of subscription logic

Dieser Commit ist enthalten in:
merefield 2021-10-25 15:31:44 +01:00
Ursprung a806e14c64
Commit 7b129debac
2 geänderte Dateien mit 67 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
import { default as discourseComputed } from "discourse-common/utils/decorators"; import { default as discourseComputed } from "discourse-common/utils/decorators";
import wizardSchema, { import wizardSchema, {
actionsRequiringAdditionalSubscription, actionsRequiringAdditionalSubscription,
requiringAdditionalSubscription,
actionSubscriptionLevel, actionSubscriptionLevel,
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
import { empty, equal, or } from "@ember/object/computed"; import { empty, equal, or } from "@ember/object/computed";
@ -99,7 +100,9 @@ export default Component.extend(UndoChanges, {
@discourseComputed("subscribed", "subscription") @discourseComputed("subscribed", "subscription")
actionTypes(subscribed, subscription) { actionTypes(subscribed, subscription) {
let unsubscribedActions = actionsRequiringAdditionalSubscription( let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions");
debugger;
let unsubscribedActionslong = actionsRequiringAdditionalSubscription(
subscription subscription
); );
return Object.keys(wizardSchema.action.types).reduce((result, type) => { return Object.keys(wizardSchema.action.types).reduce((result, type) => {

Datei anzeigen

@ -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 = { const wizardSchema = {
wizard, wizard,
step, step,
field, field,
custom_field, custom_field,
action, 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( export function actionsRequiringAdditionalSubscription(
currentSubscription currentSubscription