From 16d65c37f8e83151983207f9322f1ce1b8102939 Mon Sep 17 00:00:00 2001 From: jasonfine Date: Tue, 16 Jan 2024 09:51:11 -0500 Subject: [PATCH 01/10] Update image_and_files.md --- docs/tutorials/image_and_files.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/tutorials/image_and_files.md b/docs/tutorials/image_and_files.md index cf55aedf3..177abf161 100644 --- a/docs/tutorials/image_and_files.md +++ b/docs/tutorials/image_and_files.md @@ -13,6 +13,8 @@ Here is everything you need to know about Fae Images and Files: Fae provides models for images and files: `Fae::Image` and `Fae::File` respectively. These models come with their own attributes, validations and uploaders and can be polymorphically associated to your application models. +:rotating_light: _Please do not name your image or file attachments as_ `image` or `file` _as this will lead to some unexpected behaviors._ E.g. don't do `has_fae_file :file` or `has_fae_image :image`. + Here's a basic example: ```ruby From 0424e606ab522819b1a27b3cb44c1bd381108c8d Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Tue, 12 Mar 2024 14:05:42 -0400 Subject: [PATCH 02/10] update cloning docs to accurately reflect that asset associations will be cloned --- .gitignore | 4 +++- docs/features/cloning.md | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 37f9388f6..18298e21b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ spec/dummy/public/uploads/* /vendor docker-compose.override.yml -.env \ No newline at end of file +.env +mysql +node_modules \ No newline at end of file diff --git a/docs/features/cloning.md b/docs/features/cloning.md index d8e69e612..88a67bbba 100644 --- a/docs/features/cloning.md +++ b/docs/features/cloning.md @@ -49,7 +49,7 @@ That's all for basic set-up. If you want complete control over which attributes and associations are cloned, we wouldn't call you a control freak. We've baked in some nice simple methods to make this possible. -**Note:** Asset cloning is not currently supported, so if you try to pass in those associations, cloning will fail. +**Note:** Asset cloning is supported. ## Whitelisting Attributes @@ -69,13 +69,11 @@ end Belongs_to associations are automatically copied over, unless you are whitelisting attributes and forget to/ purposely don't add it there. For the rest of the associations you may have (i.e. has_one, has_many, has_and_belongs_to_many, has_many_through), you may use the `associations_for_cloning` method by passing in array of symbols. -**Note:** Any images or files you have will **not** be copied along, if you have included those relationships. - **Example** ```ruby def associations_for_cloning - [:aromas, :events] + [:aromas, :events, :bottle_shot_image] end ``` From 6f9a616b67b95ed15267c38d2795c97f78ffb81b Mon Sep 17 00:00:00 2001 From: JJ Date: Tue, 19 Mar 2024 16:18:37 -0400 Subject: [PATCH 03/10] Fae slack integration --- Gemfile.lock | 12 ++++--- app/models/concerns/fae/base_model_concern.rb | 32 +++++++++++++++++++ fae.gemspec | 1 + spec/dummy/app/models/wine.rb | 4 +++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8e7d6eef3..36395a190 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,7 @@ PATH sass (>= 3.4.0) sass-rails (>= 5.0.7) simple_form (<= 5.1) + slack-notifier slim uglifier @@ -115,7 +116,7 @@ GEM bundler rake thor (>= 0.14.0) - bcrypt (3.1.16) + bcrypt (3.1.20) better_errors (2.9.1) coderay (>= 1.0.0) erubi (>= 1.0.0) @@ -172,7 +173,7 @@ GEM msgpack debase-ruby_core_source (0.10.16) debug_inspector (1.1.0) - devise (4.8.1) + devise (4.9.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -357,9 +358,9 @@ GEM ffi (~> 1.0) regexp_parser (2.6.1) remotipart (1.4.4) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) @@ -411,6 +412,7 @@ GEM simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) + slack-notifier (2.4.0) slim (4.1.0) temple (>= 0.7.6, < 0.9) tilt (>= 2.0.6, < 2.1) diff --git a/app/models/concerns/fae/base_model_concern.rb b/app/models/concerns/fae/base_model_concern.rb index 398327383..dbdd9c8cd 100644 --- a/app/models/concerns/fae/base_model_concern.rb +++ b/app/models/concerns/fae/base_model_concern.rb @@ -2,12 +2,38 @@ module Fae module BaseModelConcern extend ActiveSupport::Concern require 'csv' + require 'slack-notifier' attr_accessor :filter included do include Fae::Trackable if Fae.track_changes include Fae::Sortable + after_create :notify_initiation + before_save :notify_changes + end + + def notify_changes + return unless notifiable_attributes.present? + notifiable_attributes.each do |field_name_symbol| + if self.send("#{field_name_symbol}_changed?") && self.send(field_name_symbol).present? + send_slack(field_name_symbol) + end + end + end + + def notify_initiation + return unless notifiable_attributes.present? + notifiable_attributes.each do |field_name_symbol| + if self.send(field_name_symbol).present? + send_slack(field_name_symbol) + end + end + end + + def notifiable_attributes + # override this method in your model + # array of attributes to notify if changed end def fae_display_field @@ -36,6 +62,12 @@ def fae_form_manager_model_id self.id end + def send_slack(field_name_symbol) + notifier = Slack::Notifier.new ENV["SLACK_WEBHOOK_URL"] + notifier.ping "#{Rails.application.class.module_parent_name} - #{name} (#{self.class.name.constantize}) - #{field_name_symbol.to_s} set to '#{self.send(field_name_symbol)}'" + + end + module ClassMethods def for_fae_index order(order_method) diff --git a/fae.gemspec b/fae.gemspec index 9d07dfcca..da56f4559 100644 --- a/fae.gemspec +++ b/fae.gemspec @@ -57,6 +57,7 @@ Gem::Specification.new do |s| s.add_dependency 'remotipart', '~> 1.4.0' s.add_dependency 'simple_form', '<= 5.1' s.add_dependency 'slim' + s.add_dependency 'slack-notifier' s.add_development_dependency 'appraisal' s.add_development_dependency 'better_errors' diff --git a/spec/dummy/app/models/wine.rb b/spec/dummy/app/models/wine.rb index c1b4299f3..c90e41495 100644 --- a/spec/dummy/app/models/wine.rb +++ b/spec/dummy/app/models/wine.rb @@ -24,4 +24,8 @@ def self.for_fae_index order(:position) end + def notifiable_attributes + [:on_stage, :on_prod, :description_en] + end + end From 19dc0659139ee9d93d0ec5b5af97f538675800d0 Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 20 Mar 2024 09:55:16 -0400 Subject: [PATCH 04/10] allows multiple webhooks for slack message --- app/models/concerns/fae/base_model_concern.rb | 12 +++++------- app/services/fae/slack_notification.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 app/services/fae/slack_notification.rb diff --git a/app/models/concerns/fae/base_model_concern.rb b/app/models/concerns/fae/base_model_concern.rb index 2a102ab92..31edbed94 100644 --- a/app/models/concerns/fae/base_model_concern.rb +++ b/app/models/concerns/fae/base_model_concern.rb @@ -2,7 +2,6 @@ module Fae module BaseModelConcern extend ActiveSupport::Concern require 'csv' - require 'slack-notifier' attr_accessor :filter @@ -17,7 +16,7 @@ def notify_changes return unless notifiable_attributes.present? notifiable_attributes.each do |field_name_symbol| if self.send("#{field_name_symbol}_changed?") && self.send(field_name_symbol).present? - send_slack(field_name_symbol) + format_and_send_slack(field_name_symbol) end end end @@ -26,7 +25,7 @@ def notify_initiation return unless notifiable_attributes.present? notifiable_attributes.each do |field_name_symbol| if self.send(field_name_symbol).present? - send_slack(field_name_symbol) + format_and_send_slack(field_name_symbol) end end end @@ -62,10 +61,9 @@ def fae_form_manager_model_id self.id end - def send_slack(field_name_symbol) - notifier = Slack::Notifier.new ENV["SLACK_WEBHOOK_URL"] - notifier.ping "#{Rails.application.class.module_parent_name} - #{name} (#{self.class.name.constantize}) - #{field_name_symbol.to_s} set to '#{self.send(field_name_symbol)}'" - + def format_and_send_slack(field_name_symbol) + message = "#{Rails.application.class.module_parent_name} - #{name} (#{self.class.name.constantize}) - #{field_name_symbol.to_s} set to '#{self.send(field_name_symbol)}'" + Fae::SlackNotification.new().send_slack(message: message) end module ClassMethods diff --git a/app/services/fae/slack_notification.rb b/app/services/fae/slack_notification.rb new file mode 100644 index 000000000..83bb8f425 --- /dev/null +++ b/app/services/fae/slack_notification.rb @@ -0,0 +1,17 @@ +require 'slack-notifier' + +module Fae + class SlackNotification + + def send_slack(webhook: ENV["SLACK_WEBHOOK_URL"], message: nil) + if webhook.is_a?(String) + webhook = webhook.split(',') + end + webhook.each do |wh| + notifier = Slack::Notifier.new wh + notifier.ping message + end + end + + end +end \ No newline at end of file From 1ca5fa54dc267fe44b114c96a3b96f53dfa14692 Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 20 Mar 2024 13:10:44 -0400 Subject: [PATCH 05/10] Allow dev to create custom message --- app/models/concerns/fae/base_model_concern.rb | 10 ++++++++-- spec/dummy/app/models/wine.rb | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/fae/base_model_concern.rb b/app/models/concerns/fae/base_model_concern.rb index 31edbed94..ca7464a0d 100644 --- a/app/models/concerns/fae/base_model_concern.rb +++ b/app/models/concerns/fae/base_model_concern.rb @@ -61,9 +61,15 @@ def fae_form_manager_model_id self.id end + def slack_message(field_name_symbol) + # override this method in your model + end + def format_and_send_slack(field_name_symbol) - message = "#{Rails.application.class.module_parent_name} - #{name} (#{self.class.name.constantize}) - #{field_name_symbol.to_s} set to '#{self.send(field_name_symbol)}'" - Fae::SlackNotification.new().send_slack(message: message) + message = slack_message(field_name_symbol) + if message.present? + Fae::SlackNotification.new().send_slack(message: message) + end end module ClassMethods diff --git a/spec/dummy/app/models/wine.rb b/spec/dummy/app/models/wine.rb index 96576e9c7..7d6262fc8 100644 --- a/spec/dummy/app/models/wine.rb +++ b/spec/dummy/app/models/wine.rb @@ -36,4 +36,8 @@ def notifiable_attributes [:on_stage, :on_prod, :description_en] end + def slack_message(field_name_symbol) + "#{Rails.application.class.module_parent_name} - [#{name}](#{Rails.application.routes.url_helpers.edit_admin_wine_url(self)}) (#{self.class.name.constantize}) is live #{field_name_symbol.to_s.gsub('_',' ')}" + end + end From 04ac104389c947a174662a98a400d853269f5955 Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Thu, 16 May 2024 16:37:29 -0400 Subject: [PATCH 06/10] tests/etc --- .gitignore | 4 ++- Gemfile.lock | 41 +++++++++++++------------- app/services/fae/slack_notification.rb | 2 +- spec/dummy/app/models/wine.rb | 7 ++++- spec/dummy/config/environment.rb | 5 +++- spec/models/fae/base_spec.rb | 23 +++++++++++++++ 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 37f9388f6..18298e21b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ spec/dummy/public/uploads/* /vendor docker-compose.override.yml -.env \ No newline at end of file +.env +mysql +node_modules \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index c0c38ce48..877169968 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,11 +18,11 @@ GIT PATH remote: . specs: - fae-rails (3.0.0) + fae-rails (3.1.0) acts_as_list (~> 0.9.11) browser (~> 2.5.3) carrierwave - devise (~> 4.0) + devise devise-two-factor jquery-rails (~> 4.3.1) jquery-ui-rails (~> 6.0.1) @@ -149,13 +149,12 @@ GEM capybara-screenshot (1.0.26) capybara (>= 1.0, < 4) launchy - carrierwave (2.2.2) - activemodel (>= 5.0.0) - activesupport (>= 5.0.0) + carrierwave (3.0.7) + activemodel (>= 6.0.0) + activesupport (>= 6.0.0) addressable (~> 2.6) image_processing (~> 1.1) marcel (~> 1.0.0) - mini_mime (>= 0.1.3) ssrf_filter (~> 1.0) childprocess (4.1.0) chunky_png (1.4.0) @@ -176,7 +175,7 @@ GEM msgpack debase-ruby_core_source (0.10.16) debug_inspector (1.1.0) - devise (4.9.3) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -192,7 +191,7 @@ GEM erubi (1.12.0) eventmachine (1.2.7) excon (0.92.4) - execjs (2.8.1) + execjs (2.9.1) factory_bot (4.8.2) activesupport (>= 3.0.0) factory_bot_rails (4.8.2) @@ -284,7 +283,7 @@ GEM mime-types (3.4.1) mime-types-data (~> 3.2015) mime-types-data (3.2022.0105) - mini_magick (4.11.0) + mini_magick (4.12.0) mini_mime (1.1.2) minitest (5.21.2) msgpack (1.5.6) @@ -372,8 +371,8 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.5) - rotp (6.2.0) - rqrcode (2.1.2) + rotp (6.3.0) + rqrcode (2.2.0) chunky_png (~> 1.0) rqrcode_core (~> 1.0) rqrcode_core (1.2.0) @@ -399,7 +398,7 @@ GEM rspec-support (~> 3.10) rspec-support (3.11.0) ruby-prof (1.4.3) - ruby-vips (2.1.4) + ruby-vips (2.2.1) ffi (~> 1.12) rubyzip (2.3.2) sass (3.7.4) @@ -428,12 +427,12 @@ GEM actionpack (>= 5.2) activemodel (>= 5.2) slack-notifier (2.4.0) - slim (4.1.0) - temple (>= 0.7.6, < 0.9) - tilt (>= 2.0.6, < 2.1) - sprockets (4.0.3) + slim (5.2.1) + temple (~> 0.10.0) + tilt (>= 2.1.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) @@ -441,15 +440,15 @@ GEM sshkit (1.21.2) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - ssrf_filter (1.0.7) + ssrf_filter (1.1.2) strscan (3.0.1) - temple (0.8.2) + temple (0.10.3) thin (1.8.1) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) thor (1.3.0) - tilt (2.0.10) + tilt (2.3.0) timeout (0.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -489,7 +488,7 @@ DEPENDENCIES guard-rspec mysql2 pg - pry-nav + pry puma (~> 5.0) rails (~> 7.0.2) rails-controller-testing diff --git a/app/services/fae/slack_notification.rb b/app/services/fae/slack_notification.rb index 83bb8f425..34039aeb7 100644 --- a/app/services/fae/slack_notification.rb +++ b/app/services/fae/slack_notification.rb @@ -10,7 +10,7 @@ def send_slack(webhook: ENV["SLACK_WEBHOOK_URL"], message: nil) webhook.each do |wh| notifier = Slack::Notifier.new wh notifier.ping message - end + end if webhook.present? end end diff --git a/spec/dummy/app/models/wine.rb b/spec/dummy/app/models/wine.rb index 7d6262fc8..d3a0ec336 100644 --- a/spec/dummy/app/models/wine.rb +++ b/spec/dummy/app/models/wine.rb @@ -37,7 +37,12 @@ def notifiable_attributes end def slack_message(field_name_symbol) - "#{Rails.application.class.module_parent_name} - [#{name}](#{Rails.application.routes.url_helpers.edit_admin_wine_url(self)}) (#{self.class.name.constantize}) is live #{field_name_symbol.to_s.gsub('_',' ')}" + msg = '' + msg += "#{Rails.application.class.module_parent_name} - " + msg += "[#{name}](#{Rails.application.routes.url_helpers.edit_admin_wine_url(self)}) " + msg += "(#{self.class.name.constantize}) is live " + msg += "#{field_name_symbol.to_s.gsub('_',' ')}" + msg end end diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 10718a48b..1cdcb2cf0 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -4,4 +4,7 @@ # Initialize the Rails application. Rails.application.initialize! -ActiveRecord::Migrator.migrations_paths = '../spec/dummy/db/migrate' \ No newline at end of file +ActiveRecord::Migrator.migrations_paths = '../spec/dummy/db/migrate' + +# Set the default host and port to be the same as Action Mailer. +Rails.application.default_url_options = Rails.application.config.action_mailer.default_url_options \ No newline at end of file diff --git a/spec/models/fae/base_spec.rb b/spec/models/fae/base_spec.rb index ea4c99ee5..3ec6b7d9a 100644 --- a/spec/models/fae/base_spec.rb +++ b/spec/models/fae/base_spec.rb @@ -82,4 +82,27 @@ end end + describe '#format_and_send_slack' do + it 'should send a slack notification if message is present' do + wine = FactoryBot.create(:wine) + field_name_symbol = :on_prod + + test_message = "Dummy - [asdf](http://localhost/admin/wines/#{wine.id}/edit) (Wine) is live on prod" + allow(wine).to receive(:slack_message).with(field_name_symbol).and_return(test_message) + expect(Fae::SlackNotification).to receive(:new).and_return(double(send_slack: true)) + + wine.format_and_send_slack(field_name_symbol) + end + + it 'should not send a slack notification if message is not present' do + wine = FactoryBot.create(:wine) + field_name_symbol = :name_en + + allow(wine).to receive(:slack_message).with(field_name_symbol).and_return(nil) + expect(Fae::SlackNotification).not_to receive(:new) + + wine.format_and_send_slack(field_name_symbol) + end + end + end From 64a9fe9599b8ea8c1d08e560d160c809047daa9e Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Mon, 24 Jun 2024 14:06:57 -0400 Subject: [PATCH 07/10] slack notification docs --- README.md | 1 + docs/features/slack_notifications.md | 37 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 docs/features/slack_notifications.md diff --git a/README.md b/README.md index 8a23b9718..9a78b9a42 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ https://www.faecms.com/documentation * [Form Field Label & Helper Text Manager](docs/features/form_manager.md) * [Netlify Deploy Monitor](docs/features/netlify.md) * [Multi-Factor Authentication via OTP](docs/features/mutli_factor_authentication.md) +* [Slack Notifications](docs/features/slack_notifications.md) ### Tutorials diff --git a/docs/features/slack_notifications.md b/docs/features/slack_notifications.md new file mode 100644 index 000000000..aefe85703 --- /dev/null +++ b/docs/features/slack_notifications.md @@ -0,0 +1,37 @@ +# Slack Notifications + +Built around the `slack-notifier` gem, FAE now offers the ability to send a message to a Slack channel when an object is created or saved. + +FAE's `base_model_concern.rb` has two new callbacks: + +```ruby +after_create :notify_initiation +before_save :notify_changes +``` + +There are a couple of new instance methods to drive this in your models: + +```ruby +def notifiable_attributes + # array of attributes to notify if changed e.g.: + [:slug, :on_prod] +end +``` + +You can customize the message(s) as you wish, e.g.: +```ruby +def slack_message(field_name_symbol) + case field_name_symbol + when :on_prod + status = self.on_prod? ? 'live' : 'not live' + msg = '' + msg += "#{Rails.application.class.module_parent_name} - " + msg += "[#{name}](#{Rails.application.routes.url_helpers.edit_admin_wine_url(self)}) " + msg += "(#{self.class.name.constantize}) is #{status} " + msg += "#{field_name_symbol.to_s.gsub('_',' ')}" + msg + when :slug + # Different message for slug changes. + end +end +``` \ No newline at end of file From b4d9e5f9724d1801551e745faf1f9a91915929cb Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Mon, 24 Jun 2024 14:09:13 -0400 Subject: [PATCH 08/10] slack notification docs --- docs/features/slack_notifications.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/features/slack_notifications.md b/docs/features/slack_notifications.md index aefe85703..caafc6e88 100644 --- a/docs/features/slack_notifications.md +++ b/docs/features/slack_notifications.md @@ -9,7 +9,9 @@ after_create :notify_initiation before_save :notify_changes ``` -There are a couple of new instance methods to drive this in your models: +Models created with FAE's scaffold generators include this concern by default so you shouldn't need to take any action here. + +However, there are a couple of new instance methods to drive this in your models: ```ruby def notifiable_attributes @@ -18,7 +20,7 @@ def notifiable_attributes end ``` -You can customize the message(s) as you wish, e.g.: + ```ruby def slack_message(field_name_symbol) case field_name_symbol @@ -34,4 +36,6 @@ def slack_message(field_name_symbol) # Different message for slug changes. end end -``` \ No newline at end of file +``` + +As illustrated, you can customize the messages as you wish. \ No newline at end of file From 18dbba2de2d9cdb51872e5f9500ece3d70aa91a7 Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Mon, 24 Jun 2024 15:40:24 -0400 Subject: [PATCH 09/10] follow pattern of config driven from fae.rb --- app/services/fae/slack_notification.rb | 2 +- docs/features/slack_notifications.md | 7 +++++++ lib/fae/options.rb | 3 ++- lib/generators/fae/templates/initializers/fae.rb | 4 ++++ spec/dummy/config/initializers/fae.rb | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/services/fae/slack_notification.rb b/app/services/fae/slack_notification.rb index 34039aeb7..55411d147 100644 --- a/app/services/fae/slack_notification.rb +++ b/app/services/fae/slack_notification.rb @@ -3,7 +3,7 @@ module Fae class SlackNotification - def send_slack(webhook: ENV["SLACK_WEBHOOK_URL"], message: nil) + def send_slack(webhook: Fae.slack_webhook_url, message: nil) if webhook.is_a?(String) webhook = webhook.split(',') end diff --git a/docs/features/slack_notifications.md b/docs/features/slack_notifications.md index caafc6e88..f980de14c 100644 --- a/docs/features/slack_notifications.md +++ b/docs/features/slack_notifications.md @@ -2,6 +2,13 @@ Built around the `slack-notifier` gem, FAE now offers the ability to send a message to a Slack channel when an object is created or saved. +Add the Slack webhook URL(s) to your `fae.rb` file. It can be a single value, or comma separated for multiple: + +``` +# fae.rb +config.slack_webhook_url = ENV['SLACK_WEBHOOK_URL'] +``` + FAE's `base_model_concern.rb` has two new callbacks: ```ruby diff --git a/lib/fae/options.rb b/lib/fae/options.rb index b1dacd252..b471fbc59 100644 --- a/lib/fae/options.rb +++ b/lib/fae/options.rb @@ -4,7 +4,7 @@ module Fae # configurable defaults - mattr_accessor :devise_secret_key, :devise_mailer_sender, :dashboard_exclusions, :max_image_upload_size, :max_file_upload_size, :languages, :recreate_versions, :validation_helpers, :track_changes, :tracker_history_length, :slug_separator, :disabled_environments, :per_page, :use_cache, :use_form_manager, :netlify + mattr_accessor :devise_secret_key, :devise_mailer_sender, :dashboard_exclusions, :max_image_upload_size, :max_file_upload_size, :languages, :recreate_versions, :validation_helpers, :track_changes, :tracker_history_length, :slug_separator, :disabled_environments, :per_page, :use_cache, :use_form_manager, :netlify, :slack_webhook_url self.devise_secret_key = '' self.devise_mailer_sender = 'change-me@example.com' @@ -22,6 +22,7 @@ module Fae self.use_cache = false self.use_form_manager = false self.netlify = {} + self.slack_webhook_url = '' # this function maps the vars from your app into your engine def self.setup(&block) diff --git a/lib/generators/fae/templates/initializers/fae.rb b/lib/generators/fae/templates/initializers/fae.rb index 931294e58..aa11ce53c 100644 --- a/lib/generators/fae/templates/initializers/fae.rb +++ b/lib/generators/fae/templates/initializers/fae.rb @@ -75,4 +75,8 @@ # site_id: 'site-id-in-netlify', # api_base: 'https://api.netlify.com/api/v1/' # } + + ## slack_webhook_url + # Environment variable is recommended for any sensitive Slack configuration details. + config.slack_webhook_url = ENV['SLACK_WEBHOOK_URL'] end \ No newline at end of file diff --git a/spec/dummy/config/initializers/fae.rb b/spec/dummy/config/initializers/fae.rb index b3d60657e..c698b917c 100644 --- a/spec/dummy/config/initializers/fae.rb +++ b/spec/dummy/config/initializers/fae.rb @@ -30,4 +30,6 @@ api_base: 'https://api.netlify.com/api/v1/' } end + + config.slack_webhook_url = ENV['SLACK_WEBHOOK_URL'] end From 9ab84657bd8d8ef6f0722c41cc21d4b8e260070c Mon Sep 17 00:00:00 2001 From: Jason Fine Date: Mon, 24 Jun 2024 15:43:00 -0400 Subject: [PATCH 10/10] doc --- docs/features/slack_notifications.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features/slack_notifications.md b/docs/features/slack_notifications.md index f980de14c..a360963be 100644 --- a/docs/features/slack_notifications.md +++ b/docs/features/slack_notifications.md @@ -38,7 +38,7 @@ def slack_message(field_name_symbol) msg += "[#{name}](#{Rails.application.routes.url_helpers.edit_admin_wine_url(self)}) " msg += "(#{self.class.name.constantize}) is #{status} " msg += "#{field_name_symbol.to_s.gsub('_',' ')}" - msg + return msg when :slug # Different message for slug changes. end