2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Ticket Article Attachments', type: :request do
|
|
|
|
|
2019-02-04 06:56:18 +00:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:agent) do
|
|
|
|
create(:agent, groups: [Group.lookup(name: 'Users'), group])
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does test attachment urls' do
|
2019-02-04 06:56:18 +00:00
|
|
|
ticket1 = create(:ticket, group: group)
|
2018-09-19 13:54:49 +00:00
|
|
|
article1 = create(:ticket_article, ticket_id: ticket1.id)
|
|
|
|
|
|
|
|
store1 = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: 'some content',
|
|
|
|
filename: 'some_file.txt',
|
|
|
|
preferences: {
|
2018-09-19 13:54:49 +00:00
|
|
|
'Content-Type' => 'text/plain',
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
article2 = create(:ticket_article, ticket_id: ticket1.id)
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", params: {}
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect('some content').to eq(@response.body)
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket1.id}/#{article2.id}/#{store1.id}", params: {}
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2021-05-12 11:37:44 +00:00
|
|
|
expect(@response.body).to match(%r{403: Forbidden})
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2019-02-04 06:56:18 +00:00
|
|
|
ticket2 = create(:ticket, group: group)
|
2018-09-19 13:54:49 +00:00
|
|
|
ticket1.merge_to(
|
|
|
|
ticket_id: ticket2.id,
|
|
|
|
user_id: 1,
|
|
|
|
)
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket2.id}/#{article1.id}/#{store1.id}", params: {}
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect('some content').to eq(@response.body)
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket2.id}/#{article2.id}/#{store1.id}", params: {}
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2021-05-12 11:37:44 +00:00
|
|
|
expect(@response.body).to match(%r{403: Forbidden})
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
# allow access via merged ticket id also
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", params: {}
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect('some content').to eq(@response.body)
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get "/api/v1/ticket_attachment/#{ticket1.id}/#{article2.id}/#{store1.id}", params: {}
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2021-05-12 11:37:44 +00:00
|
|
|
expect(@response.body).to match(%r{403: Forbidden})
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does test attachments for split' do
|
2020-02-18 19:51:31 +00:00
|
|
|
email_file_path = Rails.root.join('test/data/mail/mail024.box')
|
2018-09-19 13:54:49 +00:00
|
|
|
email_raw_string = File.read(email_file_path)
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get '/api/v1/ticket_split', params: { form_id: '1234-2', ticket_id: ticket_p.id, article_id: article_p.id }, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['assets']).to be_truthy
|
|
|
|
expect(json_response['attachments']).to be_a_kind_of(Array)
|
|
|
|
expect(json_response['attachments'].count).to eq(1)
|
|
|
|
expect(json_response['attachments'][0]['filename']).to eq('rulesets-report.csv')
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does test attachments for forward' do
|
2020-02-18 19:51:31 +00:00
|
|
|
email_file_path = Rails.root.join('test/data/mail/mail008.box')
|
2018-09-19 13:54:49 +00:00
|
|
|
email_raw_string = File.read(email_file_path)
|
2019-06-28 11:38:49 +00:00
|
|
|
_ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: {}, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['error']).to eq('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' }, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['attachments']).to be_a_kind_of(Array)
|
|
|
|
expect(json_response['attachments']).to be_blank
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
email_file_path = Rails.root.join('test/data/mail/mail024.box')
|
2018-09-19 13:54:49 +00:00
|
|
|
email_raw_string = File.read(email_file_path)
|
2019-06-28 11:38:49 +00:00
|
|
|
_ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: { form_id: '1234-2' }, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['attachments']).to be_a_kind_of(Array)
|
|
|
|
expect(json_response['attachments'].count).to eq(1)
|
|
|
|
expect(json_response['attachments'][0]['filename']).to eq('rulesets-report.csv')
|
|
|
|
|
|
|
|
post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: { form_id: '1234-2' }, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['attachments']).to be_a_kind_of(Array)
|
|
|
|
expect(json_response['attachments']).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|