+
+
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d70cc9a1..99b51324 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -372,6 +372,10 @@ en:
label: "Watch Categories"
categories: "Categories"
mute_remainder: "Mute Remainder"
+ watch_tags:
+ label: "Watch Tags"
+ tags: "Tags"
+ watch_x:
notification_level:
label: "Notification Level"
regular: "Normal"
diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb
index 24fe2576..c1f04c0c 100644
--- a/lib/custom_wizard/action.rb
+++ b/lib/custom_wizard/action.rb
@@ -204,6 +204,52 @@ class CustomWizard::Action
end
end
+ def watch_tags
+ tags = CustomWizard::Mapper.new(
+ inputs: action['tags'],
+ data: mapper_data,
+ user: user
+ ).perform
+
+ tags = [*tags]
+ level = action['notification_level'].to_sym
+
+ if level.blank?
+ log_error("Notifcation Level was not set. Exiting watch tags action")
+ return
+ end
+
+ users = []
+
+ if action['usernames']
+ mapped_users = CustomWizard::Mapper.new(
+ inputs: action['usernames'],
+ data: mapper_data,
+ user: user
+ ).perform
+
+ if mapped_users.present?
+ mapped_users = mapped_users.split(',')
+ .map { |username| User.find_by(username: username) }
+ users.push(*mapped_users)
+ end
+ end
+
+ if ActiveRecord::Type::Boolean.new.cast(action['wizard_user'])
+ users.push(user)
+ end
+
+ users.each do |user|
+ result = TagUser.batch_set(user, level, tags)
+
+ if result
+ log_success("#{user.username} notifications for #{tags} set to #{level}")
+ else
+ log_error("failed to set #{user.username} notifications for #{tags} to #{level}")
+ end
+ end
+ end
+
def watch_categories
watched_categories = CustomWizard::Mapper.new(
inputs: action['categories'],
diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb
index 20a444eb..593dc391 100644
--- a/lib/custom_wizard/subscription.rb
+++ b/lib/custom_wizard/subscription.rb
@@ -75,7 +75,7 @@ class CustomWizard::Subscription
action: {
type: {
none: ['create_topic', 'update_profile', 'open_composer', 'route_to'],
- standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'],
+ standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'watch_tags', 'add_to_group'],
business: ['*'],
community: ['*']
}
diff --git a/plugin.rb b/plugin.rb
index ccb08d6f..0613e88e 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -2,6 +2,7 @@
# name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.2.0
+# version: 2.1.4
# 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/action_spec.rb b/spec/components/custom_wizard/action_spec.rb
index 624844c3..6db010b5 100644
--- a/spec/components/custom_wizard/action_spec.rb
+++ b/spec/components/custom_wizard/action_spec.rb
@@ -3,12 +3,14 @@
describe CustomWizard::Action do
fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@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) }
let(:wizard_template) { get_wizard_fixture("wizard") }
let(:open_composer) { get_wizard_fixture("actions/open_composer") }
let(:create_category) { get_wizard_fixture("actions/create_category") }
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(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
let(:send_message) { get_wizard_fixture("actions/send_message") }
@@ -219,6 +221,20 @@ describe CustomWizard::Action do
enable_subscription("standard")
end
+ it 'watches tags' do
+ watch_tags[:tags][0][:output] = tag.name
+ wizard_template[:actions] << watch_tags
+ 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
+
+ expect(TagUser.where(
+ tag_id: tag.id,
+ user_id: user.id
+ ).first.notification_level).to eq(2)
+ end
+
it 'watches categories' do
watch_categories[:categories][0][:output] = category.id
wizard_template[:actions] << watch_categories
diff --git a/spec/fixtures/actions/watch_tags.json b/spec/fixtures/actions/watch_tags.json
new file mode 100644
index 00000000..29e50207
--- /dev/null
+++ b/spec/fixtures/actions/watch_tags.json
@@ -0,0 +1,15 @@
+{
+ "id": "action_3",
+ "run_after": "step_1",
+ "type": "watch_tags",
+ "notification_level": "tracking",
+ "wizard_user": true,
+ "tags": [
+ {
+ "type": "assignment",
+ "output": "tag1",
+ "output_type": "text",
+ "output_connector": "set"
+ }
+ ]
+}