Browse Source

Some small improvements to email channel management.

Martin Edenhofer 9 years ago
parent
commit
71c774cb99

+ 9 - 2
app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee

@@ -204,8 +204,15 @@ class App.ControllerGenericDestroyConfirm extends App.ControllerModal
 
   onSubmit: (e) ->
     e.preventDefault()
-    @hide()
-    @item.destroy()
+    @item.destroy(
+      done: =>
+        if @callback
+          @callback()
+        @hide()
+      fail: =>
+        @log 'errors'
+        @hide()
+    )
 
 class App.ControllerDrox extends App.Controller
   constructor: (params) ->

+ 51 - 26
app/assets/javascripts/app/controllers/_channel/email.js.coffee

@@ -411,7 +411,7 @@ class App.ChannelEmailAccountWizard extends App.Controller
         configure_attributes: configureAttributesOutbound
         className: ''
       params:
-        adapter: @account.outbound.adapter || 'sendmail'
+        adapter: @account.outbound.adapter || 'smtp'
     )
     @toggleOutboundAdapter()
 
@@ -419,8 +419,8 @@ class App.ChannelEmailAccountWizard extends App.Controller
     configureAttributesInbound = [
       { name: 'adapter',            display: 'Type',     tag: 'select', multiple: false, null: false, options: { imap: 'imap', pop3: 'pop3' } },
       { name: 'options::host',      display: 'Host',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false },
-      { name: 'options::user',      display: 'User',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false },
-      { name: 'options::password',  display: 'Password', tag: 'input',  type: 'password', limit: 120, null: false, autocapitalize: false, single: true },
+      { name: 'options::user',      display: 'User',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', },
+      { name: 'options::password',  display: 'Password', tag: 'input',  type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true },
     ]
     new App.ControllerForm(
       el:    @$('.base-inbound-settings'),
@@ -439,13 +439,13 @@ class App.ChannelEmailAccountWizard extends App.Controller
       channel_used['options']['password'] = @account['meta']['password']
 
     # show used backend
-    @el.find('.base-outbound-settings').html('')
+    @$('.base-outbound-settings').html('')
     adapter = @$('.js-outbound [name=adapter]').val()
     if adapter is 'smtp'
       configureAttributesOutbound = [
         { name: 'options::host',     display: 'Host',     tag: 'input', type: 'text',     limit: 120, null: false, autocapitalize: false, autofocus: true },
-        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false },
-        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true },
+        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, autocomplete: 'off', },
+        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true },
       ]
       @form = new App.ControllerForm(
         el:    @$('.base-outbound-settings')
@@ -504,7 +504,8 @@ class App.ChannelEmailAccountWizard extends App.Controller
     params = @formParam(e.target)
 
     # let backend know about the channel
-    params.channel_id = @channel.id
+    if @channel
+      params.channel_id = @channel.id
 
     @disable(e)
 
@@ -523,17 +524,26 @@ class App.ChannelEmailAccountWizard extends App.Controller
           @account.inbound = params
 
           @showSlide('js-outbound')
+
+          # fill user / password based on inbound settings
           if !@channel
-            @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] )
-            @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] )
+            if @account['inbound']['options']
+              @$('.js-outbound [name="options::host"]').val( @account['inbound']['options']['host'] )
+              @$('.js-outbound [name="options::user"]').val( @account['inbound']['options']['user'] )
+              @$('.js-outbound [name="options::password"]').val( @account['inbound']['options']['password'] )
+            else
+              @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] )
+              @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] )
 
         else
           @showSlide('js-inbound')
           @showAlert('js-inbound', data.message_human || data.message )
+          @showInvalidField('js-inbound', data.invalid_field)
         @enable(e)
       fail: =>
         @showSlide('js-inbound')
         @showAlert('js-inbound', data.message_human || data.message )
+        @showInvalidField('js-inbound', data.invalid_field)
         @enable(e)
     )
 
@@ -550,7 +560,8 @@ class App.ChannelEmailAccountWizard extends App.Controller
         params['email'] = email_addresses[0].email
 
     # let backend know about the channel
-    params.channel_id = @channel.id
+    if @channel
+      params.channel_id = @channel.id
 
     @disable(e)
 
@@ -572,10 +583,12 @@ class App.ChannelEmailAccountWizard extends App.Controller
         else
           @showSlide('js-outbound')
           @showAlert('js-outbound', data.message_human || data.message )
+          @showInvalidField('js-outbound', data.invalid_field)
         @enable(e)
       fail: =>
         @showSlide('js-outbound')
         @showAlert('js-outbound', data.message_human || data.message )
+        @showInvalidField('js-outbound', data.invalid_field)
         @enable(e)
     )
 
@@ -599,24 +612,29 @@ class App.ChannelEmailAccountWizard extends App.Controller
       processData: true
       success: (data, status, xhr) =>
         if data.result is 'ok'
-          @el.remove()
+          @el.modal('hide')
         else
-          if count is 2
-            @showAlert('js-verify', data.message_human || data.message )
-            @delay(
-              =>
-                @showSlide('js-intro')
-                @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
-
-              2300
-            )
+          if data.source is 'inbound' || data.source is 'outbound'
+              @showSlide("js-#{data.source}")
+              @showAlert("js-#{data.source}", data.message_human || data.message )
+              @showInvalidField("js-#{data.source}", data.invalid_field)
           else
-            if data.subject && @account
-              @account.subject = data.subject
-            @verify( @account, count + 1 )
+            if count is 2
+              @showAlert('js-verify', data.message_human || data.message )
+              @delay(
+                =>
+                  @showSlide('js-intro')
+                  @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.')
+
+                2300
+              )
+            else
+              if data.subject && @account
+                @account.subject = data.subject
+              @verify( @account, count + 1 )
       fail: =>
         @showSlide('js-intro')
-        @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
+        @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.')
     )
 
   goToSlide: (e) =>
@@ -644,6 +662,13 @@ class App.ChannelEmailAccountWizard extends App.Controller
     @formEnable(e)
     @$('.wizard-controls .btn').attr('disabled', false)
 
+  showInvalidField: (screen, fields) =>
+    @$(".#{screen}").find('.form-group').removeClass('has-error')
+    return if !fields
+    for field, type of fields
+      if type
+        @$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error')
+
   hide: (e) =>
     e.preventDefault()
     @el.modal('hide')
@@ -727,8 +752,8 @@ class App.ChannelEmailNotificationWizard extends App.Controller
     if adapter is 'smtp'
       configureAttributesOutbound = [
         { name: 'options::host',     display: 'Host',     tag: 'input', type: 'text',     limit: 120, null: false, autocapitalize: false, autofocus: true },
-        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false },
-        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true },
+        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, autocomplete: 'off' },
+        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true },
       ]
       @form = new App.ControllerForm(
         el:    @$('.base-outbound-settings')

+ 49 - 21
app/assets/javascripts/app/controllers/getting_started.js.coffee

@@ -466,8 +466,8 @@ class EmailNotification extends App.ControllerContent
     if adapter is 'smtp'
       configureAttributesOutbound = [
         { name: 'options::host',     display: 'Host',     tag: 'input', type: 'text',     limit: 120, null: false, autocapitalize: false, autofocus: true, default: (channel_used['options']&&channel_used['options']['host']) },
-        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) },
-        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true, default: (channel_used['options']&&channel_used['options']['password']) },
+        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, autocomplete: 'off', default: (channel_used['options']&&channel_used['options']['user']) },
+        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true, default: (channel_used['options']&&channel_used['options']['password']) },
       ]
       @form = new App.ControllerForm(
         el:    @$('.base-outbound-settings')
@@ -696,7 +696,7 @@ class ChannelEmail extends App.ControllerContent
     adapters =
       sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup'
       smtp:     'SMTP - configure your own outgoing SMTP settings'
-    adapter_used = 'sendmail'
+    adapter_used = 'smtp'
     configureAttributesOutbound = [
       { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used },
     ]
@@ -710,8 +710,8 @@ class ChannelEmail extends App.ControllerContent
     configureAttributesInbound = [
       { name: 'adapter',            display: 'Type',     tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } },
       { name: 'options::host',      display: 'Host',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false },
-      { name: 'options::user',      display: 'User',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false },
-      { name: 'options::password',  display: 'Password', tag: 'input',  type: 'password', limit: 120, null: false, autocapitalize: false, single: true },
+      { name: 'options::user',      display: 'User',     tag: 'input',  type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', },
+      { name: 'options::password',  display: 'Password', tag: 'input',  type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true },
     ]
     new App.ControllerForm(
       el:    @$('.base-inbound-settings'),
@@ -727,12 +727,13 @@ class ChannelEmail extends App.ControllerContent
       channel_used['options']['password'] = @account['meta']['password']
 
     # show used backend
+    @$('.base-outbound-settings').html('')
     adapter = @$('.js-outbound [name=adapter]').val()
     if adapter is 'smtp'
       configureAttributesOutbound = [
         { name: 'options::host',     display: 'Host',     tag: 'input', type: 'text',     limit: 120, null: false, autocapitalize: false, autofocus: true, default: (channel_used['options']&&channel_used['options']['host']) },
-        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) },
-        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true, default: (channel_used['options']&&channel_used['options']['password']) },
+        { name: 'options::user',     display: 'User',     tag: 'input', type: 'text',     limit: 120, null: true, autocapitalize: false, autocomplete: 'off', default: (channel_used['options']&&channel_used['options']['user']) },
+        { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, autocomplete: 'new-password', single: true, default: (channel_used['options']&&channel_used['options']['password']) },
       ]
       @form = new App.ControllerForm(
         el:    @$('.base-outbound-settings')
@@ -764,6 +765,9 @@ class ChannelEmail extends App.ControllerContent
             for key, value of data.setting
               @account[key] = value
           @verify(@account)
+        else if data.result is 'duplicate'
+          @showSlide('js-intro')
+          @showAlert('js-intro', 'Account already exists!' )
         else
           @showSlide('js-inbound')
           @showAlert('js-inbound', 'Unable to detect your server settings. Manual configuration needed.' )
@@ -798,16 +802,26 @@ class ChannelEmail extends App.ControllerContent
           @account.inbound = params
 
           @showSlide('js-outbound')
-          @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] )
-          @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] )
+
+          # fill user / password based on inbound settings
+          if !@channel
+            if @account['inbound']['options']
+              @$('.js-outbound [name="options::host"]').val( @account['inbound']['options']['host'] )
+              @$('.js-outbound [name="options::user"]').val( @account['inbound']['options']['user'] )
+              @$('.js-outbound [name="options::password"]').val( @account['inbound']['options']['password'] )
+            else
+              @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] )
+              @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] )
 
         else
           @showSlide('js-inbound')
           @showAlert('js-inbound', data.message_human || data.message )
+          @showInvalidField('js-inbound', data.invalid_field)
         @enable(e)
       fail: =>
         @showSlide('js-inbound')
         @showAlert('js-inbound', data.message_human || data.message )
+        @showInvalidField('js-inbound', data.invalid_field)
         @enable(e)
     )
 
@@ -837,10 +851,12 @@ class ChannelEmail extends App.ControllerContent
         else
           @showSlide('js-outbound')
           @showAlert('js-outbound', data.message_human || data.message )
+          @showInvalidField('js-outbound', data.invalid_field)
         @enable(e)
       fail: =>
         @showSlide('js-outbound')
         @showAlert('js-outbound', data.message_human || data.message )
+        @showInvalidField('js-outbound', data.invalid_field)
         @enable(e)
     )
 
@@ -857,19 +873,24 @@ class ChannelEmail extends App.ControllerContent
         if data.result is 'ok'
           @navigate 'getting_started/agents'
         else
-          if count is 2
-            @showAlert('js-verify', data.message_human || data.message )
-            @delay(
-              =>
-                @showSlide('js-intro')
-                @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
-
-              2300
-            )
+          if data.source is 'inbound' || data.source is 'outbound'
+              @showSlide("js-#{data.source}")
+              @showAlert("js-#{data.source}", data.message_human || data.message )
+              @showInvalidField("js-#{data.source}", data.invalid_field)
           else
-            if data.subject && @account
-              @account.subject = data.subject
-            @verify( @account, count + 1 )
+            if count is 2
+              @showAlert('js-verify', data.message_human || data.message )
+              @delay(
+                =>
+                  @showSlide('js-intro')
+                  @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
+
+                2300
+              )
+            else
+              if data.subject && @account
+                @account.subject = data.subject
+              @verify( @account, count + 1 )
       fail: =>
         @showSlide('js-intro')
         @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' )
@@ -900,6 +921,13 @@ class ChannelEmail extends App.ControllerContent
     @formEnable(e)
     @$('.wizard-controls .btn').attr('disabled', false)
 
+  showInvalidField: (screen, fields) =>
+    @$(".#{screen}").find('.form-group').removeClass('has-error')
+    return if !fields
+    for field, type of fields
+      if type
+        @$(".#{screen}").find("[name=\"options::#{field}\"]").closest('.form-group').addClass('has-error')
+
 App.Config.set( 'getting_started/channel/email', ChannelEmail, 'Routes' )
 
 

+ 2 - 2
app/assets/javascripts/app/views/channel/email_account_wizard.jst.eco

@@ -17,11 +17,11 @@
           </div>
           <div class="form-group">
             <label><%- @T('Email') %></label>
-            <input type="email" class="form-control" value="" name="email" placeholder="<%- @Ti('support@example.com') %>" required>
+            <input type="email" class="form-control" value="" name="email" placeholder="<%- @Ti('support@example.com') %>" required autocomplete="off">
           </div>
           <div class="form-group">
             <label><%- @T('Password') %></label>
-            <input type="password" class="form-control" name="password" value="" required>
+            <input type="password" class="form-control" name="password" value="" required autocomplete="new-password">
           </div>
         </fieldset>
       </div>

+ 5 - 2
app/assets/javascripts/app/views/getting_started/email.jst.eco

@@ -2,6 +2,7 @@
   <svg class="wizard-logo icon-full-logo"><use xlink:href="#icon-full-logo" /></svg>
 
   <form class="setup wizard js-intro">
+    <input type="password" style="display:none"/><!-- dummy to prevent chrome to ask for password save -->
     <div class="wizard-slide">
       <h2><%- @T('Email Account') %></h2>
       <div class="wizard-body vertical justified">
@@ -13,11 +14,11 @@
           </div>
           <div class="form-group">
             <label><%- @T('Email') %></label>
-            <input type="email" class="form-control" value="" name="email" placeholder="<%- @Ti('support@example.com') %>" required>
+            <input type="email" class="form-control" value="" name="email" placeholder="<%- @Ti('support@example.com') %>" required autocomplete="off">
           </div>
           <div class="form-group">
             <label><%- @T('Password') %></label>
-            <input type="password" class="form-control" name="password" value="" required>
+            <input type="password" class="form-control" name="password" value="" required autocomplete="new-password">
           </div>
         </fieldset>
       </div>
@@ -63,6 +64,7 @@
   </form>
 
   <form class="setup wizard hide js-inbound">
+    <input type="password" style="display:none"/><!-- dummy to prevent chrome to ask for password save -->
     <div class="wizard-slide">
       <h2><%- @T('Email Inbound') %></h2>
       <div class="wizard-body vertical justified">
@@ -77,6 +79,7 @@
   </form>
 
   <form class="setup wizard hide js-outbound">
+    <input type="password" style="display:none"/><!-- dummy to prevent chrome to ask for password save -->
     <div class="wizard-slide">
       <h2><%- @T('Email Outbound') %></h2>
       <div class="wizard-body vertical justified">

+ 45 - 46
app/controllers/channels_controller.rb

@@ -5,10 +5,11 @@ class ChannelsController < ApplicationController
 
 =begin
 
-Format:
-JSON
+Resource:
+GET /api/v1/channels/#{id}.json
+
+Response example 1:
 
-Example:
 {
   "id":1,
   "area":"Email::Account",
@@ -38,6 +39,8 @@ Example:
   "created_by_id":2,
 }
 
+Response example 2:
+
 {
   "id":1,
   "area":"Twitter::Account",
@@ -84,49 +87,6 @@ Example:
   "created_by_id":2,
 }
 
-=end
-
-=begin
-
-Resource:
-GET /api/v1/channels.json
-
-Response:
-[
-  {
-    "id": 1,
-    "area":"Email::Account",
-    ...
-  },
-  {
-    "id": 2,
-    "area":"Email::Account",
-    ...
-  }
-]
-
-Test:
-curl http://localhost/api/v1/channels.json -v -u #{login}:#{password}
-
-=end
-
-  def index
-    return if deny_if_not_role(Z_ROLENAME_ADMIN)
-    model_index_render(Channel, params)
-  end
-
-=begin
-
-Resource:
-GET /api/v1/channels/#{id}.json
-
-Response:
-{
-  "id": 1,
-  "area":"Email::Account",
-  ...
-}
-
 Test:
 curl http://localhost/api/v1/channels/#{id}.json -v -u #{login}:#{password}
 
@@ -134,6 +94,7 @@ curl http://localhost/api/v1/channels/#{id}.json -v -u #{login}:#{password}
 
   def show
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    return if !check_access
     model_show_render(Channel, params)
   end
 
@@ -230,6 +191,7 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
 
   def update
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    return if !check_access
     model_update_render(Channel, params)
   end
 
@@ -248,6 +210,7 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
 
   def destroy
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    return if !check_access
     model_destory_render(Channel, params)
   end
 
@@ -256,9 +219,11 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
 
     assets = {}
     Channel.all.each {|channel|
+      next if channel.preferences && channel.preferences[:online_service_disable]
       assets = channel.assets(assets)
     }
     EmailAddress.all.each {|email_address|
+      next if email_address.preferences && email_address.preferences[:online_service_disable]
       assets = email_address.assets(assets)
     }
     render json: {
@@ -290,6 +255,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
     # check admin permissions
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
 
+    # verify access
+    return if !check_access(params[:channel_id]) if params[:channel_id]
+
     # connection test
     render json: EmailHelper::Probe.outbound(params, params[:email])
   end
@@ -299,6 +267,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
     # check admin permissions
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
 
+    # verify access
+    return if !check_access(params[:channel_id]) if params[:channel_id]
+
     # connection test
     result = EmailHelper::Probe.inbound(params)
 
@@ -317,6 +288,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
     email = email.downcase
     channel_id = params[:channel_id]
 
+    # verify access
+    return if !check_access(channel_id) if channel_id
+
     # check account duplicate
     return if email_account_duplicate?({ setting: { inbound: params[:inbound] } }, channel_id)
 
@@ -359,6 +333,10 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
         inbound: params[:inbound],
         outbound: params[:outbound],
       },
+      last_log_in: nil,
+      last_log_out: nil,
+      status_in: 'ok',
+      status_out: 'ok',
       active: true,
       group_id: Group.first.id,
     )
@@ -394,6 +372,8 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
 
   def email_notification
 
+    return if !check_online_service
+
     # check admin permissions
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
 
@@ -455,4 +435,23 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
     }
     false
   end
+
+  def check_online_service
+    return true if !Setting.get('system_online_service')
+    response_access_deny
+    false
+   end
+
+  def check_access(id = nil)
+    if !id
+      id = params[:id]
+    end
+    return true if !Setting.get('system_online_service')
+
+    channel = Channel.find(id)
+    return true if channel.preferences && !channel.preferences[:online_service_disable]
+
+    response_access_deny
+    false
+  end
 end

+ 1 - 0
app/controllers/settings_controller.rb

@@ -91,6 +91,7 @@ class SettingsController < ApplicationController
   # DELETE /settings/1
   def destroy
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    return if !check_access
     model_destory_render(Setting, params)
   end
 

+ 1 - 0
app/models/channel.rb

@@ -2,6 +2,7 @@
 
 class Channel < ApplicationModel
   store :options
+  store :preferences
 
   after_create   :email_address_check
   after_update   :email_address_check

+ 0 - 1
config/routes/channel.rb

@@ -10,7 +10,6 @@ Zammad::Application.routes.draw do
   match api_path + '/channels/email_notification',    to: 'channels#email_notification',  via: :post
 
   # channels
-  match api_path + '/channels',                       to: 'channels#index',   via: :get
   match api_path + '/channels/:id',                   to: 'channels#show',    via: :get
   match api_path + '/channels',                       to: 'channels#create',  via: :post
   match api_path + '/channels/:id',                   to: 'channels#update',  via: :put

+ 53 - 0
db/migrate/20150828000001_add_setting_online_service2.rb

@@ -0,0 +1,53 @@
+class AddSettingOnlineService2 < ActiveRecord::Migration
+  def up
+
+    # add preferences
+    add_column :channels, :preferences, :string, limit: 2000, null: true
+    Channel.reset_column_information
+    Channel.where(area: 'Email::Notification').each {|channel|
+      channel.preferences[:online_service_disable] = true
+      channel.save
+    }
+    Channel.where(area: 'Email::Account').each {|channel|
+      next if !channel.options
+      next if !channel.options[:options]
+      next if !channel.options[:options][:host]
+      next if channel.options[:options][:host] !~ /zammad/i
+      channel.preferences[:online_service_disable] = true
+      channel.save
+    }
+
+    add_column :email_addresses, :preferences, :string, limit: 2000, null: true
+    EmailAddress.reset_column_information
+    EmailAddress.all.each {|email_address|
+      next if email_address.email !~ /zammad/i
+      email_address.preferences[:online_service_disable] = true
+      email_address.save
+    }
+
+    # return if it's a new setup
+    return if !Setting.find_by(name: 'system_init_done')
+
+    Setting.create_or_update(
+      title: 'Block Notifications',
+      name: 'send_no_auto_response_reg_exp',
+      area: 'Email::Base',
+      description: 'If this regex matches, no notification will be send by the sender.',
+      options: {
+        form: [
+          {
+            display: '',
+            null: false,
+            name: 'send_no_auto_response_reg_exp',
+            tag: 'input',
+          },
+        ],
+      },
+      state: '(MAILER-DAEMON|postmaster|abuse)@.+?\..+?',
+      preferences: { online_service_disable: true },
+      frontend: false
+    )
+
+  end
+
+end

Some files were not shown because too many files changed in this diff