Merge pull request #26 from exstake/add-slack-notifications
add slack notifications
This commit is contained in:
2
.env
2
.env
@@ -4,7 +4,7 @@ MAILTRAP_ADDRESS=smtp.mailtrap.io
|
|||||||
MAILTRAP_DOMAIN=smtp.mailtrap.io
|
MAILTRAP_DOMAIN=smtp.mailtrap.io
|
||||||
MAILTRAP_PORT=2525
|
MAILTRAP_PORT=2525
|
||||||
MAILER_DEFAULT_URL_HOST=localhost:5000
|
MAILER_DEFAULT_URL_HOST=localhost:5000
|
||||||
|
# SLACK_WEBHOOK_URL=https://hooks.slack.com/services/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
|
||||||
|
|
||||||
# production
|
# production
|
||||||
# MAILGUN_DOMAIN=
|
# MAILGUN_DOMAIN=
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -17,7 +17,7 @@ gem "image_processing", "~> 1.12"
|
|||||||
|
|
||||||
gem "devise"
|
gem "devise"
|
||||||
gem "devise-i18n"
|
gem "devise-i18n"
|
||||||
|
gem "slack-notifier"
|
||||||
gem "administrate-field-active_storage"
|
gem "administrate-field-active_storage"
|
||||||
gem "administrate-field-enumerize"
|
gem "administrate-field-enumerize"
|
||||||
gem "tailwindcss-rails"
|
gem "tailwindcss-rails"
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ GEM
|
|||||||
semantic_range (3.0.0)
|
semantic_range (3.0.0)
|
||||||
shoulda-matchers (5.0.0)
|
shoulda-matchers (5.0.0)
|
||||||
activesupport (>= 5.2.0)
|
activesupport (>= 5.2.0)
|
||||||
|
slack-notifier (2.4.0)
|
||||||
spring (2.1.1)
|
spring (2.1.1)
|
||||||
sprockets (4.0.2)
|
sprockets (4.0.2)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
@@ -367,6 +368,7 @@ DEPENDENCIES
|
|||||||
rubocop-shopify
|
rubocop-shopify
|
||||||
sass-rails (>= 6)
|
sass-rails (>= 6)
|
||||||
shoulda-matchers (~> 5.0)
|
shoulda-matchers (~> 5.0)
|
||||||
|
slack-notifier
|
||||||
spring
|
spring
|
||||||
tailwindcss-rails
|
tailwindcss-rails
|
||||||
turbolinks (~> 5)
|
turbolinks (~> 5)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#
|
#
|
||||||
class BuyCryptoOrder < ApplicationRecord
|
class BuyCryptoOrder < ApplicationRecord
|
||||||
include Processable
|
include Processable
|
||||||
|
include Notifiable
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :currency
|
belongs_to :currency
|
||||||
@@ -33,4 +34,14 @@ class BuyCryptoOrder < ApplicationRecord
|
|||||||
|
|
||||||
validates :paid_amount_cents, presence: true, numericality: { greater_than: 0 }
|
validates :paid_amount_cents, presence: true, numericality: { greater_than: 0 }
|
||||||
validates :received_amount, presence: true, if: :completed?
|
validates :received_amount, presence: true, if: :completed?
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def notification_message
|
||||||
|
"
|
||||||
|
💸 New buy crypto order! 💸 \n
|
||||||
|
user: #{user.email} \n
|
||||||
|
amount: #{paid_amount.format}
|
||||||
|
"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
18
app/models/concerns/notifiable.rb
Normal file
18
app/models/concerns/notifiable.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# frozen_string_literal: true
|
||||||
|
module Notifiable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
after_commit on: :create do
|
||||||
|
SlackNotifier.ping(notification_message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def notification_message
|
||||||
|
raise NotImplementedError, "method should be implemented"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#
|
#
|
||||||
class SellCryptoOrder < ApplicationRecord
|
class SellCryptoOrder < ApplicationRecord
|
||||||
include Processable
|
include Processable
|
||||||
|
include Notifiable
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :currency
|
belongs_to :currency
|
||||||
@@ -33,4 +34,14 @@ class SellCryptoOrder < ApplicationRecord
|
|||||||
|
|
||||||
validates :paid_amount, presence: true, numericality: { greater_than: 0 }
|
validates :paid_amount, presence: true, numericality: { greater_than: 0 }
|
||||||
validates :received_amount_cents, presence: true, if: :completed?
|
validates :received_amount_cents, presence: true, if: :completed?
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def notification_message
|
||||||
|
"
|
||||||
|
💸 New sell crypto order! 💸\n
|
||||||
|
user: #{user.email} \n
|
||||||
|
amount: #{paid_amount} #{currency.name}
|
||||||
|
"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
||||||
#
|
#
|
||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
|
include Notifiable
|
||||||
|
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :validatable
|
:recoverable, :rememberable, :validatable
|
||||||
|
|
||||||
@@ -43,4 +45,10 @@ class User < ApplicationRecord
|
|||||||
def create_balances
|
def create_balances
|
||||||
CreateUserBalances.new(self).call
|
CreateUserBalances.new(self).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def notification_message
|
||||||
|
"🎉 New user: #{email} 🎉"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
8
app/services/slack_notifier.rb
Normal file
8
app/services/slack_notifier.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
module SlackNotifier
|
||||||
|
def self.ping(message)
|
||||||
|
return if ENV["SLACK_WEBHOOK_URL"].blank?
|
||||||
|
|
||||||
|
Slack::Notifier.new(ENV["SLACK_WEBHOOK_URL"]).ping(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
16
erd.svg
16
erd.svg
@@ -67,13 +67,13 @@
|
|||||||
<text text-anchor="start" x="44" y="-458.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string ∗</text>
|
<text text-anchor="start" x="44" y="-458.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string ∗</text>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_Currency->m_Balance -->
|
<!-- m_Currency->m_Balance -->
|
||||||
<g id="edge8" class="edge">
|
<g id="edge9" class="edge">
|
||||||
<title>m_Currency->m_Balance</title>
|
<title>m_Currency->m_Balance</title>
|
||||||
<path fill="none" stroke="black" d="M120.56,-492.09C146.51,-506.62 181.46,-526.2 212.21,-543.42"/>
|
<path fill="none" stroke="black" d="M120.56,-492.09C146.51,-506.62 181.46,-526.2 212.21,-543.42"/>
|
||||||
<polygon fill="black" stroke="black" points="210.95,-546.32 220.34,-547.97 214.03,-540.83 210.95,-546.32"/>
|
<polygon fill="black" stroke="black" points="210.95,-546.32 220.34,-547.97 214.03,-540.83 210.95,-546.32"/>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_Currency->m_BuyCryptoOrder -->
|
<!-- m_Currency->m_BuyCryptoOrder -->
|
||||||
<g id="edge5" class="edge">
|
<g id="edge6" class="edge">
|
||||||
<title>m_Currency->m_BuyCryptoOrder</title>
|
<title>m_Currency->m_BuyCryptoOrder</title>
|
||||||
<path fill="none" stroke="black" d="M153.08,-470.5C164.62,-470.5 176.72,-470.5 188.7,-470.5"/>
|
<path fill="none" stroke="black" d="M153.08,-470.5C164.62,-470.5 176.72,-470.5 188.7,-470.5"/>
|
||||||
<polygon fill="black" stroke="black" points="188.82,-473.65 197.82,-470.5 188.82,-467.35 188.82,-473.65"/>
|
<polygon fill="black" stroke="black" points="188.82,-473.65 197.82,-470.5 188.82,-467.35 188.82,-473.65"/>
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
<text text-anchor="start" x="245" y="-307.5" font-family="Arial Italic" font-size="10.00" fill="#999999">integer (8) ∗ FK</text>
|
<text text-anchor="start" x="245" y="-307.5" font-family="Arial Italic" font-size="10.00" fill="#999999">integer (8) ∗ FK</text>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_Currency->m_SellCryptoOrder -->
|
<!-- m_Currency->m_SellCryptoOrder -->
|
||||||
<g id="edge7" class="edge">
|
<g id="edge8" class="edge">
|
||||||
<title>m_Currency->m_SellCryptoOrder</title>
|
<title>m_Currency->m_SellCryptoOrder</title>
|
||||||
<path fill="none" stroke="black" d="M116.84,-448.73C139.24,-434.72 169.37,-415.89 197.77,-398.15"/>
|
<path fill="none" stroke="black" d="M116.84,-448.73C139.24,-434.72 169.37,-415.89 197.77,-398.15"/>
|
||||||
<polygon fill="black" stroke="black" points="199.76,-400.62 205.72,-393.18 196.42,-395.27 199.76,-400.62"/>
|
<polygon fill="black" stroke="black" points="199.76,-400.62 205.72,-393.18 196.42,-395.27 199.76,-400.62"/>
|
||||||
@@ -151,30 +151,30 @@
|
|||||||
<text text-anchor="start" x="109" y="-182.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string</text>
|
<text text-anchor="start" x="109" y="-182.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string</text>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_User->m_Balance -->
|
<!-- m_User->m_Balance -->
|
||||||
<g id="edge2" class="edge">
|
<g id="edge3" class="edge">
|
||||||
<title>m_User->m_Balance</title>
|
<title>m_User->m_Balance</title>
|
||||||
<path fill="none" stroke="black" d="M106.63,-294.01C122.7,-333.81 143.96,-387.11 162,-434.5 178.66,-478.25 167.99,-497.56 198,-533.5 200.43,-536.42 203.09,-539.2 205.91,-541.85"/>
|
<path fill="none" stroke="black" d="M106.63,-294.01C122.7,-333.81 143.96,-387.11 162,-434.5 178.66,-478.25 167.99,-497.56 198,-533.5 200.43,-536.42 203.09,-539.2 205.91,-541.85"/>
|
||||||
<polygon fill="black" stroke="black" points="203.89,-544.27 212.76,-547.79 208.02,-539.51 203.89,-544.27"/>
|
<polygon fill="black" stroke="black" points="203.89,-544.27 212.76,-547.79 208.02,-539.51 203.89,-544.27"/>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_User->m_BuyCryptoOrder -->
|
<!-- m_User->m_BuyCryptoOrder -->
|
||||||
<g id="edge4" class="edge">
|
<g id="edge5" class="edge">
|
||||||
<title>m_User->m_BuyCryptoOrder</title>
|
<title>m_User->m_BuyCryptoOrder</title>
|
||||||
<path fill="none" stroke="black" d="M115.16,-294.4C136.17,-329.91 165.48,-374.29 198,-408.5 200.6,-411.23 203.33,-413.93 206.16,-416.59"/>
|
<path fill="none" stroke="black" d="M115.16,-294.4C136.17,-329.91 165.48,-374.29 198,-408.5 200.6,-411.23 203.33,-413.93 206.16,-416.59"/>
|
||||||
<polygon fill="black" stroke="black" points="204.11,-418.98 212.9,-422.68 208.34,-414.31 204.11,-418.98"/>
|
<polygon fill="black" stroke="black" points="204.11,-418.98 212.9,-422.68 208.34,-414.31 204.11,-418.98"/>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_User->m_FiatBalance -->
|
<!-- m_User->m_FiatBalance -->
|
||||||
<g id="edge3" class="edge">
|
<g id="edge4" class="edge">
|
||||||
<title>m_User->m_FiatBalance</title>
|
<title>m_User->m_FiatBalance</title>
|
||||||
<path fill="none" stroke="black" d="M162.2,-233.5C178.28,-233.5 195.08,-233.5 210.83,-233.5"/>
|
<path fill="none" stroke="black" d="M162.2,-233.5C178.28,-233.5 195.08,-233.5 210.83,-233.5"/>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_User->m_SellCryptoOrder -->
|
<!-- m_User->m_SellCryptoOrder -->
|
||||||
<g id="edge6" class="edge">
|
<g id="edge7" class="edge">
|
||||||
<title>m_User->m_SellCryptoOrder</title>
|
<title>m_User->m_SellCryptoOrder</title>
|
||||||
<path fill="none" stroke="black" d="M162.2,-278.41C172.76,-284.33 183.63,-290.41 194.32,-296.4"/>
|
<path fill="none" stroke="black" d="M162.2,-278.41C172.76,-284.33 183.63,-290.41 194.32,-296.4"/>
|
||||||
<polygon fill="black" stroke="black" points="193.05,-299.3 202.44,-300.95 196.12,-293.8 193.05,-299.3"/>
|
<polygon fill="black" stroke="black" points="193.05,-299.3 202.44,-300.95 196.12,-293.8 193.05,-299.3"/>
|
||||||
</g>
|
</g>
|
||||||
<!-- m_User->m_StakeOrder -->
|
<!-- m_User->m_StakeOrder -->
|
||||||
<g id="edge9" class="edge">
|
<g id="edge2" class="edge">
|
||||||
<title>m_User->m_StakeOrder</title>
|
<title>m_User->m_StakeOrder</title>
|
||||||
<path fill="none" stroke="black" d="M162.2,-191C175.51,-183.94 189.32,-176.62 202.62,-169.57"/>
|
<path fill="none" stroke="black" d="M162.2,-191C175.51,-183.94 189.32,-176.62 202.62,-169.57"/>
|
||||||
<polygon fill="black" stroke="black" points="204.35,-172.22 210.83,-165.22 201.4,-166.65 204.35,-172.22"/>
|
<polygon fill="black" stroke="black" points="204.35,-172.22 210.83,-165.22 201.4,-166.65 204.35,-172.22"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user