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

Fix tests and linting

Dieser Commit ist enthalten in:
Angus McLeod 2023-01-26 11:26:24 +01:00
Ursprung 7d2e876584
Commit dfc1540d52
8 geänderte Dateien mit 40 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -46,10 +46,9 @@ export default SingleSelectComponent.extend(Subscription, {
if (allowGuests) { if (allowGuests) {
const filteredFeature = wizardSchema.filters.allow_guests[feature]; const filteredFeature = wizardSchema.filters.allow_guests[feature];
if (filteredFeature) { if (filteredFeature) {
const filteredAttribute = filteredFeature[attribute]; const filteredAttribute = filteredFeature[attribute];
if (filteredAttribute) { if (filteredAttribute) {
attributes = attributes.filter(a => filteredAttribute.includes(a)) attributes = attributes.filter((a) => filteredAttribute.includes(a));
} }
} }
} }

Datei anzeigen

@ -18,7 +18,6 @@ const wizard = {
allow_guests: null, allow_guests: null,
theme_id: null, theme_id: null,
permitted: null, permitted: null,
allow_guests: null
}, },
mapped: ["permitted"], mapped: ["permitted"],
required: ["id"], required: ["id"],
@ -209,10 +208,10 @@ const action = {
const filters = { const filters = {
allow_guests: { allow_guests: {
action: { action: {
type: ['route_to', 'send_message'] type: ["route_to", "send_message"],
} },
} },
} };
const custom_field = { const custom_field = {
klass: ["topic", "post", "group", "category"], klass: ["topic", "post", "group", "category"],
@ -228,7 +227,7 @@ const wizardSchema = {
field, field,
custom_field, custom_field,
action, action,
filters filters,
}; };
export function buildFieldTypes(types) { export function buildFieldTypes(types) {

Datei anzeigen

@ -6,6 +6,7 @@ export default Route.extend({
const wizard = getCachedWizard(); const wizard = getCachedWizard();
if ( if (
wizard && wizard &&
(wizard.user || wizard.allow_guests) &&
wizard.permitted && wizard.permitted &&
!wizard.completed && !wizard.completed &&
wizard.start wizard.start

Datei anzeigen

@ -7,7 +7,12 @@ export default Route.extend({
const wizard = getCachedWizard(); const wizard = getCachedWizard();
this.set("wizard", wizard); this.set("wizard", wizard);
if (!wizard || !wizard.permitted || wizard.completed) { if (
!wizard ||
(!wizard.user && !wizard.allow_guests) ||
!wizard.permitted ||
wizard.completed
) {
this.replaceWith("customWizard"); this.replaceWith("customWizard");
} }
}, },

Datei anzeigen

@ -24,6 +24,12 @@ class CustomWizard::Subscription
standard: ['*'], standard: ['*'],
business: ['*'], business: ['*'],
community: ['*'] community: ['*']
},
allow_guests: {
none: [],
standard: ['*'],
business: ['*'],
community: ['*']
} }
}, },
step: { step: {

Datei anzeigen

@ -24,6 +24,7 @@ describe CustomWizard::StepsController do
context "with allow_guests enabled" do context "with allow_guests enabled" do
before do before do
enable_subscription("standard")
new_template = wizard_template.dup new_template = wizard_template.dup
new_template["allow_guests"] = true new_template["allow_guests"] = true
new_template.delete("actions") new_template.delete("actions")

Datei anzeigen

@ -9,6 +9,7 @@ import {
import { import {
wizard, wizard,
wizardCompleted, wizardCompleted,
wizardGuest,
wizardNoUser, wizardNoUser,
wizardNotPermitted, wizardNotPermitted,
} from "../helpers/wizard"; } from "../helpers/wizard";
@ -106,3 +107,19 @@ acceptance("Wizard | Wizard", function (needs) {
assert.strictEqual($("body.custom-wizard").length, 0); assert.strictEqual($("body.custom-wizard").length, 0);
}); });
}); });
acceptance("Wizard | Guest access", function (needs) {
needs.pretender((server, helper) => {
server.get("/w/wizard.json", () => helper.response(wizardGuest));
});
test("Does not require login", async function (assert) {
await visit("/w/wizard");
assert.ok(!exists(".wizard-no-access.requires-login"));
});
test("Starts", async function (assert) {
await visit("/w/wizard");
assert.ok(query(".wizard-column"), true);
});
});

Datei anzeigen

@ -6,6 +6,8 @@ import updateJson from "../fixtures/update";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
const wizardNoUser = cloneJSON(wizardJson); const wizardNoUser = cloneJSON(wizardJson);
const wizardGuest = cloneJSON(wizardJson);
wizardGuest.allow_guests = true;
const wizard = cloneJSON(wizardJson); const wizard = cloneJSON(wizardJson);
wizard.user = cloneJSON(userJson); wizard.user = cloneJSON(userJson);
@ -40,6 +42,7 @@ export {
wizardNoUser, wizardNoUser,
wizardNotPermitted, wizardNotPermitted,
wizardCompleted, wizardCompleted,
wizardGuest,
stepNotPermitted, stepNotPermitted,
allFieldsWizard, allFieldsWizard,
wizard, wizard,