mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +08:00
Remove unassign_user_from_project notification and change code to use helper method for assignment notification generation
This commit is contained in:
parent
2793777463
commit
41935a9471
6 changed files with 8 additions and 70 deletions
|
@ -100,11 +100,6 @@ class UserProjectsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
if @up.destroy
|
if @up.destroy
|
||||||
log_activity(:unassign_user_from_project)
|
log_activity(:unassign_user_from_project)
|
||||||
generate_notification(current_user,
|
|
||||||
@up.user,
|
|
||||||
false,
|
|
||||||
@up.role_str,
|
|
||||||
@project)
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
redirect_to project_users_edit_path(format: :json),
|
redirect_to project_users_edit_path(format: :json),
|
||||||
|
|
|
@ -4,6 +4,7 @@ module Users
|
||||||
class InvitationsController < Devise::InvitationsController
|
class InvitationsController < Devise::InvitationsController
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
include UsersGenerator
|
include UsersGenerator
|
||||||
|
include NotificationsHelper
|
||||||
|
|
||||||
prepend_before_action :check_captcha, only: [:update]
|
prepend_before_action :check_captcha, only: [:update]
|
||||||
|
|
||||||
|
@ -115,8 +116,8 @@ module Users
|
||||||
generate_notification(
|
generate_notification(
|
||||||
@user,
|
@user,
|
||||||
user,
|
user,
|
||||||
user_team.role_str,
|
user_team.team,
|
||||||
user_team.team
|
user_team.role_str
|
||||||
)
|
)
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: :invite_user_to_team,
|
.call(activity_type: :invite_user_to_team,
|
||||||
|
@ -172,23 +173,6 @@ module Users
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_notification(user, target_user, role, team)
|
|
||||||
title = I18n.t('notifications.assign_user_to_team',
|
|
||||||
assigned_user: target_user.name,
|
|
||||||
role: role,
|
|
||||||
team: team.name,
|
|
||||||
assigned_by_user: user.name)
|
|
||||||
|
|
||||||
message = "#{I18n.t('search.index.team')} #{team.name}"
|
|
||||||
notification = Notification.create(
|
|
||||||
type_of: :assignment,
|
|
||||||
title: sanitize_input(title),
|
|
||||||
message: sanitize_input(message)
|
|
||||||
)
|
|
||||||
|
|
||||||
UserNotification.create(notification: notification, user: target_user) if target_user.assignments_notification
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_captcha_for_invite
|
def check_captcha_for_invite
|
||||||
if Rails.configuration.x.enable_recaptcha
|
if Rails.configuration.x.enable_recaptcha
|
||||||
unless verify_recaptcha
|
unless verify_recaptcha
|
||||||
|
|
|
@ -156,7 +156,6 @@ module Users
|
||||||
generate_notification(current_user,
|
generate_notification(current_user,
|
||||||
@user_t.user,
|
@user_t.user,
|
||||||
@user_t.team,
|
@user_t.team,
|
||||||
false,
|
|
||||||
false)
|
false)
|
||||||
format.json { render json: { status: :ok } }
|
format.json { render json: { status: :ok } }
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,24 +1,10 @@
|
||||||
module NotificationsHelper
|
module NotificationsHelper
|
||||||
def create_system_notification(title, message)
|
|
||||||
notification = Notification.new
|
|
||||||
notification.title = title
|
|
||||||
notification.message = message
|
|
||||||
notification.type_of = :system_message
|
|
||||||
notification.transaction do
|
|
||||||
User.where.not(confirmed_at: nil).find_each do |u|
|
|
||||||
UserNotification
|
|
||||||
.new(user: u, notification: notification, checked: false)
|
|
||||||
.save!
|
|
||||||
end
|
|
||||||
notification.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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, team, role, project)
|
# generate assignment notification
|
||||||
|
def generate_notification(user, target_user, team, role)
|
||||||
if team
|
if team
|
||||||
title = I18n.t('notifications.unassign_user_from_team',
|
title = I18n.t('notifications.unassign_user_from_team',
|
||||||
unassigned_user: target_user.name,
|
unassigned_user: target_user.name,
|
||||||
|
@ -30,13 +16,6 @@ module NotificationsHelper
|
||||||
team: team.name,
|
team: team.name,
|
||||||
assigned_by_user: user.name) if role
|
assigned_by_user: user.name) if role
|
||||||
message = "#{I18n.t('search.index.team')} #{team.name}"
|
message = "#{I18n.t('search.index.team')} #{team.name}"
|
||||||
elsif project
|
|
||||||
title = I18n.t('activities.unassign_user_from_project',
|
|
||||||
user_target: target_user.full_name,
|
|
||||||
project: project.name,
|
|
||||||
user: user.full_name,
|
|
||||||
role: role)
|
|
||||||
message = "#{I18n.t('search.index.project')} #{@project.name}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
notification = Notification.create(
|
notification = Notification.create(
|
||||||
|
|
|
@ -2,6 +2,7 @@ module ClientApi
|
||||||
class InvitationsService
|
class InvitationsService
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
include UsersGenerator
|
include UsersGenerator
|
||||||
|
include NotificationsHelper
|
||||||
|
|
||||||
def initialize(args)
|
def initialize(args)
|
||||||
@user = args[:user]
|
@user = args[:user]
|
||||||
|
@ -131,30 +132,11 @@ module ClientApi
|
||||||
generate_notification(
|
generate_notification(
|
||||||
@user,
|
@user,
|
||||||
user,
|
user,
|
||||||
user_team.role_str,
|
user_team.team,
|
||||||
user_team.team
|
user_team.role_str
|
||||||
)
|
)
|
||||||
user_team
|
user_team
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_notification(user, target_user, role, team)
|
|
||||||
title = I18n.t('notifications.assign_user_to_team',
|
|
||||||
assigned_user: target_user.name,
|
|
||||||
role: role,
|
|
||||||
team: team.name,
|
|
||||||
assigned_by_user: user.name)
|
|
||||||
|
|
||||||
message = "#{I18n.t('search.index.team')} #{team.name}"
|
|
||||||
notification = Notification.create(
|
|
||||||
type_of: :assignment,
|
|
||||||
title: sanitize_input(title),
|
|
||||||
message: sanitize_input(message)
|
|
||||||
)
|
|
||||||
|
|
||||||
if target_user.assignments_notification
|
|
||||||
UserNotification.create(notification: notification, user: target_user)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
CustomInvitationsError = Class.new(StandardError)
|
CustomInvitationsError = Class.new(StandardError)
|
||||||
|
|
|
@ -69,7 +69,6 @@ module ClientApi
|
||||||
generate_notification(user,
|
generate_notification(user,
|
||||||
user,
|
user,
|
||||||
@user_team.team,
|
@user_team.team,
|
||||||
false,
|
|
||||||
false)
|
false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue