Update Slack Notifications (#2870) [ci skip]
This commit is contained in:
parent
80f42a544a
commit
21f595ea2c
5 changed files with 15 additions and 14 deletions
|
|
@ -2,7 +2,7 @@ class ApplicationObserver < ActiveRecord::Observer
|
|||
def warned_user_ping(activity)
|
||||
return unless activity.user.warned == true
|
||||
|
||||
SlackBot.delay.ping "@#{activity.user.username} just posted.\nThey've been warned since #{activity.user.roles.where(name: 'warned')[0].updated_at.strftime('%d %B %Y')}\nhttps://dev.to#{activity.path}",
|
||||
SlackBot.delay.ping "Activity: https://dev.to/#{activity.path}\nManage @#{activity.user.username}: https://dev.to/internal/users/#{activity.user.id}",
|
||||
channel: "warned-user-activity",
|
||||
username: "sloan_watch_bot",
|
||||
icon_emoji: ":sloan:"
|
||||
|
|
|
|||
|
|
@ -2,15 +2,17 @@ class ArticleObserver < ApplicationObserver
|
|||
def after_save(article)
|
||||
return if Rails.env.development?
|
||||
|
||||
if article.published && article.published_at > 30.seconds.ago
|
||||
SlackBot.delay.ping "New Article Published: #{article.title}\nhttps://dev.to#{article.path}",
|
||||
channel: "activity",
|
||||
username: "article_bot",
|
||||
icon_emoji: ":writing_hand:"
|
||||
|
||||
end
|
||||
warned_user_ping(article)
|
||||
ping_new_article(article)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error(e)
|
||||
end
|
||||
|
||||
def ping_new_article(article)
|
||||
return unless article.published && article.published_at > 30.seconds.ago
|
||||
|
||||
SlackBot.delay.ping "New Article Published: #{article.title}\nhttps://dev.to#{article.path}",
|
||||
channel: "activity",
|
||||
username: "article_bot",
|
||||
icon_emoji: ":writing_hand:"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class CommentObserver < ApplicationObserver
|
||||
def after_save(comment)
|
||||
def after_create(comment)
|
||||
return if Rails.env.development?
|
||||
|
||||
warned_user_ping(comment)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ RSpec.describe ArticleObserver, type: :observer do
|
|||
allow(SlackBot).to receive(:ping).and_return(true)
|
||||
end
|
||||
|
||||
it "pings slack if user with warned role creates an article" do
|
||||
user.add_role :warned
|
||||
it "pings slack #activity if new article is created" do
|
||||
Article.observers.enable :article_observer do
|
||||
run_background_jobs_immediately do
|
||||
create(:article, user_id: user.id)
|
||||
end
|
||||
end
|
||||
expect(SlackBot).to have_received(:ping).twice
|
||||
expect(SlackBot).to have_received(:ping).once
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ RSpec.describe CommentObserver, type: :observer do
|
|||
end
|
||||
end
|
||||
end
|
||||
expect(SlackBot).to have_received(:ping).twice
|
||||
expect(SlackBot).to have_received(:ping).once
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue