mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Merge pull request #260 from mlorb/ml_sci_614
Add notification for removing user from team and removing user from project [SCI-614]
This commit is contained in:
commit
0793fb9f11
5 changed files with 47 additions and 24 deletions
|
@ -1,4 +1,6 @@
|
||||||
class UserProjectsController < ApplicationController
|
class UserProjectsController < ApplicationController
|
||||||
|
include NotificationsHelper
|
||||||
|
|
||||||
before_action :load_vars
|
before_action :load_vars
|
||||||
before_action :check_view_tab_permissions, only: [ :index ]
|
before_action :check_view_tab_permissions, only: [ :index ]
|
||||||
before_action :check_view_permissions, only: [ :index_edit ]
|
before_action :check_view_permissions, only: [ :index_edit ]
|
||||||
|
@ -191,6 +193,7 @@ class UserProjectsController < ApplicationController
|
||||||
unassigned_by_user: current_user.full_name
|
unassigned_by_user: current_user.full_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
generate_notification(current_user, @up.user, false, false, @project)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Users::SettingsController < ApplicationController
|
class Users::SettingsController < ApplicationController
|
||||||
include UsersGenerator
|
include UsersGenerator
|
||||||
|
include NotificationsHelper
|
||||||
|
|
||||||
before_action :load_user, only: [
|
before_action :load_user, only: [
|
||||||
:preferences,
|
:preferences,
|
||||||
|
@ -224,8 +225,9 @@ class Users::SettingsController < ApplicationController
|
||||||
|
|
||||||
generate_notification(@user_organization.user,
|
generate_notification(@user_organization.user,
|
||||||
@new_user_org.user,
|
@new_user_org.user,
|
||||||
|
@new_user_org.organization,
|
||||||
@new_user_org.role_str,
|
@new_user_org.role_str,
|
||||||
@new_user_org.organization)
|
false)
|
||||||
|
|
||||||
flash[:notice] = I18n.t(
|
flash[:notice] = I18n.t(
|
||||||
'users.settings.organizations.edit.modal_add_user.existing_flash_success',
|
'users.settings.organizations.edit.modal_add_user.existing_flash_success',
|
||||||
|
@ -409,7 +411,11 @@ class Users::SettingsController < ApplicationController
|
||||||
)
|
)
|
||||||
flash.keep(:notice)
|
flash.keep(:notice)
|
||||||
end
|
end
|
||||||
|
generate_notification(@user_organization.user,
|
||||||
|
@user_org.user,
|
||||||
|
@user_org.organization,
|
||||||
|
false,
|
||||||
|
false)
|
||||||
format.json {
|
format.json {
|
||||||
render json: {
|
render json: {
|
||||||
status: :ok
|
status: :ok
|
||||||
|
@ -579,27 +585,6 @@ class Users::SettingsController < ApplicationController
|
||||||
)
|
)
|
||||||
end
|
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)
|
def reset_user_current_organization(user_org)
|
||||||
ids = user_org.user.organizations_ids
|
ids = user_org.user.organizations_ids
|
||||||
ids -= [user_org.organization.id]
|
ids -= [user_org.organization.id]
|
||||||
|
|
|
@ -17,4 +17,37 @@ module NotificationsHelper
|
||||||
def send_email_notification(user, notification)
|
def send_email_notification(user, notification)
|
||||||
AppMailer.delay.notification(user, notification)
|
AppMailer.delay.notification(user, notification)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_notification(user, target_user, org, role, project)
|
||||||
|
if org
|
||||||
|
title = I18n.t('notifications.unassign_user_from_organization',
|
||||||
|
unassigned_user: target_user.name,
|
||||||
|
organization: org.name,
|
||||||
|
unassigned_by_user: user.name)
|
||||||
|
title = I18n.t('notifications.assign_user_to_organization',
|
||||||
|
assigned_user: target_user.name,
|
||||||
|
role: role,
|
||||||
|
organization: org.name,
|
||||||
|
assigned_by_user: user.name) if role
|
||||||
|
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
|
end
|
||||||
|
|
|
@ -65,7 +65,8 @@ class Activity < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_notification
|
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
|
notification_type = :assignment
|
||||||
else
|
else
|
||||||
notification_type = :recent_changes
|
notification_type = :recent_changes
|
||||||
|
|
|
@ -1521,6 +1521,7 @@ en:
|
||||||
system_message: "sciNote system message"
|
system_message: "sciNote system message"
|
||||||
email_title: "You've received a sciNote notification!"
|
email_title: "You've received a sciNote notification!"
|
||||||
assign_user_to_organization: "<i>%{assigned_user}</i> was added as %{role} to team <strong>%{organization}</strong> by <i>%{assigned_by_user}</i>."
|
assign_user_to_organization: "<i>%{assigned_user}</i> was added as %{role} to team <strong>%{organization}</strong> by <i>%{assigned_by_user}</i>."
|
||||||
|
unassign_user_from_organization: "<i>%{unassigned_user}</i> was removed from team <strong>%{organization}</strong> by <i>%{unassigned_by_user}</i>."
|
||||||
|
|
||||||
# This section contains general words that can be used in any parts of
|
# This section contains general words that can be used in any parts of
|
||||||
# application.
|
# application.
|
||||||
|
|
Loading…
Add table
Reference in a new issue