From 41935a9471c101fc6f38db3fd5b0918aac09a8d6 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 1 Jul 2019 13:44:27 +0200 Subject: [PATCH] Remove unassign_user_from_project notification and change code to use helper method for assignment notification generation --- app/controllers/user_projects_controller.rb | 5 ---- .../users/invitations_controller.rb | 22 +++------------- .../users/settings/user_teams_controller.rb | 1 - app/helpers/notifications_helper.rb | 25 ++----------------- .../client_api/invitations_service.rb | 24 +++--------------- app/services/client_api/user_team_service.rb | 1 - 6 files changed, 8 insertions(+), 70 deletions(-) diff --git a/app/controllers/user_projects_controller.rb b/app/controllers/user_projects_controller.rb index fafa0aaac..ac29ddfbd 100644 --- a/app/controllers/user_projects_controller.rb +++ b/app/controllers/user_projects_controller.rb @@ -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), diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 4d8f70205..9742c643c 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -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 diff --git a/app/controllers/users/settings/user_teams_controller.rb b/app/controllers/users/settings/user_teams_controller.rb index f23822d5c..de9f224af 100644 --- a/app/controllers/users/settings/user_teams_controller.rb +++ b/app/controllers/users/settings/user_teams_controller.rb @@ -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 diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index c834a56b5..897d46c3a 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -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( diff --git a/app/services/client_api/invitations_service.rb b/app/services/client_api/invitations_service.rb index 63380c239..39f2df0f2 100644 --- a/app/services/client_api/invitations_service.rb +++ b/app/services/client_api/invitations_service.rb @@ -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) diff --git a/app/services/client_api/user_team_service.rb b/app/services/client_api/user_team_service.rb index 6cd5685a7..38547e905 100644 --- a/app/services/client_api/user_team_service.rb +++ b/app/services/client_api/user_team_service.rb @@ -69,7 +69,6 @@ module ClientApi generate_notification(user, user, @user_team.team, - false, false) end