Merge pull request #147 from paviliondev/pro-release-api
Pro release api
Dieser Commit ist enthalten in:
Commit
bbd1253891
48 geänderte Dateien mit 427 neuen und 165 gelöschten Zeilen
|
@ -1,27 +1,27 @@
|
|||
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";
|
||||
|
||||
const klasses = ["topic", "post", "group", "category"];
|
||||
const types = ["string", "boolean", "integer", "json"];
|
||||
const subscriptionTypes = {
|
||||
klass: ["group", "category"],
|
||||
type: ["json"],
|
||||
};
|
||||
import wizardSchema, {
|
||||
requiringAdditionalSubscription,
|
||||
subscriptionLevel,
|
||||
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
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;
|
||||
}, []);
|
||||
};
|
||||
|
@ -32,12 +32,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"),
|
||||
|
@ -54,12 +48,26 @@ export default Component.extend({
|
|||
const serializers = this.get(`${klass}Serializers`);
|
||||
|
||||
if (serializers) {
|
||||
return generateContent(serializers, "serializers", this.subscribed);
|
||||
} else {
|
||||
return [];
|
||||
return serializers.reduce((result, key) => {
|
||||
result.push({
|
||||
id: key,
|
||||
name: I18n.t(`admin.wizard.custom_field.serializers.${key}`),
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
},
|
||||
|
||||
@discourseComputed("subscription")
|
||||
customFieldTypes(subscription) {
|
||||
return generateContent("type", subscription);
|
||||
},
|
||||
|
||||
@discourseComputed("subscription")
|
||||
customFieldKlasses(subscription) {
|
||||
return generateContent("klass", subscription);
|
||||
},
|
||||
|
||||
@observes("field.klass")
|
||||
clearSerializersWhenClassChanges() {
|
||||
this.set("field.serializers", null);
|
||||
|
|
|
@ -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`;
|
||||
}
|
||||
});
|
||||
return `admin.wizard.subscription_container.${
|
||||
subscribed ? "subscribed" : "not_subscribed"
|
||||
}.title`;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
||||
import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||
import wizardSchema, {
|
||||
requiringAdditionalSubscription,
|
||||
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";
|
||||
import { computed } from "@ember/object";
|
||||
|
@ -94,17 +97,21 @@ export default Component.extend(UndoChanges, {
|
|||
return apis.find((a) => a.name === api).endpoints;
|
||||
},
|
||||
|
||||
@discourseComputed("subscribed")
|
||||
actionTypes(subscribed) {
|
||||
@discourseComputed("subscription")
|
||||
actionTypes(subscription) {
|
||||
let unsubscribedActions = requiringAdditionalSubscription(
|
||||
subscription,
|
||||
"actions",
|
||||
""
|
||||
);
|
||||
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,
|
||||
});
|
||||
}
|
||||
let disabled = unsubscribedActions.includes(type);
|
||||
result.push({
|
||||
id: type,
|
||||
name: I18n.t(`admin.wizard.action.${type}.label`),
|
||||
subscription: subscriptionLevel(type, "actions", ""),
|
||||
disabled,
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
|
@ -193,32 +193,110 @@ const action = {
|
|||
"members_visibility_level",
|
||||
],
|
||||
required: ["id", "type"],
|
||||
subscriptionTypes: [
|
||||
"send_message",
|
||||
"add_to_group",
|
||||
"create_category",
|
||||
"create_group",
|
||||
"send_to_api",
|
||||
],
|
||||
required: ["id", "type"],
|
||||
proTypes: [
|
||||
"send_message",
|
||||
"add_to_group",
|
||||
"create_category",
|
||||
"create_group",
|
||||
"send_to_api",
|
||||
],
|
||||
dependent: {},
|
||||
objectArrays: {},
|
||||
};
|
||||
|
||||
const custom_field = {
|
||||
klass: ["topic", "post", "group", "category"],
|
||||
type: ["string", "boolean", "integer", "json"],
|
||||
};
|
||||
|
||||
const 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: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const wizardSchema = {
|
||||
wizard,
|
||||
step,
|
||||
field,
|
||||
custom_field,
|
||||
action,
|
||||
subscription_levels,
|
||||
};
|
||||
|
||||
export function requiringAdditionalSubscription(
|
||||
currentSubscription,
|
||||
category,
|
||||
subCategory
|
||||
) {
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
|
||||
export function subscriptionLevel(type, category, 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 buildFieldTypes(types) {
|
||||
wizardSchema.field.types = types;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
export default CustomWizardNotice;
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -40,6 +40,7 @@ export default DiscourseRoute.extend({
|
|||
currentAction: wizard.actions[0],
|
||||
creating: model.create,
|
||||
subscribed: parentModel.subscribed,
|
||||
subscription: parentModel.subscription,
|
||||
};
|
||||
|
||||
controller.setProperties(props);
|
||||
|
|
|
@ -4,16 +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("notices", A(model.notices));
|
||||
controller.set("api_section", model.api_section);
|
||||
},
|
||||
|
||||
afterModel(model, transition) {
|
||||
if (transition.targetName === "adminWizards.index") {
|
||||
this.transitionTo("adminWizardsWizard");
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
field=field
|
||||
removeField=(action "removeField")
|
||||
saveField=(action "saveField")
|
||||
subscribed=subscribed}}
|
||||
subscribed=subscribed
|
||||
subscription=subscription}}
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -178,7 +178,8 @@
|
|||
apis=apis
|
||||
removeAction="removeAction"
|
||||
wizardFields=wizardFields
|
||||
subscribed=subscribed}}
|
||||
subscribed=subscribed
|
||||
subscription=subscription}}
|
||||
{{/each}}
|
||||
|
||||
<div class="admin-wizard-buttons">
|
||||
|
|
|
@ -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 api_section}}
|
||||
{{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}}
|
||||
{{/if}}
|
||||
{{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}}
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
<td>
|
||||
{{wizard-subscription-selector
|
||||
value=field.klass
|
||||
content=klassContent
|
||||
content=customFieldKlasses
|
||||
none="admin.wizard.custom_field.klass.select"
|
||||
onChange=(action (mut field.klass))}}
|
||||
</td>
|
||||
<td>
|
||||
{{wizard-subscription-selector
|
||||
value=field.type
|
||||
content=typeContent
|
||||
content=customFieldTypes
|
||||
none="admin.wizard.custom_field.type.select"
|
||||
onChange=(action (mut field.type))}}
|
||||
</td>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</div>
|
||||
|
||||
<div class="notice-message">
|
||||
{{{notice.message}}}
|
||||
{{html-safe notice.message}}
|
||||
</div>
|
||||
|
||||
{{#if importantOnDashboard}}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
<div class="texts">
|
||||
<span class="name">{{html-safe label}}</span>
|
||||
{{#if item.subscription}}
|
||||
<span class="subscription-label">{{i18n "admin.wizard.subscription.label"}}</span>
|
||||
<span class="subscription-label">
|
||||
{{item.subscription}}
|
||||
</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -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"),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -788,11 +788,6 @@
|
|||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.subscription-label {
|
||||
color: var(--tertiary);
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.admin-wizards-subscription {
|
||||
.admin-wizard-controls {
|
||||
h3,
|
||||
|
@ -853,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -924,7 +926,7 @@
|
|||
}
|
||||
|
||||
.d-icon {
|
||||
margin-right: .4em;
|
||||
margin-right: 0.4em;
|
||||
}
|
||||
|
||||
.notice-header {
|
||||
|
@ -935,9 +937,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;
|
||||
|
@ -963,12 +965,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 {
|
||||
|
|
|
@ -466,7 +466,8 @@ en:
|
|||
|
||||
subscription:
|
||||
nav_label: Subscription
|
||||
label: Subscription
|
||||
label: In subscription
|
||||
additional_label: "Add subscription"
|
||||
title: Custom Wizard Subscription
|
||||
authorize: Authorize
|
||||
authorized: Authorized
|
||||
|
@ -474,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
|
||||
|
|
|
@ -15,9 +15,6 @@ plugins:
|
|||
refresh: true
|
||||
type: list
|
||||
list_type: compact
|
||||
wizard_apis_enabled:
|
||||
client: true
|
||||
default: false
|
||||
wizard_important_notices_on_dashboard:
|
||||
client: true
|
||||
default: true
|
||||
default: true
|
||||
|
|
|
@ -4,6 +4,8 @@ class CustomWizard::AdminController < ::Admin::AdminController
|
|||
|
||||
def index
|
||||
render_json_dump(
|
||||
#TODO replace with appropriate static?
|
||||
api_section: ["business"].include?(CustomWizard::Subscription.type),
|
||||
notices: ActiveModel::ArraySerializer.new(
|
||||
CustomWizard::Notice.list,
|
||||
each_serializer: CustomWizard::NoticeSerializer
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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(endpoint.url, headers: headers)
|
||||
|
||||
params = { method: endpoint.method }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -85,7 +84,7 @@ class ::CustomWizard::CustomField
|
|||
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 +99,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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -27,6 +44,10 @@ class CustomWizard::Subscription
|
|||
"stripe"
|
||||
end
|
||||
|
||||
def type
|
||||
@subscription.type
|
||||
end
|
||||
|
||||
def client_name
|
||||
"custom-wizard"
|
||||
end
|
||||
|
@ -35,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"
|
||||
[]
|
||||
when "standard"
|
||||
SUBSCRIPTION_LEVELS[:business][kategory.to_sym]
|
||||
else
|
||||
SUBSCRIPTION_LEVELS[:standard][kategory.to_sym] + SUBSCRIPTION_LEVELS[:business][kategory.to_sym]
|
||||
end
|
||||
when "custom_fields"
|
||||
case self.type
|
||||
when "business"
|
||||
[]
|
||||
when "standard"
|
||||
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
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @authentication.active?
|
||||
response = Excon.get(
|
||||
|
@ -119,6 +165,14 @@ class CustomWizard::Subscription
|
|||
self.new.subscribed?
|
||||
end
|
||||
|
||||
def self.type
|
||||
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
|
||||
|
|
|
@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription
|
|||
end
|
||||
|
||||
def types
|
||||
%w(community business)
|
||||
%w(none standard business)
|
||||
end
|
||||
|
||||
def active?
|
||||
|
|
|
@ -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)
|
||||
|
@ -176,7 +179,7 @@ describe CustomWizard::Action do
|
|||
|
||||
context "subscription actions" do
|
||||
before do
|
||||
enable_subscription
|
||||
enable_subscription("standard")
|
||||
end
|
||||
|
||||
it '#send_message' do
|
||||
|
@ -265,5 +268,51 @@ describe CustomWizard::Action do
|
|||
|
||||
expect(group.users.first.username).to eq('angus')
|
||||
end
|
||||
|
||||
it '#send_to_api successful' 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
|
||||
|
||||
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({ error: "API request failed" })
|
||||
expect(log_entry.status).to eq('FAIL')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
3
spec/fixtures/api/no_authorization.json
gevendort
Normale Datei
3
spec/fixtures/api/no_authorization.json
gevendort
Normale Datei
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"auth_type": "none"
|
||||
}
|
5
spec/fixtures/endpoints/test_endpoint.json
gevendort
Normale Datei
5
spec/fixtures/endpoints/test_endpoint.json
gevendort
Normale Datei
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"method": "PUT",
|
||||
"url": "https://myexternalapi.com/update",
|
||||
"success_codes": [200]
|
||||
}
|
3
spec/fixtures/endpoints/test_endpoint_body.json
gevendort
Normale Datei
3
spec/fixtures/endpoints/test_endpoint_body.json
gevendort
Normale Datei
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"data": "some_data"
|
||||
}
|
|
@ -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(
|
||||
|
@ -28,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Laden …
In neuem Issue referenzieren