1
0
Fork 0

Add community subscription as an explicit type

Dieser Commit ist enthalten in:
Angus McLeod 2022-09-23 15:52:05 +02:00
Ursprung 785bd5d956
Commit c79dee3d16
20 geänderte Dateien mit 176 neuen und 90 gelöschten Zeilen

Datei anzeigen

@ -1,2 +1,8 @@
inherit_gem: inherit_gem:
rubocop-discourse: default.yml rubocop-discourse: default.yml
RSpec/ContextWording:
Enabled: false
RSpec/DescribeClass:
Enabled: false

Datei anzeigen

@ -11,7 +11,7 @@ export default Component.extend(Subscription, {
@discourseComputed("subscriptionType") @discourseComputed("subscriptionType")
i18nKey(type) { i18nKey(type) {
return `admin.wizard.subscription_container.type.${type ? type : "none"}`; return `admin.wizard.subscription.type.${type ? type : "none"}`;
}, },
@discourseComputed("i18nKey") @discourseComputed("i18nKey")

Datei anzeigen

@ -12,14 +12,14 @@ export default Component.extend(Subscription, {
@discourseComputed("subscribed") @discourseComputed("subscribed")
subscribedLabel(subscribed) { subscribedLabel(subscribed) {
return `admin.wizard.subscription_container.${ return `admin.wizard.subscription.${
subscribed ? "subscribed" : "not_subscribed" subscribed ? "subscribed" : "not_subscribed"
}.label`; }.label`;
}, },
@discourseComputed("subscribed") @discourseComputed("subscribed")
subscribedTitle(subscribed) { subscribedTitle(subscribed) {
return `admin.wizard.subscription_container.${ return `admin.wizard.subscription.${
subscribed ? "subscribed" : "not_subscribed" subscribed ? "subscribed" : "not_subscribed"
}.title`; }.title`;
}, },

Datei anzeigen

@ -0,0 +1,34 @@
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,10 +1,6 @@
import SingleSelectComponent from "select-kit/components/single-select"; import SingleSelectComponent from "select-kit/components/single-select";
import Subscription from "../mixins/subscription"; import Subscription from "../mixins/subscription";
import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
import {
subscriptionTypeSufficient,
subscriptionTypes,
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-subscription";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n"; import I18n from "I18n";
@ -29,45 +25,50 @@ export default SingleSelectComponent.extend(Subscription, {
caretDownIcon: "caret-down", caretDownIcon: "caret-down",
}, },
requiredSubscriptionType(feature, attribute, value) { allowedSubscriptionTypes(feature, attribute, value) {
let attributes = this.subscriptionAttributes[feature]; let attributes = this.subscriptionAttributes[feature];
if (!attributes || !attributes[attribute]) { if (!attributes || !attributes[attribute]) {
return null; return ['none'];
} }
let allowedTypes = [];
let requiredType = null; Object.keys(attributes[attribute]).forEach((subscriptionType) => {
Object.keys(attributes[attribute]).some((subscriptionType) => {
let values = attributes[attribute][subscriptionType]; let values = attributes[attribute][subscriptionType];
if (values[0] === "*" || values.includes(value)) { if (values[0] === "*" || values.includes(value)) {
if (subscriptionTypes.includes(subscriptionType)) { allowedTypes.push(subscriptionType);
requiredType = subscriptionType;
}
return true;
} }
return false;
}); });
return allowedTypes;
return requiredType;
}, },
@discourseComputed("feature", "attribute") @discourseComputed("feature", "attribute")
content(feature, attribute) { content(feature, attribute) {
return wizardSchema[feature][attribute] return wizardSchema[feature][attribute]
.map((value) => { .map((value) => {
let requiredSubscriptionType = this.requiredSubscriptionType( let allowedSubscriptionTypes = this.allowedSubscriptionTypes(
feature, feature,
attribute, attribute,
value value
); );
return {
let subscriptionRequired = allowedSubscriptionTypes.length &&
!allowedSubscriptionTypes.includes('none');
let attrs = {
id: value, id: value,
name: I18n.t(nameKey(feature, attribute, value)), name: I18n.t(nameKey(feature, attribute, value)),
subscriptionType: requiredSubscriptionType, subscriptionRequired
disabled: !subscriptionTypeSufficient(
this.subscriptionType,
requiredSubscriptionType
),
}; };
if (subscriptionRequired) {
let subscribed = allowedSubscriptionTypes.includes(this.subscriptionType);
let selectorKey = subscribed ? "subscribed" : "not_subscribed";
let selectorLabel = `admin.wizard.subscription.${selectorKey}.selector`;
attrs.disabled = !subscribed;
attrs.selectorLabel = selectorLabel;
}
return attrs;
}) })
.sort(function (a, b) { .sort(function (a, b) {
if (a.subscriptionType && !b.subscriptionType) { if (a.subscriptionType && !b.subscriptionType) {

Datei anzeigen

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

Datei anzeigen

@ -1,22 +0,0 @@
const subscriptionTypes = ["standard", "business"];
function subscriptionTypeSufficient(subscriptionType, requiredType) {
if (requiredType && !subscriptionType) {
return false;
}
if (requiredType === "none" || requiredType === null) {
return true;
}
if (
requiredType === "standard" &&
subscriptionTypes.includes(subscriptionType)
) {
return true;
}
if (requiredType === "business" && subscriptionType === "business") {
return true;
}
return false;
}
export { subscriptionTypeSufficient, subscriptionTypes };

Datei anzeigen

@ -3,8 +3,12 @@ import { getOwner } from "discourse-common/lib/get-owner";
import { readOnly } from "@ember/object/computed"; import { readOnly } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
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 Mixin.create({ export default Mixin.create({
subscriptionLandingUrl: "https://custom-wizard.pavilion.tech", subscriptionLandingUrl: PRODUCT_PAGE,
subscriptionClientUrl: "/admin/plugins/subscription-client", subscriptionClientUrl: "/admin/plugins/subscription-client",
@discourseComputed @discourseComputed
@ -15,6 +19,7 @@ export default Mixin.create({
subscribed: readOnly("adminWizards.subscribed"), subscribed: readOnly("adminWizards.subscribed"),
subscriptionType: readOnly("adminWizards.subscriptionType"), subscriptionType: readOnly("adminWizards.subscriptionType"),
businessSubscription: readOnly("adminWizards.businessSubscription"), businessSubscription: readOnly("adminWizards.businessSubscription"),
communitySubscription: readOnly("adminWizards.communitySubscription"),
standardSubscription: readOnly("adminWizards.standardSubscription"), standardSubscription: readOnly("adminWizards.standardSubscription"),
subscriptionAttributes: readOnly("adminWizards.subscriptionAttributes"), subscriptionAttributes: readOnly("adminWizards.subscriptionAttributes"),
subscriptionClientInstalled: readOnly( subscriptionClientInstalled: readOnly(
@ -27,4 +32,15 @@ export default Mixin.create({
? this.subscriptionClientUrl ? this.subscriptionClientUrl
: this.subscriptionLandingUrl; : this.subscriptionLandingUrl;
}, },
@discourseComputed("subscriptionType")
subscriptionCtaLink(subscriptionType) {
switch (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

@ -2,7 +2,6 @@ import { A } from "@ember/array";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import CustomWizardAdmin from "../models/custom-wizard-admin"; import CustomWizardAdmin from "../models/custom-wizard-admin";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import CustomWizard from "../models/custom-wizard";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model(params) { model(params) {

Datei anzeigen

@ -2,17 +2,15 @@
{{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}} {{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}}
{{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}} {{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}}
{{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}} {{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}}
{{#if businessSubscription}} {{#if showApi}}
{{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}} {{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}}
{{/if}} {{/if}}
{{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}}
{{nav-item route="adminWizardsManager" label="admin.wizard.manager.nav_label"}} {{nav-item route="adminWizardsManager" label="admin.wizard.manager.nav_label"}}
<div class="announcement"> <div class="admin-actions">
<a href="https://custom-wizard.pavilion.tech/subscriptions" target="_blank" title="Click to learn more about Custom Wizard Subscriptions"> {{wizard-subscription-badge}}
<img src='/images/emoji/twitter/man_mage.png?v=12'> {{wizard-subscription-cta}}
<span>Custom Wizard Subscriptions Are Coming!</span>
</a>
</div> </div>
{{/admin-nav}} {{/admin-nav}}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -7,10 +7,8 @@
shouldDisplayClearableButton=shouldDisplayClearableButton shouldDisplayClearableButton=shouldDisplayClearableButton
}} }}
{{#if selectedContent.subscriptionType}} {{#if subscriptionRequired}}
<span class="subscription-label"> <span class="subscription-label">{{i18n selectorLabel}}</span>
{{selectedContent.subscriptionType}}
</span>
{{/if}} {{/if}}
{{d-icon caretIcon class="caret-icon"}} {{d-icon caretIcon class="caret-icon"}}

Datei anzeigen

@ -9,9 +9,7 @@
<div class="texts"> <div class="texts">
<span class="name">{{html-safe label}}</span> <span class="name">{{html-safe label}}</span>
{{#if item.subscriptionType}} {{#if item.subscriptionRequired}}
<span class="subscription-label"> <span class="subscription-label">{{i18n item.selectorLabel}}</span>
{{item.subscriptionType}}
</span>
{{/if}} {{/if}}
</div> </div>

Datei anzeigen

@ -841,7 +841,7 @@ $error: #ef1700;
vertical-align: middle; vertical-align: middle;
} }
.btn[href].btn-pavilion-support { .btn.btn-pavilion-support {
background: var(--pavilion-primary); background: var(--pavilion-primary);
color: var(--pavilion-secondary); color: var(--pavilion-secondary);
@ -920,6 +920,12 @@ $error: #ef1700;
color: $secondary; color: $secondary;
} }
&.community {
background-color: $subscription_community;
border: 1.5px solid $pavilion_primary;
color: $pavilion_primary;
}
.d-icon { .d-icon {
margin-right: 0.75em; margin-right: 0.75em;
} }

Datei anzeigen

@ -4,6 +4,7 @@ $pavilion_warning: rgb(243, 163, 61);
$subscription_standard: $pavilion_primary; $subscription_standard: $pavilion_primary;
$subscription_business: #333; $subscription_business: #333;
$subscription_community: #fff;
:root { :root {
--pavilion-primary: #{$pavilion_primary}; --pavilion-primary: #{$pavilion_primary};
@ -11,4 +12,5 @@ $subscription_business: #333;
--pavilion-warning: #{$pavilion_warning}; --pavilion-warning: #{$pavilion_warning};
--subscription-standard: #{$subscription_standard}; --subscription-standard: #{$subscription_standard};
--subscription-business: #{$subscription_business}; --subscription-business: #{$subscription_business};
--subscription-community: #{$subscription_community};
} }

Datei anzeigen

@ -129,9 +129,6 @@ en:
edit_columns: "Edit Columns" edit_columns: "Edit Columns"
expand_text: "Read More" expand_text: "Read More"
collapse_text: "Show Less" collapse_text: "Show Less"
support_button:
title: "Request Support"
label: "Support"
category_settings: category_settings:
custom_wizard: custom_wizard:
title: "Custom Wizard" title: "Custom Wizard"
@ -535,14 +532,16 @@ en:
destroy: Destroy destroy: Destroy
destroyed: destroyed destroyed: destroyed
subscription_container: subscription:
title: Subscriber Features title: Subscriber Features
subscribed: subscribed:
label: Subscribed label: Subscribed
title: You're subscribed and can use these features title: You're subscribed and can use these features
selector: subscribed
not_subscribed: not_subscribed:
label: Not Subscribed label: Not Subscribed
title: Subscribe to use these features title: Subscribe to use these features
selector: not subscribed
type: type:
none: none:
label: Not Subscribed label: Not Subscribed
@ -553,6 +552,17 @@ en:
standard: standard:
label: Standard label: Standard
title: There is a Custom Wizard Standard subscription active on this forum. title: There is a Custom Wizard Standard subscription active on this forum.
community:
label: Community
title: There is a Custom Wizard Community subscription active on this forum.
cta:
none:
label: Get a Subscription
title: Get a subscription for this forum.
subscribed:
label: Support
title: Get support for your subscription.
wizard_js: wizard_js:
group: group:

Datei anzeigen

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class CustomWizard::Subscription class CustomWizard::Subscription
STANDARD_PRODUCT_ID = 'prod_LNAGVAaIqDsHmB' STANDARD_PRODUCT_ID = 'prod_MH11woVoZU5AWb'
BUSINESS_PRODUCT_ID = 'prod_LNABQ50maBQ1pY' BUSINESS_PRODUCT_ID = 'prod_MH0wT627okh3Ef'
COMMUNITY_PRODUCT_ID = 'prod_MU7l9EjxhaukZ7'
def self.attributes def self.attributes
{ {
@ -9,75 +10,88 @@ class CustomWizard::Subscription
required: { required: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
permitted: { permitted: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
} }
}, },
step: { step: {
condition: { condition: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
index: { index: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
required_data: { required_data: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
permitted_params: { permitted_params: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
} }
}, },
field: { field: {
condition: { condition: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
index: { index: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
type: { type: {
none: ['text', 'textarea', 'text_only', 'date', 'time', 'date_time', 'number', 'checkbox', 'dropdown', 'upload'], none: ['text', 'textarea', 'text_only', 'date', 'time', 'date_time', 'number', 'checkbox', 'dropdown', 'upload'],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
}, },
realtime_validations: { realtime_validations: {
none: [], none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*'],
community: ['*']
} }
}, },
action: { action: {
type: { type: {
none: ['create_topic', 'update_profile', 'open_composer', 'route_to'], none: ['create_topic', 'update_profile', 'open_composer', 'route_to'],
standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'], standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'],
business: ['*'] business: ['*'],
community: ['*']
} }
}, },
custom_field: { custom_field: {
klass: { klass: {
none: ['topic', 'post'], none: ['topic', 'post'],
standard: ['topic', 'post'], standard: ['topic', 'post'],
business: ['*'] business: ['*'],
community: ['*']
}, },
type: { type: {
none: ['string', 'boolean', 'integer'], none: ['string', 'boolean', 'integer'],
standard: ['string', 'boolean', 'integer'], standard: ['string', 'boolean', 'integer'],
business: ['*'] business: ['*'],
community: ['*']
} }
} }
} }
@ -109,10 +123,11 @@ class CustomWizard::Subscription
return :none unless subscribed? return :none unless subscribed?
return :standard if standard? return :standard if standard?
return :business if business? return :business if business?
return :community if community?
end end
def subscribed? def subscribed?
standard? || business? standard? || business? || community?
end end
def standard? def standard?
@ -123,6 +138,10 @@ class CustomWizard::Subscription
@subscription.product_id === BUSINESS_PRODUCT_ID @subscription.product_id === BUSINESS_PRODUCT_ID
end end
def community?
@subscription.product_id === COMMUNITY_PRODUCT_ID
end
def client_installed? def client_installed?
defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module
end end
@ -132,7 +151,7 @@ class CustomWizard::Subscription
if client_installed? if client_installed?
subscription = SubscriptionClientSubscription.active subscription = SubscriptionClientSubscription.active
.where(product_id: [STANDARD_PRODUCT_ID, BUSINESS_PRODUCT_ID]) .where(product_id: [STANDARD_PRODUCT_ID, BUSINESS_PRODUCT_ID, COMMUNITY_PRODUCT_ID])
.order("product_id = '#{BUSINESS_PRODUCT_ID}' DESC") .order("product_id = '#{BUSINESS_PRODUCT_ID}' DESC")
.first .first
end end
@ -152,6 +171,10 @@ class CustomWizard::Subscription
new.business? new.business?
end end
def self.community?
new.community?
end
def self.standard? def self.standard?
new.standard? new.standard?
end end

Datei anzeigen

@ -17,7 +17,7 @@ describe CustomWizard::Submission do
).to eq("I am user submission") ).to eq("I am user submission")
end end
context "#list" do describe "#list" do
before do before do
template_json_2 = template_json.dup template_json_2 = template_json.dup
template_json_2["id"] = "super_mega_fun_wizard_2" template_json_2["id"] = "super_mega_fun_wizard_2"

Datei anzeigen

@ -96,7 +96,21 @@ describe CustomWizard::Subscription do
expect(described_class.type).to eq(:business) expect(described_class.type).to eq(:business)
end end
it "business are included" do it "business features are included" do
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
end
end
context "with community subscription" do
before do
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID)
end
it "detects community type" do
expect(described_class.type).to eq(:community)
end
it "community features are included" do
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
end end
end end