Skip to content

Commit ab059e0

Browse files
committed
Add new settings keys/logic for ticket behavior
- global bcc on all customer emails - default channel from admin ticket form - include ticket history in customer emails - include ticket body (or just link) in customer emails - default helpcenter form to private or public forum posts
1 parent bcad3dc commit ab059e0

File tree

15 files changed

+134
-10
lines changed

15 files changed

+134
-10
lines changed

app/assets/javascripts/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ Helpy.didthisHelp = function(yesno){
459459
Helpy.showGroup = function() {
460460
if ($('#topic_private_true').is(':checked')) {
461461
$('#topic_team_list').parent().removeClass('hidden');
462+
$("#topic_forum_id").parent().hide();
463+
$('#new_topic').append("<input type='hidden' id='new_topic_forum_id' name='topic[forum_id]' value='1'/>");
464+
$('#topic_team_list').removeClass('hidden');
462465
} else if ($('#topic_private_false').is(':checked')) {
463466
$('#topic_team_list').parent().addClass('hidden');
464467
} else {

app/controllers/admin/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def show
6666
def new
6767
fetch_counts
6868

69-
@topic = Topic.new
69+
@topic = Topic.new(channel: AppSettings['settings.default_channel'])
7070
@user = params[:user_id].present? ? User.find(params[:user_id]) : User.new
7171
end
7272

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def associate_with_doc
166166
private
167167

168168
def initialize_new_ticket_form_vars
169-
@topic = Topic.new #unless @topic
169+
@topic = Topic.new(private: AppSettings['settings.default_private']) #unless @topic
170170
@user = @topic.build_user unless user_signed_in?
171171
@topic.posts.build #unless @topic.posts
172172
get_all_teams

app/helpers/email_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,19 @@ def body_tokens(text, topic)
1515
text = text.gsub('%customer_email_address', topic.user.email)
1616
return text
1717
end
18+
19+
# include the ticket history in email
20+
def include_history?
21+
AppSettings['settings.include_ticket_history'] == "1"
22+
end
23+
24+
# include the ticket body or just a link?
25+
def include_body?
26+
AppSettings['settings.include_ticket_body'] == "1"
27+
end
28+
29+
def link_to_topic
30+
t('response_added', default: 'A response has been added to your ticket. Click here to see it: %{ticket_link}',
31+
ticket_link: ticket_url(@topic, host: AppSettings['settings.site_url']))
32+
end
1833
end

app/mailers/post_mailer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def new_post(post_id)
3131
mail(
3232
to: email_with_name,
3333
cc: @post.cc,
34-
bcc: @post.bcc,
34+
bcc: @post.bccs,
3535
from: @topic.from_email_address,
3636
subject: "[#{AppSettings['settings.site_name']}] ##{@topic.id}-#{@topic.name}"
3737
)

app/models/post.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ def text_formatted_body
151151
"#{ActionView::Base.full_sanitizer.sanitize(ApplicationController.helpers.body_tokens(body, topic))}".html_safe
152152
end
153153

154+
def bccs
155+
bccs = []
156+
unless bcc.nil?
157+
bccs += bcc&.split(',').collect{|b| b.strip}
158+
end
159+
unless AppSettings['settings.global_bcc'].nil? || AppSettings['settings.global_bcc'].blank?
160+
bccs += AppSettings['settings.global_bcc']&.split(',').collect{|b| b.strip}
161+
end
162+
return bccs
163+
end
164+
154165
private
155166

156167
def truncate_body

app/views/post_mailer/new_post.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
<%= @header.html_safe %>
1414
<p style="color: #666;">
1515
<small>
16-
<%= t('above_this_line', default: "Make sure your reply appears above this line") %><br/>
16+
<%= t('above_this_line', default: "Make sure your reply appears above this line") if include_body? %><br/>
1717
</small>
1818
</p>
1919

2020
<p>
21-
<%= @post.html_formatted_body %>
21+
<%= include_body? ? @post.html_formatted_body : link_to_topic %>
2222
<%= simple_format(@post.user.signature) if @post.user.signature.present? %>
2323
</p>
2424
<%= render :partial => 'posts/thumbnail', locals: { :model_name => @post } %>
25-
<%= render partial: 'mailer_shared/post', collection: @posts %>
25+
<%= render partial: 'mailer_shared/post', collection: @posts if include_history? %>
2626
<br/>
2727
<%= footer_tokens(@footer).html_safe %>
2828
</body>

app/views/post_mailer/new_post.text.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<%= strip_tags(@header) %>
22

3+
<% if include_body? %>
34
<%= t('above_this_line', default: "Make sure your reply appears above this line") %>
45
=================================================================
56
<%= t('message_id', default: 'Message ID') %>:<%= @topic.id %>
7+
<% end %>
68

79
<%= t('message_response', default: 'The following message has been posted in response to your question:') %>
810

9-
<%= @post.text_formatted_body %>
11+
<%= @post.text_formatted_body if include_body? %>
1012
<%= strip_tags(@post.user.signature) if @post.user.signature.present? %>
1113

1214
<%= t('view_online', default: 'View this online:') %> <%= ticket_url(@topic, host: AppSettings['settings.site_url']) %>

app/views/topics/new.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<% end %>
2222
<% end %>
2323

24-
<% if (user_signed_in? && !@widget) || (!user_signed_in? && recaptcha_enabled? && !@widget) %>
25-
<% if forums? and tickets? %>
24+
<% if (user_signed_in?) || (!user_signed_in? && recaptcha_enabled?) %>
25+
<% if forums? && tickets? %>
2626
<label class="control-label" for="doc_active"> <%= t(:should_message_be_private) %> </label>
2727
<%= f.collection_radio_buttons :private, [[true, t(:only_support_can_respond)] ,[false, t(:responses_can_come_from_everyone)]], :first, :last, item_wrapper_class: 'radio', item_label_class: 'radio-label', collection_wrapper_tag: :div %>
2828
<%= f.input(:forum_id, collection: @forums, :label => t(:forum_name), locale: I18n.locale, prompt: nil) %>

config/initializers/default_settings.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
AppSettings.defaults["settings.knowledgebase"] = Settings.knowledgebase
2424
AppSettings.defaults["settings.teams"] = Settings.teams
2525
AppSettings.defaults["settings.welcome_email"] = Settings.welcome_email
26+
AppSettings.defaults['settings.global_bcc'] = []
27+
AppSettings.defaults['settings.default_channel'] = 'email'
28+
AppSettings.defaults['settings.include_ticket_history'] = '1'
29+
AppSettings.defaults['settings.include_ticket_body'] = '1'
30+
AppSettings.defaults['settings.default_private'] = '0'
2631

2732
# Webhook Integrations
2833

0 commit comments

Comments
 (0)