Remove unassign_user_from_project notification and change code to use helper method for assignment notification generation

This commit is contained in:
Mojca Lorber 2019-07-01 13:44:27 +02:00
parent 2793777463
commit 41935a9471
6 changed files with 8 additions and 70 deletions

View file

@ -100,11 +100,6 @@ class UserProjectsController < ApplicationController
def destroy
if @up.destroy
log_activity(:unassign_user_from_project)
generate_notification(current_user,
@up.user,
false,
@up.role_str,
@project)
respond_to do |format|
format.json do
redirect_to project_users_edit_path(format: :json),

View file

@ -4,6 +4,7 @@ module Users
class InvitationsController < Devise::InvitationsController
include InputSanitizeHelper
include UsersGenerator
include NotificationsHelper
prepend_before_action :check_captcha, only: [:update]
@ -115,8 +116,8 @@ module Users
generate_notification(
@user,
user,
user_team.role_str,
user_team.team
user_team.team,
user_team.role_str
)
Activities::CreateActivityService
.call(activity_type: :invite_user_to_team,
@ -172,23 +173,6 @@ module Users
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
if Rails.configuration.x.enable_recaptcha
unless verify_recaptcha

View file

@ -156,7 +156,6 @@ module Users
generate_notification(current_user,
@user_t.user,
@user_t.team,
false,
false)
format.json { render json: { status: :ok } }
else

View file

@ -1,24 +1,10 @@
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)
AppMailer.delay.notification(user, notification)
end
def generate_notification(user, target_user, team, role, project)
# generate assignment notification
def generate_notification(user, target_user, team, role)
if team
title = I18n.t('notifications.unassign_user_from_team',
unassigned_user: target_user.name,
@ -30,13 +16,6 @@ module NotificationsHelper
team: team.name,
assigned_by_user: user.name) if role
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
notification = Notification.create(

View file

@ -2,6 +2,7 @@ module ClientApi
class InvitationsService
include InputSanitizeHelper
include UsersGenerator
include NotificationsHelper
def initialize(args)
@user = args[:user]
@ -131,30 +132,11 @@ module ClientApi
generate_notification(
@user,
user,
user_team.role_str,
user_team.team
user_team.team,
user_team.role_str
)
user_team
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
CustomInvitationsError = Class.new(StandardError)

View file

@ -69,7 +69,6 @@ module ClientApi
generate_notification(user,
user,
@user_team.team,
false,
false)
end