mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 23:21:30 +08:00
23 lines
646 B
Ruby
23 lines
646 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Notification < ApplicationRecord
|
|
has_many :user_notifications, inverse_of: :notification, dependent: :destroy
|
|
has_many :users, through: :user_notifications
|
|
belongs_to :generator_user, class_name: 'User', optional: true
|
|
|
|
enum type_of: Extends::NOTIFICATIONS_TYPES
|
|
|
|
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)
|
|
end
|
|
|
|
private
|
|
|
|
def can_send_to_user?(_user)
|
|
true # overridable send permission method
|
|
end
|
|
end
|