mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-24 04:39:59 +08:00
refactoring notification method
This commit is contained in:
parent
749b108928
commit
27c83992b4
3 changed files with 43 additions and 48 deletions
|
|
@ -1,4 +1,6 @@
|
|||
class UserProjectsController < ApplicationController
|
||||
include NotificationsHelper
|
||||
|
||||
before_action :load_vars
|
||||
before_action :check_view_tab_permissions, only: [ :index ]
|
||||
before_action :check_view_permissions, only: [ :index_edit ]
|
||||
|
|
@ -191,7 +193,7 @@ class UserProjectsController < ApplicationController
|
|||
unassigned_by_user: current_user.full_name
|
||||
)
|
||||
)
|
||||
generate_notification(current_user, @up.user, @project)
|
||||
generate_notification(current_user, @up.user, false, false, @project)
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
@ -276,24 +278,6 @@ class UserProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, project)
|
||||
title = I18n.t('activities.unassign_user_from_project',
|
||||
unassigned_user: target_user.full_name,
|
||||
project: project.name,
|
||||
unassigned_by_user: user.full_name)
|
||||
message = "#{I18n.t('search.index.project')} #{@project.name}"
|
||||
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
|
||||
|
||||
def init_gui
|
||||
@users = @project.unassigned_users
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class Users::SettingsController < ApplicationController
|
||||
include UsersGenerator
|
||||
include NotificationsHelper
|
||||
|
||||
before_action :load_user, only: [
|
||||
:preferences,
|
||||
|
|
@ -225,7 +226,8 @@ class Users::SettingsController < ApplicationController
|
|||
generate_notification(@user_organization.user,
|
||||
@new_user_org.user,
|
||||
@new_user_org.organization,
|
||||
@new_user_org.role_str)
|
||||
@new_user_org.role_str,
|
||||
false)
|
||||
|
||||
flash[:notice] = I18n.t(
|
||||
'users.settings.organizations.edit.modal_add_user.existing_flash_success',
|
||||
|
|
@ -412,6 +414,7 @@ class Users::SettingsController < ApplicationController
|
|||
generate_notification(@user_organization.user,
|
||||
@user_org.user,
|
||||
@user_org.organization,
|
||||
false,
|
||||
false)
|
||||
format.json {
|
||||
render json: {
|
||||
|
|
@ -582,34 +585,6 @@ class Users::SettingsController < ApplicationController
|
|||
)
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, org, role)
|
||||
if role
|
||||
title = I18n.t('notifications.assign_user_to_organization',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
assigned_by_user: user.name)
|
||||
else
|
||||
title = I18n.t('notifications.unassign_user_from_organization',
|
||||
unassigned_user: target_user.name,
|
||||
organization: org.name,
|
||||
unassigned_by_user: user.name)
|
||||
end
|
||||
|
||||
message = "#{I18n.t('search.index.organization')} #{org.name}"
|
||||
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
|
||||
|
||||
def reset_user_current_organization(user_org)
|
||||
ids = user_org.user.organizations_ids
|
||||
ids -= [user_org.organization.id]
|
||||
|
|
|
|||
|
|
@ -17,4 +17,40 @@ module NotificationsHelper
|
|||
def send_email_notification(user, notification)
|
||||
AppMailer.delay.notification(user, notification)
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, org, role, project)
|
||||
if org
|
||||
if role
|
||||
title = I18n.t('notifications.assign_user_to_organization',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
assigned_by_user: user.name)
|
||||
else
|
||||
title = I18n.t('notifications.unassign_user_from_organization',
|
||||
unassigned_user: target_user.name,
|
||||
organization: org.name,
|
||||
unassigned_by_user: user.name)
|
||||
end
|
||||
message = "#{I18n.t('search.index.organization')} #{org.name}"
|
||||
elsif project
|
||||
title = I18n.t('activities.unassign_user_from_project',
|
||||
unassigned_user: target_user.full_name,
|
||||
project: project.name,
|
||||
unassigned_by_user: user.full_name)
|
||||
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
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue