From 1ff11fe3a493753ec56849c4451d8e363d3726c6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 25 Feb 2016 22:04:51 +0100 Subject: [PATCH] Added check for reply via email if email address is set for group. --- .../ticket_zoom/article_actions.coffee | 3 ++- app/models/email_address.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee index d42e19c84..68770b19b 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee @@ -68,7 +68,8 @@ class App.TicketZoomArticleActions extends App.Controller ] #if @article.type.name is 'note' # actions.push [] - if article.type.name is 'email' || article.type.name is 'phone' || article.type.name is 'web' + group = @ticket.group + if group.email_address_id && (article.type.name is 'email' || article.type.name is 'phone' || article.type.name is 'web') actions.push { name: 'reply' type: 'emailReply' diff --git a/app/models/email_address.rb b/app/models/email_address.rb index 1bac82234..74bba6007 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -8,6 +8,8 @@ class EmailAddress < ApplicationModel before_create :check_if_channel_exists_set_inactive before_update :check_if_channel_exists_set_inactive + after_create :update_email_address_id + after_update :update_email_address_id after_destroy :delete_group_reference latest_change_support @@ -60,4 +62,17 @@ check and if channel not exists reset configured channels for email addresses group.email_address_id = nil } end + + # keep email email address is of inital group filled + def update_email_address_id + not_configured = Group.where(email_address_id: nil).count + total = Group.count + return if not_configured == 0 + return if total != 1 + group = Group.find_by(email_address_id: nil) + group.email_address_id = id + group.updated_by_id = updated_by_id + group.save + end + end