diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index c99e3920d..66218a936 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -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] diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 1ee0fb2fa..9aa0b3220 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -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]