From 90fcff7bd98bc75ad204090ce99b70afea91af35 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 31 Mar 2017 13:59:58 +0200 Subject: [PATCH] Fixed issue #859 - Changing "Product Name" breaks "Admin" menu. --- .../controllers/_settings/area_item.coffee | 35 +++---------------- .../javascripts/app/models/setting.coffee | 29 ++++++++------- db/seeds.rb | 1 - test/browser/setting_test.rb | 32 +++++++++++++++++ 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_settings/area_item.coffee b/app/assets/javascripts/app/controllers/_settings/area_item.coffee index 1685cc292..94fd86a99 100644 --- a/app/assets/javascripts/app/controllers/_settings/area_item.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area_item.coffee @@ -47,37 +47,10 @@ class App.SettingsAreaItem extends App.Controller for item in @setting.options['form'] directValue += 1 directData = params[item.name] - + value = undefined if directValue > 1 - state_current = { - value: params - } - #App.Config.set((@setting.name, params) + value = params else - state_current = { - value: directData - } - #App.Config.set(@setting.name, directData) + value = directData - @setting['state_current'] = state_current - ui = @ - @setting.save( - done: => - ui.formEnable(e) - App.Event.trigger 'notify', { - type: 'success' - msg: App.i18n.translateContent('Update successful!') - timeout: 2000 - } - - # rerender ui || get new collections and session data - App.Setting.preferencesPost(@setting) - - fail: (settings, details) -> - ui.formEnable(e) - App.Event.trigger 'notify', { - type: 'error' - msg: App.i18n.translateContent(details.error_human || details.error || 'Unable to update object!') - timeout: 2000 - } - ) + App.Setting.set(@setting['name'], value) diff --git a/app/assets/javascripts/app/models/setting.coffee b/app/assets/javascripts/app/models/setting.coffee index 8e3a79d36..04bb58d12 100644 --- a/app/assets/javascripts/app/models/setting.coffee +++ b/app/assets/javascripts/app/models/setting.coffee @@ -5,10 +5,12 @@ class App.Setting extends App.Model @get: (name) -> setting = App.Setting.findByAttribute('name', name) + throw "No such setting '#{name}' found!" if !setting setting.state_current.value @set: (name, value, options = {}) -> setting = App.Setting.findByAttribute('name', name) + throw "No such setting '#{name}' found!" if !setting setting.state_current.value = value if !options.done options.done = -> @@ -27,22 +29,25 @@ class App.Setting extends App.Model msg: App.i18n.translateContent(details.error_human || details.error || 'Unable to update object!') timeout: 2000 } - App.Config.set(name, value) + if setting.frontend + App.Config.set(name, value) setting.save(options) @preferencesPost: (setting) -> return if !setting.preferences if setting.preferences.render - App.Event.trigger('ui:rerender') + setting.preferences.trigger ||= [] + setting.preferences.trigger.push 'ui:rerender' - if setting.preferences.trigger - events = setting.preferences.trigger - if !_.isArray(setting.preferences.trigger) - events = [setting.preferences.trigger] - delay = -> - for event in events + return if _.isEmpty(setting.preferences.trigger) + events = setting.preferences.trigger + if !_.isArray(setting.preferences.trigger) + events = [setting.preferences.trigger] + + count = 0 + for event in events + count += 1 + do (event, count) -> + delay = -> App.Event.trigger(event) - App.Delay.set(delay, 20) - - if setting.preferences.session_check - App.Auth.loginCheck() + App.Delay.set(delay, 300 * count) diff --git a/db/seeds.rb b/db/seeds.rb index f58beccce..9854a093e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -115,7 +115,6 @@ Setting.create_if_not_exists( }, preferences: { render: true, - session_check: true, prio: 1, placeholder: true, permission: ['admin.branding'], diff --git a/test/browser/setting_test.rb b/test/browser/setting_test.rb index 6512348eb..2cbd02b40 100644 --- a/test/browser/setting_test.rb +++ b/test/browser/setting_test.rb @@ -140,4 +140,36 @@ class SettingTest < TestCase value: 'facebook', ) end + + def test_product_name + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + verify_title(value: 'Zammad Test System') + + click(css: 'a[href="#manage"]') + click(css: '.content.active a[href="#settings/branding"]') + set( + css: '.content.active [name="product_name"]', + value: 'ABC App', + ) + click(css: '.content.active #product_name button[type=submit]') + + sleep 2 + verify_title(value: 'ABC App') + set( + css: '.content.active [name="product_name"]', + value: 'Zammad Test System', + ) + click(css: '.content.active #product_name button[type=submit]') + + sleep 2 + verify_title(value: 'Zammad Test System') + end + end