diff --git a/app/controllers/user_projects_controller.rb b/app/controllers/user_projects_controller.rb
index 14aadd776..c736795cf 100644
--- a/app/controllers/user_projects_controller.rb
+++ b/app/controllers/user_projects_controller.rb
@@ -191,6 +191,7 @@ class UserProjectsController < ApplicationController
unassigned_by_user: current_user.full_name
)
)
+ generate_notification(current_user, @up.user, @project)
respond_to do |format|
format.html {
@@ -275,6 +276,26 @@ 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
diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb
index 931773186..d3d5e03f9 100644
--- a/app/controllers/users/settings_controller.rb
+++ b/app/controllers/users/settings_controller.rb
@@ -224,8 +224,8 @@ class Users::SettingsController < ApplicationController
generate_notification(@user_organization.user,
@new_user_org.user,
- @new_user_org.role_str,
- @new_user_org.organization)
+ @new_user_org.organization,
+ @new_user_org.role_str)
flash[:notice] = I18n.t(
'users.settings.organizations.edit.modal_add_user.existing_flash_success',
@@ -409,7 +409,10 @@ class Users::SettingsController < ApplicationController
)
flash.keep(:notice)
end
-
+ generate_notification(@user_organization.user,
+ @user_org.user,
+ @user_org.organization,
+ false)
format.json {
render json: {
status: :ok
@@ -579,12 +582,19 @@ class Users::SettingsController < ApplicationController
)
end
- def generate_notification(user, target_user, role, org)
- title = I18n.t('notifications.assign_user_to_organization',
+ 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(
@@ -592,7 +602,7 @@ class Users::SettingsController < ApplicationController
title:
ActionController::Base.helpers.sanitize(title),
message:
- ActionController::Base.helpers.sanitize(message),
+ ActionController::Base.helpers.sanitize(message),
)
if target_user.assignments_notification
diff --git a/app/models/activity.rb b/app/models/activity.rb
index 9d00b9453..c1f3d3dd7 100644
--- a/app/models/activity.rb
+++ b/app/models/activity.rb
@@ -54,7 +54,7 @@ class Activity < ActiveRecord::Base
private
def generate_notification
- if %w(assign_user_to_project assign_user_to_module).include? type_of
+ if %w(assign_user_to_project assign_user_to_module unassign_user_from_module).include? type_of
notification_type = :assignment
else
notification_type = :recent_changes
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ce68913e1..64183246c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1510,6 +1510,7 @@ en:
system_message: "sciNote system message"
email_title: "You've received a sciNote notification!"
assign_user_to_organization: "%{assigned_user} was added as %{role} to team %{organization} by %{assigned_by_user}."
+ unassign_user_from_organization: "%{unassigned_user} was removed from team %{organization} by %{unassigned_by_user}."
# This section contains general words that can be used in any parts of
# application.