2016-09-29 22:51:27 +08:00
|
|
|
module NotificationsHelper
|
|
|
|
def create_system_notification(title, message)
|
2016-10-03 21:12:48 +08:00
|
|
|
notification = Notification.new
|
|
|
|
notification.title = title
|
|
|
|
notification.message = message
|
|
|
|
notification.type_of = :system_message
|
|
|
|
notification.transaction do
|
|
|
|
User.where.not(confirmed_at: nil).find_each do |u|
|
|
|
|
UserNotification
|
|
|
|
.new(user: u, notification: notification, checked: false)
|
|
|
|
.save!
|
|
|
|
end
|
|
|
|
notification.save!
|
2016-09-29 22:51:27 +08:00
|
|
|
end
|
|
|
|
end
|
2016-10-05 16:52:27 +08:00
|
|
|
|
|
|
|
def send_email_notification(user, notification)
|
|
|
|
AppMailer.delay.notification(user, notification)
|
|
|
|
end
|
2016-11-07 22:31:06 +08:00
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def generate_notification(user, target_user, team, role, project)
|
|
|
|
if team
|
|
|
|
title = I18n.t('notifications.unassign_user_from_team',
|
2016-11-08 18:20:14 +08:00
|
|
|
unassigned_user: target_user.name,
|
2017-01-25 16:48:49 +08:00
|
|
|
team: team.name,
|
2016-11-08 18:20:14 +08:00
|
|
|
unassigned_by_user: user.name)
|
2017-01-25 16:48:49 +08:00
|
|
|
title = I18n.t('notifications.assign_user_to_team',
|
2016-11-08 18:20:14 +08:00
|
|
|
assigned_user: target_user.name,
|
|
|
|
role: role,
|
2017-01-25 16:48:49 +08:00
|
|
|
team: team.name,
|
2016-11-08 18:20:14 +08:00
|
|
|
assigned_by_user: user.name) if role
|
2017-01-25 16:48:49 +08:00
|
|
|
message = "#{I18n.t('search.index.team')} #{team.name}"
|
2016-11-07 22:31:06 +08:00
|
|
|
elsif project
|
|
|
|
title = I18n.t('activities.unassign_user_from_project',
|
2016-11-07 22:33:21 +08:00
|
|
|
unassigned_user: target_user.full_name,
|
|
|
|
project: project.name,
|
|
|
|
unassigned_by_user: user.full_name)
|
2016-11-07 22:31:06 +08:00
|
|
|
message = "#{I18n.t('search.index.project')} #{@project.name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
notification = Notification.create(
|
|
|
|
type_of: :assignment,
|
|
|
|
title:
|
|
|
|
ActionController::Base.helpers.sanitize(title),
|
|
|
|
message:
|
|
|
|
ActionController::Base.helpers.sanitize(message)
|
|
|
|
)
|
|
|
|
|
|
|
|
if target_user.assignments_notification
|
|
|
|
UserNotification.create(notification: notification, user: target_user)
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 22:51:27 +08:00
|
|
|
end
|