mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 19:51:01 +08:00
Also add notification when UserOrganization is created
This commit is contained in:
parent
0ab62576a2
commit
ce7733e9e9
2 changed files with 26 additions and 21 deletions
|
@ -98,6 +98,13 @@ module Users
|
|||
)
|
||||
user_org.save
|
||||
|
||||
generate_notification(
|
||||
@user,
|
||||
user,
|
||||
user_org.role_str,
|
||||
user_org.organization
|
||||
)
|
||||
|
||||
if result[:status] == :user_exists
|
||||
result[:status] = :user_exists_invited_to_org
|
||||
else
|
||||
|
@ -124,6 +131,25 @@ module Users
|
|||
|
||||
private
|
||||
|
||||
def generate_notification(user, target_user, role, org)
|
||||
title = I18n.t('notifications.assign_user_to_organization',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
assigned_by_user: user.name)
|
||||
|
||||
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 check_invite_users_permission
|
||||
@user = current_user
|
||||
@emails = params[:emails]
|
||||
|
|
|
@ -412,27 +412,6 @@ class Users::SettingsController < ApplicationController
|
|||
)
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, role, org)
|
||||
title = I18n.t('notifications.assign_user_to_organization',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
assigned_by_user: user.name)
|
||||
|
||||
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]
|
||||
|
|
Loading…
Reference in a new issue