0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 11:52:54 +01:00

Merge pull request #266 from paviliondev/use_subscription_gem

DEV: switch to using subscription gem to avoid the need to rely on Subscription Client plugin
Dieser Commit ist enthalten in:
Angus McLeod 2023-11-17 14:03:40 +01:00 committet von GitHub
Commit 7028471603
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
73 geänderte Dateien mit 651 neuen und 289 gelöschten Zeilen

Datei anzeigen

@ -2,16 +2,6 @@
class CustomWizard::AdminController < ::Admin::AdminController class CustomWizard::AdminController < ::Admin::AdminController
before_action :ensure_admin before_action :ensure_admin
def index
subcription = CustomWizard::Subscription.new
render_json_dump(
subscribed: subcription.subscribed?,
subscription_type: subcription.type,
subscription_attributes: CustomWizard::Subscription.attributes,
subscription_client_installed: CustomWizard::Subscription.client_installed?
)
end
private private
def find_wizard def find_wizard

Datei anzeigen

@ -0,0 +1,18 @@
# frozen_string_literal: true
class CustomWizard::SubscriptionController < ::Admin::AdminController
before_action :ensure_admin
def index
if params[:update_from_remote]
subscription = CustomWizard::Subscription.new(true)
else
subscription = CustomWizard::Subscription.new
end
render_json_dump(
subscribed: subscription.subscribed?,
subscription_type: subscription.type,
subscription_attributes: CustomWizard::Subscription.attributes,
)
end
end

Datei anzeigen

@ -5,11 +5,13 @@ import I18n from "I18n";
export default class AdminWizardsColumnComponent extends Component { export default class AdminWizardsColumnComponent extends Component {
title = I18n.t("admin.wizard.edit_columns"); title = I18n.t("admin.wizard.edit_columns");
@action save() { @action
save() {
this.args.closeModal(); this.args.closeModal();
} }
@action resetToDefault() { @action
resetToDefault() {
this.args.model.reset(); this.args.model.reset();
} }
} }

Datei anzeigen

@ -18,13 +18,15 @@ export default class NextSessionScheduledComponent extends Component {
return moment().isAfter(this.bufferedDateTime); return moment().isAfter(this.bufferedDateTime);
} }
@action submit() { @action
submit() {
const dateTime = this.bufferedDateTime; const dateTime = this.bufferedDateTime;
this.args.model.update(moment(dateTime).utc().toISOString()); this.args.model.update(moment(dateTime).utc().toISOString());
this.args.closeModal(); this.args.closeModal();
} }
@action dateTimeChanged(dateTime) { @action
dateTimeChanged(dateTime) {
this.bufferedDateTime = dateTime; this.bufferedDateTime = dateTime;
} }
} }

Datei anzeigen

@ -15,7 +15,7 @@ import {
import Component from "@ember/component"; import Component from "@ember/component";
import { bind, later } from "@ember/runloop"; import { bind, later } from "@ember/runloop";
import I18n from "I18n"; import I18n from "I18n";
import Subscription from "../mixins/subscription"; import { inject as service } from "@ember/service";
const customFieldActionMap = { const customFieldActionMap = {
topic: ["create_topic", "send_message"], topic: ["create_topic", "send_message"],
@ -27,8 +27,9 @@ const customFieldActionMap = {
const values = ["present", "true", "false"]; const values = ["present", "true", "false"];
export default Component.extend(Subscription, { export default Component.extend({
classNameBindings: [":mapper-selector", "activeType"], classNameBindings: [":mapper-selector", "activeType"],
subscription: service(),
showText: computed("activeType", function () { showText: computed("activeType", function () {
return this.showInput("text"); return this.showInput("text");
@ -130,7 +131,11 @@ export default Component.extend(Subscription, {
return this.connector === "is"; return this.connector === "is";
}), }),
@discourseComputed("site.groups", "guestGroup", "subscriptionType") @discourseComputed(
"site.groups",
"guestGroup",
"subscription.subscriptionType"
)
groups(groups, guestGroup, subscriptionType) { groups(groups, guestGroup, subscriptionType) {
let result = groups; let result = groups;
if (!guestGroup) { if (!guestGroup) {

Datei anzeigen

@ -0,0 +1,19 @@
<DButton
@action={{this.click}}
class="wizard-subscription-badge {{this.subscription.subscriptionType}}"
@title={{this.title}}
>
{{d-icon "pavilion-logo"}}
<span>{{this.label}}</span>
</DButton>
<DButton
@icon={{this.updateIcon}}
@action={{this.update}}
class="btn btn-primary update"
@disabled={{this.updating}}
@title="admin.wizard.subscription.update.title"
>
{{#if this.updating}}
{{loading-spinner size="small"}}
{{/if}}
</DButton>

Datei anzeigen

@ -0,0 +1,47 @@
import { inject as service } from "@ember/service";
import { action, computed } from "@ember/object";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import DiscourseURL from "discourse/lib/url";
import I18n from "I18n";
export default class WizardSubscriptionBadge extends Component {
@service subscription;
@tracked updating = false;
@tracked updateIcon = "sync";
basePath = "/admin/plugins/subscription-client";
@computed("subscription.subscriptionType")
get i18nKey() {
return `admin.wizard.subscription.type.${
this.subscription.subscriptionType
? this.subscription.subscriptionType
: "none"
}`;
}
@computed("i18nKey")
get title() {
return `${this.i18nKey}.title`;
}
@computed("i18nKey")
get label() {
return I18n.t(`${this.i18nKey}.label`);
}
@action
click() {
DiscourseURL.routeTo(this.subscription.subscriptionLink);
}
@action
update() {
this.updating = true;
this.updateIcon = null;
this.subscription.updateSubscriptionStatus().finally(() => {
this.updateIcon = "sync";
this.updating = false;
});
}
}

Datei anzeigen

@ -1,30 +0,0 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import Subscription from "../mixins/subscription";
import DiscourseURL from "discourse/lib/url";
import I18n from "I18n";
export default Component.extend(Subscription, {
tagName: "a",
classNameBindings: [":wizard-subscription-badge", "subscriptionType"],
attributeBindings: ["title"],
@discourseComputed("subscriptionType")
i18nKey(type) {
return `admin.wizard.subscription.type.${type ? type : "none"}`;
},
@discourseComputed("i18nKey")
title(i18nKey) {
return I18n.t(`${i18nKey}.title`);
},
@discourseComputed("i18nKey")
label(i18nKey) {
return I18n.t(`${i18nKey}.label`);
},
click() {
DiscourseURL.routeTo(this.subscriptionLink);
},
});

Datei anzeigen

@ -0,0 +1,17 @@
<div
class="wizard-subscription-container
{{if this.subscription.subscribed 'subscribed'}}"
>
<div class="subscription-header">
<h4>{{i18n "admin.wizard.subscription.title"}}</h4>
<a href={{subscriptionLink}} title={{i18n subscribedTitle}}>
{{d-icon subscribedIcon}}
{{i18n subscribedLabel}}
</a>
</div>
<div class="subscription-settings">
{{yield}}
</div>
</div>

Datei anzeigen

@ -0,0 +1,26 @@
import Component from "@glimmer/component";
import { computed } from "@ember/object";
import { inject as service } from "@ember/service";
export default class WizardSubscriptionContainer extends Component {
@service subscription;
@computed("subscription.subscribed")
get subscribedIcon() {
return this.subscription.subscribed ? "check" : "times";
}
@computed("subscription.subscribed")
get subscribedLabel() {
return `admin.wizard.subscription.${
this.subscription.subscribed ? "subscribed" : "not_subscribed"
}.label`;
}
@computed("subscription.subscribed")
get subscribedTitle() {
return `admin.wizard.subscription.${
this.subscription.subscribed ? "subscribed" : "not_subscribed"
}.title`;
}
}

Datei anzeigen

@ -1,26 +0,0 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import Subscription from "../mixins/subscription";
export default Component.extend(Subscription, {
classNameBindings: [":wizard-subscription-container", "subscribed"],
@discourseComputed("subscribed")
subscribedIcon(subscribed) {
return subscribed ? "check" : "times";
},
@discourseComputed("subscribed")
subscribedLabel(subscribed) {
return `admin.wizard.subscription.${
subscribed ? "subscribed" : "not_subscribed"
}.label`;
},
@discourseComputed("subscribed")
subscribedTitle(subscribed) {
return `admin.wizard.subscription.${
subscribed ? "subscribed" : "not_subscribed"
}.title`;
},
});

Datei anzeigen

@ -0,0 +1,7 @@
<DButton
@action={{this.click}}
class="btn btn-pavilion-support {{this.subscription.subscriptionType}}"
@title={{this.title}}
@label={{this.label}}
@icon={{this.icon}}
/>

Datei anzeigen

@ -0,0 +1,34 @@
import { inject as service } from "@ember/service";
import { action, computed } from "@ember/object";
import Component from "@glimmer/component";
export default class WizardSubscriptionCta extends Component {
@service subscription;
@computed("subscription.subscribed")
get i18nKey() {
return `admin.wizard.subscription.cta.${
this.subscription.subscribed ? "subscribed" : "none"
}`;
}
@computed("subscription.subscribed")
get icon() {
return this.subscription.subscribed ? "far-life-ring" : "external-link-alt";
}
@computed("i18nKey")
get title() {
return `${this.i18nKey}.title`;
}
@computed("i18nKey")
get label() {
return `${this.i18nKey}.label`;
}
@action
click() {
window.open(this.subscription.subscriptionCtaLink, "_blank").focus();
}
}

Datei anzeigen

@ -1,36 +0,0 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import Subscription from "../mixins/subscription";
import I18n from "I18n";
export default Component.extend(Subscription, {
tagName: "a",
classNameBindings: [":btn", ":btn-pavilion-support", "subscriptionType"],
attributeBindings: ["title"],
@discourseComputed("subscribed")
i18nKey(subscribed) {
return `admin.wizard.subscription.cta.${
subscribed ? "subscribed" : "none"
}`;
},
@discourseComputed("subscribed")
icon(subscribed) {
return subscribed ? "far-life-ring" : "external-link-alt";
},
@discourseComputed("i18nKey")
title(i18nKey) {
return I18n.t(`${i18nKey}.title`);
},
@discourseComputed("i18nKey")
label(i18nKey) {
return I18n.t(`${i18nKey}.label`);
},
click() {
window.open(this.subscriptionCtaLink, "_blank").focus();
},
});

Datei anzeigen

@ -1,5 +1,5 @@
import SingleSelectComponent from "select-kit/components/single-select"; import SingleSelectComponent from "select-kit/components/single-select";
import Subscription from "../mixins/subscription"; import { inject as service } from "@ember/service";
import { filterValues } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import { filterValues } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n"; import I18n from "I18n";
@ -12,8 +12,9 @@ const nameKey = function (feature, attribute, value) {
} }
}; };
export default SingleSelectComponent.extend(Subscription, { export default SingleSelectComponent.extend({
classNames: ["combo-box", "wizard-subscription-selector"], classNames: ["combo-box", "wizard-subscription-selector"],
subscription: service(),
selectKitOptions: { selectKitOptions: {
autoFilterable: false, autoFilterable: false,
@ -26,7 +27,7 @@ export default SingleSelectComponent.extend(Subscription, {
}, },
allowedSubscriptionTypes(feature, attribute, value) { allowedSubscriptionTypes(feature, attribute, value) {
let attributes = this.subscriptionAttributes[feature]; let attributes = this.subscription.subscriptionAttributes[feature];
if (!attributes || !attributes[attribute]) { if (!attributes || !attributes[attribute]) {
return ["none"]; return ["none"];
} }
@ -59,10 +60,9 @@ export default SingleSelectComponent.extend(Subscription, {
name: I18n.t(nameKey(feature, attribute, value)), name: I18n.t(nameKey(feature, attribute, value)),
subscriptionRequired, subscriptionRequired,
}; };
if (subscriptionRequired) { if (subscriptionRequired) {
let subscribed = allowedSubscriptionTypes.includes( let subscribed = allowedSubscriptionTypes.includes(
this.subscriptionType this.subscription.subscriptionType
); );
let selectorKey = subscribed ? "subscribed" : "not_subscribed"; let selectorKey = subscribed ? "subscribed" : "not_subscribed";
let selectorLabel = `admin.wizard.subscription.${selectorKey}.selector`; let selectorLabel = `admin.wizard.subscription.${selectorKey}.selector`;

Datei anzeigen

@ -0,0 +1,23 @@
<div class="supplier-authorize">
{{#if authorized}}
{{conditional-loading-spinner size="small" condition=unauthorizing}}
<DButton
class="deauthorize"
@title="admin.wizard.subscription.deauthorize.title"
@disabled={{unauthorizing}}
@action={{this.deauthorize}}
>
{{i18n "admin.wizard.subscription.deauthorize.label"}}
</DButton>
{{else}}
<DButton
@icon="id-card"
class="btn-primary"
@label="admin.wizard.subscription.authorize.label"
@title="admin.wizard.subscription.authorize.title"
@action={{this.authorize}}
/>
{{/if}}
<WizardSubscriptionBadge />
<WizardSubscriptionCta />
</div>

Datei anzeigen

@ -0,0 +1,53 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default class WizardSubscriptionStatus extends Component {
@service siteSettings;
@service subscription;
@tracked supplierId = null;
@tracked authorized = false;
@tracked unauthorizing = false;
basePath = "/admin/plugins/subscription-client/suppliers";
constructor() {
super(...arguments);
ajax(`${this.basePath}`)
.then((result) => {
this.supplierId = result.suppliers[0].id;
this.authorized = result.suppliers[0].authorized;
})
.finally(() => {
this.subscription.retrieveSubscriptionStatus();
});
}
@action
authorize() {
window.location.href = `${this.basePath}/authorize?supplier_id=${this.supplierId}&final_landing_path=/admin/wizards/wizard`;
}
@action
deauthorize() {
this.unauthorizing = true;
ajax(`${this.basePath}/authorize`, {
type: "DELETE",
data: {
supplier_id: this.supplierId,
},
})
.then((result) => {
this.supplierId = result.supplier.id;
this.authorized = !(result.supplier.authorized_at === null);
})
.finally(() => {
this.unauthorizing = false;
this.subscription.retrieveSubscriptionStatus();
})
.catch(popupAjaxError);
}
}

Datei anzeigen

@ -1,9 +1,12 @@
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import { equal, or } from "@ember/object/computed"; import { or } from "@ember/object/computed";
import { inject as service } from "@ember/service";
export default Controller.extend({ export default Controller.extend({
businessSubscription: equal("subscriptionType", "business"), subscription: service(),
communitySubscription: equal("subscriptionType", "community"),
standardSubscription: equal("subscriptionType", "standard"), showApi: or(
showApi: or("businessSubscription", "communitySubscription"), "subscription.businessSubscription",
"subscription.communitySubscription"
),
}); });

Datei anzeigen

@ -0,0 +1,21 @@
import I18n from "I18n";
import Handlebars from "handlebars";
export default function wizardCharCounter(body, maxLength) {
let bodyLength = body ? body.length : 0;
let finalString;
if (maxLength) {
let isOverMax = bodyLength > maxLength ? "true" : "false";
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${I18n.t(
"wizard.x_characters",
{ count: parseInt(maxLength, 10) }
)}</div>`;
} else {
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
count: parseInt(bodyLength, 10),
})}</div>`;
}
return new Handlebars.SafeString(finalString);
}

Datei anzeigen

@ -1,25 +0,0 @@
import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "I18n";
import Handlebars from "handlebars";
export default registerUnbound(
"wizard-char-counter",
function (body, maxLength) {
let bodyLength = body ? body.length : 0;
let finalString;
if (maxLength) {
let isOverMax = bodyLength > maxLength ? "true" : "false";
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${I18n.t(
"wizard.x_characters",
{ count: parseInt(maxLength, 10) }
)}</div>`;
} else {
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
count: parseInt(bodyLength, 10),
})}</div>`;
}
return new Handlebars.SafeString(finalString);
}
);

Datei anzeigen

@ -1,23 +1,9 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { ajax } from "discourse/lib/ajax";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
router: service(), router: service(),
model() {
return ajax("/admin/wizards");
},
setupController(controller, model) {
controller.setProperties({
subscribed: model.subscribed,
subscriptionType: model.subscription_type,
subscriptionAttributes: model.subscription_attributes,
subscriptionClientInstalled: model.subscription_client_installed,
});
},
afterModel(model, transition) { afterModel(model, transition) {
if (transition.targetName === "adminWizards.index") { if (transition.targetName === "adminWizards.index") {
this.router.transitionTo("adminWizardsWizard"); this.router.transitionTo("adminWizardsWizard");

Datei anzeigen

@ -0,0 +1,70 @@
import Service from "@ember/service";
import { tracked } from "@glimmer/tracking";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
const PRODUCT_PAGE = "https://custom-wizard.pavilion.tech";
const SUPPORT_MESSAGE =
"https://coop.pavilion.tech/new-message?username=support&title=Custom%20Wizard%20Support";
const MANAGER_CATEGORY =
"https://discourse.pluginmanager.org/c/discourse-custom-wizard";
export default class SubscriptionService extends Service {
@tracked subscribed = false;
@tracked subscriptionType = "";
@tracked businessSubscription = false;
@tracked communitySubscription = false;
@tracked standardSubscription = false;
@tracked subscriptionAttributes = {};
subscriptionLandingUrl = PRODUCT_PAGE;
async init() {
super.init(...arguments);
await this.retrieveSubscriptionStatus();
}
async retrieveSubscriptionStatus() {
let result = await ajax("/admin/wizards/subscription").catch(
popupAjaxError
);
this.subscribed = result.subscribed;
this.subscriptionType = result.subscription_type;
this.subscriptionAttributes = result.subscription_attributes;
this.businessSubscription = this.subscriptionType === "business";
this.communitySubscription = this.subscriptionType === "community";
this.standardSubscription = this.subscriptionType === "standard";
}
async updateSubscriptionStatus() {
let result = await ajax(
"/admin/wizards/subscription?update_from_remote=true"
).catch(popupAjaxError);
this.subscribed = result.subscribed;
this.subscriptionType = result.subscription_type;
this.subscriptionAttributes = result.subscription_attributes;
this.businessSubscription = this.subscriptionType === "business";
this.communitySubscription = this.subscriptionType === "community";
this.standardSubscription = this.subscriptionType === "standard";
}
get subscriptionLink() {
return this.subscriptionLandingUrl;
}
get subscriptionCtaLink() {
switch (this.subscriptionType) {
case "none":
return PRODUCT_PAGE;
case "standard":
return SUPPORT_MESSAGE;
case "business":
return SUPPORT_MESSAGE;
case "community":
return MANAGER_CATEGORY;
default:
return PRODUCT_PAGE;
}
}
}

Datei anzeigen

@ -18,8 +18,7 @@
}} }}
<div class="admin-actions"> <div class="admin-actions">
{{wizard-subscription-badge}} <WizardSubscriptionStatus />
{{wizard-subscription-cta}}
</div> </div>
{{/admin-nav}} {{/admin-nav}}

Datei anzeigen

@ -1,12 +0,0 @@
<div class="subscription-header">
<h4>{{i18n "admin.wizard.subscription.title"}}</h4>
<a href={{subscriptionLink}} title={{i18n subscribedTitle}}>
{{d-icon subscribedIcon}}
{{i18n subscribedLabel}}
</a>
</div>
<div class="subscription-settings">
{{yield}}
</div>

Datei anzeigen

@ -1 +0,0 @@
{{d-icon icon}}{{label}}

Datei anzeigen

@ -43,14 +43,6 @@ $error: #ef1700;
} }
} }
.admin-wizards .admin-actions {
display: flex;
.btn-pavilion-support {
margin-left: 10px;
}
}
.wizard-message { .wizard-message {
background-color: var(--primary-low); background-color: var(--primary-low);
width: 100%; width: 100%;
@ -940,3 +932,52 @@ $error: #ef1700;
font-size: 0.75em; font-size: 0.75em;
} }
} }
.admin-wizards .admin-actions {
.supplier-authorize {
display: inline-flex;
button.update {
width: 40px;
height: 34px;
}
.btn-pavilion-support {
&:hover {
color: var(--pavilion-secondary);
}
}
.wizard-subscription-badge {
margin-right: 5px;
svg {
margin-right: 0.45em;
}
&.none {
svg {
color: #919191;
}
}
&.community,
&.standard,
&.business {
svg {
color: #fff;
}
}
}
.loading-container {
svg,
div {
vertical-align: -moz-middle-with-baseline;
vertical-align: -webkit-baseline-middle;
margin-right: 3px;
}
}
.btn-primary {
margin-right: 5px;
}
}
}

Datei anzeigen

@ -545,6 +545,14 @@ en:
subscription: subscription:
title: Subscriber Features title: Subscriber Features
authorize:
label: Authorize
title: Authorize your subscription on this site
deauthorize:
label: deauthorize
title: Deauthorize your subscription on this site
update:
title: "Update subscription status"
subscribed: subscribed:
label: Subscribed label: Subscribed
title: You're subscribed and can use these features title: You're subscribed and can use these features

Datei anzeigen

@ -14,6 +14,7 @@ Discourse::Application.routes.append do
scope module: 'custom_wizard', constraints: AdminConstraint.new do scope module: 'custom_wizard', constraints: AdminConstraint.new do
get 'admin/wizards' => 'admin#index' get 'admin/wizards' => 'admin#index'
get 'admin/wizards/subscription' => 'subscription#index'
get 'admin/wizards/wizard' => 'admin_wizard#index' get 'admin/wizards/wizard' => 'admin_wizard#index'
get 'admin/wizards/wizard/create' => 'admin#index' get 'admin/wizards/wizard/create' => 'admin#index'

Datei anzeigen

@ -1,4 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require "discourse_subscription_client"
class CustomWizard::Subscription class CustomWizard::Subscription
PRODUCT_HIERARCHY = %w[ PRODUCT_HIERARCHY = %w[
community community
@ -104,25 +106,27 @@ class CustomWizard::Subscription
attr_accessor :product_id, attr_accessor :product_id,
:product_slug :product_slug
def initialize def initialize(update = false)
if CustomWizard::Subscription.client_installed? if update
result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") ::DiscourseSubscriptionClient::Subscriptions.update
end
if result&.any? result = ::DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard")
ids_and_slugs = result.subscriptions.map do |subscription|
{
id: subscription.product_id,
slug: result.products[subscription.product_id]
}
end
id_and_slug = ids_and_slugs.sort do |a, b| if result&.any?
PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug]) ids_and_slugs = result.subscriptions.map do |subscription|
end.first {
id: subscription.product_id,
@product_id = id_and_slug[:id] slug: result.products[subscription.product_id]
@product_slug = id_and_slug[:slug] }
end end
id_and_slug = ids_and_slugs.sort do |a, b|
PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug])
end.first
@product_id = id_and_slug[:id]
@product_slug = id_and_slug[:slug]
end end
@product_slug ||= ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] @product_slug ||= ENV["CUSTOM_WIZARD_PRODUCT_SLUG"]
@ -176,6 +180,7 @@ class CustomWizard::Subscription
product_slug === "community" product_slug === "community"
end end
# TODO candidate for removal once code that depends on it externally is no longer used.
def self.client_installed? def self.client_installed?
defined?(DiscourseSubscriptionClient) == 'constant' && DiscourseSubscriptionClient.class == Module defined?(DiscourseSubscriptionClient) == 'constant' && DiscourseSubscriptionClient.class == Module
end end

Datei anzeigen

@ -1,16 +1,18 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-custom-wizard # name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.5.0 # version: 2.5.1
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech # contact_emails: development@pavilion.tech
# subscription_url: https://coop.pavilion.tech # subscription_url: https://coop.pavilion.tech
gem 'liquid', '5.0.1', require: true gem 'liquid', '5.0.1', require: true
gem "discourse_subscription_client", "0.1.0.pre15", require_name: "discourse_subscription_client"
gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true
register_asset 'stylesheets/common/admin.scss' register_asset 'stylesheets/common/admin.scss'
register_asset 'stylesheets/common/wizard.scss' register_asset 'stylesheets/common/wizard.scss'
register_svg_icon 'pavilion-logo'
enabled_site_setting :custom_wizard_enabled enabled_site_setting :custom_wizard_enabled
@ -36,6 +38,7 @@ after_initialize do
../lib/custom_wizard/engine.rb ../lib/custom_wizard/engine.rb
../config/routes.rb ../config/routes.rb
../app/controllers/custom_wizard/admin/admin.rb ../app/controllers/custom_wizard/admin/admin.rb
../app/controllers/custom_wizard/admin/subscription.rb
../app/controllers/custom_wizard/admin/wizard.rb ../app/controllers/custom_wizard/admin/wizard.rb
../app/controllers/custom_wizard/admin/submissions.rb ../app/controllers/custom_wizard/admin/submissions.rb
../app/controllers/custom_wizard/admin/api.rb ../app/controllers/custom_wizard/admin/api.rb

Datei anzeigen

@ -42,6 +42,7 @@ describe CustomWizard::Action do
} }
before do before do
stub_out_subscription_classes
Group.refresh_automatic_group!(:trust_level_2) Group.refresh_automatic_group!(:trust_level_2)
update_template(wizard_template) update_template(wizard_template)
end end

Datei anzeigen

@ -29,6 +29,7 @@ describe CustomWizard::Builder do
} }
before do before do
stub_out_subscription_classes
Group.refresh_automatic_group!(:trust_level_3) Group.refresh_automatic_group!(:trust_level_3)
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard') @template = CustomWizard::Template.find('super_mega_fun_wizard')

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::CustomField do
let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") }
before do before do
stub_out_subscription_classes
CustomWizard::CustomField.invalidate_cache CustomWizard::CustomField.invalidate_cache
end end

Datei anzeigen

@ -7,6 +7,7 @@ describe CustomWizard::Submission do
let(:guest_id) { CustomWizard::Wizard.generate_guest_id } let(:guest_id) { CustomWizard::Wizard.generate_guest_id }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template_json, skip_jobs: true) CustomWizard::Template.save(template_json, skip_jobs: true)
@wizard = CustomWizard::Wizard.create(template_json["id"], user) @wizard = CustomWizard::Wizard.create(template_json["id"], user)
described_class.new(@wizard, step_1_field_1: "I am user submission").save described_class.new(@wizard, step_1_field_1: "I am user submission").save

Datei anzeigen

@ -13,41 +13,9 @@ describe CustomWizard::Subscription do
} }
} }
after do context "with subscription client gem mocked out" do
undefine_client_classes
end
it "detects the subscription client" do
undefine_client_classes
expect(described_class.client_installed?).to eq(false)
end
context "without a subscription client" do
it "is not subscribed" do
expect(described_class.subscribed?).to eq(false)
end
it "has none type" do
subscription = described_class.new
expect(subscription.type).to eq(:none)
end
it "non subscriber features are included" do
expect(described_class.includes?(:wizard, :after_signup, true)).to eq(true)
end
it "subscriber features are not included" do
expect(described_class.includes?(:wizard, :permitted, {})).to eq(false)
end
end
context "with subscription client" do
before do before do
define_client_classes stub_out_subscription_classes
end
it "detects the subscription client" do
expect(described_class.client_installed?).to eq(true)
end end
context "without a subscription" do context "without a subscription" do
@ -69,11 +37,12 @@ describe CustomWizard::Subscription do
end end
context "with subscriptions" do context "with subscriptions" do
def get_subscription_result(product_ids) def get_subscription_result(product_ids)
result = DiscourseSubscriptionClient::Subscriptions::Result.new result = DiscourseSubscriptionClient::Subscriptions::Result.new
result.supplier = SubscriptionClientSupplier.new(product_slugs) result.supplier = SubscriptionClientSupplier.new(product_slugs)
result.resource = SubscriptionClientResource.new result.resource = SubscriptionClientResource.new
result.subscriptions = product_ids.map { |product_id| SubscriptionClientSubscription.new(product_id) } result.subscriptions = product_ids.map { |product_id| ::SubscriptionClientSubscription.new(product_id) }
result.products = product_slugs result.products = product_slugs
result result
end end

Datei anzeigen

@ -7,6 +7,7 @@ describe CustomWizard::Template do
fab!(:upload) { Fabricate(:upload) } fab!(:upload) { Fabricate(:upload) }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template_json, skip_jobs: true) CustomWizard::Template.save(template_json, skip_jobs: true)
end end

Datei anzeigen

@ -39,6 +39,10 @@ describe CustomWizard::TemplateValidator do
expect(validator.errors.first.message).to eq("Liquid syntax error in #{object_id}: #{message}") expect(validator.errors.first.message).to eq("Liquid syntax error in #{object_id}: #{message}")
end end
before do
stub_out_subscription_classes
end
it "validates valid templates" do it "validates valid templates" do
expect( expect(
CustomWizard::TemplateValidator.new(template).perform CustomWizard::TemplateValidator.new(template).perform

Datei anzeigen

@ -6,6 +6,7 @@ describe CustomWizard::UpdateValidator do
let(:url_field) { get_wizard_fixture("field/url") } let(:url_field) { get_wizard_fixture("field/url") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard') @template = CustomWizard::Template.find('super_mega_fun_wizard')
end end

Datei anzeigen

@ -10,6 +10,7 @@ describe CustomWizard::Wizard do
let(:step_json) { get_wizard_fixture("step/step") } let(:step_json) { get_wizard_fixture("step/step") }
before do before do
stub_out_subscription_classes
Group.refresh_automatic_group!(:trust_level_3) Group.refresh_automatic_group!(:trust_level_3)
@permitted_template = template_json.dup @permitted_template = template_json.dup
@permitted_template["permitted"] = permitted_json["permitted"] @permitted_template["permitted"] = permitted_json["permitted"]

Datei anzeigen

@ -11,6 +11,7 @@ describe "custom field extensions" do
let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") }
before do before do
stub_out_subscription_classes
custom_field_json['custom_fields'].each do |field_json| custom_field_json['custom_fields'].each do |field_json|
custom_field = CustomWizard::CustomField.new(nil, field_json) custom_field = CustomWizard::CustomField.new(nil, field_json)
custom_field.save custom_field.save

Datei anzeigen

@ -7,6 +7,7 @@ describe ExtraLocalesControllerCustomWizard, type: :request do
let(:permitted) { get_wizard_fixture("wizard/permitted") } let(:permitted) { get_wizard_fixture("wizard/permitted") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
end end

Datei anzeigen

@ -33,6 +33,7 @@ describe ::Guardian do
end end
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard') @template = CustomWizard::Template.find('super_mega_fun_wizard')
end end

Datei anzeigen

@ -6,6 +6,7 @@ describe InvitesControllerCustomWizard, type: :request do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
@controller = InvitesController.new @controller = InvitesController.new
end end

Datei anzeigen

@ -4,6 +4,7 @@ describe CustomWizardUsersController, type: :request do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
@controller = UsersController.new @controller = UsersController.new
end end

Datei anzeigen

@ -5,7 +5,7 @@ module DiscourseSubscriptionClient
end end
end end
class SubscriptionClientSupplier SubscriptionClientSupplier = Class.new Object do
attr_reader :product_slugs attr_reader :product_slugs
def initialize(product_slugs) def initialize(product_slugs)
@ -13,10 +13,10 @@ class SubscriptionClientSupplier
end end
end end
class SubscriptionClientResource SubscriptionClientResource = Class.new Object do
end end
class SubscriptionClientSubscription SubscriptionClientSubscription = Class.new Object do
attr_reader :product_id attr_reader :product_id
def initialize(product_id) def initialize(product_id)

Datei anzeigen

@ -9,11 +9,13 @@ def get_wizard_fixture(path)
end end
def enable_subscription(type) def enable_subscription(type)
stub_out_subscription_classes
CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true)
CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true)
end end
def disable_subscriptions def disable_subscriptions
stub_out_subscription_classes
%w[ %w[
standard standard
business business
@ -24,11 +26,11 @@ def disable_subscriptions
end end
end end
def undefine_client_classes def unstub_out_subscription_classes
Object.send(:remove_const, :DiscourseSubscriptionClient) if Object.constants.include?(:DiscourseSubscriptionClient) Object.send(:remove_const, :DiscourseSubscriptionClient) if Object.constants.include?(:DiscourseSubscriptionClient)
Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription)
end end
def define_client_classes def stub_out_subscription_classes
load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__)
end end

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::AdminApiController do
let(:api_json) { get_wizard_fixture("api/api") } let(:api_json) { get_wizard_fixture("api/api") }
before do before do
stub_out_subscription_classes
sign_in(admin_user) sign_in(admin_user)
end end

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::AdminCustomFieldsController do
let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") }
before do before do
stub_out_subscription_classes
custom_field_json['custom_fields'].each do |field_json| custom_field_json['custom_fields'].each do |field_json|
CustomWizard::CustomField.new(nil, field_json).save CustomWizard::CustomField.new(nil, field_json).save
end end

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::AdminLogsController do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
["first", "second", "third"].each_with_index do |key, index| ["first", "second", "third"].each_with_index do |key, index|
temp = template.dup temp = template.dup
temp["id"] = "#{key}_test_wizard" temp["id"] = "#{key}_test_wizard"

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::AdminManagerController do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
sign_in(admin_user) sign_in(admin_user)
template_2 = template.dup template_2 = template.dup

Datei anzeigen

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
describe CustomWizard::AdminController do describe CustomWizard::SubscriptionController do
fab!(:admin_user) { Fabricate(:user, admin: true) } fab!(:admin_user) { Fabricate(:user, admin: true) }
it "requires an admin" do it "requires an admin" do
@ -16,28 +16,26 @@ describe CustomWizard::AdminController do
context "without a subscription" do context "without a subscription" do
before do before do
disable_subscriptions disable_subscriptions
define_client_classes stub_out_subscription_classes
end end
it "returns the right subscription details" do it "returns the right subscription details" do
get "/admin/wizards.json" get "/admin/wizards/subscription.json"
expect(response.parsed_body["subscribed"]).to eq(false) expect(response.parsed_body["subscribed"]).to eq(false)
expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json) expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json)
expect(response.parsed_body["subscription_client_installed"]).to eq(true)
end end
end end
context "with a subscription" do context "with a subscription" do
before do before do
enable_subscription("standard") enable_subscription("standard")
define_client_classes stub_out_subscription_classes
end end
it "returns the right subscription details" do it "returns the right subscription details" do
get "/admin/wizards.json" get "/admin/wizards/subscription.json"
expect(response.parsed_body["subscribed"]).to eq(true) expect(response.parsed_body["subscribed"]).to eq(true)
expect(response.parsed_body["subscription_type"]).to eq("standard") expect(response.parsed_body["subscription_type"]).to eq("standard")
expect(response.parsed_body["subscription_client_installed"]).to eq(true)
end end
end end
end end

Datei anzeigen

@ -8,9 +8,8 @@ describe CustomWizard::AdminWizardController do
let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: template['name'].parameterize(separator: "_") }) } let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: template['name'].parameterize(separator: "_") }) }
before do before do
CustomWizard::Template.save(template, skip_jobs: true)
enable_subscription("standard") enable_subscription("standard")
CustomWizard::Template.save(template, skip_jobs: true)
template_2 = template.dup template_2 = template.dup
template_2["id"] = 'super_mega_fun_wizard_2' template_2["id"] = 'super_mega_fun_wizard_2'
template_2["permitted"] = template_2['permitted'] template_2["permitted"] = template_2['permitted']

