mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Initial code for system notifications [SCI-444]
This commit is contained in:
parent
7807bd37cd
commit
036bda3afa
3 changed files with 33 additions and 0 deletions
10
app/helpers/notifications_helper.rb
Normal file
10
app/helpers/notifications_helper.rb
Normal 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
|
|
@ -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
|
||||||
|
|
10
lib/tasks/notifications.rake
Normal file
10
lib/tasks/notifications.rake
Normal 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
|
Loading…
Reference in a new issue