1
0
Fork 0

Merge branch 'main' into field_type_subscription_ui

Dieser Commit ist enthalten in:
Angus McLeod 2023-05-08 18:42:14 +02:00 committet von GitHub
Commit 7c56b6d4d7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
12 geänderte Dateien mit 167 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,8 @@ on:
branches: branches:
- main - main
pull_request: pull_request:
schedule:
- cron: "0 0 * * *"
jobs: jobs:
ci: ci:

Datei anzeigen

@ -35,6 +35,7 @@ function inputTypesContent(options = {}) {
const connectors = { const connectors = {
pair: [ pair: [
"equal", "equal",
"not_equal",
"greater", "greater",
"less", "less",
"greater_or_equal", "greater_or_equal",

Datei anzeigen

@ -324,6 +324,7 @@ en:
then: "then" then: "then"
set: "set" set: "set"
equal: '=' equal: '='
not_equal: '!='
greater: '>' greater: '>'
less: '<' less: '<'
greater_or_equal: '>=' greater_or_equal: '>='

Datei anzeigen

@ -456,11 +456,16 @@ class CustomWizard::Action
if new_group_params[:usernames].present? if new_group_params[:usernames].present?
user_ids = get_user_ids(new_group_params[:usernames]) user_ids = get_user_ids(new_group_params[:usernames])
if user_ids.count < new_group_params[:usernames].count
log_error("Warning, group creation: some users were not found!")
end
user_ids -= owner_ids if owner_ids user_ids -= owner_ids if owner_ids
user_ids.each { |user_id| group.group_users.build(user_id: user_id) } user_ids.each { |user_id| group.group_users.build(user_id: user_id) }
end end
if group.save
log_success("Group created", group.name) log_success("Group created", group.name)
end
result.output = group.name result.output = group.name
else else

Datei anzeigen

@ -15,13 +15,13 @@ class CustomWizard::Log
@username = attrs['username'] @username = attrs['username']
end end
def self.create(wizard_id, action, username, message) def self.create(wizard_id, action, username, message, date = Time.now)
log_id = SecureRandom.hex(12) log_id = SecureRandom.hex(12)
PluginStore.set('custom_wizard_log', PluginStore.set('custom_wizard_log',
log_id.to_s, log_id.to_s,
{ {
date: Time.now, date: date,
wizard_id: wizard_id, wizard_id: wizard_id,
action: action, action: action,
username: username, username: username,

Datei anzeigen

@ -30,6 +30,7 @@ class CustomWizard::Mapper
OPERATORS = { OPERATORS = {
equal: '==', equal: '==',
not_equal: "!=",
greater: '>', greater: '>',
less: '<', less: '<',
greater_or_equal: '>=', greater_or_equal: '>=',

Datei anzeigen

@ -1,7 +1,7 @@
# 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.3.1 # version: 2.3.4
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# 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

Datei anzeigen

@ -2,6 +2,7 @@
describe CustomWizard::Action do describe CustomWizard::Action do
fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com", trust_level: TrustLevel[2]) } fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com", trust_level: TrustLevel[2]) }
fab!(:user1) { Fabricate(:user, name: "Angus One", username: 'angus1', email: "angus_one@email.com", trust_level: TrustLevel[2]) }
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') } fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
fab!(:tag) { Fabricate(:tag, name: 'tag1') } fab!(:tag) { Fabricate(:tag, name: 'tag1') }
fab!(:group) { Fabricate(:group) } fab!(:group) { Fabricate(:group) }
@ -12,6 +13,7 @@ describe CustomWizard::Action do
let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_categories) { get_wizard_fixture("actions/watch_categories") }
let(:watch_tags) { get_wizard_fixture("actions/watch_tags") } let(:watch_tags) { get_wizard_fixture("actions/watch_tags") }
let(:create_group) { get_wizard_fixture("actions/create_group") } let(:create_group) { get_wizard_fixture("actions/create_group") }
let(:create_group_with_nonexistent_user) { get_wizard_fixture("actions/create_group_bad_user") }
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message) { get_wizard_fixture("actions/send_message") }
let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") }
@ -350,7 +352,25 @@ describe CustomWizard::Action do
wizard = CustomWizard::Builder.new(@template[:id], user).build wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
group_id = Group.where(name: wizard.current_submission.fields['action_9']).first.id
user_id = User.find_by(username: wizard_template['actions'][4]['usernames'][0]["output"][0]).id
expect(Group.where(name: wizard.current_submission.fields['action_9']).exists?).to eq(true) expect(Group.where(name: wizard.current_submission.fields['action_9']).exists?).to eq(true)
expect(GroupUser.where(group_id: group_id, user_id: user_id).exists?).to eq(true)
end
it '#create_group completes successfully when user included in usernames does not exist but excludes users who do not exist and includes warning in log' do
wizard_template['actions'] << create_group_with_nonexistent_user
update_template(wizard_template)
wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
group_id = Group.where(name: wizard.current_submission.fields['action_9']).first.id
expect(CustomWizard::Log.list_query.all.last.value.include? "some users were not found").to eq(true)
expect(Group.where(name: wizard.current_submission.fields['action_9']).exists?).to eq(true)
expect(GroupUser.where(group_id: group_id).count).to eq(1)
end end
it '#add_to_group' do it '#add_to_group' do

Datei anzeigen

@ -291,6 +291,19 @@ describe CustomWizard::Mapper do
end end
end end
it "handles not equal pairs" do
expect(CustomWizard::Mapper.new(
inputs: inputs['not_equals_pair'],
data: data,
user: user1
).perform).to eq(true)
expect(CustomWizard::Mapper.new(
inputs: inputs['not_equals_pair'],
data: data,
user: user2
).perform).to eq(false)
end
it "handles greater than pairs" do it "handles greater than pairs" do
expect(CustomWizard::Mapper.new( expect(CustomWizard::Mapper.new(
inputs: inputs['greater_than_pair'], inputs: inputs['greater_than_pair'],

Datei anzeigen

@ -0,0 +1,104 @@
{
"id": "action_9",
"run_after": "step_1",
"type": "create_group",
"title": [
{
"type": "assignment",
"output": "New Group Member",
"output_type": "text",
"output_connector": "set"
}
],
"custom_fields": [
{
"type": "association",
"pairs": [
{
"index": 0,
"key": "group_custom_field",
"key_type": "text",
"value": "step_3_field_1",
"value_type": "wizard_field",
"connector": "association"
}
]
}
],
"name": [
{
"type": "assignment",
"output": "step_1_field_1",
"output_type": "wizard_field",
"output_connector": "set"
}
],
"full_name": [
{
"type": "assignment",
"output": "step_1_field_1",
"output_type": "wizard_field",
"output_connector": "set"
}
],
"usernames": [
{
"type": "assignment",
"output_type": "user",
"output_connector": "set",
"output": [
"angus3"
]
}
],
"owner_usernames": [
{
"type": "assignment",
"output_type": "user",
"output_connector": "set",
"output": [
"angus"
]
}
],
"grant_trust_level": [
{
"type": "assignment",
"output": "3",
"output_type": "text",
"output_connector": "set"
}
],
"mentionable_level": [
{
"type": "assignment",
"output": "1",
"output_type": "text",
"output_connector": "set"
}
],
"messageable_level": [
{
"type": "assignment",
"output": "2",
"output_type": "text",
"output_connector": "set"
}
],
"visibility_level": [
{
"type": "assignment",
"output": "3",
"output_type": "text",
"output_connector": "set"
}
],
"members_visibility_level": [
{
"type": "assignment",
"output": "99",
"output_type": "text",
"output_connector": "set"
}
]
}

Datei anzeigen

@ -195,6 +195,21 @@
] ]
} }
], ],
"not_equals_pair": [
{
"type": "validation",
"pairs": [
{
"index": 0,
"key": "trust_level",
"key_type": "user_field",
"value": "1",
"value_type": "text",
"connector": "not_equal"
}
]
}
],
"greater_than_pair": [ "greater_than_pair": [
{ {
"type": "validation", "type": "validation",

Datei anzeigen

@ -4,7 +4,7 @@ describe CustomWizard::LogSerializer do
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
it 'should return log attributes' do it 'should return log attributes' do
CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message', 1.day.ago)
CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message')
json_array = ActiveModel::ArraySerializer.new( json_array = ActiveModel::ArraySerializer.new(