Browse Source

Fixed #2382 - Added Option to switch the Full-Quote-Header on and off

Billy Zhou 6 years ago
parent
commit
0c97a66d6a

+ 8 - 5
app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee

@@ -149,11 +149,14 @@ class EmailReply extends App.Controller
         selected = App.Utils.text2html(selected)
 
     if selected
-      date = @date_format(article.created_at)
-      name = article.updated_by.displayName()
-      email = article.updated_by.email
-      quote_header = App.i18n.translateInline('On %s, %s wrote:', date, name)
-      selected = "<div><br><br/></div><div><blockquote type=\'cite\'>#{quote_header}<br><br>#{selected}<br></blockquote></div><div><br></div>"
+      quote_header = ''
+      if App.Config.get('ui_ticket_zoom_article_email_full_quote_header')
+        date = @date_format(article.created_at)
+        name = article.updated_by.displayName()
+        email = article.updated_by.email
+        quote_header = App.i18n.translateInline('On %s, %s wrote:', date, name) + '<br><br>'
+
+      selected = "<div><br><br/></div><div><blockquote type=\'cite\'>#{quote_header}#{selected}<br></blockquote></div><div><br></div>"
 
       # add selected text to body
       body = selected + body

+ 34 - 0
db/migrate/20181203000000_setting_add_email_full_quote_header.rb

@@ -0,0 +1,34 @@
+class SettingAddEmailFullQuoteHeader < ActiveRecord::Migration[5.1]
+  def up
+    # return if it's a new setup
+    return if !Setting.find_by(name: 'system_init_done')
+
+    Setting.create_if_not_exists(
+      title: 'Email - quote header',
+      name: 'ui_ticket_zoom_article_email_full_quote_header',
+      area: 'UI::TicketZoom',
+      description: 'Enable if you want a timestamped reply header to be automatically inserted in front of quoted messages.',
+      options: {
+        form: [
+          {
+            display: '',
+            null: true,
+            name: 'ui_ticket_zoom_article_email_full_quote_header',
+            tag: 'boolean',
+            translate: true,
+            options: {
+              true  => 'yes',
+              false => 'no',
+            },
+          },
+        ],
+      },
+      state: true,
+      preferences: {
+        prio: 240,
+        permission: ['admin.ui'],
+      },
+      frontend: true
+    )
+  end
+end

+ 27 - 0
db/seeds/settings.rb

@@ -699,6 +699,33 @@ Setting.create_if_not_exists(
   },
   frontend: true
 )
