From 6b2dd5a4433a83f34a258dd242d9264d4ee810a3 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 6 Apr 2023 17:04:01 +0100 Subject: [PATCH 1/9] FIX: users not being added to group as part of create action --- lib/custom_wizard/action.rb | 6 +++++- spec/components/custom_wizard/action_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 34f81455..eb614076 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -460,7 +460,11 @@ class CustomWizard::Action user_ids.each { |user_id| group.group_users.build(user_id: user_id) } end - log_success("Group created", group.name) + if group.save + log_success("Group created", group.name) + else + log_error("Group users creation failed", group.errors.messages) + end result.output = group.name else diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 79c64520..d2fde3df 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -2,6 +2,7 @@ describe CustomWizard::Action do 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!(:tag) { Fabricate(:tag, name: 'tag1') } fab!(:group) { Fabricate(:group) } @@ -350,7 +351,11 @@ describe CustomWizard::Action do 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 + 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(GroupUser.where(group_id: group_id, user_id: user_id).exists?).to eq(true) end it '#add_to_group' do From 766cae92bad45c6d04d59ef79917674407e7d241 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 6 Apr 2023 17:05:06 +0100 Subject: [PATCH 2/9] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 3a65d315..ab596540 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.0 +# version: 2.3.1 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 37cef2ccc261b3f254b4a12fe3227ab5040652dd Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 11 Apr 2023 09:54:37 +0100 Subject: [PATCH 3/9] IMPROVE: warn in logs when at least one user in wizard did not exist --- lib/custom_wizard/action.rb | 5 +- spec/components/custom_wizard/action_spec.rb | 15 +++ .../actions/create_group_bad_user.json | 104 ++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/actions/create_group_bad_user.json diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index eb614076..ac0799f3 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -456,14 +456,15 @@ class CustomWizard::Action if new_group_params[:usernames].present? 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.each { |user_id| group.group_users.build(user_id: user_id) } end if group.save log_success("Group created", group.name) - else - log_error("Group users creation failed", group.errors.messages) end result.output = group.name diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index d2fde3df..9a89e5b4 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -13,6 +13,7 @@ describe CustomWizard::Action do let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_tags) { get_wizard_fixture("actions/watch_tags") } let(:create_group) { get_wizard_fixture("actions/create_group") } + let(:create_group_with_nonexistant_user) { get_wizard_fixture("actions/create_group_bad_user") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } @@ -358,6 +359,20 @@ describe CustomWizard::Action do 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_nonexistant_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 + it '#add_to_group' do wizard_template['actions'] << create_group wizard_template['actions'] << add_to_group diff --git a/spec/fixtures/actions/create_group_bad_user.json b/spec/fixtures/actions/create_group_bad_user.json new file mode 100644 index 00000000..96d6796d --- /dev/null +++ b/spec/fixtures/actions/create_group_bad_user.json @@ -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" + } + ] +} \ No newline at end of file From f7cdc77a065d1636460198a3ca4a3bdad1833b6f Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 11 Apr 2023 09:59:22 +0100 Subject: [PATCH 4/9] fix spelling --- spec/components/custom_wizard/action_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 9a89e5b4..a2690208 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -13,7 +13,7 @@ describe CustomWizard::Action do let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_tags) { get_wizard_fixture("actions/watch_tags") } let(:create_group) { get_wizard_fixture("actions/create_group") } - let(:create_group_with_nonexistant_user) { get_wizard_fixture("actions/create_group_bad_user") } + let(:existentcreate_group_with_nonexistent_user) { get_wizard_fixture("actions/create_group_bad_user") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } @@ -360,7 +360,7 @@ describe CustomWizard::Action do 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_nonexistant_user + wizard_template['actions'] << existentcreate_group_with_nonexistent_user update_template(wizard_template) wizard = CustomWizard::Builder.new(@template[:id], user).build From 93b574beb794a549728ec0b54a35fca02b40c331 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 11 Apr 2023 10:00:42 +0100 Subject: [PATCH 5/9] fix spelling --- spec/components/custom_wizard/action_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index a2690208..c450582d 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -13,7 +13,7 @@ describe CustomWizard::Action do let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_tags) { get_wizard_fixture("actions/watch_tags") } let(:create_group) { get_wizard_fixture("actions/create_group") } - let(:existentcreate_group_with_nonexistent_user) { get_wizard_fixture("actions/create_group_bad_user") } + 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(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") } @@ -360,7 +360,7 @@ describe CustomWizard::Action do 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'] << existentcreate_group_with_nonexistent_user + wizard_template['actions'] << create_group_with_nonexistent_user update_template(wizard_template) wizard = CustomWizard::Builder.new(@template[:id], user).build From 32a8dcf19fa555fa2a8867d7dc9b7cc3025957d9 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 28 Apr 2023 16:15:48 +0200 Subject: [PATCH 6/9] Add cron schedule to Custom Wizard workflow --- .github/workflows/discourse-plugin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml index f5cf62e5..13850e3e 100644 --- a/.github/workflows/discourse-plugin.yml +++ b/.github/workflows/discourse-plugin.yml @@ -5,6 +5,8 @@ on: branches: - main pull_request: + schedule: + - cron: "0 0 * * *" jobs: ci: From caab850127c8e63a8cd9813455fcc6d585423cb1 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 1 May 2023 21:49:44 +0100 Subject: [PATCH 7/9] FIX: failing log spec --- lib/custom_wizard/log.rb | 4 ++-- spec/serializers/custom_wizard/log_serializer_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/custom_wizard/log.rb b/lib/custom_wizard/log.rb index cb5b78c7..ed9624e1 100644 --- a/lib/custom_wizard/log.rb +++ b/lib/custom_wizard/log.rb @@ -15,13 +15,13 @@ class CustomWizard::Log @username = attrs['username'] 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) PluginStore.set('custom_wizard_log', log_id.to_s, { - date: Time.now, + date: date, wizard_id: wizard_id, action: action, username: username, diff --git a/spec/serializers/custom_wizard/log_serializer_spec.rb b/spec/serializers/custom_wizard/log_serializer_spec.rb index 7dd1db0f..cad4a85b 100644 --- a/spec/serializers/custom_wizard/log_serializer_spec.rb +++ b/spec/serializers/custom_wizard/log_serializer_spec.rb @@ -4,7 +4,7 @@ describe CustomWizard::LogSerializer do fab!(:user) { Fabricate(:user) } 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') json_array = ActiveModel::ArraySerializer.new( From 8b443e0f087614fc6d7b60fd7cda40e691717df0 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 1 May 2023 21:52:10 +0100 Subject: [PATCH 8/9] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index ab596540..8d5d1a89 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.1 +# version: 2.3.2 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 4c784d98e6c76c22d201ef1fa26977ffc66cb418 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 3 May 2023 11:01:54 +0200 Subject: [PATCH 9/9] Add not equals support to mapper --- .../discourse/lib/wizard-mapper.js.es6 | 1 + config/locales/client.en.yml | 1 + lib/custom_wizard/mapper.rb | 1 + plugin.rb | 2 +- spec/components/custom_wizard/mapper_spec.rb | 13 +++++++++++++ spec/fixtures/mapper/inputs.json | 15 +++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index c398eaf4..9037bec5 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -35,6 +35,7 @@ function inputTypesContent(options = {}) { const connectors = { pair: [ "equal", + "not_equal", "greater", "less", "greater_or_equal", diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 8a856636..98519335 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -324,6 +324,7 @@ en: then: "then" set: "set" equal: '=' + not_equal: '!=' greater: '>' less: '<' greater_or_equal: '>=' diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 4e18ad01..66a10736 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -30,6 +30,7 @@ class CustomWizard::Mapper OPERATORS = { equal: '==', + not_equal: "!=", greater: '>', less: '<', greater_or_equal: '>=', diff --git a/plugin.rb b/plugin.rb index 8d5d1a89..b90e0965 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.2 +# version: 2.3.3 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index 510632a9..3e0e6ce6 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -291,6 +291,19 @@ describe CustomWizard::Mapper do 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 expect(CustomWizard::Mapper.new( inputs: inputs['greater_than_pair'], diff --git a/spec/fixtures/mapper/inputs.json b/spec/fixtures/mapper/inputs.json index 3fd406a4..2ef81a28 100644 --- a/spec/fixtures/mapper/inputs.json +++ b/spec/fixtures/mapper/inputs.json @@ -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": [ { "type": "validation",