zoom_spec.rb 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. require 'rails_helper'
  2. RSpec.describe 'Ticket zoom', type: :system do
  3. describe 'owner auto-assignment' do
  4. let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), state: Ticket::State.find_by(name: 'new')) }
  5. let!(:session_user) { User.find_by(login: 'master@example.com') }
  6. context 'for agent disabled' do
  7. before do
  8. Setting.set('ticket_auto_assignment', false)
  9. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  10. Setting.set('ticket_auto_assignment_user_ids_ignore', [])
  11. end
  12. it 'do not assign ticket to current session user' do
  13. refresh
  14. visit "#ticket/zoom/#{ticket.id}"
  15. within(:active_content) do
  16. expect(page).to have_css('select[name=owner_id]')
  17. expect(page).to have_select('owner_id',
  18. selected: '-',
  19. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  20. end
  21. end
  22. end
  23. context 'for agent enabled' do
  24. before do
  25. Setting.set('ticket_auto_assignment', true)
  26. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  27. end
  28. context 'with empty "ticket_auto_assignment_user_ids_ignore"' do
  29. it 'assigns ticket to current session user' do
  30. refresh
  31. visit "#ticket/zoom/#{ticket.id}"
  32. within(:active_content) do
  33. expect(page).to have_css('.content.active select[name=owner_id]')
  34. expect(page).to have_select('owner_id',
  35. selected: session_user.fullname,
  36. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  37. end
  38. end
  39. end
  40. context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do
  41. it 'assigns ticket not to current session user' do
  42. Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id)
  43. refresh
  44. visit "#ticket/zoom/#{ticket.id}"
  45. within(:active_content) do
  46. expect(page).to have_css('select[name=owner_id]')
  47. expect(page).to have_select('owner_id',
  48. selected: '-',
  49. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  50. end
  51. end
  52. end
  53. context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do
  54. it 'assigns ticket not to current session user' do
  55. Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id.to_s)
  56. refresh
  57. visit "#ticket/zoom/#{ticket.id}"
  58. within(:active_content) do
  59. expect(page).to have_css('select[name=owner_id]')
  60. expect(page).to have_select('owner_id',
  61. selected: '-',
  62. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  63. end
  64. end
  65. end
  66. context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do
  67. it 'assigns ticket not to current session user' do
  68. Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id])
  69. refresh
  70. visit "#ticket/zoom/#{ticket.id}"
  71. within(:active_content) do
  72. expect(page).to have_css('select[name=owner_id]')
  73. expect(page).to have_select('owner_id',
  74. selected: '-',
  75. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  76. end
  77. end
  78. end
  79. context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do
  80. it 'assigns ticket not to current session user' do
  81. Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id.to_s])
  82. refresh
  83. visit "#ticket/zoom/#{ticket.id}"
  84. within(:active_content) do
  85. expect(page).to have_css('select[name=owner_id]')
  86. expect(page).to have_select('owner_id',
  87. selected: '-',
  88. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  89. end
  90. end
  91. end
  92. context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do
  93. it 'assigns ticket to current session user' do
  94. Setting.set('ticket_auto_assignment_user_ids_ignore', [99_999, 999_999])
  95. refresh
  96. visit "#ticket/zoom/#{ticket.id}"
  97. within(:active_content) do
  98. expect(page).to have_css('select[name=owner_id]')
  99. expect(page).to have_select('owner_id',
  100. selected: session_user.fullname,
  101. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  102. end
  103. end
  104. end
  105. end
  106. end
  107. context 'when ticket has an attachment' do
  108. let(:group) { Group.find_by(name: 'Users') }
  109. let(:ticket) { create(:ticket, group: group) }
  110. let(:article) { create(:ticket_article, ticket: ticket) }
  111. let(:attachment_name) { 'some_file.txt' }
  112. before do
  113. Store.add(
  114. object: 'Ticket::Article',
  115. o_id: article.id,
  116. data: 'some content',
  117. filename: attachment_name,
  118. preferences: {
  119. 'Content-Type' => 'text/plain',
  120. },
  121. created_by_id: 1,
  122. )
  123. end
  124. context 'article was already forwarded once' do
  125. before do
  126. visit "#ticket/zoom/#{ticket.id}"
  127. within(:active_content) do
  128. find('a[data-type=emailForward]').click
  129. click('.js-reset')
  130. have_no_css('.js-reset')
  131. end
  132. end
  133. it 'adds attachments when forwarding multiple times' do
  134. within(:active_content) do
  135. find('a[data-type=emailForward]').click
  136. end
  137. within('.js-writeArea') do
  138. expect(page).to have_text attachment_name
  139. end
  140. end
  141. end
  142. end
  143. context 'replying' do
  144. context 'Group without signature' do
  145. let(:ticket) { create(:ticket) }
  146. let(:current_user) { create(:agent, password: 'test', groups: [ticket.group]) }
  147. before do
  148. # initial article to reply to
  149. create(:ticket_article, ticket: ticket)
  150. end
  151. it 'ensures that text input opens on multiple replies', authenticated_as: :current_user do
  152. visit "ticket/zoom/#{ticket.id}"
  153. 2.times do |article_offset|
  154. articles_existing = 1
  155. articles_expected = articles_existing + (article_offset + 1)
  156. all('a[data-type=emailReply]').last.click
  157. # wait till input box expands completely
  158. find('.attachmentPlaceholder-label').in_fixed_postion
  159. expect(page).not_to have_css('.attachmentPlaceholder-hint', wait: 0)
  160. find('.articleNewEdit-body').send_keys('Some reply')
  161. click '.js-submit'
  162. expect(page).to have_css('.ticket-article-item', count: articles_expected)
  163. end
  164. end
  165. end
  166. end
  167. describe 'delete article', authenticated_as: :user do
  168. let(:admin) { create :admin, groups: [Group.first] }
  169. let(:agent) { create :agent, groups: [Group.first] }
  170. let(:other_agent) { create :agent, groups: [Group.first] }
  171. let(:customer) { create :customer }
  172. let(:ticket) { create :ticket, group: agent.groups.first, customer: customer }
  173. let(:article) { send(item) }
  174. def article_communication
  175. create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer)
  176. end
  177. def article_note_self
  178. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: user)
  179. end
  180. def article_note_other
  181. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: other_agent)
  182. end
  183. def article_note_customer
  184. create_ticket_article(sender_name: 'Customer', internal: false, type_name: 'note', updated_by: customer)
  185. end
  186. def article_note_communication_self
  187. create(:ticket_article_type, name: 'note_communication', communication: true)
  188. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: user)
  189. end
  190. def article_note_communication_other
  191. create(:ticket_article_type, name: 'note_communication', communication: true)
  192. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: other_agent)
  193. end
  194. def create_ticket_article(sender_name:, internal:, type_name:, updated_by:)
  195. create(:ticket_article,
  196. sender_name: sender_name, internal: internal, type_name: type_name, ticket: ticket,
  197. body: "to be deleted #{offset} #{item}",
  198. updated_by_id: updated_by.id, created_by_id: updated_by.id,
  199. created_at: offset.ago, updated_at: offset.ago)
  200. end
  201. context 'going through full stack' do
  202. context 'as admin' do
  203. let(:user) { admin }
  204. let(:item) { 'article_note_self' }
  205. let(:offset) { 0.minutes }
  206. it 'succeeds' do
  207. refresh # make sure user roles are loaded
  208. ensure_websocket do
  209. visit "ticket/zoom/#{ticket.id}"
  210. end
  211. within :active_ticket_article, article, wait: 15 do
  212. click '.js-ArticleAction[data-type=delete]'
  213. end
  214. in_modal do
  215. click '.js-submit'
  216. end
  217. wait.until_disappears { find :active_ticket_article, article, wait: false }
  218. end
  219. end
  220. end
  221. context 'verifying permissions matrix' do
  222. shared_examples 'according to permission matrix' do |item:, expects_visible:, offset:, description:|
  223. context "looking at #{description} #{item}" do
  224. let(:item) { item }
  225. let!(:article) { send(item) }
  226. let(:offset) { offset }
  227. let(:matcher) { expects_visible ? :have_css : :have_no_css }
  228. it expects_visible ? 'delete button is visible' : 'delete button is not visible' do
  229. refresh # make sure user roles are loaded
  230. visit "ticket/zoom/#{ticket.id}"
  231. within :active_ticket_article, article, wait: 15 do
  232. expect(page).to send(matcher, '.js-ArticleAction[data-type=delete]', wait: 0)
  233. end
  234. end
  235. end
  236. end
  237. shared_examples 'deleting ticket article' do |item:, now:, later:, much_later:|
  238. include_examples 'according to permission matrix', item: item, expects_visible: now, offset: 0.minutes, description: 'just created'
  239. include_examples 'according to permission matrix', item: item, expects_visible: later, offset: 6.minutes, description: 'few minutes old'
  240. include_examples 'according to permission matrix', item: item, expects_visible: much_later, offset: 11.minutes, description: 'very old'
  241. end
  242. context 'as admin' do
  243. let(:user) { admin }
  244. include_examples 'deleting ticket article',
  245. item: 'article_communication',
  246. now: false, later: false, much_later: false
  247. include_examples 'deleting ticket article',
  248. item: 'article_note_self',
  249. now: true, later: true, much_later: false
  250. include_examples 'deleting ticket article',
  251. item: 'article_note_other',
  252. now: false, later: false, much_later: false
  253. include_examples 'deleting ticket article',
  254. item: 'article_note_customer',
  255. now: false, later: false, much_later: false
  256. include_examples 'deleting ticket article',
  257. item: 'article_note_communication_self',
  258. now: false, later: false, much_later: false
  259. include_examples 'deleting ticket article',
  260. item: 'article_note_communication_other',
  261. now: false, later: false, much_later: false
  262. end
  263. context 'as agent' do
  264. let(:user) { agent }
  265. include_examples 'deleting ticket article',
  266. item: 'article_communication',
  267. now: false, later: false, much_later: false
  268. include_examples 'deleting ticket article',
  269. item: 'article_note_self',
  270. now: true, later: true, much_later: false
  271. include_examples 'deleting ticket article',
  272. item: 'article_note_other',
  273. now: false, later: false, much_later: false
  274. include_examples 'deleting ticket article',
  275. item: 'article_note_customer',
  276. now: false, later: false, much_later: false
  277. include_examples 'deleting ticket article',
  278. item: 'article_note_communication_self',
  279. now: false, later: false, much_later: false
  280. include_examples 'deleting ticket article',
  281. item: 'article_note_communication_other',
  282. now: false, later: false, much_later: false
  283. end
  284. context 'as customer' do
  285. let(:user) { customer }
  286. include_examples 'deleting ticket article',
  287. item: 'article_communication',
  288. now: false, later: false, much_later: false
  289. include_examples 'deleting ticket article',
  290. item: 'article_note_customer',
  291. now: false, later: false, much_later: false
  292. end
  293. context 'with custom offset' do
  294. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 6000 }
  295. context 'as admin' do
  296. let(:user) { admin }
  297. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 5000.seconds, description: 'outside of delete timeframe'
  298. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: false, offset: 8000.seconds, description: 'outside of delete timeframe'
  299. end
  300. context 'as agent' do
  301. let(:user) { agent }
  302. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 5000.seconds, description: 'outside of delete timeframe'
  303. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: false, offset: 8000.seconds, description: 'outside of delete timeframe'
  304. end
  305. end
  306. context 'with timeframe as 0' do
  307. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 0 }
  308. context 'as agent' do
  309. let(:user) { agent }
  310. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 99.days, description: 'long after'
  311. end
  312. end
  313. end
  314. context 'button is hidden on the go' do
  315. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 5 }
  316. let(:user) { agent }
  317. let(:item) { 'article_note_self' }
  318. let!(:article) { send(item) }
  319. let(:offset) { 0.seconds }
  320. it 'successfully' do
  321. refresh # make sure user roles are loaded
  322. visit "ticket/zoom/#{ticket.id}"
  323. within :active_ticket_article, article do
  324. find '.js-ArticleAction[data-type=delete]' # make sure delete button did show up
  325. expect(page).to have_no_css('.js-ArticleAction[data-type=delete]', wait: 15)
  326. end
  327. end
  328. end
  329. end
  330. context 'S/MIME active', authenticated_as: :authenticate do
  331. let(:system_email_address) { 'smime1@example.com' }
  332. let(:email_address) { create(:email_address, email: system_email_address) }
  333. let(:group) { create(:group, email_address: email_address) }
  334. let(:agent_groups) { [group] }
  335. let(:agent) { create(:agent, groups: agent_groups) }
  336. let(:sender_email_address) { 'smime2@example.com' }
  337. let(:customer) { create(:customer, email: sender_email_address) }
  338. let!(:ticket) { create(:ticket, group: group, owner: agent, customer: customer) }
  339. def authenticate
  340. Setting.set('smime_integration', true)
  341. agent
  342. end
  343. context 'received mail' do
  344. context 'article meta information' do
  345. context 'success' do
  346. it 'shows encryption/sign information' do
  347. create(:ticket_article, preferences: {
  348. security: {
  349. type: 'S/MIME',
  350. encryption: {
  351. success: true,
  352. comment: 'COMMENT_ENCRYPT_SUCCESS',
  353. },
  354. sign: {
  355. success: true,
  356. comment: 'COMMENT_SIGN_SUCCESS',
  357. },
  358. }
  359. }, ticket: ticket)
  360. visit "#ticket/zoom/#{ticket.id}"
  361. expect(page).to have_css('svg.icon-lock')
  362. expect(page).to have_css('svg.icon-signed')
  363. open_article_meta
  364. expect(page).to have_css('span', text: 'Encrypted')
  365. expect(page).to have_css('span', text: 'Signed')
  366. expect(page).to have_css('span[title=COMMENT_ENCRYPT_SUCCESS]')
  367. expect(page).to have_css('span[title=COMMENT_SIGN_SUCCESS]')
  368. end
  369. end
  370. context 'error' do
  371. it 'shows create information about encryption/sign failed' do
  372. create(:ticket_article, preferences: {
  373. security: {
  374. type: 'S/MIME',
  375. encryption: {
  376. success: false,
  377. comment: 'Encryption failed because XXX',
  378. },
  379. sign: {
  380. success: false,
  381. comment: 'Sign failed because XXX',
  382. },
  383. }
  384. }, ticket: ticket)
  385. visit "#ticket/zoom/#{ticket.id}"
  386. expect(page).to have_css('svg.icon-not-signed')
  387. open_article_meta
  388. expect(page).to have_css('div.alert.alert--warning', text: 'Encryption failed because XXX')
  389. expect(page).to have_css('div.alert.alert--warning', text: 'Sign failed because XXX')
  390. end
  391. end
  392. end
  393. context 'certificate not present at time of arrival' do
  394. it 'retry' do
  395. smime1 = create(:smime_certificate, :with_private, fixture: system_email_address)
  396. smime2 = create(:smime_certificate, :with_private, fixture: sender_email_address)
  397. mail = Channel::EmailBuild.build(
  398. from: sender_email_address,
  399. to: system_email_address,
  400. body: 'somebody with some text',
  401. content_type: 'text/plain',
  402. security: {
  403. type: 'S/MIME',
  404. sign: {
  405. success: true,
  406. },
  407. encryption: {
  408. success: true,
  409. },
  410. },
  411. )
  412. smime1.destroy
  413. smime2.destroy
  414. parsed_mail = Channel::EmailParser.new.parse(mail.to_s)
  415. ticket, article, _user, _mail = Channel::EmailParser.new.process({ group_id: group.id }, parsed_mail['raw'])
  416. expect(Ticket::Article.find(article.id).body).to eq('no visible content')
  417. create(:smime_certificate, fixture: sender_email_address)
  418. create(:smime_certificate, :with_private, fixture: system_email_address)
  419. visit "#ticket/zoom/#{ticket.id}"
  420. expect(page).not_to have_css('.article-content', text: 'somebody with some text')
  421. click '.js-securityRetryProcess'
  422. expect(page).to have_css('.article-content', text: 'somebody with some text')
  423. end
  424. end
  425. end
  426. context 'replying', authenticated_as: :setup_and_authenticate do
  427. def setup_and_authenticate
  428. create(:ticket_article, ticket: ticket, from: customer.email)
  429. create(:smime_certificate, :with_private, fixture: system_email_address)
  430. create(:smime_certificate, fixture: sender_email_address)
  431. authenticate
  432. end
  433. it 'plain' do
  434. visit "#ticket/zoom/#{ticket.id}"
  435. all('a[data-type=emailReply]').last.click
  436. find('.articleNewEdit-body').send_keys('Test')
  437. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  438. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  439. click '.js-securityEncrypt'
  440. click '.js-securitySign'
  441. click '.js-submit'
  442. expect(page).to have_css('.ticket-article-item', count: 2)
  443. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be nil
  444. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be nil
  445. end
  446. it 'signed' do
  447. visit "#ticket/zoom/#{ticket.id}"
  448. all('a[data-type=emailReply]').last.click
  449. find('.articleNewEdit-body').send_keys('Test')
  450. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  451. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  452. click '.js-securityEncrypt'
  453. click '.js-submit'
  454. expect(page).to have_css('.ticket-article-item', count: 2)
  455. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be nil
  456. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be true
  457. end
  458. it 'encrypted' do
  459. visit "#ticket/zoom/#{ticket.id}"
  460. all('a[data-type=emailReply]').last.click
  461. find('.articleNewEdit-body').send_keys('Test')
  462. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  463. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  464. click '.js-securitySign'
  465. click '.js-submit'
  466. expect(page).to have_css('.ticket-article-item', count: 2)
  467. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be true
  468. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be nil
  469. end
  470. it 'signed and encrypted' do
  471. visit "#ticket/zoom/#{ticket.id}"
  472. all('a[data-type=emailReply]').last.click
  473. find('.articleNewEdit-body').send_keys('Test')
  474. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  475. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  476. click '.js-submit'
  477. expect(page).to have_css('.ticket-article-item', count: 2)
  478. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be true
  479. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be true
  480. end
  481. end
  482. context 'Group default behavior' do
  483. let(:smime_config) { {} }
  484. def authenticate
  485. Setting.set('smime_integration', true)
  486. Setting.set('smime_config', smime_config)
  487. create(:ticket_article, ticket: ticket, from: customer.email)
  488. create(:smime_certificate, :with_private, fixture: system_email_address)
  489. create(:smime_certificate, fixture: sender_email_address)
  490. agent
  491. end
  492. shared_examples 'security defaults example' do |sign:, encrypt:|
  493. it "security defaults sign: #{sign}, encrypt: #{encrypt}" do
  494. within(:active_content) do
  495. encrypt_button = find('.js-securityEncrypt', wait: 5)
  496. sign_button = find('.js-securitySign', wait: 5)
  497. await_empty_ajax_queue
  498. active_button_class = '.btn--active'
  499. expect(encrypt_button.matches_css?(active_button_class, wait: 2)).to be(encrypt)
  500. expect(sign_button.matches_css?(active_button_class, wait: 2)).to be(sign)
  501. end
  502. end
  503. end
  504. shared_examples 'security defaults' do |sign:, encrypt:|
  505. before do
  506. visit "#ticket/zoom/#{ticket.id}"
  507. within(:active_content) do
  508. all('a[data-type=emailReply]').last.click
  509. find('.articleNewEdit-body').send_keys('Test')
  510. await_empty_ajax_queue
  511. end
  512. end
  513. include_examples 'security defaults example', sign: sign, encrypt: encrypt
  514. end
  515. shared_examples 'security defaults group change' do |sign:, encrypt:|
  516. before do
  517. visit "#ticket/zoom/#{ticket.id}"
  518. within(:active_content) do
  519. all('a[data-type=emailReply]').last.click
  520. find('.articleNewEdit-body').send_keys('Test')
  521. await_empty_ajax_queue
  522. select new_group.name, from: 'group_id'
  523. end
  524. end
  525. include_examples 'security defaults example', sign: sign, encrypt: encrypt
  526. end
  527. context 'not configured' do
  528. it_behaves_like 'security defaults', sign: true, encrypt: true
  529. end
  530. context 'configuration present' do
  531. let(:smime_config) do
  532. {
  533. 'group_id' => group_defaults
  534. }
  535. end
  536. let(:group_defaults) do
  537. {
  538. 'default_encryption' => {
  539. group.id.to_s => default_encryption,
  540. },
  541. 'default_sign' => {
  542. group.id.to_s => default_sign,
  543. }
  544. }
  545. end
  546. let(:default_sign) { true }
  547. let(:default_encryption) { true }
  548. shared_examples 'sign and encrypt variations' do |check_examples_name|
  549. it_behaves_like check_examples_name, sign: true, encrypt: true
  550. context 'no value' do
  551. let(:group_defaults) { {} }
  552. it_behaves_like check_examples_name, sign: true, encrypt: true
  553. end
  554. context 'signing disabled' do
  555. let(:default_sign) { false }
  556. it_behaves_like check_examples_name, sign: false, encrypt: true
  557. end
  558. context 'encryption disabled' do
  559. let(:default_encryption) { false }
  560. it_behaves_like check_examples_name, sign: true, encrypt: false
  561. end
  562. end
  563. context 'same Group' do
  564. it_behaves_like 'sign and encrypt variations', 'security defaults'
  565. end
  566. context 'Group change' do
  567. let(:new_group) { create(:group, email_address: email_address) }
  568. let(:agent_groups) { [group, new_group] }
  569. let(:group_defaults) do
  570. {
  571. 'default_encryption' => {
  572. new_group.id.to_s => default_encryption,
  573. },
  574. 'default_sign' => {
  575. new_group.id.to_s => default_sign,
  576. }
  577. }
  578. end
  579. it_behaves_like 'sign and encrypt variations', 'security defaults group change'
  580. end
  581. end
  582. end
  583. end
  584. describe 'linking Knowledge Base answer' do
  585. include_context 'basic Knowledge Base'
  586. let(:ticket) { create :ticket, group: Group.find_by(name: 'Users') }
  587. let(:answer) { published_answer }
  588. let(:translation) { answer.translations.first }
  589. shared_examples 'verify linking' do
  590. it 'allows to look up an answer' do
  591. visit "#ticket/zoom/#{ticket.id}"
  592. within :active_content do
  593. within '.link_kb_answers' do
  594. find('.js-add').click
  595. find('.js-input').send_keys translation.title
  596. find(%(li[data-value="#{translation.id}"])).click
  597. expect(find('.link_kb_answers ol')).to have_text translation.title
  598. end
  599. end
  600. end
  601. end
  602. context 'with ES', searchindex: true, authenticated_as: :authenticate do
  603. def authenticate
  604. configure_elasticsearch(required: true, rebuild: true) do
  605. answer
  606. end
  607. true
  608. end
  609. include_examples 'verify linking'
  610. end
  611. context 'without ES', authenticated_as: :authenticate do
  612. def authenticate
  613. answer
  614. true
  615. end
  616. include_examples 'verify linking'
  617. end
  618. end
  619. end