1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134 |
- # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe CoreWorkflow, mariadb: true, type: :model do
- let(:group) { create(:group) }
- let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 5.days.from_now, group: group) }
- let!(:base_payload) do
- {
- 'event' => 'core_workflow',
- 'request_id' => 'default',
- 'class_name' => 'Ticket',
- 'screen' => 'create_middle',
- 'params' => {},
- }
- end
- let(:payload) { base_payload }
- let!(:action_user) { create(:agent, groups: [ticket.group]) }
- let(:result) { described_class.perform(payload: payload, user: action_user) }
- describe '.perform - No assets' do
- let(:result) { described_class.perform(payload: payload, user: action_user, assets: false) }
- it 'does not contain assets' do
- expect(result[:assets]).to be_blank
- end
- end
- describe '.perform - Default - Group' do
- let!(:group_change) { create(:group) }
- let!(:group_create) { create(:group) }
- describe 'for agent with full permissions on screen create_middle' do
- let(:action_user) { create(:agent) }
- before do
- action_user.group_names_access_map = {
- group_create.name => ['full'],
- group_change.name => ['change'],
- }
- end
- it 'does show group_create for agent with all permissions' do
- expect(result[:restrict_values]['group_id']).to include(group_create.id.to_s)
- end
- it 'does not show group_change for agent with all permissions' do
- expect(result[:restrict_values]['group_id']).not_to include(group_change.id.to_s)
- end
- end
- describe 'for agent with full permissions on screen edit' do
- let(:payload) do
- base_payload.merge('screen' => 'edit')
- end
- let(:action_user) { create(:agent) }
- before do
- action_user.group_names_access_map = {
- group_create.name => ['full'],
- group_change.name => ['change'],
- }
- end
- it 'does show group_create for agent with all permissions' do
- expect(result[:restrict_values]['group_id']).to include(group_create.id.to_s)
- end
- it 'does show group_change for agent with all permissions' do
- expect(result[:restrict_values]['group_id']).to include(group_change.id.to_s)
- end
- end
- describe 'for agent with change permissions on screen create_middle' do
- let(:action_user) { create(:agent) }
- before do
- action_user.group_names_access_map = {
- group_create.name => ['change'],
- group_change.name => ['change'],
- }
- end
- it 'does not show group_create for agent with change permissions' do
- expect(result[:restrict_values]['group_id']).not_to include(group_create.id.to_s)
- end
- it 'does not show group_change for agent with change permissions' do
- expect(result[:restrict_values]['group_id']).not_to include(group_change.id.to_s)
- end
- end
- describe 'for agent with change permissions on screen edit' do
- let(:payload) do
- base_payload.merge('screen' => 'edit')
- end
- let(:action_user) { create(:agent) }
- before do
- action_user.group_names_access_map = {
- group_create.name => ['change'],
- group_change.name => ['change'],
- }
- end
- it 'does show group_create for agent with change permissions' do
- expect(result[:restrict_values]['group_id']).to include(group_create.id.to_s)
- end
- it 'does show group_change for agent with change permissions' do
- expect(result[:restrict_values]['group_id']).to include(group_change.id.to_s)
- end
- end
- describe 'for customer on screen create_middle' do
- let(:action_user) { create(:customer) }
- it 'does show group_create for customer' do
- expect(result[:restrict_values]['group_id']).to include(group_create.id.to_s)
- end
- it 'does show group_change for customer' do
- expect(result[:restrict_values]['group_id']).to include(group_change.id.to_s)
- end
- end
- describe 'for customer on screen edit' do
- let(:payload) do
- base_payload.merge('screen' => 'edit')
- end
- let(:action_user) { create(:customer) }
- it 'does show group_create for customer' do
- expect(result[:restrict_values]['group_id']).to include(group_create.id.to_s)
- end
- it 'does show group_change for customer' do
- expect(result[:restrict_values]['group_id']).to include(group_change.id.to_s)
- end
- end
- end
- describe '.perform - Default - Owner' do
- before do
- another_group = create(:group)
- action_user.group_names_access_map = {
- ticket.group.name => ['full'],
- another_group.name => ['full'],
- }
- end
- it 'does not show any owners for no group' do
- expect(result[:restrict_values]['owner_id']).to eq([''])
- end
- describe 'on group' do
- let(:payload) do
- base_payload.merge('params' => { 'group_id' => ticket.group.id })
- end
- it 'does show ticket agent' do
- expect(result[:restrict_values]['owner_id']).to eq(['', action_user.id.to_s])
- end
- end
- describe 'on group save' do
- let(:payload) do
- base_payload.merge('request_id' => 'ChecksCoreWorkflow.validate_workflows', 'params' => { 'group_id' => ticket.group.id })
- end
- it 'does show ticket agent and system user' do
- expect(result[:restrict_values]['owner_id']).to eq(['', '1', action_user.id.to_s])
- end
- end
- end
- describe '.perform - Default - Bulk Owner' do
- let(:payload) do
- base_payload.merge('screen' => 'overview_bulk')
- end
- it 'does not show any owners for no group' do
- expect(result[:restrict_values]['owner_id']).to eq([''])
- end
- describe 'on ticket ids' do
- let(:payload) do
- base_payload.merge('screen' => 'overview_bulk', 'params' => { 'ticket_ids' => ticket.id.to_s })
- end
- it 'does show ticket agent' do
- expect(result[:restrict_values]['owner_id']).to eq(['', action_user.id.to_s])
- end
- end
- describe 'on ticket ids with no group overlap' do
- let(:ticket2) { create(:ticket) }
- let(:payload) do
- base_payload.merge('screen' => 'overview_bulk', 'params' => { 'ticket_ids' => "#{ticket.id},#{ticket2.id}" })
- end
- it 'does not show ticket agent' do
- expect(result[:restrict_values]['owner_id']).to eq([''])
- end
- end
- describe 'on ticket ids with group overlap' do
- let(:ticket2) { create(:ticket, group: ticket.group) }
- let(:payload) do
- base_payload.merge('screen' => 'overview_bulk', 'params' => { 'ticket_ids' => "#{ticket.id},#{ticket2.id}" })
- end
- it 'does show ticket agent' do
- expect(result[:restrict_values]['owner_id']).to eq(['', action_user.id.to_s])
- end
- end
- describe 'Ticket owner selection is not updated if owner selection should be empty #3809' do
- let(:group_no_owners) { create(:group) }
- let(:ticket2) { create(:ticket, group: group_no_owners) }
- let(:payload) do
- base_payload.merge('screen' => 'overview_bulk', 'params' => { 'ticket_ids' => ticket2.id.to_s })
- end
- before do
- action_user.group_names_access_map = {
- group_no_owners.name => %w[create read change overview],
- }
- end
- it 'does not show any owners for group with no full permitted users' do
- expect(result[:restrict_values]['owner_id']).to eq([''])
- end
- end
- end
- describe '.perform - Default - State' do
- it 'does show state type new for create_middle' do
- expect(result[:restrict_values]['state_id']).to include(Ticket::State.find_by(name: 'new').id.to_s)
- end
- describe 'on edit' do
- let(:payload) do
- base_payload.merge('screen' => 'edit')
- end
- it 'does not show state type new' do
- expect(result[:restrict_values]['state_id']).not_to include(Ticket::State.find_by(name: 'new').id.to_s)
- end
- end
- it 'does show empty value for create_middle' do
- expect(result[:restrict_values]['state_id']).to include('')
- end
- context 'with customer user' do
- let(:action_user) { create(:customer) }
- it 'does not show empty value for create_middle' do
- expect(result[:restrict_values]['state_id']).not_to include('')
- end
- end
- end
- describe '.perform - Default - Priority' do
- let(:prio_invalid) { create(:ticket_priority, active: false) }
- it 'does show valid priority' do
- expect(result[:restrict_values]['priority_id']).to include(Ticket::Priority.find_by(name: '3 high').id.to_s)
- end
- it 'does not show invalid priority' do
- expect(result[:restrict_values]['priority_id']).not_to include(prio_invalid.id.to_s)
- end
- end
- describe '.perform - Default - Customer setting customer_ticket_create_group_ids' do
- let(:action_user) { create(:customer) }
- let!(:group1) { create(:group) }
- let!(:group2) { create(:group) }
- let!(:group3) { create(:group) }
- it 'does show group 1' do
- expect(result[:restrict_values]['group_id']).to include(group1.id.to_s)
- end
- context 'with customer_ticket_create_group_ids set' do
- before do
- Setting.set('customer_ticket_create_group_ids', [group2.id.to_s, group3.id.to_s])
- end
- it 'does not show group 1' do
- expect(result[:restrict_values]['group_id']).not_to include(group1.id.to_s)
- end
- end
- end
- describe '.perform - Default - #3721 - Fields are falsey displayed as mandatory if they contain historic screen values', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let(:screens) do
- {
- create_middle: {
- 'ticket.agent' => {
- shown: true,
- },
- },
- }
- end
- before do
- create(:object_manager_attribute_text, object_name: 'Ticket', name: field_name, display: field_name, screens: screens)
- ObjectManager::Attribute.migration_execute
- end
- it 'does show the field as optional because it has no required value' do
- expect(result[:mandatory][field_name]).to be(false)
- end
- end
- describe '.perform - Default - Restrict values for multiselect fields', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- context 'without saved values' do
- it 'does return the correct list of selectable values' do
- expect(result[:restrict_values][field_name]).to eq(['', 'key_1', 'key_2', 'key_3'])
- end
- end
- context 'with saved values' do
- let(:payload) do
- base_payload.merge('params' => {
- 'id' => ticket.id,
- })
- end
- before do
- ticket.reload.update(field_name.to_sym => %w[key_2 key_3])
- end
- it 'does return the correct list of selectable values' do
- expect(result[:restrict_values][field_name]).to eq(['', 'key_1', 'key_2', 'key_3'])
- end
- end
- end
- describe '.perform - Custom - Pending Time' do
- it 'does not show pending time for non pending state' do
- expect(result[:visibility]['pending_time']).to eq('remove')
- end
- describe 'for ticket id with no state change' do
- let(:payload) do
- base_payload.merge('params' => {
- 'id' => ticket.id,
- })
- end
- it 'does show pending time for pending ticket' do
- expect(result[:visibility]['pending_time']).to eq('show')
- end
- end
- describe 'for ticket id with state change' do
- let(:payload) do
- base_payload.merge('params' => {
- 'id' => ticket.id,
- 'state_id' => Ticket::State.find_by(name: 'open').id.to_s,
- })
- end
- it 'does not show pending time for pending ticket' do
- expect(result[:visibility]['pending_time']).to eq('remove')
- end
- end
- end
- describe '.perform - Custom - Admin SLA' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'Sla',
- )
- end
- it 'does set first_response_time_in_text optional' do
- expect(result[:mandatory]['first_response_time_in_text']).to be(false)
- end
- it 'does set update_time_in_text optional' do
- expect(result[:mandatory]['update_time_in_text']).to be(false)
- end
- it 'does set solution_time_in_text optional' do
- expect(result[:mandatory]['solution_time_in_text']).to be(false)
- end
- describe 'on first_response_time_enabled' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'Sla',
- 'params' => { 'first_response_time_enabled' => 'true' }
- )
- end
- it 'does set first_response_time_in_text mandatory' do
- expect(result[:mandatory]['first_response_time_in_text']).to be(true)
- end
- it 'does set update_time_in_text optional' do
- expect(result[:mandatory]['update_time_in_text']).to be(false)
- end
- it 'does set solution_time_in_text optional' do
- expect(result[:mandatory]['solution_time_in_text']).to be(false)
- end
- end
- describe 'on update_time_enabled' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'Sla',
- 'params' => { 'update_time_enabled' => 'true', 'update_type' => 'update' }
- )
- end
- it 'does set first_response_time_in_text optional' do
- expect(result[:mandatory]['first_response_time_in_text']).to be(false)
- end
- it 'does set update_time_in_text mandatory' do
- expect(result[:mandatory]['update_time_in_text']).to be(true)
- end
- it 'does set solution_time_in_text optional' do
- expect(result[:mandatory]['solution_time_in_text']).to be(false)
- end
- end
- describe 'on solution_time_enabled' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'Sla',
- 'params' => { 'solution_time_enabled' => 'true' }
- )
- end
- it 'does set first_response_time_in_text optional' do
- expect(result[:mandatory]['first_response_time_in_text']).to be(false)
- end
- it 'does set update_time_in_text optional' do
- expect(result[:mandatory]['update_time_in_text']).to be(false)
- end
- it 'does set solution_time_in_text mandatory' do
- expect(result[:mandatory]['solution_time_in_text']).to be(true)
- end
- end
- end
- describe '.perform - Custom - Admin CoreWorkflow' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'CoreWorkflow',
- )
- end
- it 'does not show screens for empty object' do
- expect(result[:restrict_values]['preferences::screen']).to eq([''])
- end
- it 'does not show invalid objects' do
- expect(result[:restrict_values]['object']).not_to include('CoreWorkflow')
- end
- describe 'on object Ticket' do
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'CoreWorkflow',
- 'params' => { 'object' => 'Ticket' },
- )
- end
- it 'does show screen create_middle' do
- expect(result[:restrict_values]['preferences::screen']).to include('create_middle')
- end
- it 'does show screen edit' do
- expect(result[:restrict_values]['preferences::screen']).to include('edit')
- end
- end
- describe 'on saved object Ticket' do
- let(:workflow) { create(:core_workflow, object: 'Ticket') }
- let(:payload) do
- base_payload.merge(
- 'screen' => 'edit',
- 'class_name' => 'CoreWorkflow',
- 'params' => { 'id' => workflow.id },
- )
- end
- it 'does show screen create_middle' do
- expect(result[:restrict_values]['preferences::screen']).to include('create_middle')
- end
- it 'does show screen edit' do
- expect(result[:restrict_values]['preferences::screen']).to include('edit')
- end
- end
- end
- describe '.perform - Condition - owner_id not set' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.owner_id': {
- operator: 'not_set',
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for owner id 1' do
- let(:payload) do
- base_payload.merge(
- 'params' => { 'owner_id' => '1' },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.role_ids' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.role_ids': {
- operator: 'is',
- value: [ Role.find_by(name: 'Agent').id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.group_ids_full' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.group_ids_full': {
- operator: 'is',
- value: [ ticket.group.id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.group_ids_change' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.group_ids_change': {
- operator: 'is',
- value: [ ticket.group.id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.group_ids_read' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.group_ids_read': {
- operator: 'is',
- value: [ ticket.group.id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.group_ids_overview' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.group_ids_overview': {
- operator: 'is',
- value: [ ticket.group.id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.group_ids_create' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.group_ids_create': {
- operator: 'is',
- value: [ ticket.group.id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - session.permission_ids' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.permission_ids': {
- operator: 'is',
- value: [ Permission.find_by(name: 'ticket.agent').id.to_s ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for customer' do
- let!(:action_user) { create(:customer) } # rubocop:disable RSpec/LetSetup
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Regex match' do
- let(:payload) do
- base_payload.merge(
- 'params' => { 'title' => 'workflow ticket' },
- )
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.title': {
- operator: 'regex match',
- value: [ '^workflow' ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for invalid regex' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.title': {
- operator: 'regex match',
- value: [ '^workfluw' ],
- },
- })
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Regex mismatch' do
- let(:payload) do
- base_payload.merge(
- 'params' => { 'title' => 'workflow ticket' },
- )
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.title': {
- operator: 'regex mismatch',
- value: [ '^workfluw' ],
- },
- })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- describe 'for invalid regex' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.title': {
- operator: 'regex mismatch',
- value: [ '^workflow' ],
- },
- })
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Contains', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name}": {
- operator: 'contains',
- value: %w[key_1 key_2],
- },
- })
- end
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- context 'when empty' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => [] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when same value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => %w[key_1 key_2] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- context 'when 50% value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_1'] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- context 'when value differs' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_3'] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Contains not', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name}": {
- operator: 'contains not',
- value: %w[key_1 key_2],
- },
- })
- end
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- context 'when empty' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => [] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- context 'when same value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => %w[key_1 key_2] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when 50% value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_1'] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when value differs' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_3'] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Contains all', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name}": {
- operator: 'contains all',
- value: %w[key_1 key_2],
- },
- })
- end
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- context 'when empty' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => [] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when same value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => %w[key_1 key_2] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- context 'when 50% value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_1'] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when value differs' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_3'] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- end
- describe '.perform - Condition - Contains all not', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name}": {
- operator: 'contains all not',
- value: %w[key_1 key_2],
- },
- })
- end
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- context 'when empty' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => [] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- context 'when same value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => %w[key_1 key_2] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when 50% value' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_1'] },
- )
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when value differs' do
- let(:payload) do
- base_payload.merge(
- 'params' => { field_name => ['key_3'] },
- )
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe '.perform - Stop after match' do
- let(:stop_after_match) { false }
- before do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.priority_id': {
- operator: 'show',
- show: 'true'
- },
- },
- stop_after_match: stop_after_match)
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- end
- it 'does not stop' do
- expect(result[:visibility]['priority_id']).to eq('hide')
- end
- describe 'with stop_after_match' do
- let(:stop_after_match) { true }
- it 'does stop' do
- expect(result[:visibility]['priority_id']).to eq('show')
- end
- end
- end
- describe '.perform - Condition - Custom module' do
- let(:modules) { ['CoreWorkflow::Custom::Testa', 'CoreWorkflow::Custom::Testb', 'CoreWorkflow::Custom::Testc'] }
- let(:custom_class_false) do
- Class.new(CoreWorkflow::Custom::Backend) do
- def selected_attribute_match?
- false
- end
- end
- end
- let(:custom_class_true) do
- Class.new(CoreWorkflow::Custom::Backend) do
- def selected_attribute_match?
- true
- end
- end
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'custom.module': {
- operator: operator,
- value: modules,
- },
- })
- end
- describe 'with "match all modules" false' do
- let(:operator) { 'match all modules' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_false
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- describe 'with "match all modules" true' do
- let(:operator) { 'match all modules' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_true
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_true
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_true
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe 'with "match all modules" blank' do
- let(:modules) { [] }
- let(:operator) { 'match all modules' }
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe 'with "match one module" true' do
- let(:operator) { 'match one module' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_true
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe 'with "match one module" false' do
- let(:operator) { 'match one module' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_false
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- describe 'with "match one module" blank' do
- let(:modules) { [] }
- let(:operator) { 'match one module' }
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe 'with "match no modules" true' do
- let(:operator) { 'match no modules' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_false
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_false
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe 'with "match no modules" false' do
- let(:operator) { 'match no modules' }
- before do
- stub_const 'CoreWorkflow::Custom::Testa', custom_class_true
- stub_const 'CoreWorkflow::Custom::Testb', custom_class_true
- stub_const 'CoreWorkflow::Custom::Testc', custom_class_true
- end
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- describe 'with "match no modules" blank' do
- let(:modules) { [] }
- let(:operator) { 'match no modules' }
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe '.perform - Select' do
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- end
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is',
- value: ticket.group.id.to_s
- },
- },
- perform: {
- 'ticket.owner_id': {
- operator: 'select',
- select: [action_user.id.to_s]
- },
- })
- end
- it 'does match workflows' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- it 'does select group' do
- expect(result[:select]['group_id']).to eq(ticket.group.id.to_s)
- end
- it 'does select owner (recursion)' do
- expect(result[:select]['owner_id']).to eq(action_user.id.to_s)
- end
- it 'does rerun 2 times (group select + owner select)' do
- expect(result[:rerun_count]).to eq(2)
- end
- end
- describe '.perform - Auto Select' do
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'auto_select',
- auto_select: true
- },
- })
- end
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is',
- value: ticket.group.id.to_s
- },
- },
- perform: {
- 'ticket.owner_id': {
- operator: 'auto_select',
- auto_select: true
- },
- })
- end
- it 'does match workflows' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- it 'does select group' do
- expect(result[:select]['group_id']).to eq(ticket.group.id.to_s)
- end
- it 'does select owner (recursion)' do
- expect(result[:select]['owner_id']).to eq(action_user.id.to_s)
- end
- it 'does rerun 2 times (group select + owner select)' do
- expect(result[:rerun_count]).to eq(2)
- end
- describe 'with owner' do
- let(:payload) do
- base_payload.merge('params' => {
- 'group_id' => ticket.group.id.to_s,
- 'owner_id' => action_user.id.to_s,
- })
- end
- it 'does not select owner' do
- expect(result[:select]['owner_id']).to be_nil
- end
- it 'does rerun 0 times' do
- expect(result[:rerun_count]).to eq(0)
- end
- end
- end
- describe '.perform - Fill in' do
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- end
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is',
- value: ticket.group.id.to_s
- },
- },
- perform: {
- 'ticket.title': {
- operator: 'fill_in',
- fill_in: 'hello'
- },
- })
- end
- it 'does match workflows' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- it 'does select group' do
- expect(result[:select]['group_id']).to eq(ticket.group.id.to_s)
- end
- it 'does fill in title' do
- expect(result[:fill_in]['title']).to eq('hello')
- end
- it 'does rerun 1 time (group select + title fill in)' do
- expect(result[:rerun_count]).to eq(1)
- end
- end
- describe '.perform - Fill in empty' do
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- end
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is',
- value: ticket.group.id.to_s
- },
- },
- perform: {
- 'ticket.title': {
- operator: 'fill_in_empty',
- fill_in_empty: 'hello'
- },
- })
- end
- it 'does match workflows' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- it 'does select group' do
- expect(result[:select]['group_id']).to eq(ticket.group.id.to_s)
- end
- it 'does fill in title' do
- expect(result[:fill_in]['title']).to eq('hello')
- end
- it 'does rerun 1 time (group select + title fill in)' do
- expect(result[:rerun_count]).to eq(1)
- end
- describe 'with title' do
- let(:payload) do
- base_payload.merge('params' => {
- 'title' => 'ha!',
- })
- end
- it 'does not fill in title' do
- expect(result[:fill_in]['title']).to be_nil
- end
- it 'does rerun 1 times (group select)' do
- expect(result[:rerun_count]).to eq(1)
- end
- end
- end
- describe '.perform - Rerun attributes default cache bug' do
- before do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.owner_id': {
- operator: 'select',
- select: [action_user.id.to_s]
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.owner_id': {
- operator: 'not_set',
- },
- },
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- end
- it 'does not hide priority id' do
- expect(result[:visibility]['priority_id']).to eq('show')
- end
- end
- describe '.perform - Clean up params after restrict values removed selected value by set_fixed_to' do
- let(:payload) do
- base_payload.merge('params' => {
- 'owner_id' => action_user.id,
- })
- end
- before do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.owner_id': {
- operator: 'set_fixed_to',
- set_fixed_to: ['']
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.owner_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- end
- it 'does not allow owner_id' do
- expect(result[:restrict_values]['owner_id']).not_to include(action_user.id)
- end
- it 'does not hide priority id' do
- expect(result[:visibility]['priority_id']).to eq('show')
- end
- end
- describe '.perform - Clean up params after restrict values removed selected value by remove_option' do
- let(:payload) do
- base_payload.merge('params' => {
- 'owner_id' => action_user.id,
- })
- end
- before do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'select',
- select: [ticket.group.id.to_s]
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.group_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.owner_id': {
- operator: 'remove_option',
- remove_option: [action_user.id]
- },
- })
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.owner_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- end
- it 'does not allow owner_id' do
- expect(result[:restrict_values]['owner_id']).not_to include(action_user.id)
- end
- it 'does not hide priority id' do
- expect(result[:visibility]['priority_id']).to eq('show')
- end
- end
- describe '.perform - Clean up params after restrict values removed selected value by default attributes' do
- let(:payload) do
- base_payload.merge('params' => {
- 'owner_id' => action_user.id,
- })
- end
- before do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.owner_id': {
- operator: 'is_set',
- },
- },
- perform: {
- 'ticket.priority_id': {
- operator: 'hide',
- hide: 'true'
- },
- })
- end
- it 'does not allow owner_id' do
- expect(result[:restrict_values]['owner_id']).not_to include(action_user.id)
- end
- it 'does not hide priority id' do
- expect(result[:visibility]['priority_id']).to eq('show')
- end
- end
- describe '.perform - Default - auto selection based on only_shown_if_selectable' do
- it 'does auto select group' do
- expect(result[:select]['group_id']).not_to be_nil
- end
- it 'does auto hide group' do
- expect(result[:visibility]['group_id']).to eq('hide')
- end
- end
- describe '.perform - One field and two perform actions' do
- before do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.owner_id': {
- operator: %w[select set_optional],
- select: [action_user.id.to_s],
- set_optional: 'true',
- },
- })
- end
- it 'does auto select owner' do
- expect(result[:select]['owner_id']).to eq(action_user.id.to_s)
- end
- it 'does set owner optional' do
- expect(result[:mandatory]['owner_id']).to be(false)
- end
- end
- describe '.perform - Hide mobile based on user login' do
- let(:base_payload) do
- {
- 'event' => 'core_workflow',
- 'request_id' => 'default',
- 'class_name' => 'User',
- 'screen' => 'create',
- 'params' => {
- 'login' => 'nicole.special@zammad.org',
- },
- }
- end
- before do
- create(:core_workflow,
- object: 'User',
- condition_selected: { 'user.login'=>{ 'operator' => 'is', 'value' => 'nicole.special@zammad.org' } },
- perform: { 'user.mobile'=>{ 'operator' => 'hide', 'hide' => 'true' } },)
- end
- it 'does hide mobile for user' do
- expect(result[:visibility]['mobile']).to eq('hide')
- end
- end
- describe '.perform - Condition - group active is true' do
- let(:payload) do
- base_payload.merge('params' => {
- 'group_id' => Group.first.id,
- })
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: { 'group.active'=>{ 'operator' => 'is', 'value' => true } })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- describe '.perform - Condition - group.assignment_timeout (Integer) matches' do
- let(:group) { create(:group, assignment_timeout: 10) }
- let(:payload) do
- base_payload.merge('params' => {
- 'group_id' => group.id,
- })
- end
- before do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: { 'group.assignment_timeout'=>{ 'operator' => 'is', 'value' => 10 } },
- perform: { 'ticket.priority_id'=>{ 'operator' => 'hide', 'hide' => 'true' } },)
- end
- it 'does match' do
- expect(result[:visibility]['priority_id']).to eq('hide')
- end
- end
- describe '.perform - Readonly' do
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'set_readonly',
- set_readonly: 'true'
- },
- })
- end
- it 'does match workflow' do
- expect(result[:matched_workflows]).to include(workflow1.id)
- end
- it 'does set group readonly' do
- expect(result[:readonly]['group_id']).to be(true)
- end
- context 'when readonly unset' do
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.group_id': {
- operator: 'unset_readonly',
- unset_readonly: 'true'
- },
- })
- end
- it 'does match workflows' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- it 'does set group readonly' do
- expect(result[:readonly]['group_id']).to be(false)
- end
- end
- end
- describe 'Core Workflow "is not" operator is working unexpected #3752' do
- let(:approval_role) { create(:role) }
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'session.role_ids': {
- operator: 'is_not',
- value: [ approval_role.id.to_s ]
- },
- })
- end
- context 'when not action user has approval role' do
- let(:action_user) { create(:agent, roles: [Role.find_by(name: 'Agent'), approval_role]) }
- it 'does not match' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when action user has not approval role' do
- let(:action_user) { create(:agent) }
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe 'Saved conditions break on selections without reloading #3758', db_strategy: :reset do
- let(:field_name) { SecureRandom.uuid }
- let(:screens) do
- {
- edit: {
- 'ticket.agent' => {
- shown: true,
- },
- },
- }
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_saved: {
- "ticket.#{field_name}": {
- operator: 'is_not',
- value: 'true',
- },
- })
- end
- let(:payload) do
- base_payload.merge('params' => { 'id' => ticket.id }, 'screen' => 'edit')
- end
- before do
- create(:object_manager_attribute_boolean, object_name: 'Ticket', name: field_name, display: field_name, screens: screens)
- ObjectManager::Attribute.migration_execute
- end
- it 'does match the workflow because saved value is false' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- context 'when params contain boolean field true' do
- let(:payload) do
- base_payload.merge('params' => { 'id' => ticket.id, field_name => true }, 'screen' => 'edit')
- end
- it 'does match the workflow because saved value is false' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe 'Core Workflow: Add organization condition attributes for object User #3779' do
- let(:organization) { create(:organization, note: 'hello') }
- let!(:base_payload) do
- {
- 'event' => 'core_workflow',
- 'request_id' => 'default',
- 'class_name' => 'User',
- 'screen' => 'create',
- 'params' => {},
- }
- end
- let!(:workflow) do
- create(:core_workflow,
- object: 'User',
- condition_selected: {
- 'organization.note': {
- operator: 'is',
- value: 'hello',
- },
- })
- end
- context 'when new user has no organization' do
- it 'does not match the workflow' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- context 'when new user is part of the organization' do
- let(:payload) do
- base_payload.merge('params' => { 'organization_id' => organization.id.to_s })
- end
- it 'does match the workflow' do
- expect(result[:matched_workflows]).to include(workflow.id)
- end
- end
- end
- describe 'Ticket owner selection is not updated if owner selection should be empty #3809' do
- let(:group_no_owners) { create(:group) }
- let(:payload) do
- base_payload.merge('params' => { 'group_id' => group_no_owners.id })
- end
- before do
- action_user.group_names_access_map = {
- group_no_owners.name => %w[create read change overview],
- }
- end
- it 'does not show any owners because no one has full permissions' do
- expect(result[:restrict_values]['owner_id']).to eq([''])
- end
- end
- describe 'If selected value is not part of the restriction of set_fixed_to it should recalculate it with the new value #3822', db_strategy: :reset do
- let(:field_name1) { SecureRandom.uuid }
- let(:screens) do
- {
- 'create_middle' => {
- 'ticket.agent' => {
- 'shown' => false,
- 'required' => false,
- }
- }
- }
- end
- let!(:workflow1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: { "ticket.#{field_name1}" => { 'operator' => 'set_fixed_to', 'set_fixed_to' => ['key_3'] } })
- end
- let!(:workflow2) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name1}": {
- operator: 'is',
- value: 'key_3',
- },
- })
- end
- before do
- create(:object_manager_attribute_select, name: field_name1, display: field_name1, screens: screens)
- ObjectManager::Attribute.migration_execute
- end
- it 'does select key_3 as new param value and based on this executes workflow 2' do
- expect(result[:matched_workflows]).to include(workflow1.id, workflow2.id)
- end
- end
- describe 'Add clear selection action or has changed condition #3821' do
- let!(:workflow_has_changed) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.priority_id': {
- operator: 'has_changed',
- },
- })
- end
- let!(:workflow_changed_to) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.priority_id': {
- operator: 'changed_to',
- value: [ Ticket::Priority.find_by(name: '3 high').id.to_s ]
- },
- })
- end
- context 'when priority changed' do
- let(:payload) do
- base_payload.merge('last_changed_attribute' => 'priority_id', 'params' => { 'priority_id' => Ticket::Priority.find_by(name: '3 high').id.to_s })
- end
- it 'does match on condition has changed' do
- expect(result[:matched_workflows]).to include(workflow_has_changed.id)
- end
- it 'does match on condition changed to' do
- expect(result[:matched_workflows]).to include(workflow_changed_to.id)
- end
- end
- context 'when nothing changed' do
- it 'does not match on condition has changed' do
- expect(result[:matched_workflows]).not_to include(workflow_has_changed.id)
- end
- it 'does not match on condition changed to' do
- expect(result[:matched_workflows]).not_to include(workflow_changed_to.id)
- end
- end
- context 'when state changed' do
- let(:payload) do
- base_payload.merge('last_changed_attribute' => 'state_id')
- end
- it 'does not match on condition has changed' do
- expect(result[:matched_workflows]).not_to include(workflow_has_changed.id)
- end
- it 'does not match on condition changed to' do
- expect(result[:matched_workflows]).not_to include(workflow_changed_to.id)
- end
- end
- end
- describe 'Wrong core workflow execution because of missing relation defaults #4541' do
- let!(:workflow) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.priority_id': {
- operator: 'is',
- value: [ Ticket::Priority.find_by(name: '1 low').id.to_s ]
- },
- })
- end
- before do
- Ticket::Priority.find_by(name: '2 normal').update(note: 'Test')
- workflow
- end
- it 'does not execute the core workflow because the default priority is 2 normal and not 1 low' do
- expect(result[:matched_workflows]).not_to include(workflow.id)
- end
- end
- describe 'Core Workflow: Readded options are not usable in conditions #4763' do
- before do
- workflow_1 && workflow_2
- end
- context 'when single value' do
- let(:workflow_1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.priority_id': {
- operator: 'remove_option',
- remove_option: Ticket::Priority.pluck(:id).map(&:to_s),
- },
- })
- end
- let(:workflow_2) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- 'ticket.priority_id': {
- operator: 'add_option',
- add_option: Ticket::Priority.pluck(:id).map(&:to_s),
- },
- })
- end
- let!(:workflow_3) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- 'ticket.priority_id': {
- operator: 'is',
- value: Ticket::Priority.where(name: '3 high').pluck(:id).map(&:to_s),
- },
- })
- end
- let(:payload) do
- base_payload.merge('params' => { 'priority_id' => Ticket::Priority.find_by(name: '3 high').id.to_s })
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow_3.id)
- end
- end
- context 'when multiple value', db_strategy: :reset do
- let(:workflow_1) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- "ticket.#{field_name}": {
- operator: 'remove_option',
- remove_option: ['key_1'],
- },
- })
- end
- let(:workflow_2) do
- create(:core_workflow,
- object: 'Ticket',
- perform: {
- "ticket.#{field_name}": {
- operator: 'add_option',
- add_option: ['key_1'],
- },
- })
- end
- let!(:workflow_3) do
- create(:core_workflow,
- object: 'Ticket',
- condition_selected: {
- "ticket.#{field_name}": {
- operator: 'is',
- value: ['key_1'],
- },
- })
- end
- let(:payload) do
- base_payload.merge('params' => { field_name => ['key_1'] })
- end
- let(:field_name) { SecureRandom.uuid }
- before do
- create(:object_manager_attribute_multiselect, name: field_name, display: field_name)
- ObjectManager::Attribute.migration_execute
- end
- it 'does match' do
- expect(result[:matched_workflows]).to include(workflow_3.id)
- end
- end
- end
- end
|