Code cleanup.
This commit is contained in:
parent
712acdfe2a
commit
63ff844f38
7 changed files with 119 additions and 59 deletions
|
@ -10,13 +10,6 @@ class EmailReply extends App.Controller
|
|||
icon: 'reply'
|
||||
href: '#'
|
||||
}
|
||||
actions.push {
|
||||
name: 'forward'
|
||||
type: 'emailForward'
|
||||
#icon: 'forward'
|
||||
icon: 'info'
|
||||
href: '#'
|
||||
}
|
||||
recipients = []
|
||||
if article.sender.name is 'Customer'
|
||||
if article.from
|
||||
|
@ -57,6 +50,15 @@ class EmailReply extends App.Controller
|
|||
icon: 'reply-all'
|
||||
href: '#'
|
||||
}
|
||||
|
||||
actions.push {
|
||||
name: 'forward'
|
||||
type: 'emailForward'
|
||||
#icon: 'forward'
|
||||
icon: 'line-right-arrow'
|
||||
href: '#'
|
||||
}
|
||||
|
||||
if article.sender.name is 'Customer' && article.type.name is 'phone'
|
||||
actions.push {
|
||||
name: 'reply'
|
||||
|
@ -68,7 +70,7 @@ class EmailReply extends App.Controller
|
|||
name: 'forward'
|
||||
type: 'emailForward'
|
||||
#icon: 'forward'
|
||||
icon: 'info'
|
||||
icon: 'line-right-arrow'
|
||||
href: '#'
|
||||
}
|
||||
if article.sender.name is 'Agent' && article.type.name is 'phone'
|
||||
|
@ -82,7 +84,7 @@ class EmailReply extends App.Controller
|
|||
name: 'forward'
|
||||
type: 'emailForward'
|
||||
#icon: 'forward'
|
||||
icon: 'info'
|
||||
icon: 'line-right-arrow'
|
||||
href: '#'
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="article-content article-actions horizontal stretch">
|
||||
<% for action in @actions: %>
|
||||
<a href="<%= action.href %>" data-type="<%= action.type %>" class="article-action js-ArticleAction u-clickable<% if action.class: %> <%= action.class %><% end %>">
|
||||
<%- @Icon(action.icon, 'article-action-icon') %><%- @T(action.name) %>
|
||||
<%- @Icon(action.icon, 'article-action-icon') %><span class="article-action-name"><%- @T(action.name) %></span>
|
||||
</a>
|
||||
<% end %>
|
||||
</div>
|
|
@ -4985,6 +4985,18 @@ footer {
|
|||
fill: currentColor;
|
||||
}
|
||||
|
||||
.article-action-name {
|
||||
@media screen and (max-width: 1080px) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1358px) {
|
||||
.main:not(.is-closed) & {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.article-add {
|
||||
position: relative;
|
||||
z-index: 1; // fixed chrome 49 + flex issue, not shown article
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
module ClonesTicketArticleAttachments
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
private
|
||||
|
||||
def article_attachments_clone(article)
|
||||
raise Exceptions::UnprocessableEntity, 'Need form_id to attach attachments to new form.' if params[:form_id].blank?
|
||||
|
||||
existing_attachments = Store.list(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
)
|
||||
attachments = []
|
||||
article.attachments.each do |new_attachment|
|
||||
next if new_attachment.preferences['Content-ID'].present?
|
||||
next if new_attachment.preferences['content-alternative'] == true
|
||||
already_added = false
|
||||
existing_attachments.each do |existing_attachment|
|
||||
next if existing_attachment.filename != new_attachment.filename || existing_attachment.size != new_attachment.size
|
||||
already_added = true
|
||||
break
|
||||
end
|
||||
next if already_added == true
|
||||
file = Store.add(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
data: new_attachment.content,
|
||||
filename: new_attachment.filename,
|
||||
preferences: new_attachment.preferences,
|
||||
)
|
||||
attachments.push file
|
||||
end
|
||||
|
||||
attachments
|
||||
end
|
||||
|
||||
end
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class TicketArticlesController < ApplicationController
|
||||
include CreatesTicketArticles
|
||||
include ClonesTicketArticleAttachments
|
||||
|
||||
prepend_before_action :authentication_check
|
||||
|
||||
|
@ -210,38 +211,11 @@ class TicketArticlesController < ApplicationController
|
|||
|
||||
# POST /ticket_attachment_upload_clone_by_article
|
||||
def ticket_attachment_upload_clone_by_article
|
||||
|
||||
article = Ticket::Article.find(params[:article_id])
|
||||
access!(article.ticket, 'read')
|
||||
|
||||
raise Exceptions::NotAuthorized, 'Need form_id to attach attachmeints.' if params[:form_id].blank?
|
||||
|
||||
existing_attachments = Store.list(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
).to_a
|
||||
new_attachments = []
|
||||
article.attachments.each do |new_attachment|
|
||||
next if new_attachment.preferences['Content-ID'].present?
|
||||
already_added = false
|
||||
existing_attachments.each do |local_attachment|
|
||||
next if local_attachment.filename != new_attachment.filename || local_attachment.size != new_attachment.size
|
||||
already_added = true
|
||||
break
|
||||
end
|
||||
next if already_added == true
|
||||
file = Store.add(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
data: new_attachment.content,
|
||||
filename: new_attachment.filename,
|
||||
preferences: new_attachment.preferences,
|
||||
)
|
||||
new_attachments.push file
|
||||
end
|
||||
|
||||
render json: {
|
||||
attachments: new_attachments,
|
||||
attachments: article_attachments_clone(article),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class TicketsController < ApplicationController
|
||||
include CreatesTicketArticles
|
||||
include ClonesTicketArticleAttachments
|
||||
include TicketStats
|
||||
|
||||
prepend_before_action :authentication_check
|
||||
|
@ -353,32 +354,13 @@ class TicketsController < ApplicationController
|
|||
access!(ticket, 'read')
|
||||
assets = ticket.assets({})
|
||||
|
||||
# get related articles
|
||||
article = Ticket::Article.find(params[:article_id])
|
||||
access!(article.ticket, 'read')
|
||||
assets = article.assets(assets)
|
||||
|
||||
attachments = []
|
||||
if params[:form_id].present?
|
||||
attachments = Store.list(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
).to_a
|
||||
article.attachments.each do |attachment|
|
||||
next if attachment.preferences['Content-ID'].present?
|
||||
file = Store.add(
|
||||
object: 'UploadCache',
|
||||
o_id: params[:form_id],
|
||||
data: attachment.content,
|
||||
filename: attachment.filename,
|
||||
preferences: attachment.preferences,
|
||||
)
|
||||
attachments.push file
|
||||
end
|
||||
end
|
||||
|
||||
render json: {
|
||||
assets: assets,
|
||||
attachments: attachments,
|
||||
attachments: article_attachments_clone(article),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -141,4 +141,57 @@ class TicketArticleAttachmentsControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
end
|
||||
|
||||
test '01.02 test attachments for split' do
|
||||
headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
|
||||
|
||||
email_raw_string = IO.binread('test/fixtures/mail24.box')
|
||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
||||
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
|
||||
get "/api/v1/ticket_split", params: { form_id: '1234-2', ticket_id: ticket_p.id, article_id: article_p.id }, headers: headers.merge('Authorization' => credentials)
|
||||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert(result['assets'])
|
||||
assert_equal(result['attachments'].class, Array)
|
||||
assert_equal(result['attachments'].count, 1)
|
||||
assert_equal(result['attachments'][0]['filename'], 'rulesets-report.csv')
|
||||
|
||||
end
|
||||
|
||||
test '01.03 test attachments for forward' do
|
||||
headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
|
||||
|
||||
email_raw_string = IO.binread('test/fixtures/mail8.box')
|
||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
||||
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
|
||||
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: {}, headers: headers.merge('Authorization' => credentials)
|
||||
assert_response(422)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result.class, Hash)
|
||||
assert(result['error'], 'Need form_id to attach attachments to new form')
|
||||
|
||||
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: { form_id: '1234-1' }.to_json, headers: headers.merge('Authorization' => credentials)
|
||||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result['attachments'].class, Array)
|
||||
assert(result['attachments'].blank?)
|
||||
|
||||
email_raw_string = IO.binread('test/fixtures/mail24.box')
|
||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
||||
|
||||
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: { form_id: '1234-2' }.to_json, headers: headers.merge('Authorization' => credentials)
|
||||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result['attachments'].class, Array)
|
||||
assert_equal(result['attachments'].count, 1)
|
||||
assert_equal(result['attachments'][0]['filename'], 'rulesets-report.csv')
|
||||
|
||||
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: { form_id: '1234-2' }.to_json, headers: headers.merge('Authorization' => credentials)
|
||||
assert_response(200)
|
||||
result = JSON.parse(@response.body)
|
||||
assert_equal(result['attachments'].class, Array)
|
||||
assert(result['attachments'].blank?)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue