123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe 'Ticket Article API endpoints', type: :request do
- let(:admin) do
- create(:admin, groups: Group.all)
- end
- let!(:group) { create(:group) }
- let(:agent) do
- create(:agent, groups: Group.all)
- end
- let(:customer) do
- create(:customer)
- end
- describe 'request handling' do
- it 'does ticket create with agent and articles' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: 'some body',
- }
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- params = {
- ticket_id: json_response['id'],
- content_type: 'text/plain', # or text/html
- body: 'some body',
- type: 'note',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['ticket_id'])
- expect(ticket.articles.count).to eq(2)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- params = {
- ticket_id: json_response['ticket_id'],
- content_type: 'text/html', # or text/html
- body: 'some body <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
- AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
- 9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />',
- type: 'note',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).not_to match(%r{some body <img src="cid:.+?})
- expect(json_response['body']).to match(%r{some body <img src="/api/v1/ticket_attachment/.+?" alt="Red dot"})
- expect(json_response['content_type']).to eq('text/html')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket.articles.reload
- expect(ticket.articles.count).to eq(3)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- expect(ticket.articles[2].attachments.count).to eq(1)
- expect(ticket.articles[2].attachments[0]['id']).to be_truthy
- expect(ticket.articles[2].attachments[0]['filename']).to eq('image1.png')
- expect(ticket.articles[2].attachments[0]['size']).to eq('21')
- expect(ticket.articles[2].attachments[0]['preferences']['Mime-Type']).to eq('image/png')
- expect(ticket.articles[2].attachments[0]['preferences']['Content-Disposition']).to eq('inline')
- expect(ticket.articles[2].attachments[0]['preferences']['Content-ID']).to match(%r{@zammad.example.com})
- params = {
- ticket_id: json_response['ticket_id'],
- content_type: 'text/html', # or text/html
- body: 'some body',
- type: 'note',
- attachments: [
- { 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=',
- 'mime-type' => 'text/plain' },
- ],
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/html')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket.articles.reload
- expect(ticket.articles.count).to eq(4)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- expect(ticket.articles[2].attachments.count).to eq(1)
- expect(ticket.articles[3].attachments.count).to eq(1)
- get "/api/v1/ticket_articles/#{json_response['id']}?expand=true", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['attachments'].count).to eq(1)
- expect(json_response['attachments'][0]['id']).to be_truthy
- expect(json_response['attachments'][0]['filename']).to eq('some_file.txt')
- expect(json_response['attachments'][0]['size']).to eq('8')
- expect(json_response['attachments'][0]['preferences']['Mime-Type']).to eq('text/plain')
- params = {
- ticket_id: json_response['ticket_id'],
- content_type: 'text/plain',
- body: 'some body',
- type: 'note',
- internal: false,
- preferences: {
- some_key1: 123,
- highlight: '123',
- },
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body')
- expect(json_response['internal']).to be(false)
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- expect(json_response['preferences']['some_key1']).to eq(123)
- expect(json_response['preferences']['highlight']).to eq('123')
- expect(ticket.articles.count).to eq(5)
- params = {
- body: 'some body 2',
- internal: true,
- preferences: {
- some_key2: 'abc',
- highlight: '234',
- },
- }
- put "/api/v1/ticket_articles/#{json_response['id']}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).not_to eq('some body 2')
- expect(json_response['internal']).to be(true)
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- expect(json_response['preferences']['some_key1']).to eq(123)
- expect(json_response['preferences']['some_key2']).not_to eq('abc')
- expect(json_response['preferences']['highlight']).to eq('234')
- end
- it 'does ticket create with customer and articles' do
- params = {
- title: 'a new ticket #2',
- group: 'Users',
- article: {
- body: 'some body',
- }
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- params = {
- ticket_id: json_response['id'],
- content_type: 'text/plain', # or text/html
- body: 'some body',
- type: 'note',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- ticket = Ticket.find(json_response['ticket_id'])
- expect(ticket.articles.count).to eq(2)
- expect(ticket.articles[1].sender.name).to eq('Customer')
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- params = {
- ticket_id: json_response['ticket_id'],
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Agent',
- type: 'note',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- ticket.articles.reload
- ticket = Ticket.find(json_response['ticket_id'])
- expect(ticket.articles.count).to eq(3)
- expect(ticket.articles[2].sender.name).to eq('Customer')
- expect(ticket.articles[2].internal).to be(false)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- expect(ticket.articles[2].attachments.count).to eq(0)
- params = {
- ticket_id: json_response['ticket_id'],
- content_type: 'text/plain', # or text/html
- body: 'some body 2',
- sender: 'Agent',
- type: 'note',
- internal: true,
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['subject']).to be_nil
- expect(json_response['body']).to eq('some body 2')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- ticket.articles.reload
- ticket = Ticket.find(json_response['ticket_id'])
- expect(ticket.articles.count).to eq(4)
- expect(ticket.articles[3].sender.name).to eq('Customer')
- expect(ticket.articles[3].internal).to be(false)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- expect(ticket.articles[2].attachments.count).to eq(0)
- expect(ticket.articles[3].attachments.count).to eq(0)
- # add internal article
- article = create(
- :ticket_article,
- ticket_id: ticket.id,
- internal: true,
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- type: Ticket::Article::Type.find_by(name: 'note'),
- )
- ticket.articles.reload
- expect(ticket.articles.count).to eq(5)
- expect(ticket.articles[4].sender.name).to eq('Agent')
- expect(ticket.articles[4].updated_by_id).to eq(1)
- expect(ticket.articles[4].created_by_id).to eq(1)
- expect(ticket.articles[0].attachments.count).to eq(0)
- expect(ticket.articles[1].attachments.count).to eq(0)
- expect(ticket.articles[2].attachments.count).to eq(0)
- expect(ticket.articles[3].attachments.count).to eq(0)
- expect(ticket.articles[4].attachments.count).to eq(0)
- get "/api/v1/ticket_articles/#{article.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a(Hash)
- expect(json_response['error']).to eq('Not authorized')
- put "/api/v1/ticket_articles/#{article.id}", params: { internal: false }, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a(Hash)
- expect(json_response['error']).to eq('Not authorized')
- end
- it 'does create phone ticket for customer and expected origin_by_id' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: 'some body',
- sender: 'Customer',
- type: 'phone',
- }
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(json_response['title']).to eq('a new ticket #1')
- expect(Ticket::Article.where(ticket_id: json_response['id']).count).to eq(2) # original + auto responder
- article = Ticket::Article.where(ticket_id: json_response['id']).first
- expect(article.origin_by_id).to eq(customer.id)
- expect(article.from).to be_in(
- [
- "#{customer.firstname} #{customer.lastname} <#{customer.email}>",
- "\"#{customer.firstname} #{customer.lastname}\" <#{customer.email}>"
- ]
- )
- end
- it 'does create phone ticket by customer and manipulate origin_by_id' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: 'some body',
- sender: 'Customer',
- type: 'phone',
- origin_by_id: 1,
- }
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a(Hash)
- expect(Ticket::Article.where(ticket_id: json_response['id']).count).to eq(1) # ony original
- article = Ticket::Article.where(ticket_id: json_response['id']).first
- expect(article.origin_by_id).to eq(customer.id)
- end
- it 'does ticket split with html - check attachments' do
- ticket = create(:ticket, group: group)
- article = create(
- :ticket_article,
- ticket_id: ticket.id,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- body: '<b>test</b> <img src="cid:15.274327094.140938@ZAMMAD.example.com"/> test <img src="cid:15.274327094.140938.3@ZAMMAD.example.com"/>',
- content_type: 'text/html',
- )
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file1.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938@zammad.example.com',
- 'Content-Disposition' => 'inline',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file2_normally_should_be_an_image',
- filename: 'some_file2.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.2@zammad.example.com',
- 'Content-Disposition' => 'inline',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file3_normally_should_be_an_image',
- filename: 'some_file3.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.3@zammad.example.com',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file4_normally_should_be_an_image',
- filename: 'some_file4.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.4@zammad.example.com',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_pdf',
- filename: 'Rechnung_RE-2018-200.pdf',
- preferences: {
- 'Content-Type' => 'application/octet-stream; name="Rechnung_RE-2018-200.pdf"',
- 'Mime-Type' => 'application/octet-stream',
- 'Content-ID' => '8AB0BEC88984EE4EBEF643C79C8E0346@zammad.example.com',
- 'Content-Description' => 'Rechnung_RE-2018-200.pdf',
- 'Content-Disposition' => 'attachment',
- })
- params = {
- form_id: 'b47ea422-1b96-49db-8399-aeffaa0e3fc9',
- }
- authenticated_as(agent)
- post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(3)
- post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(0)
- end
- it 'does ticket split with plain - check attachments' do
- ticket = create(
- :ticket,
- group: group,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- article = create(
- :ticket_article,
- ticket_id: ticket.id,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- body: '<b>test</b> <img src="cid:15.274327094.140938@zammad.example.com"/>',
- content_type: 'text/plain',
- updated_by_id: 1,
- created_by_id: 1,
- )
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file1.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938@zammad.example.com',
- 'Content-Disposition' => 'inline',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file2.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.2@zammad.example.com',
- 'Content-Disposition' => 'inline',
- })
- create(:store,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_pdf',
- filename: 'Rechnung_RE-2018-200.pdf',
- preferences: {
- 'Content-Type' => 'application/octet-stream; name="Rechnung_RE-2018-200.pdf"',
- 'Mime-Type' => 'application/octet-stream',
- 'Content-ID' => '8AB0BEC88984EE4EBEF643C79C8E0346@zammad.example.com',
- 'Content-Description' => 'Rechnung_RE-2018-200.pdf',
- 'Content-Disposition' => 'attachment',
- })
- params = {
- form_id: 'b47ea422-1b96-49db-8399-aeffaa0e3fc9',
- }
- authenticated_as(agent)
- post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(3)
- post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a(Hash)
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(0)
- end
- it 'does ticket create with mentions' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: "some body <a data-mention-user-id=\"#{agent.id}\">agent</a>",
- }
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(Mention.where(mentionable: Ticket.last).count).to eq(1)
- end
- it 'does not ticket create with invalid mentions' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: "some body <a data-mention-user-id=\"#{create(:customer).id}\">customer</a>",
- }
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(Mention.count).to eq(0)
- end
- it 'does not ticket create with mentions when customer' do
- params = {
- title: 'a new ticket #1',
- group: 'Users',
- customer_id: customer.id,
- article: {
- body: "some body <a data-mention-user-id=\"#{agent.id}\">agent</a>",
- }
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(Mention.count).to eq(0)
- end
- end
- describe 'DELETE /api/v1/ticket_articles/:id', authenticated_as: -> { user } do
- let(:other_agent) { create(:agent, groups: [Group.first]) }
- let(:ticket) do
- create(:ticket, group: Group.first)
- end
- let(:article_communication) do
- create(:ticket_article,
- sender_name: 'Agent', type_name: 'email', ticket: ticket,
- updated_by_id: agent.id, created_by_id: agent.id)
- end
- let(:article_note_self) do
- create(:ticket_article,
- sender_name: 'Agent', internal: true, type_name: 'note', ticket: ticket,
- updated_by_id: user.id, created_by_id: user.id)
- end
- let(:article_note_other) do
- create(:ticket_article,
- sender_name: 'Agent', internal: true, type_name: 'note', ticket: ticket,
- updated_by_id: other_agent.id, created_by_id: other_agent.id)
- end
- let(:article_note_customer) do
- create(:ticket_article,
- sender_name: 'Customer', internal: false, type_name: 'note', ticket: ticket,
- updated_by_id: customer.id, created_by_id: customer.id)
- end
- let(:article_note_communication_self) do
- create(:ticket_article_type, name: 'note_communication', communication: true)
- create(:ticket_article,
- sender_name: 'Agent', internal: true, type_name: 'note_communication', ticket: ticket,
- updated_by_id: user.id, created_by_id: user.id)
- end
- let(:article_note_communication_other) do
- create(:ticket_article_type, name: 'note_communication', communication: true)
- create(:ticket_article,
- sender_name: 'Agent', internal: true, type_name: 'note_communication', ticket: ticket,
- updated_by_id: other_agent.id, created_by_id: other_agent.id)
- end
- def delete_article_via_rest(article)
- delete "/api/v1/ticket_articles/#{article.id}", params: {}, as: :json
- end
- shared_examples 'succeeds' do
- it 'succeeds' do
- expect { delete_article_via_rest(article) }.to change { Ticket::Article.exists?(id: article.id) }
- end
- end
- shared_examples 'fails' do
- it 'fails' do
- expect { delete_article_via_rest(article) }.not_to change { Ticket::Article.exists?(id: article.id) }
- end
- end
- shared_examples 'deleting' do |item:, now:, later:, much_later:|
- context "deleting #{item}" do
- let(:article) { send(item) }
- include_examples now ? 'succeeds' : 'fails'
- context '8 minutes later' do
- before { article && travel(8.minutes) }
- include_examples later ? 'succeeds' : 'fails'
- end
- context '11 minutes later' do
- before { article && travel(11.minutes) }
- include_examples much_later ? 'succeeds' : 'fails'
- end
- end
- end
- context 'as admin' do
- let(:user) { admin }
- include_examples 'deleting',
- item: 'article_communication',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_self',
- now: true, later: true, much_later: false
- include_examples 'deleting',
- item: 'article_note_other',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_customer',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_self',
- now: true, later: true, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_other',
- now: false, later: false, much_later: false
- end
- context 'as agent' do
- let(:user) { agent }
- include_examples 'deleting',
- item: 'article_communication',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_self',
- now: true, later: true, much_later: false
- include_examples 'deleting',
- item: 'article_note_other',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_customer',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_self',
- now: true, later: true, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_other',
- now: false, later: false, much_later: false
- end
- context 'as customer' do
- let(:user) { customer }
- include_examples 'deleting',
- item: 'article_communication',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_other',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_customer',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_self',
- now: false, later: false, much_later: false
- include_examples 'deleting',
- item: 'article_note_communication_other',
- now: false, later: false, much_later: false
- end
- context 'with custom timeframe' do
- before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 6000 }
- let(:article) { article_note_self }
- context 'as admin' do
- let(:user) { admin }
- context 'deleting before timeframe' do
- before { article && travel(5000.seconds) }
- include_examples 'succeeds'
- end
- context 'deleting after timeframe' do
- before { article && travel(8000.seconds) }
- include_examples 'fails'
- end
- end
- context 'as agent' do
- let(:user) { agent }
- context 'deleting before timeframe' do
- before { article && travel(5000.seconds) }
- include_examples 'succeeds'
- end
- context 'deleting after timeframe' do
- before { article && travel(8000.seconds) }
- include_examples 'fails'
- end
- end
- end
- context 'with timeframe as 0' do
- before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 0 }
- let(:article) { article_note_self }
- context 'as agent' do
- let(:user) { agent }
- context 'deleting long after' do
- before { article && travel(99.days) }
- include_examples 'succeeds'
- end
- end
- end
- end
- end
|