Datei anzeigen

@ -5,6 +5,7 @@ describe ApplicationController do
let(:wizard_template) { get_wizard_fixture("wizard") } let(:wizard_template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard') @template = CustomWizard::Template.find('super_mega_fun_wizard')
end end

Datei anzeigen

@ -10,6 +10,7 @@ describe "custom field extensions" do
let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") }
before do before do
stub_out_subscription_classes
custom_field_json['custom_fields'].each do |field_json| custom_field_json['custom_fields'].each do |field_json|
custom_field = CustomWizard::CustomField.new(nil, field_json) custom_field = CustomWizard::CustomField.new(nil, field_json)
custom_field.save custom_field.save

Datei anzeigen

@ -11,6 +11,7 @@ describe CustomWizard::StepsController do
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
end end

Datei anzeigen

@ -6,6 +6,7 @@ describe CustomWizard::WizardController do
let(:permitted_json) { get_wizard_fixture("wizard/permitted") } let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find("super_mega_fun_wizard") @template = CustomWizard::Template.find("super_mega_fun_wizard")
end end

Datei anzeigen

@ -4,6 +4,10 @@ describe CustomWizard::BasicWizardSerializer do
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do
stub_out_subscription_classes
end
it 'should return basic wizard attributes' do it 'should return basic wizard attributes' do
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
json = CustomWizard::BasicWizardSerializer.new( json = CustomWizard::BasicWizardSerializer.new(

Datei anzeigen

@ -4,6 +4,10 @@ describe CustomWizard::CustomFieldSerializer do
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") }
before do
stub_out_subscription_classes
end
it 'should return custom field attributes' do it 'should return custom field attributes' do
custom_field_json['custom_fields'].each do |field_json| custom_field_json['custom_fields'].each do |field_json|
CustomWizard::CustomField.new(nil, field_json).save CustomWizard::CustomField.new(nil, field_json).save

Datei anzeigen

@ -13,6 +13,7 @@ describe CustomWizard::SubmissionSerializer do
} }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template_json, skip_jobs: true) CustomWizard::Template.save(template_json, skip_jobs: true)
wizard = CustomWizard::Wizard.create(template_json["id"], user1) wizard = CustomWizard::Wizard.create(template_json["id"], user1)

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::FieldSerializer do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
end end

