1
0
Fork 0

Restrict guest support to standard and business subscriptions

- Support mapped value subscription restrictions
- Restrict permitted guest value to standard and business
Dieser Commit ist enthalten in:
Angus McLeod 2023-02-08 13:32:24 +01:00
Ursprung 0cb76659e9
Commit edc94b6ea7
5 geänderte Dateien mit 62 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -15,6 +15,7 @@ import {
import Component from "@ember/component";
import { bind, later } from "@ember/runloop";
import I18n from "I18n";
import Subscription from "../mixins/subscription";
const customFieldActionMap = {
topic: ["create_topic", "send_message"],
@ -26,7 +27,7 @@ const customFieldActionMap = {
const values = ["present", "true", "false"];
export default Component.extend({
export default Component.extend(Subscription, {
classNameBindings: [":mapper-selector", "activeType"],
showText: computed("activeType", function () {
@ -129,13 +130,14 @@ export default Component.extend({
return this.connector === "is";
}),
@discourseComputed("site.groups", "guestGroup")
groups(groups, guestGroup) {
@discourseComputed("site.groups", "guestGroup", "subscriptionType")
groups(groups, guestGroup, subscriptionType) {
let result = groups;
if (!guestGroup) {
return result;
}
if (["standard", "business"].includes(subscriptionType)) {
let guestIndex;
result.forEach((r, index) => {
if (r.id === 0) {
@ -147,6 +149,8 @@ export default Component.extend({
id: -1,
name: I18n.t("admin.wizard.selector.label.guests"),
});
}
return result;
},
categories: alias("site.categories"),

Datei anzeigen

@ -53,7 +53,7 @@ en:
after_signup_after_time: "You can't use 'after time' and 'after signup' on the same wizard."
after_time: "After time setting is invalid."
liquid_syntax_error: "Liquid syntax error in %{attribute}: %{message}"
subscription: "%{type} %{property} is subscription only"
subscription: "%{type} %{property} usage is not supported on your subscription"
not_permitted_for_guests: "%{object_id} is not permitted when guests can access the wizard"
site_settings:

Datei anzeigen

@ -284,4 +284,8 @@ class CustomWizard::Mapper
user.avatar_template_url.gsub("{size}", parts.last)
end
end
def self.mapped_value?(value)
value.is_a?(Array) && value.all? { |v| v.is_a?(Hash) && v.key?("type") }
end
end

Datei anzeigen

@ -17,7 +17,7 @@ class CustomWizard::Subscription
none: [],
standard: ['*'],
business: ['*'],
community: ['*']
community: ['*', "!#{CustomWizard::Wizard::GUEST_GROUP_ID}"]
},
restart_on_revisit: {
none: [],
@ -114,8 +114,15 @@ class CustomWizard::Subscription
## Subscription type does not support the attribute.
return false if values.blank?
## Value is an exception for the subscription type
if (exceptions = get_exceptions(values)).any?
value = mapped_output(value) if CustomWizard::Mapper.mapped_value?(value)
value = [*value].map(&:to_s)
return false if (exceptions & value).length > 0
end
## Subscription type supports all values of the attribute.
return true if values.first === "*"
return true if values.include?("*")
## Subscription type supports some values of the attributes.
values.include?(value)
@ -192,4 +199,21 @@ class CustomWizard::Subscription
def self.includes?(feature, attribute, value)
new.includes?(feature, attribute, value)
end
protected
def get_exceptions(values)
values.reduce([]) do |result, value|
result << value.split("!").last if value.start_with?("!")
result
end
end
def mapped_output(value)
value.reduce([]) do |result, v|
## We can only validate mapped assignment values at the moment
result << v["output"] if v.is_a?(Hash) && v["type"] === "assignment"
result
end.flatten
end
end

Datei anzeigen

@ -1,6 +1,8 @@
# frozen_string_literal: true
describe CustomWizard::Subscription do
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }
def undefine_client_classes
Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient)
Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription)
@ -40,7 +42,7 @@ describe CustomWizard::Subscription do
expect(described_class.includes?(:wizard, :after_signup, true)).to eq(true)
end
it "ubscriber features are not included" do
it "subscriber features are not included" do
expect(described_class.includes?(:wizard, :permitted, {})).to eq(false)
end
end
@ -69,6 +71,16 @@ describe CustomWizard::Subscription do
end
end
context "with a subscription" do
it "handles mapped values" do
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID)
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(true)
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID)
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(false)
end
end
context "with standard subscription" do
before do
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID)