Skip to content

Commit d57130d

Browse files
committed
feat(cms): ability to attach case files & attachments
Jira: PWNN-730
1 parent 3604060 commit d57130d

File tree

56 files changed

+1279
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1279
-224
lines changed

app/assets/stylesheets/base/_misc.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@
7777
.govuk-table__cell.vertical_middle {
7878
vertical-align: middle;
7979
}
80+
81+
.fake-link {
82+
@extend .govuk-link;
83+
color: $govuk-link-colour;
84+
cursor: pointer;
85+
}

app/assets/stylesheets/components/supported/_template-edit.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
border-bottom: 1px solid $govuk-border-colour;
77
}
88

9+
.template-edit__attachment.dz-error {
10+
border: $govuk-border-width solid $govuk-error-colour;
11+
padding-left: 10px;
12+
padding-right: 10px;
13+
}
14+
915
.template-edit__attachment-name {
1016
@include govuk-font($size: 19);
1117
}
@@ -16,6 +22,13 @@
1622
gap: govuk-spacing(2);
1723
}
1824

25+
.template-edit__attachment-error {
26+
@include govuk-font($size: 19);
27+
@include govuk-typography-weight-bold;
28+
29+
color: $govuk-error-colour;
30+
}
31+
1932
.template-edit__attachment-download {
2033
@include govuk-font($size: 19);
2134
}

app/controllers/support/cases/message_threads_controller.rb

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module Cases
33
class MessageThreadsController < Cases::ApplicationController
44
before_action :redirect_to_messages_tab, unless: :turbo_frame_request?, only: %i[show templated_messages logged_contacts]
55
before_action :current_thread, only: %i[show]
6-
before_action :reply_form, only: %i[new]
7-
before_action :back_url, only: %i[index show new templated_messages logged_contacts]
6+
before_action :back_url, only: %i[index show edit templated_messages logged_contacts]
87

98
content_security_policy do |policy|
109
policy.style_src_attr :unsafe_inline
@@ -28,6 +27,34 @@ def new
2827
@to_recipients = Array(current_case.email).to_json
2928
end
3029

30+
def edit
31+
@reply_form = Email::Draft.find(params[:id])
32+
end
33+
34+
def create
35+
draft = Email::Draft.new(
36+
default_content: default_template,
37+
default_subject:,
38+
template_id: params[:template_id],
39+
ticket: current_case.to_model,
40+
to_recipients: Array(current_case.email).to_json,
41+
).save_draft!
42+
43+
redirect_to edit_support_case_message_thread_path(id: draft.id)
44+
end
45+
46+
def submit
47+
@reply_form = Email::Draft.find(params[:id])
48+
@reply_form.attributes = new_thread_params
49+
if @reply_form.valid?
50+
@reply_form.save_draft!
51+
@reply_form.deliver_as_new_message
52+
redirect_to support_case_message_threads_path(case_id: current_case.id)
53+
else
54+
render :edit
55+
end
56+
end
57+
3158
def templated_messages; end
3259

3360
def logged_contacts; end
@@ -63,6 +90,10 @@ def redirect_to_messages_tab
6390
redirect_to support_case_path(id: params[:case_id], anchor: "messages", messages_tab_url: request.url)
6491
end
6592

93+
def new_thread_params
94+
params.require(:"message_reply_form_#{params[:unique_id]}").permit(:html_content, :subject, :to_recipients, :cc_recipients, :bcc_recipients, :template_id)
95+
end
96+
6697
def set_reply_frame_url
6798
return if params[:reply_frame_url].blank?
6899

app/controllers/support/cases/messages/replies_controller.rb

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ class Cases::Messages::RepliesController < Cases::ApplicationController
33
before_action :current_email
44
before_action :back_url
55

6-
def new
7-
@reply_form = Email::Draft.new(
8-
default_content: default_template,
9-
template_id: params[:template_id],
10-
)
11-
@last_received_reply = Support::Messages::OutlookMessagePresenter.new(Support::Email.find(params[:message_id]))
6+
def edit
7+
@reply_form = Email::Draft.find(params[:id])
8+
@last_received_reply = Support::Messages::OutlookMessagePresenter.new(current_email)
129
end
1310

1411
def create
15-
@reply_form = Email::Draft.new(**form_params, reply_to_email: current_email)
12+
@draft = Email::Draft.new(
13+
default_content: default_template,
14+
template_id: params[:template_id],
15+
ticket: current_case.to_model,
16+
reply_to_email: current_email,
17+
).save_draft!
18+
19+
redirect_to redirect_url
20+
end
1621

22+
def submit
23+
@reply_form = Email::Draft.find(params[:id])
24+
@reply_form.reply_to_email = current_email
25+
@reply_form.attributes = form_params
1726
if @reply_form.valid?
27+
@reply_form.save_draft!
1828
@reply_form.delivery_as_reply
1929

2030
respond_to do |format|
@@ -24,9 +34,7 @@ def create
2434
format.html { redirect_to support_case_message_thread_path(id: @current_email.outlook_conversation_id, case_id: current_case.id) }
2535
end
2636
else
27-
@body = form_params[:body]
28-
@show_attachment_warning = Array(form_params[:attachments]).any?
29-
37+
@last_received_reply = Support::Messages::OutlookMessagePresenter.new(current_email)
3038
render :edit
3139
end
3240
end
@@ -43,6 +51,15 @@ def current_email
4351
@current_email = Support::Email.find(params[:message_id]) if params[:message_id].present?
4452
end
4553

54+
def redirect_url
55+
return edit_support_case_message_reply_path(message_id: current_email.id, id: @draft.id) if params[:redirect_back].blank?
56+
57+
url = URI.parse(url_for(params[:redirect_back]))
58+
query = URI.decode_www_form(url.query) << ["reply_frame_url", edit_support_case_message_reply_path(message_id: current_email.id, id: @draft.id)]
59+
url.query = URI.encode_www_form(query)
60+
url.to_s
61+
end
62+
4663
def back_url
4764
@back_url = support_case_message_thread_path(id: @current_email.outlook_conversation_id, case_id: current_case.id)
4865
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
class Tickets::AttachCaseFilesController < ApplicationController
2+
include SupportAgents
3+
4+
content_security_policy do |policy|
5+
policy.style_src_attr :unsafe_inline
6+
end
7+
8+
before_action :turbo_frame
9+
before_action :redirect_to_portal, unless: :turbo_frame_request?
10+
before_action :set_back_url
11+
before_action :find_email
12+
before_action :find_case_files, only: :index
13+
14+
def index
15+
@blob_attachment_picker = @email.blob_attachment_picker(form_params)
16+
end
17+
18+
def create
19+
@blob_attachment_picker = @email.blob_attachment_picker(form_params)
20+
if @blob_attachment_picker.valid?
21+
@blob_attachment_picker.save!
22+
redirect_to @back_url
23+
else
24+
render :index
25+
end
26+
end
27+
28+
private
29+
30+
def find_email
31+
@email = Email.find(params[:message_id])
32+
end
33+
34+
def find_case_files
35+
@case_files = @email.ticket
36+
.case_attachments
37+
.paginate(page: params[:page], per_page: 20)
38+
end
39+
40+
def form_params
41+
params.fetch(:blob_attachment_picker, {}).permit(attachments: [])
42+
end
43+
44+
def set_back_url
45+
@back_url = back_link_param
46+
end
47+
48+
def turbo_frame
49+
@turbo_frame = params[:turbo_frame] || "messages_frame"
50+
end
51+
52+
def authorize_agent_scope = :access_proc_ops_portal?
53+
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
class Tickets::AttachEmailAttachmentsController < ApplicationController
2+
include SupportAgents
3+
4+
content_security_policy do |policy|
5+
policy.style_src_attr :unsafe_inline
6+
end
7+
8+
before_action :turbo_frame
9+
before_action :redirect_to_portal, unless: :turbo_frame_request?
10+
before_action :set_back_url
11+
before_action :set_filter_form
12+
before_action :find_email
13+
before_action :find_attachments, only: :index
14+
15+
def index
16+
@blob_attachment_picker = @email.blob_attachment_picker(form_params)
17+
end
18+
19+
def create
20+
@blob_attachment_picker = @email.blob_attachment_picker(form_params)
21+
if @blob_attachment_picker.valid?
22+
@blob_attachment_picker.save!
23+
redirect_to @back_url
24+
else
25+
render :index
26+
end
27+
end
28+
29+
private
30+
31+
def find_email
32+
@email = Email.find(params[:message_id])
33+
end
34+
35+
def find_attachments
36+
@email_attachments = @email.ticket
37+
.unique_attachments(folder: @filter_form.sent_received)
38+
.paginate(page: params[:page], per_page: 20)
39+
end
40+
41+
def set_filter_form
42+
@filter_form = FilterAttachmentsForm.new({ sent_received: "all" }.merge(filter_params))
43+
end
44+
45+
def filter_params
46+
params.fetch(:blob_attachment_picker, {}).permit(:sent_received)
47+
end
48+
49+
def form_params
50+
params.fetch(:blob_attachment_picker, {}).permit(attachments: [])
51+
end
52+
53+
def set_back_url
54+
@back_url = back_link_param
55+
end
56+
57+
def turbo_frame
58+
@turbo_frame = params[:turbo_frame] || "messages-frame"
59+
end
60+
61+
def authorize_agent_scope = :access_proc_ops_portal?
62+
63+
class FilterAttachmentsForm
64+
include ActiveModel::Model
65+
attr_accessor :sent_received
66+
end
67+
end

app/controllers/tickets/message_replies_controller.rb

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,54 @@ class Tickets::MessageRepliesController < ApplicationController
33

44
before_action :redirect_to_portal, unless: :turbo_frame_request?
55
before_action :find_email
6-
before_action :set_back_url
76

8-
def create
9-
@draft = Email::Draft.new(**form_params, reply_to_email: @email)
7+
def edit
8+
@reply_form = Email::Draft.find(params[:id])
9+
@last_received_reply = Support::Messages::OutlookMessagePresenter.new(@email)
10+
end
1011

11-
if @draft.valid?
12-
@draft.delivery_as_reply
12+
def create
13+
@draft = Email::Draft.new(
14+
default_content:,
15+
template_id: params[:template_id],
16+
ticket: @email.ticket,
17+
reply_to_email: @email,
18+
).save_draft!
19+
20+
redirect_to edit_message_reply_path(message_id: @email.id, id: @draft.id)
21+
end
1322

14-
redirect_to message_thread_path(ticket_type: @email.ticket_type, ticket_id: @email.ticket_id, id: @email.outlook_conversation_id, back_to: params[:back_to])
23+
def submit
24+
@reply_form = Email::Draft.find(params[:id])
25+
@reply_form.reply_to_email = @email
26+
@reply_form.attributes = form_params
27+
if @reply_form.valid?
28+
@reply_form.save_draft!
29+
@reply_form.delivery_as_reply
30+
31+
respond_to do |format|
32+
format.turbo_stream do
33+
render turbo_stream: turbo_stream.redirect(message_thread_path(ticket_type: @email.ticket_type, ticket_id: @email.ticket_id, id: @email.outlook_conversation_id, back_to: params[:back_to]), "messages-frame")
34+
end
35+
format.html { redirect_to message_thread_path(ticket_type: @email.ticket_type, ticket_id: @email.ticket_id, id: @email.outlook_conversation_id, back_to: params[:back_to]) }
36+
end
37+
else
38+
@last_received_reply = Support::Messages::OutlookMessagePresenter.new(@email)
39+
render :edit
1540
end
1641
end
1742

1843
private
1944

45+
def default_content = render_to_string(partial: "support/cases/messages/reply_form_template")
46+
2047
def form_params
21-
params.require(:"message_reply_form_#{params[:unique_id]}").permit(:html_content, :subject, :to_recipients, :cc_recipients, :bcc_recipients, :template_id, :blob_attachments, file_attachments: [])
48+
params.require(:"message_reply_form_#{params[:unique_id]}").permit(:html_content, :subject, :to_recipients, :cc_recipients, :bcc_recipients, :template_id)
2249
end
2350

2451
def find_email
2552
@email = Email.find(params[:message_id])
2653
end
2754

28-
def set_back_url
29-
@back_url = back_link_param
30-
end
31-
3255
def authorize_agent_scope = :access_proc_ops_portal?
3356
end

0 commit comments

Comments
 (0)