From b41ee028ca9dbb85a1f5b85b3fc5b1f8e558ba98 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Wed, 28 Jul 2021 13:14:07 +0200 Subject: [PATCH] Added overridable send permission method to notifications [SCI-5938] --- app/models/notification.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 240d31d5b..3470b83b5 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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