From 428c68d06a402b75b971f54add4943191be16160 Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Wed, 8 Aug 2018 16:16:05 +0800 Subject: [PATCH] Fixed issue #2170 by moving channel setting to the model --- .../app/controllers/_channel/email.coffee | 69 ++++--------------- .../app/models/postmaster_filter.coffee | 3 + test/browser/admin_channel_email_test.rb | 52 ++++++++++++++ 3 files changed, 67 insertions(+), 57 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_channel/email.coffee b/app/assets/javascripts/app/controllers/_channel/email.coffee index e5e4ba321..6889e4c14 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.coffee @@ -60,68 +60,23 @@ class App.ChannelEmailFilter extends App.Controller new: (e) => e.preventDefault() - new App.ChannelEmailFilterEdit( + new App.ControllerGenericNew( + pageData: + object: 'Postmaster Filter' + genericObject: 'PostmasterFilter' container: @el.closest('.content') + callback: @load ) - + edit: (id, e) => e.preventDefault() - new App.ChannelEmailFilterEdit( - object: App.PostmasterFilter.find(id) + new App.ControllerGenericEdit( + id: id, + pageData: + object: 'Postmaster Filter' + genericObject: 'PostmasterFilter' container: @el.closest('.content') - ) - -class App.ChannelEmailFilterEdit extends App.ControllerModal - buttonClose: true - buttonCancel: true - buttonSubmit: true - head: 'Postmaster Filter' - - content: => - if @object - @form = new App.ControllerForm( - model: App.PostmasterFilter, - params: @object, - autofocus: true, - ) - else - @form = new App.ControllerForm( - model: App.PostmasterFilter, - autofocus: true, - ) - - @form.form - - onSubmit: (e) => - e.preventDefault() - - # get params - params = @formParam(e.target) - params['channel'] = 'email' - - object = @object || new App.PostmasterFilter - object.load(params) - - # validate form - errors = @form.validate(params) - - # show errors in form - if errors - @log 'error', errors - @formValidate(form: e.target, errors: errors) - return false - - # disable form - @formDisable(e) - - # save object - object.save( - done: => - @close() - fail: (settings, details) => - @log 'errors', details - @formEnable(e) - @form.showAlert(details.error_human || details.error || 'Unable to create object!') + callback: @load ) class App.ChannelEmailSignature extends App.Controller diff --git a/app/assets/javascripts/app/models/postmaster_filter.coffee b/app/assets/javascripts/app/models/postmaster_filter.coffee index 81092a047..28a7eda6c 100644 --- a/app/assets/javascripts/app/models/postmaster_filter.coffee +++ b/app/assets/javascripts/app/models/postmaster_filter.coffee @@ -21,3 +21,6 @@ class App.PostmasterFilter extends App.Model 'name', ] @configure_clone = true + + @on 'create', (newRecord) -> + newRecord.channel = 'email' \ No newline at end of file diff --git a/test/browser/admin_channel_email_test.rb b/test/browser/admin_channel_email_test.rb index 3ff92b526..5b62f1ec2 100644 --- a/test/browser/admin_channel_email_test.rb +++ b/test/browser/admin_channel_email_test.rb @@ -128,4 +128,56 @@ class AdminChannelEmailTest < TestCase end + # test the creation and cloning of Postmaster filters + # confirm fix for issue #2170 - Cannot clone PostmasterFilter + def test_filter_clone + filter_name = "Test Filter #{rand(999_999)}" + + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + click(css: 'a[href="#manage"]') + click(css: '.content.active a[href="#channels/email"]') + + click(css: '.content.active a[href="#c-filter"]') + + # create a new email filter + click(css: '.content.active a[data-type="new"]') + + modal_ready() + set( + css: '.modal input[name="name"]', + value: filter_name, + ) + set( + css: '.modal input[name="match::from::value"]', + value: 'target', + ) + click(css: '.modal .js-submit') + modal_disappear() + + watch_for( + css: '.content.active .table', + value: filter_name, + ) + + # now clone filter that we just created + click(css: '.content.active .table #tableActions') + click(css: '.content.active .table .dropdown .js-clone') + + modal_ready() + click(css: '.modal .js-submit') + modal_disappear() + + # confirm the clone exists in the table + watch_for( + css: '.content.active .table', + value: "Clone: #{filter_name}", + ) + end end