+Setting.create_if_not_exists(
+  title: 'Email - quote header',
+  name: 'ui_ticket_zoom_article_email_full_quote_header',
+  area: 'UI::TicketZoom',
+  description: 'Enable if you want a timestamped reply header to be automatically inserted in front of quoted messages.',
+  options: {
+    form: [
+      {
+        display: '',
+        null: true,
+        name: 'ui_ticket_zoom_article_email_full_quote_header',
+        tag: 'boolean',
+        translate: true,
+        options: {
+          true  => 'yes',
+          false => 'no',
+        },
+      },
+    ],
+  },
+  state: true,
+  preferences: {
+    prio: 240,
+    permission: ['admin.ui'],
+  },
+  frontend: true
+)
 Setting.create_if_not_exists(
   title: 'Twitter - tweet initials',
   name: 'ui_ticket_zoom_article_twitter_initials',

+ 61 - 31
test/browser/agent_ticket_email_reply_keep_body_test.rb

@@ -79,6 +79,24 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
 
   end
 
+  def change_quote_config(params = {})
+    scroll_to(
+      position: 'botton',
+      css:      '.content.active .js-settingContainer .js-setting',
+    )
+    click(css: '.content.active .js-settingContainer .js-setting')
+    modal_ready()
+    select(
+      css: params[:css],
+      value: params[:value]
+    )
+    click(
+      css: params[:submit_css],
+    )
+    modal_close()
+    modal_disappear()
+  end
+
   def test_full_quote
     @browser = instance = browser_instance
     login(
@@ -96,30 +114,21 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
     )
 
     # enable email full quote in the ticket zoom config page
-    scroll_to(
-      position: 'botton',
-      css:      '.content.active .js-settingContainer .js-setting .dropdown-icon',
-    )
-    click(css: '.content.active .js-settingContainer .js-setting .dropdown-icon')
-    modal_ready()
-    select(
+    change_quote_config(
       css: '.modal #ui_ticket_zoom_article_email_full_quote select[name="ui_ticket_zoom_article_email_full_quote"]',
-      value: 'yes'
+      value: 'yes',
+      submit_css: '.modal #ui_ticket_zoom_article_email_full_quote .btn[type="submit"]',
     )
-    click(
-      css: '.modal #ui_ticket_zoom_article_email_full_quote .btn[type="submit"]',
+    change_quote_config(
+      css: '.modal #ui_ticket_zoom_article_email_full_quote_header select[name="ui_ticket_zoom_article_email_full_quote_header"]',
+      value: 'yes',
+      submit_css: '.modal #ui_ticket_zoom_article_email_full_quote_header .btn[type="submit"]',
     )
-    modal_close()
-    modal_disappear()
-
-    exists(css: '.content.active .ticket-article [data-type="emailReply"]')
 
-    # scroll to reply - needed for chrome
     scroll_to(
       position: 'botton',
       css:      '.content.active .ticket-article [data-type="emailReply"]',
     )
-
     click(css: '.content.active .ticket-article [data-type="emailReply"]')
 
     full_text = @browser.find_element(css: '.content.active .article-new .articleNewEdit-body').text
@@ -128,6 +137,39 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
     assert match
     assert match[1]
     assert Time.zone.parse(match[1])
+
+    # try again, but with the full quote header disabled
+    tasks_close_all()
+    ticket_open_by_title(
+      title: 'Welcome to Zammad',
+    )
+    change_quote_config(
+      css: '.modal #ui_ticket_zoom_article_email_full_quote_header select[name="ui_ticket_zoom_article_email_full_quote_header"]',
+      value: 'no',
+      submit_css: '.modal #ui_ticket_zoom_article_email_full_quote_header .btn[type="submit"]',
+    )
+
+    scroll_to(
+      position: 'botton',
+      css:      '.content.active .ticket-article [data-type="emailReply"]',
+    )
+    click(css: '.content.active .ticket-article [data-type="emailReply"]')
+
+    full_text = @browser.find_element(css: '.content.active .article-new .articleNewEdit-body').text
+
+    match = full_text.match(/\nOn (.*?) Nicole Braun wrote:/)
+    assert_nil match
+
+    # after test, turn full quote header back on again
+    tasks_close_all()
+    ticket_open_by_title(
+      title: 'Welcome to Zammad',
+    )
+    change_quote_config(
+      css: '.modal #ui_ticket_zoom_article_email_full_quote_header select[name="ui_ticket_zoom_article_email_full_quote_header"]',
+      value: 'yes',
+      submit_css: '.modal #ui_ticket_zoom_article_email_full_quote_header .btn[type="submit"]',
+    )
   end
 
   # Regression test for issue #2344 - Missing translation for Full-Quote-Text "on xy wrote"
@@ -148,23 +190,11 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
     )
 
     # enable email full quote in the ticket zoom config page
-    scroll_to(
-      position: 'botton',
-      css:      '.content.active .js-settingContainer .js-setting .dropdown-icon',
-    )
-    click(css: '.content.active .js-settingContainer .js-setting .dropdown-icon')
-    modal_ready()
-    select(
+    change_quote_config(
       css: '.modal #ui_ticket_zoom_article_email_full_quote select[name="ui_ticket_zoom_article_email_full_quote"]',
-      value: 'yes'
-    )
-    click(
-      css: '.modal #ui_ticket_zoom_article_email_full_quote .btn[type="submit"]',
+      value: 'yes',
+      submit_css: '.modal #ui_ticket_zoom_article_email_full_quote .btn[type="submit"]',
     )
-    modal_close()
-    modal_disappear()
-
-    exists(css: '.content.active .ticket-article [data-type="emailReply"]')
 
     # switch user profile language to German
     switch_language(