Initial code for system notifications [SCI-444]

This commit is contained in:
Oleksii Kriuchykhin 2016-09-29 16:51:27 +02:00
parent 7807bd37cd
commit 036bda3afa
3 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,10 @@
module NotificationsHelper
def create_system_notification(title, message)
users = User.where.not(confirmed_at: nil)
users.each do |u|
UserNotification.create_notification(u, title, message, :system_message)
end
end
end

View file

@ -12,4 +12,17 @@ class UserNotification < ActiveRecord::Base
def self.unseen_notification(user) def self.unseen_notification(user)
where('user_id = ? AND checked = false', user.id).count where('user_id = ? AND checked = false', user.id).count
end end
def self.create_notification(user, title, message, type)
notification = Notification.new
notification.transaction do
notification.title = title
notification.message = message
notification.type_of = type
notification.save!
usernotification = UserNotification.new(user: user, notification: notification, checked: false)
usernotification.save!
end
end
end end

View file

@ -0,0 +1,10 @@
namespace :notifications do
desc 'Creates new system notification for all active users'
task :new_release => :environment do
include NotificationsHelper
puts 'Creation of system notification for all active users with link to release notes'
create_system_notification('New release', 'http://scinote.net/docs/release-notes/')
end
end