Some small improvements to email channel management.

This commit is contained in:
Martin Edenhofer 2015-08-28 10:19:27 +02:00
parent c60ee02a4e
commit 7e8b3adc3b
7 changed files with 77 additions and 30 deletions

View file

@ -7,8 +7,8 @@ class App.ChannelEmail extends App.ControllerTabs
@tabs = [
{
name: 'Email Accounts',
target: 'c-channel',
name: 'Accounts',
target: 'c-account',
controller: App.ChannelEmailAccountOverview,
},
{

View file

@ -23,8 +23,10 @@
<tr data-id="<%- channel.id %>">
<td class="<% if channel.status_in is 'ok': %>success<% else if channel.status_in is 'error': %>danger<% else: %>warning<% end %>">
<%- @T('State') %>: <%- @T(channel.status_in || 'unknown') %><br>
<a href="#" data-type="edit-inbound">
<%= channel.options.inbound.options.user %><br>
<a href="#" data-type="edit-inbound"><%= channel.options.inbound.options.host %> (<%= channel.options.inbound.adapter %>)</a>
<%= channel.options.inbound.options.host %> (<%= channel.options.inbound.adapter %>)
</a>
</td>
<td class="<% if channel.status_out is 'ok': %>success<% else if channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
<%- @T('State') %>: <%- @T(channel.status_out || 'unknown') %><br>
@ -79,9 +81,10 @@
<tr data-id="<%- @channel.id %>">
<td class="<% if @channel.status_out is 'ok': %>success<% else if @channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
<%- @T('State') %>: <%- @T(@channel.status_out || 'unknown') %><br>
<a href="#" data-type="edit-notification-outbound">
<% if @channel.options.outbound && @channel.options.outbound.options: %>
<%= @channel.options.outbound.options.user %><br>
<a href="#" data-type="edit-notification-outbound"><%= @channel.options.outbound.options.host %>
<%= @channel.options.outbound.options.host %>
<% end %>
(<%= @channel.options.outbound.adapter %>)</a>
</td>

View file

@ -341,10 +341,10 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
inbound: params[:inbound],
outbound: params[:outbound],
},
last_log_in: '',
last_log_out: '',
status_in: nil,
status_out: nil,
last_log_in: nil,
last_log_out: nil,
status_in: 'ok',
status_out: 'ok',
)
render json: {
result: 'ok',
@ -399,6 +399,15 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
adapter = params[:adapter].downcase
# validate adapter
if adapter !~ /^(smtp|sendmail)$/
render json: {
result: 'failed',
message: "Unknown adapter '#{adapter}'",
}
return
end
email = Setting.get('notification_sender')
# connection test
@ -407,15 +416,6 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
# save settings
if result[:result] == 'ok'
# validate adapter
if adapter !~ /^(smtp|sendmail)$/
render json: {
result: 'failed',
message: "Unknown adapter '#{adapter}'",
}
return
end
Channel.where(area: 'Email::Notification').each {|channel|
active = false
if adapter =~ /^#{channel.options[:outbound][:adapter]}$/i
@ -426,6 +426,8 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
options: params[:options],
},
}
channel.status_out = 'ok'
channel.last_log_out = nil
end
channel.active = active
channel.save

View file

@ -3,6 +3,10 @@
class Channel < ApplicationModel
store :options
after_create :email_address_check
after_update :email_address_check
after_destroy :email_address_check
=begin
fetch all accounts
@ -108,4 +112,12 @@ send via account
result
end
private
def email_address_check
# reset non existing channel_ids
EmailAddress.channel_cleanup
end
end

View file

@ -1,11 +1,38 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class EmailAddress < ApplicationModel
has_many :groups, after_add: :cache_update, after_remove: :cache_update
belongs_to :channel
validates :realname, presence: true
validates :email, presence: true
has_many :groups, after_add: :cache_update, after_remove: :cache_update
belongs_to :channel
validates :realname, presence: true
validates :email, presence: true
before_create :channel_check
before_update :channel_check
latest_change_support
=begin
check and if channel not exists reset configured channels for email addresses
EmailAddress.channel_cleanup
=end
def self.channel_cleanup
EmailAddress.all.each {|email_address|
next if !email_address.channel_id
next if Channel.find_by(id: email_address.channel_id)
email_address.channel_id = nil
email_address.save
}
end
private
def channel_check
return if Channel.find_by(id: channel_id)
self.channel_id = nil
end
end

View file

@ -118,8 +118,8 @@ returns
# create EmailAddresses/Channels/Signatures
model_map = {
'EmailAddresses' => 'EmailAddress',
'Channels' => 'Channel',
'EmailAddresses' => 'EmailAddress',
'Signatures' => 'Signature',
}
model_map.each {|map_name, model|

View file

@ -272,20 +272,23 @@ returns on fail
# prepare test email
if subject
mail = {
:from => email,
:to => email,
:subject => "Zammad Getting started Test Email #{subject}",
:body => "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
'x-zammad-ignore' => 'true',
from: email,
to: email,
subject: "Zammad Getting started Test Email #{subject}",
body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
}
else
mail = {
from: email,
to: 'emailtrytest@znuny.com',
from: email,
to: 'emailtrytest@znuny.com',
subject: 'This is a Test Email',
body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.",
body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.",
}
end
mail['X-Zammad-Ignore'] = 'true'
mail['X-Loop'] = 'yes'
mail['Precedence'] = 'bulk'
mail['Auto-Submitted'] = 'auto-generated'
# test connection
begin