mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-01 04:32:16 +08:00
Merge pull request #3458 from artoscinote/ma_SCI_5938
Added overridable send permission method to notifications [SCI-5938]
This commit is contained in:
commit
4e2363fc64
1 changed files with 12 additions and 3 deletions
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Notification < ApplicationRecord
|
||||
has_many :user_notifications, inverse_of: :notification, dependent: :destroy
|
||||
has_many :users, through: :user_notifications
|
||||
|
@ -7,13 +9,20 @@ class Notification < ApplicationRecord
|
|||
|
||||
def already_seen(user)
|
||||
UserNotification.where(notification: self, user: user)
|
||||
.pluck(:checked)
|
||||
.first
|
||||
.pick(:checked)
|
||||
end
|
||||
|
||||
def create_user_notification(user)
|
||||
return if user == generator_user
|
||||
return unless can_send_to_user?(user)
|
||||
return unless user.enabled_notifications_for?(type_of.to_sym, :web)
|
||||
|
||||
user_notifications.create!(user: user) if user.enabled_notifications_for?(type_of.to_sym, :web)
|
||||
user_notifications.create!(user: user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def can_send_to_user?(_user)
|
||||
true # overridable send permission method
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue