diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index 9cc92f9b6..51509bebf 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -243,6 +243,8 @@ class App.ChannelEmailAccountOverview extends App.Controller render: (data = {}) => + @channelDriver = data.channel_driver + # get channels account_channels = [] for channel_id in data.account_channel_ids @@ -272,8 +274,9 @@ class App.ChannelEmailAccountOverview extends App.Controller wizard: (e) => e.preventDefault() new App.ChannelEmailAccountWizard( - container: @el.closest('.content') - callback: @load + container: @el.closest('.content') + callback: @load + channelDriver: @channelDriver ) edit_inbound: (e) => @@ -282,10 +285,11 @@ class App.ChannelEmailAccountOverview extends App.Controller channel = App.Channel.find(id) slide = 'js-inbound' new App.ChannelEmailAccountWizard( - container: @el.closest('.content') - slide: slide - channel: channel - callback: @load + container: @el.closest('.content') + slide: slide + channel: channel + callback: @load + channelDriver: @channelDriver ) edit_outbound: (e) => @@ -294,10 +298,11 @@ class App.ChannelEmailAccountOverview extends App.Controller channel = App.Channel.find(id) slide = 'js-outbound' new App.ChannelEmailAccountWizard( - container: @el.closest('.content') - slide: slide - channel: channel - callback: @load + container: @el.closest('.content') + slide: slide + channel: channel + callback: @load + channelDriver: @channelDriver ) delete: (e) => @@ -341,9 +346,10 @@ class App.ChannelEmailAccountOverview extends App.Controller channel = App.Channel.find(id) slide = 'js-outbound' new App.ChannelEmailNotificationWizard( - container: @el.closest('.content') - channel: channel - callback: @load + container: @el.closest('.content') + channel: channel + callback: @load + channelDriver: @channelDriver ) class App.ChannelEmailAccountWizard extends App.Wizard @@ -403,11 +409,8 @@ class App.ChannelEmailAccountWizard extends App.Wizard @showSlide('js-intro') # outbound - adapters = - sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup' - smtp: 'SMTP - configure your own outgoing SMTP settings' configureAttributesOutbound = [ - { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters }, + { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound }, ] new App.ControllerForm( el: @$('.base-outbound-type') @@ -421,7 +424,7 @@ class App.ChannelEmailAccountWizard extends App.Wizard # inbound configureAttributesInbound = [ - { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'imap', pop3: 'pop3' } }, + { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: @channelDriver.email.inbound }, { 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, autocomplete: 'off', }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, @@ -700,11 +703,8 @@ class App.ChannelEmailNotificationWizard extends App.Wizard @showSlide('js-outbound') # outbound - adapters = - sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup' - smtp: 'SMTP - configure your own outgoing SMTP settings' configureAttributesOutbound = [ - { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters }, + { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound }, ] new App.ControllerForm( el: @$('.base-outbound-type') diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index a09db8ee5..349e03e66 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -404,13 +404,10 @@ class EmailNotification extends App.Wizard # set title @title 'Email Notifications' - @adapters = [ - { - name: 'Email' - class: 'email' - link: '#getting_started/channel/email' - }, - ] + @channelDriver = + email: + inbound: {} + outbound: {} @fetch() @@ -432,43 +429,45 @@ class EmailNotification extends App.Wizard @navigate '#import/' + data.import_backend return + @channelDriver = data.channel_driver + # render page @render() ) render: -> @html App.view('getting_started/email_notification')() - adapters = - sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup' - smtp: 'SMTP - configure your own outgoing SMTP settings' - adapter_used = 'sendmail' configureAttributesOutbound = [ - { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used }, + { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound }, ] new App.ControllerForm( - el: @$('.base-outbound-type'), - model: { configure_attributes: configureAttributesOutbound, className: '' }, + el: @$('.base-outbound-type') + model: + configure_attributes: configureAttributesOutbound + className: '' + params: + adapter: @account.outbound.adapter || 'sendmail' ) @toggleOutboundAdapter() toggleOutboundAdapter: => # show used backend - channel_used = { options: {} } + @el.find('.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, 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']) }, + { 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, 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') - model: { configure_attributes: configureAttributesOutbound, className: '' } + model: + configure_attributes: configureAttributesOutbound + className: '' + params: @account.outbound ) - else - @el.find('.base-outbound-settings').html('') - submit: (e) => e.preventDefault() @@ -634,6 +633,11 @@ class ChannelEmail extends App.Wizard outbound: {} meta: {} + @channelDriver = + email: + inbound: {} + outbound: {} + @fetch() release: => @@ -654,6 +658,8 @@ class ChannelEmail extends App.Wizard @navigate '#import/' + data.import_backend return + @channelDriver = data.channel_driver + # render page @render() ) @@ -664,29 +670,32 @@ class ChannelEmail extends App.Wizard @showSlide('js-intro') # outbound - adapters = - sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup' - smtp: 'SMTP - configure your own outgoing SMTP settings' - adapter_used = 'smtp' configureAttributesOutbound = [ - { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: adapters , default: adapter_used }, + { name: 'adapter', display: 'Send Mails via', tag: 'select', multiple: false, null: false, options: @channelDriver.email.outbound }, ] new App.ControllerForm( - el: @$('.base-outbound-type'), - model: { configure_attributes: configureAttributesOutbound, className: '' }, + el: @$('.base-outbound-type') + model: + configure_attributes: configureAttributesOutbound + className: '' + params: + adapter: @account.outbound.adapter || 'smtp' ) @toggleOutboundAdapter() # inbound configureAttributesInbound = [ - { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } }, + { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: @channelDriver.email.inbound }, { 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, 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'), - model: { configure_attributes: configureAttributesInbound, className: '' }, + model: + configure_attributes: configureAttributesInbound + className: '' + params: @account.inbound ) toggleOutboundAdapter: => @@ -702,16 +711,17 @@ class ChannelEmail extends App.Wizard 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, 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']) }, + { 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, 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') - model: { configure_attributes: configureAttributesOutbound, className: '' } + model: + configure_attributes: configureAttributesOutbound + className: '' + params: @account.outbound ) - else - @el.find('.base-outbound-settings').html('') probeBasedOnIntro: (e) => e.preventDefault() diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 485320a24..2a340c83f 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -62,6 +62,9 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten notification_channel_ids: notification_channel_ids, email_address_ids: email_address_ids, not_used_email_address_ids: not_used_email_address_ids, + channel_driver: { + email: EmailHelper.available_driver, + } } end diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index e38d18efb..48b30a26b 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -226,6 +226,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} addresses: addresses, groups: groups, config: config_to_update, + channel_driver: { + email: EmailHelper.available_driver, + }, } true end diff --git a/lib/email_helper.rb b/lib/email_helper.rb index f4b8bcbbd..459965e50 100644 --- a/lib/email_helper.rb +++ b/lib/email_helper.rb @@ -9,8 +9,14 @@ get available driver returns { - :inbound => ['imap', 'pop3'], - :outbound => ['smtp', 'sendmail'], + inbound: { + imap: 'IMAP', + pop3: 'POP3', + }, + outbound: { + smtp: 'SMTP - configure your own outgoing SMTP settings', + sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup', + }, } =end @@ -18,13 +24,24 @@ returns def self.available_driver if Setting.get('system_online_service') return { - inbound: %w(imap pop3), - outbound: %w(smtp), + inbound: { + imap: 'IMAP', + pop3: 'POP3', + }, + outbound: { + smtp: 'SMTP - configure your own outgoing SMTP settings', + }, } end { - inbound: %w(imap pop3), - outbound: %w(smtp sendmail), + inbound: { + imap: 'IMAP', + pop3: 'POP3', + }, + outbound: { + smtp: 'SMTP - configure your own outgoing SMTP settings', + sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup', + }, } end diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 00449a4e3..c6298b7f6 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -189,7 +189,7 @@ returns on fail adapter = params[:adapter].downcase # validate adapter - if !EmailHelper.available_driver[:inbound].include?(adapter) + if !EmailHelper.available_driver[:inbound][adapter.to_sym] return { result: 'failed', message: "Unknown adapter '#{adapter}'", @@ -268,7 +268,7 @@ returns on fail adapter = params[:adapter].downcase # validate adapter - if !EmailHelper.available_driver[:outbound].include?(adapter) + if !EmailHelper.available_driver[:outbound][adapter.to_sym] return { result: 'failed', message: "Unknown adapter '#{adapter}'", diff --git a/lib/email_helper/verify.rb b/lib/email_helper/verify.rb index dec5a1a5e..1828568df 100644 --- a/lib/email_helper/verify.rb +++ b/lib/email_helper/verify.rb @@ -69,7 +69,7 @@ or # validate adapter adapter = params[:inbound][:adapter].downcase - if !EmailHelper.available_driver[:inbound].include?(adapter) + if !EmailHelper.available_driver[:inbound][adapter.to_sym] return { result: 'failed', message: "Unknown adapter '#{adapter}'",