Datei anzeigen

@ -8,6 +8,7 @@ describe CustomWizard::WizardSerializer do
let(:advanced_fields) { get_wizard_fixture("field/advanced_types") } let(:advanced_fields) { get_wizard_fixture("field/advanced_types") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard') @template = CustomWizard::Template.find('super_mega_fun_wizard')
end end

Datei anzeigen

@ -6,6 +6,7 @@ describe CustomWizard::StepSerializer do
let(:required_data_json) { get_wizard_fixture("step/required_data") } let(:required_data_json) { get_wizard_fixture("step/required_data") }
before do before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
end end

Datei anzeigen

@ -1,24 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg <svg
width="300px"
height="300px"
viewBox="0 0 300 300"
version="1.1" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink"
> >
<g <symbol
id="pavilion-logo" id="pavilion-logo"
stroke="none" viewBox="0 0 300 300"
stroke-width="1" stroke-width="35"
fill="none" stroke="currentColor"
fill-rule="evenodd" fill="currentColor"
> >
<path <path
id="Combined-Shape"
stroke="currentColor"
stroke-width="35"
d="M41.1381822,291.00006 L40.5778853,130.009744 M258.850727,291.638415 L259.290397,130.37133 M36.0002279,140.721678 L139.995368,36.2122772 M263.350577,141.009083 L138.927245,16.2478517" d="M41.1381822,291.00006 L40.5778853,130.009744 M258.850727,291.638415 L259.290397,130.37133 M36.0002279,140.721678 L139.995368,36.2122772 M263.350577,141.009083 L138.927245,16.2478517"
></path> ></path>
</g> </symbol>
</svg> </svg>
<span>{{label}}</span>

Vorher

Breite:  |  Höhe:  |  Größe: 602 B

Nachher

Breite:  |  Höhe:  |  Größe: 512 B

Datei anzeigen

@ -8,6 +8,7 @@ import { click, fillIn, findAll, visit, waitUntil } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { import {
getCustomFields, getCustomFields,
getSuppliers,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
getWizard, getWizard,
} from "../helpers/admin-wizard"; } from "../helpers/admin-wizard";
@ -24,7 +25,7 @@ acceptance("Admin | Custom Fields Unsubscribed", function (needs) {
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard); return helper.response(getWizard);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getUnsubscribedAdminWizards); return helper.response(getUnsubscribedAdminWizards);
}); });
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
@ -36,6 +37,9 @@ acceptance("Admin | Custom Fields Unsubscribed", function (needs) {
server.delete("/admin/wizards/custom-fields/topic_custom_field", () => { server.delete("/admin/wizards/custom-fields/topic_custom_field", () => {
return helper.response({ success: "OK" }); return helper.response({ success: "OK" });
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
async function selectTypeAndSerializerAndFillInName( async function selectTypeAndSerializerAndFillInName(

Datei anzeigen

@ -3,6 +3,7 @@ import { test } from "qunit";
import { click, findAll, visit } from "@ember/test-helpers"; import { click, findAll, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { import {
getSuppliers,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
getWizard, getWizard,
getWizardTestingLog, getWizardTestingLog,
@ -23,12 +24,15 @@ acceptance("Admin | Logs", function (needs) {
server.get("/admin/wizards/logs/this_is_testing_wizard", () => { server.get("/admin/wizards/logs/this_is_testing_wizard", () => {
return helper.response(getWizardTestingLog); return helper.response(getWizardTestingLog);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getUnsubscribedAdminWizards); return helper.response(getUnsubscribedAdminWizards);
}); });
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard); return helper.response(getWizard);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
test("viewing logs fields tab", async (assert) => { test("viewing logs fields tab", async (assert) => {
await visit("/admin/wizards/logs"); await visit("/admin/wizards/logs");

Datei anzeigen

@ -2,6 +2,7 @@ import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { click, find, findAll, visit, waitUntil } from "@ember/test-helpers"; import { click, find, findAll, visit, waitUntil } from "@ember/test-helpers";
import { import {
getSuppliers,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
getWizard, getWizard,
getWizardTestingLog, getWizardTestingLog,
@ -18,7 +19,7 @@ acceptance("Admin | Manager", function (needs) {
server.get("/admin/wizards/manager/this_is_testing_wizard", () => { server.get("/admin/wizards/manager/this_is_testing_wizard", () => {
return helper.response(getWizardTestingLog); return helper.response(getWizardTestingLog);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getUnsubscribedAdminWizards); return helper.response(getUnsubscribedAdminWizards);
}); });
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
@ -33,6 +34,9 @@ acceptance("Admin | Manager", function (needs) {
failures: [], failures: [],
}); });
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
async function waitForDestructionAndResetMessage() { async function waitForDestructionAndResetMessage() {
await waitUntil( await waitUntil(

Datei anzeigen

@ -4,6 +4,7 @@ import { click, findAll, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { import {
getAnotherWizardSubmission, getAnotherWizardSubmission,
getSuppliers,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
getWizard, getWizard,
getWizardSubmissions, getWizardSubmissions,
@ -28,12 +29,15 @@ acceptance("Admin | Submissions", function (needs) {
server.get("/admin/wizards/submissions/another_wizard", () => { server.get("/admin/wizards/submissions/another_wizard", () => {
return helper.response(getAnotherWizardSubmission); return helper.response(getAnotherWizardSubmission);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getUnsubscribedAdminWizards); return helper.response(getUnsubscribedAdminWizards);
}); });
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard); return helper.response(getWizard);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
test("View submissions fields tab and content", async (assert) => { test("View submissions fields tab and content", async (assert) => {
await visit("/admin/wizards/submissions"); await visit("/admin/wizards/submissions");

Datei anzeigen

@ -6,6 +6,7 @@ import {
getBusinessAdminWizard, getBusinessAdminWizard,
getCustomFields, getCustomFields,
getNewApi, getNewApi,
getSuppliers,
getWizard, getWizard,
putNewApi, putNewApi,
} from "../helpers/admin-wizard"; } from "../helpers/admin-wizard";
@ -21,7 +22,7 @@ acceptance("Admin | API tab", function (needs) {
server.get("/admin/wizards/wizard", () => { server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard); return helper.response(getWizard);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getBusinessAdminWizard); return helper.response(getBusinessAdminWizard);
}); });
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
@ -45,6 +46,9 @@ acceptance("Admin | API tab", function (needs) {
server.get("/admin/wizards/api/new_api", () => { server.get("/admin/wizards/api/new_api", () => {
return helper.response(getNewApi); return helper.response(getNewApi);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
test("Visit API tab and fill data", async function (assert) { test("Visit API tab and fill data", async function (assert) {

Datei anzeigen

@ -1,5 +1,6 @@
import { import {
acceptance, acceptance,
exists,
query, query,
visible, visible,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -11,6 +12,7 @@ import {
getBusinessAdminWizard, getBusinessAdminWizard,
getCreatedWizard, getCreatedWizard,
getCustomFields, getCustomFields,
getSuppliersAuthorized,
getWizard, getWizard,
} from "../helpers/admin-wizard"; } from "../helpers/admin-wizard";
@ -28,7 +30,7 @@ acceptance("Admin | Custom Wizard Business Subscription", function (needs) {
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
return helper.response(getCustomFields); return helper.response(getCustomFields);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getBusinessAdminWizard); return helper.response(getBusinessAdminWizard);
}); });
server.get("/admin/wizards/api", () => { server.get("/admin/wizards/api", () => {
@ -49,6 +51,9 @@ acceptance("Admin | Custom Wizard Business Subscription", function (needs) {
server.get("/admin/wizards/wizard/new_wizard_for_testing", () => { server.get("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response(getCreatedWizard); return helper.response(getCreatedWizard);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliersAuthorized);
});
}); });
test("Displaying all tabs including API", async (assert) => { test("Displaying all tabs including API", async (assert) => {
@ -58,6 +63,22 @@ acceptance("Admin | Custom Wizard Business Subscription", function (needs) {
assert.equal(count, 6, "There should be 6 admin tabs"); assert.equal(count, 6, "There should be 6 admin tabs");
}); });
test("shows authorized and subscribed", async (assert) => {
await visit("/admin/wizards");
assert.notOk(
exists(".supplier-authorize .btn-primary:not(.update)"),
"the authorize button is shown."
);
assert.strictEqual(
query("button.wizard-subscription-badge span").innerText.trim(),
"Business"
);
assert.strictEqual(
query("button.btn-pavilion-support span").innerText.trim(),
"Support"
);
});
test("creating a new wizard", async (assert) => { test("creating a new wizard", async (assert) => {
await visit("/admin/wizards/wizard"); await visit("/admin/wizards/wizard");
await click(".admin-wizard-controls button"); await click(".admin-wizard-controls button");

Datei anzeigen

@ -1,5 +1,6 @@
import { import {
acceptance, acceptance,
exists,
query, query,
visible, visible,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -11,6 +12,7 @@ import {
getCreatedWizard, getCreatedWizard,
getCustomFields, getCustomFields,
getStandardAdminWizard, getStandardAdminWizard,
getSuppliersAuthorized,
getWizard, getWizard,
} from "../helpers/admin-wizard"; } from "../helpers/admin-wizard";
@ -28,7 +30,7 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
return helper.response(getCustomFields); return helper.response(getCustomFields);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getStandardAdminWizard); return helper.response(getStandardAdminWizard);
}); });
server.get("/admin/wizards/api", () => { server.get("/admin/wizards/api", () => {
@ -49,6 +51,9 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
server.get("/admin/wizards/wizard/new_wizard_for_testing", () => { server.get("/admin/wizards/wizard/new_wizard_for_testing", () => {
return helper.response(getCreatedWizard); return helper.response(getCreatedWizard);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliersAuthorized);
});
}); });
test("Displaying all tabs except API", async (assert) => { test("Displaying all tabs except API", async (assert) => {
@ -58,6 +63,22 @@ acceptance("Admin | Custom Wizard Standard Subscription", function (needs) {
assert.equal(count, 5, "There should be 5 admin tabs"); assert.equal(count, 5, "There should be 5 admin tabs");
}); });
test("shows authorized and subscribed", async (assert) => {
await visit("/admin/wizards");
assert.notOk(
exists(".supplier-authorize .btn-primary:not(.update)"),
"the authorize button not shown."
);
assert.strictEqual(
query("button.wizard-subscription-badge span").innerText.trim(),
"Standard"
);
assert.strictEqual(
query("button.btn-pavilion-support span").innerText.trim(),
"Support"
);
});
test("creating a new wizard", async (assert) => { test("creating a new wizard", async (assert) => {
await visit("/admin/wizards/wizard"); await visit("/admin/wizards/wizard");
await click(".admin-wizard-controls button"); await click(".admin-wizard-controls button");

Datei anzeigen

@ -11,6 +11,7 @@ import {
getAdminTestingWizard, getAdminTestingWizard,
getCreatedWizard, getCreatedWizard,
getCustomFields, getCustomFields,
getSuppliers,
getUniqueWizard, getUniqueWizard,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
getWizard, getWizard,
@ -30,7 +31,7 @@ acceptance("Admin | Custom Wizard Unsubscribed", function (needs) {
server.get("/admin/wizards/custom-fields", () => { server.get("/admin/wizards/custom-fields", () => {
return helper.response(getCustomFields); return helper.response(getCustomFields);
}); });
server.get("/admin/wizards", () => { server.get("/admin/wizards/subscription", () => {
return helper.response(getUnsubscribedAdminWizards); return helper.response(getUnsubscribedAdminWizards);
}); });
server.get("/admin/wizards/api", () => { server.get("/admin/wizards/api", () => {
@ -54,6 +55,9 @@ acceptance("Admin | Custom Wizard Unsubscribed", function (needs) {
server.get("/admin/wizards/wizard/unique_wizard", () => { server.get("/admin/wizards/wizard/unique_wizard", () => {
return helper.response(getUniqueWizard); return helper.response(getUniqueWizard);
}); });
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
}); });
async function appendText(selector, text) { async function appendText(selector, text) {
@ -72,6 +76,22 @@ acceptance("Admin | Custom Wizard Unsubscribed", function (needs) {
assert.equal(count, 5, "There should be 5 admin tabs"); assert.equal(count, 5, "There should be 5 admin tabs");
}); });
test("shows unauthorized and unsubscribed", async (assert) => {
await visit("/admin/wizards");
assert.ok(
exists(".supplier-authorize .btn-primary"),
"the authorize button is shown."
);
assert.strictEqual(
query("button.wizard-subscription-badge span").innerText.trim(),
"Not Subscribed"
);
assert.strictEqual(
query("button.btn-pavilion-support span").innerText.trim(),
"Get a Subscription"
);
});
test("creating a new wizard", async (assert) => { test("creating a new wizard", async (assert) => {
await visit("/admin/wizards/wizard"); await visit("/admin/wizards/wizard");
await click(".admin-wizard-controls button"); await click(".admin-wizard-controls button");
@ -240,11 +260,14 @@ acceptance("Admin | Custom Wizard Unsubscribed", function (needs) {
await click( await click(
".wizard-custom-step .wizard-text-editor .d-editor button.link" ".wizard-custom-step .wizard-text-editor .d-editor button.link"
); );
assert.ok(exists(".insert-link.modal-body"), "hyperlink modal visible"); assert.ok(
exists(".d-modal.insert-hyperlink-modal"),
"hyperlink modal visible"
);
await fillIn(".modal-body .link-url", "google.com"); await fillIn(".d-modal__body.insert-link .inputs .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google"); await fillIn(".d-modal__body.insert-link .inputs .link-text", "Google");
await click(".modal-footer button.btn-primary"); await click(".d-modal__footer button.btn-primary");
let urlText = await query( let urlText = await query(
".wizard-custom-step .wizard-text-editor .d-editor-preview-wrapper a" ".wizard-custom-step .wizard-text-editor .d-editor-preview-wrapper a"
).innerHTML.trim(); ).innerHTML.trim();
@ -256,24 +279,26 @@ acceptance("Admin | Custom Wizard Unsubscribed", function (needs) {
await click( await click(
".wizard-custom-step .wizard-text-editor .d-editor button.local-dates" ".wizard-custom-step .wizard-text-editor .d-editor button.local-dates"
); );
assert.ok( assert.ok(
exists(".discourse-local-dates-create-modal .modal-body"), exists(".d-modal.discourse-local-dates-create-modal"),
"Insert date-time modal visible" "Insert date-time modal visible"
); );
assert.ok( assert.ok(
!exists( !exists(
".discourse-local-dates-create-modal.modal-body .advanced-options" ".discourse-local-dates-create-modal .d-modal__body .advanced-options"
), ),
"Advanced mode not visible" "Advanced mode not visible"
); );
await click(".modal-footer button.advanced-mode-btn"); await click(".d-modal__footer button.advanced-mode-btn");
assert.ok( assert.ok(
exists( exists(
".discourse-local-dates-create-modal .modal-body .advanced-options" ".discourse-local-dates-create-modal .d-modal__body .advanced-options"
), ),
"Advanced mode is visible" "Advanced mode is visible"
); );
await click(".modal-footer button.btn-primary"); await click(".d-modal__footer button.btn-primary");
assert.ok( assert.ok(
exists( exists(
".wizard-custom-step .wizard-text-editor .d-editor-preview-wrapper span.discourse-local-date" ".wizard-custom-step .wizard-text-editor .d-editor-preview-wrapper span.discourse-local-date"

Datei anzeigen

@ -68,17 +68,20 @@ acceptance("Field | Fields", function (needs) {
"This is a link to " "This is a link to "
); );
assert.ok( assert.ok(
!exists(".insert-link.modal-body"), !exists(".d-modal.insert-hyperlink-modal"),
"no hyperlink modal by default" "no hyperlink modal by default"
); );
await click( await click(
".wizard-field.composer-field .wizard-field-composer .d-editor button.link" ".wizard-field.composer-field .wizard-field-composer .d-editor button.link"
); );
assert.ok(exists(".insert-link.modal-body"), "hyperlink modal visible"); assert.ok(
exists(".d-modal.insert-hyperlink-modal"),
"hyperlink modal visible"
);
await fillIn(".modal-body .link-url", "google.com"); await fillIn(".d-modal__body.insert-link .inputs .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google"); await fillIn(".d-modal__body.insert-link .inputs .link-text", "Google");
await click(".modal-footer button.btn-primary"); await click(".d-modal__footer button.btn-primary");
assert.strictEqual( assert.strictEqual(
query(".wizard-field.composer-field .wizard-field-composer textarea") query(".wizard-field.composer-field .wizard-field-composer textarea")
@ -102,9 +105,9 @@ acceptance("Field | Fields", function (needs) {
await click( await click(
".wizard-field.composer-field .wizard-field-composer .d-editor button.link" ".wizard-field.composer-field .wizard-field-composer .d-editor button.link"
); );
await fillIn(".modal-body .link-url", "google.com"); await fillIn(".d-modal__body.insert-link .inputs .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google"); await fillIn(".d-modal__body.insert-link .inputs .link-text", "Google");
await click(".modal-footer button.btn-danger"); await click(".d-modal__footer button.btn-danger");
assert.strictEqual( assert.strictEqual(
query(".wizard-field.composer-field .wizard-field-composer textarea") query(".wizard-field.composer-field .wizard-field-composer textarea")

Datei anzeigen

@ -224,7 +224,6 @@ const getUnsubscribedAdminWizards = {
all: { none: [], standard: [], business: ["*"], community: ["*"] }, all: { none: [], standard: [], business: ["*"], community: ["*"] },
}, },
}, },
subscription_client_installed: false,
}; };
const getCustomFields = { const getCustomFields = {
custom_fields: [ custom_fields: [
@ -478,7 +477,6 @@ const getBusinessAdminWizard = {
all: { none: [], standard: [], business: ["*"], community: ["*"] }, all: { none: [], standard: [], business: ["*"], community: ["*"] },
}, },
}, },
subscription_client_installed: false,
}; };
const getStandardAdminWizard = { const getStandardAdminWizard = {
subscribed: true, subscribed: true,
@ -589,7 +587,6 @@ const getStandardAdminWizard = {
all: { none: [], standard: [], business: ["*"], community: ["*"] }, all: { none: [], standard: [], business: ["*"], community: ["*"] },
}, },
}, },
subscription_client_installed: false,
}; };
const getAdminTestingWizard = { const getAdminTestingWizard = {
id: "this_is_testing_wizard", id: "this_is_testing_wizard",
@ -917,6 +914,31 @@ const putNewApi = {
log: [], log: [],
}, },
}; };
const getSuppliers = {
suppliers: [
{
id: 1,
name: "Pavilion",
authorized: false,
authorized_at: null,
user: null,
},
],
};
const getSuppliersAuthorized = {
suppliers: [
{
id: 1,
name: "Pavilion",
authorized: true,
authorized_at: null,
user: null,
},
],
};
export { export {
getWizard, getWizard,
getUnsubscribedAdminWizards, getUnsubscribedAdminWizards,
@ -931,4 +953,6 @@ export {
putNewApi, putNewApi,
getAnotherWizardSubmission, getAnotherWizardSubmission,
getUniqueWizard, getUniqueWizard,
getSuppliers,
getSuppliersAuthorized,
}; };