Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
Merge branch 'main' into wizard-permissions
Dieser Commit ist enthalten in:
Commit
c1481e2ad4
15 geänderte Dateien mit 5491 neuen und 15 gelöschten Zeilen
44
.github/workflows/plugin-metadata.yml
gevendort
Normale Datei
44
.github/workflows/plugin-metadata.yml
gevendort
Normale Datei
|
@ -0,0 +1,44 @@
|
||||||
|
name: Metadata
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout head repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Store head version
|
||||||
|
run: |
|
||||||
|
sed -n -e 's/^.*version: /head_version=/p' plugin.rb >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Checkout base repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: "${{ github.base_ref }}"
|
||||||
|
|
||||||
|
- name: Store base version
|
||||||
|
run: |
|
||||||
|
sed -n -e 's/^.*version: /base_version=/p' plugin.rb >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
|
||||||
|
- name: Install semver
|
||||||
|
run: npm install --include=dev
|
||||||
|
|
||||||
|
- name: Check version
|
||||||
|
uses: actions/github-script@v5
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const semver = require('semver');
|
||||||
|
const { head_version, base_version } = process.env;
|
||||||
|
|
||||||
|
if (semver.lte(head_version, base_version)) {
|
||||||
|
core.setFailed("Head version is equal to or lower than base version.");
|
||||||
|
}
|
|
@ -24,6 +24,8 @@ const customFieldActionMap = {
|
||||||
user: ["update_profile"],
|
user: ["update_profile"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const values = ["present", "true", "false"];
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
classNameBindings: [":mapper-selector", "activeType"],
|
classNameBindings: [":mapper-selector", "activeType"],
|
||||||
|
|
||||||
|
@ -60,6 +62,9 @@ export default Component.extend({
|
||||||
showCustomField: computed("activeType", function () {
|
showCustomField: computed("activeType", function () {
|
||||||
return this.showInput("customField");
|
return this.showInput("customField");
|
||||||
}),
|
}),
|
||||||
|
showValue: computed("activeType", function () {
|
||||||
|
return this.showInput("value");
|
||||||
|
}),
|
||||||
textEnabled: computed("options.textSelection", "inputType", function () {
|
textEnabled: computed("options.textSelection", "inputType", function () {
|
||||||
return this.optionEnabled("textSelection");
|
return this.optionEnabled("textSelection");
|
||||||
}),
|
}),
|
||||||
|
@ -117,6 +122,9 @@ export default Component.extend({
|
||||||
listEnabled: computed("options.listSelection", "inputType", function () {
|
listEnabled: computed("options.listSelection", "inputType", function () {
|
||||||
return this.optionEnabled("listSelection");
|
return this.optionEnabled("listSelection");
|
||||||
}),
|
}),
|
||||||
|
valueEnabled: computed("connector", function () {
|
||||||
|
return this.connector === "is";
|
||||||
|
}),
|
||||||
|
|
||||||
groups: alias("site.groups"),
|
groups: alias("site.groups"),
|
||||||
categories: alias("site.categories"),
|
categories: alias("site.categories"),
|
||||||
|
@ -125,7 +133,8 @@ export default Component.extend({
|
||||||
"showWizardAction",
|
"showWizardAction",
|
||||||
"showUserField",
|
"showUserField",
|
||||||
"showUserFieldOptions",
|
"showUserFieldOptions",
|
||||||
"showCustomField"
|
"showCustomField",
|
||||||
|
"showValue"
|
||||||
),
|
),
|
||||||
showMultiSelect: or("showCategory", "showGroup"),
|
showMultiSelect: or("showCategory", "showGroup"),
|
||||||
hasTypes: gt("selectorTypes.length", 1),
|
hasTypes: gt("selectorTypes.length", 1),
|
||||||
|
@ -157,7 +166,7 @@ export default Component.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed("connector")
|
||||||
selectorTypes() {
|
selectorTypes() {
|
||||||
return selectionTypes
|
return selectionTypes
|
||||||
.filter((type) => this[`${type}Enabled`])
|
.filter((type) => this[`${type}Enabled`])
|
||||||
|
@ -268,6 +277,13 @@ export default Component.extend({
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activeType === "value") {
|
||||||
|
content = values.map((value) => ({
|
||||||
|
id: value,
|
||||||
|
name: value,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -337,7 +353,7 @@ export default Component.extend({
|
||||||
resetActiveType() {
|
resetActiveType() {
|
||||||
this.set(
|
this.set(
|
||||||
"activeType",
|
"activeType",
|
||||||
defaultSelectionType(this.selectorType, this.options)
|
defaultSelectionType(this.selectorType, this.options, this.connector)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -105,13 +105,18 @@ const selectionTypes = [
|
||||||
"tag",
|
"tag",
|
||||||
"user",
|
"user",
|
||||||
"customField",
|
"customField",
|
||||||
|
"value",
|
||||||
];
|
];
|
||||||
|
|
||||||
function defaultSelectionType(inputType, options = {}) {
|
function defaultSelectionType(inputType, options = {}, connector = null) {
|
||||||
if (options[`${inputType}DefaultSelection`]) {
|
if (options[`${inputType}DefaultSelection`]) {
|
||||||
return options[`${inputType}DefaultSelection`];
|
return options[`${inputType}DefaultSelection`];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connector === "is") {
|
||||||
|
return "value";
|
||||||
|
}
|
||||||
|
|
||||||
let type = selectionTypes[0];
|
let type = selectionTypes[0];
|
||||||
|
|
||||||
for (let t of selectionTypes) {
|
for (let t of selectionTypes) {
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
value=pair.value
|
value=pair.value
|
||||||
activeType=pair.value_type
|
activeType=pair.value_type
|
||||||
options=options
|
options=options
|
||||||
onUpdate=onUpdate}}
|
onUpdate=onUpdate
|
||||||
|
connector=pair.connector}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if showJoin}}
|
{{#if showJoin}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
export function cook(text, options) {
|
export function cook(text, options) {
|
||||||
if (!options) {
|
if (!options) {
|
||||||
options = buildOptions({
|
options = buildOptions({
|
||||||
getURL: getURL,
|
getURL,
|
||||||
siteSettings: getOwner(this).lookup("site-settings:main"),
|
siteSettings: getOwner(this).lookup("site-settings:main"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ function performSearch(
|
||||||
// need to be able to cancel this
|
// need to be able to cancel this
|
||||||
oldSearch = $.ajax(getUrl("/u/search/users"), {
|
oldSearch = $.ajax(getUrl("/u/search/users"), {
|
||||||
data: {
|
data: {
|
||||||
term: term,
|
term,
|
||||||
topic_id: topicId,
|
topic_id: topicId,
|
||||||
include_groups: includeGroups,
|
include_groups: includeGroups,
|
||||||
include_mentionable_groups: includeMentionableGroups,
|
include_mentionable_groups: includeMentionableGroups,
|
||||||
include_messageable_groups: includeMessageableGroups,
|
include_messageable_groups: includeMessageableGroups,
|
||||||
group: group,
|
group,
|
||||||
topic_allowed_users: allowedUsers,
|
topic_allowed_users: allowedUsers,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
|
||||||
p {
|
p {
|
||||||
line-height: 1.7;
|
|
||||||
|
|
||||||
img {
|
img {
|
||||||
@extend img.emoji;
|
@extend img.emoji;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ en:
|
||||||
group: "group"
|
group: "group"
|
||||||
list: "list"
|
list: "list"
|
||||||
custom_field: "custom field"
|
custom_field: "custom field"
|
||||||
|
value: "value"
|
||||||
|
|
||||||
placeholder:
|
placeholder:
|
||||||
text: "Enter text"
|
text: "Enter text"
|
||||||
|
@ -138,6 +139,7 @@ en:
|
||||||
group: "Select group"
|
group: "Select group"
|
||||||
list: "Enter item"
|
list: "Enter item"
|
||||||
custom_field: "Select field"
|
custom_field: "Select field"
|
||||||
|
value: "Select value"
|
||||||
|
|
||||||
error:
|
error:
|
||||||
failed: "failed to save wizard"
|
failed: "failed to save wizard"
|
||||||
|
|
|
@ -143,7 +143,7 @@ class CustomWizard::Mapper
|
||||||
if value == "present"
|
if value == "present"
|
||||||
result = key.public_send(operator)
|
result = key.public_send(operator)
|
||||||
elsif ["true", "false"].include?(value)
|
elsif ["true", "false"].include?(value)
|
||||||
result = key.public_send(operator, ActiveRecord::Type::Boolean.new.cast(value))
|
result = bool(key).public_send(operator, bool(value))
|
||||||
end
|
end
|
||||||
elsif [key, value, operator].all? { |i| !i.nil? }
|
elsif [key, value, operator].all? { |i| !i.nil? }
|
||||||
result = key.public_send(operator, value)
|
result = key.public_send(operator, value)
|
||||||
|
@ -265,4 +265,8 @@ class CustomWizard::Mapper
|
||||||
result = data[k]
|
result = data[k]
|
||||||
keys.empty? ? result : self.recurse(result, keys)
|
keys.empty? ? result : self.recurse(result, keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bool(value)
|
||||||
|
ActiveRecord::Type::Boolean.new.cast(value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
5363
package-lock.json
generiert
Normale Datei
5363
package-lock.json
generiert
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
|
@ -5,6 +5,7 @@
|
||||||
"author": "Pavilion",
|
"author": "Pavilion",
|
||||||
"license": "GPL V2",
|
"license": "GPL V2",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint-config-discourse": "^1.1.8"
|
"eslint-config-discourse": "^1.1.8",
|
||||||
|
"semver": "^7.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# name: discourse-custom-wizard
|
# name: discourse-custom-wizard
|
||||||
# about: Create custom wizards
|
# about: Create custom wizards
|
||||||
# version: 1.15.0
|
# version: 1.15.2
|
||||||
# authors: Angus McLeod
|
# authors: Angus McLeod
|
||||||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||||
# contact emails: angus@thepavilion.io
|
# contact emails: angus@thepavilion.io
|
||||||
|
|
|
@ -47,6 +47,14 @@ describe CustomWizard::Builder do
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let(:boolean_field_condition_json) {
|
||||||
|
JSON.parse(
|
||||||
|
File.open(
|
||||||
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/condition/boolean_field_condition.json"
|
||||||
|
).read
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Group.refresh_automatic_group!(:trust_level_3)
|
Group.refresh_automatic_group!(:trust_level_3)
|
||||||
CustomWizard::Template.save(
|
CustomWizard::Template.save(
|
||||||
|
@ -322,6 +330,7 @@ describe CustomWizard::Builder do
|
||||||
context "with condition" do
|
context "with condition" do
|
||||||
before do
|
before do
|
||||||
@template[:steps][0][:fields][0][:condition] = user_condition_json['condition']
|
@template[:steps][0][:fields][0][:condition] = user_condition_json['condition']
|
||||||
|
@template[:steps][2][:fields][5][:condition] = boolean_field_condition_json['condition']
|
||||||
CustomWizard::Template.save(@template.as_json)
|
CustomWizard::Template.save(@template.as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -334,6 +343,16 @@ describe CustomWizard::Builder do
|
||||||
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
||||||
expect(wizard.steps.first.fields.first.id).to eq(@template[:steps][0][:fields][1]['id'])
|
expect(wizard.steps.first.fields.first.id).to eq(@template[:steps][0][:fields][1]['id'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works if a field condition uses 'is true/false'" do
|
||||||
|
builder = CustomWizard::Builder.new(@template[:id], user)
|
||||||
|
wizard = builder.build
|
||||||
|
wizard.create_updater('step_2', step_2_field_5: 'true').update
|
||||||
|
|
||||||
|
builder = CustomWizard::Builder.new(@template[:id], user)
|
||||||
|
wizard = builder.build
|
||||||
|
expect(wizard.steps.last.fields.last.id).to eq(@template[:steps][2][:fields][5]['id'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
17
spec/fixtures/condition/boolean_field_condition.json
gevendort
Normale Datei
17
spec/fixtures/condition/boolean_field_condition.json
gevendort
Normale Datei
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"condition": [
|
||||||
|
{
|
||||||
|
"type": "validation",
|
||||||
|
"pairs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"key": "step_2_field_5",
|
||||||
|
"key_type": "wizard_field",
|
||||||
|
"value": "true",
|
||||||
|
"value_type": "text",
|
||||||
|
"connector": "is"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
6
spec/fixtures/wizard.json
gevendort
6
spec/fixtures/wizard.json
gevendort
|
@ -157,6 +157,12 @@
|
||||||
"label": "User Selector",
|
"label": "User Selector",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "user_selector"
|
"type": "user_selector"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "step_3_field_6",
|
||||||
|
"label": "Conditional User Selector",
|
||||||
|
"description": "Shown when checkbox in step_2_field_5 is true",
|
||||||
|
"type": "user_selector"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Unfortunately not the edible type :sushi: "
|
"description": "Unfortunately not the edible type :sushi: "
|
||||||
|
|
Laden …
In neuem Issue referenzieren