ticket_trigger_recursive_disabled_test.rb 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290
  1. require 'test_helper'
  2. class TicketTriggerRecursiveDisabledTest < ActiveSupport::TestCase
  3. setup do
  4. Setting.set('ticket_trigger_recursive', false)
  5. end
  6. test '1 basic' do
  7. Trigger.create_or_update(
  8. name: 'aaa loop check',
  9. condition: {
  10. 'article.subject' => {
  11. 'operator' => 'contains',
  12. 'value' => 'Thanks for your inquiry',
  13. },
  14. },
  15. perform: {
  16. 'ticket.tags' => {
  17. 'operator' => 'add',
  18. 'value' => 'should_not_loop',
  19. },
  20. 'notification.email' => {
  21. 'body' => 'some lala',
  22. 'recipient' => 'ticket_customer',
  23. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  24. },
  25. },
  26. disable_notification: true,
  27. active: true,
  28. created_by_id: 1,
  29. updated_by_id: 1,
  30. )
  31. Trigger.create_or_update(
  32. name: 'auto reply',
  33. condition: {
  34. 'ticket.action' => {
  35. 'operator' => 'is',
  36. 'value' => 'create',
  37. },
  38. 'ticket.state_id' => {
  39. 'operator' => 'is',
  40. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  41. }
  42. },
  43. perform: {
  44. 'notification.email' => {
  45. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  46. 'recipient' => 'ticket_customer',
  47. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  48. },
  49. 'ticket.priority_id' => {
  50. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  51. },
  52. 'ticket.tags' => {
  53. 'operator' => 'add',
  54. 'value' => 'aa, kk',
  55. },
  56. },
  57. disable_notification: true,
  58. active: true,
  59. created_by_id: 1,
  60. updated_by_id: 1,
  61. )
  62. Trigger.create_or_update(
  63. name: 'auto tag 1',
  64. condition: {
  65. 'ticket.action' => {
  66. 'operator' => 'is',
  67. 'value' => 'update',
  68. },
  69. 'ticket.state_id' => {
  70. 'operator' => 'is',
  71. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  72. }
  73. },
  74. perform: {
  75. 'ticket.priority_id' => {
  76. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  77. },
  78. 'ticket.tags' => {
  79. 'operator' => 'remove',
  80. 'value' => 'kk',
  81. },
  82. },
  83. disable_notification: true,
  84. active: true,
  85. created_by_id: 1,
  86. updated_by_id: 1,
  87. )
  88. Trigger.create_or_update(
  89. name: 'auto tag 2',
  90. condition: {
  91. 'ticket.state_id' => {
  92. 'operator' => 'is',
  93. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  94. }
  95. },
  96. perform: {
  97. 'ticket.tags' => {
  98. 'operator' => 'add',
  99. 'value' => 'abc',
  100. },
  101. },
  102. disable_notification: true,
  103. active: true,
  104. created_by_id: 1,
  105. updated_by_id: 1,
  106. )
  107. Trigger.create_or_update(
  108. name: 'not matching',
  109. condition: {
  110. 'ticket.state_id' => {
  111. 'operator' => 'is',
  112. 'value' => Ticket::State.lookup(name: 'closed').id.to_s,
  113. }
  114. },
  115. perform: {
  116. 'ticket.priority_id' => {
  117. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  118. },
  119. },
  120. disable_notification: true,
  121. active: true,
  122. created_by_id: 1,
  123. updated_by_id: 1,
  124. )
  125. Trigger.create_or_update(
  126. name: 'zzz last',
  127. condition: {
  128. 'article.subject' => {
  129. 'operator' => 'contains',
  130. 'value' => 'some subject 1234',
  131. },
  132. },
  133. perform: {
  134. 'ticket.tags' => {
  135. 'operator' => 'add',
  136. 'value' => 'article_create_trigger',
  137. },
  138. 'notification.email' => {
  139. 'body' => 'some lala',
  140. 'recipient' => 'ticket_customer',
  141. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  142. },
  143. },
  144. disable_notification: true,
  145. active: true,
  146. created_by_id: 1,
  147. updated_by_id: 1,
  148. )
  149. ticket1 = Ticket.create!(
  150. title: "some <b>title</b>\n äöüß",
  151. group: Group.lookup(name: 'Users'),
  152. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  153. updated_by_id: 1,
  154. created_by_id: 1,
  155. )
  156. Ticket::Article.create!(
  157. ticket_id: ticket1.id,
  158. from: 'some_sender@example.com',
  159. to: 'some_recipient@example.com',
  160. subject: 'some subject',
  161. message_id: 'some@id',
  162. body: "some message <b>note</b>\nnew line",
  163. internal: false,
  164. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  165. type: Ticket::Article::Type.find_by(name: 'note'),
  166. updated_by_id: 1,
  167. created_by_id: 1,
  168. )
  169. ticket1.reload
  170. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  171. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  172. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  173. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  174. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  175. assert_equal([], ticket1.tag_list)
  176. Observer::Transaction.commit
  177. ticket1.reload
  178. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  179. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  180. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  181. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  182. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  183. assert_equal(%w[aa kk abc], ticket1.tag_list)
  184. article1 = ticket1.articles.last
  185. assert_match('Zammad <zammad@localhost>', article1.from)
  186. assert_match('nicole.braun@zammad.org', article1.to)
  187. assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
  188. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article1.body)
  189. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article1.body)
  190. assert_equal('text/html', article1.content_type)
  191. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  192. ticket1.save!
  193. Observer::Transaction.commit
  194. ticket1.reload
  195. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  196. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  197. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  198. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  199. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  200. assert_equal(%w[aa kk abc], ticket1.tag_list)
  201. ticket1.state = Ticket::State.lookup(name: 'open')
  202. ticket1.save!
  203. Observer::Transaction.commit
  204. ticket1.reload
  205. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  206. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  207. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  208. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  209. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  210. assert_equal(%w[aa kk abc], ticket1.tag_list)
  211. ticket1.state = Ticket::State.lookup(name: 'new')
  212. ticket1.save!
  213. Observer::Transaction.commit
  214. ticket1.reload
  215. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  216. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  217. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  218. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  219. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  220. assert_equal(%w[aa abc], ticket1.tag_list)
  221. ticket2 = Ticket.create!(
  222. title: "some title\n äöüß",
  223. group: Group.lookup(name: 'Users'),
  224. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  225. state: Ticket::State.lookup(name: 'open'),
  226. priority: Ticket::Priority.lookup(name: '2 normal'),
  227. updated_by_id: 1,
  228. created_by_id: 1,
  229. )
  230. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  231. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  232. assert_equal('open', ticket2.state.name, 'ticket2.state verify')
  233. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  234. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  235. assert_equal([], ticket2.tag_list)
  236. Observer::Transaction.commit
  237. ticket2.reload
  238. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  239. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  240. assert_equal('open', ticket2.state.name, 'ticket2.state verify')
  241. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  242. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  243. assert_equal([], ticket2.tag_list)
  244. ticket3 = Ticket.create!(
  245. title: "some <b>title</b>\n äöüß3",
  246. group: Group.lookup(name: 'Users'),
  247. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  248. updated_by_id: 1,
  249. created_by_id: 1,
  250. )
  251. assert(ticket3, 'ticket3 created')
  252. Ticket::Article.create!(
  253. ticket_id: ticket3.id,
  254. from: 'some_sender@example.com',
  255. to: 'some_recipient@example.com',
  256. subject: 'some subject 1234',
  257. message_id: 'some@id',
  258. content_type: 'text/html',
  259. body: 'some message <b>note</b><br>new line',
  260. internal: false,
  261. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  262. type: Ticket::Article::Type.find_by(name: 'note'),
  263. updated_by_id: 1,
  264. created_by_id: 1,
  265. )
  266. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  267. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  268. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  269. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  270. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  271. assert_equal([], ticket3.tag_list)
  272. Observer::Transaction.commit
  273. ticket3.reload
  274. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  275. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  276. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  277. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  278. assert_equal(3, ticket3.articles.count, 'ticket3.articles verify')
  279. assert_equal(%w[aa kk abc article_create_trigger], ticket3.tag_list)
  280. article3 = ticket3.articles[1]
  281. assert_match('Zammad <zammad@localhost>', article3.from)
  282. assert_match('nicole.braun@zammad.org', article3.to)
  283. assert_match('Thanks for your inquiry (some <b>title</b> äöüß3)!', article3.subject)
  284. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article3.body)
  285. assert_match('&gt; some message note<br>&gt; new line', article3.body)
  286. assert_no_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article3.body)
  287. assert_equal('text/html', article3.content_type)
  288. article3 = ticket3.articles[2]
  289. assert_match('Zammad <zammad@localhost>', article3.from)
  290. assert_match('nicole.braun@zammad.org', article3.to)
  291. assert_match('Thanks for your inquiry - 1234 check (some <b>title</b> äöüß3)!', article3.subject)
  292. assert_equal('text/html', article3.content_type)
  293. Ticket::Article.create!(
  294. ticket_id: ticket3.id,
  295. from: 'some_sender@example.com',
  296. to: 'some_recipient@example.com',
  297. subject: 'some subject - not 1234',
  298. message_id: 'some@id',
  299. content_type: 'text/html',
  300. body: 'some message <b>note</b><br>new line',
  301. internal: false,
  302. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  303. type: Ticket::Article::Type.find_by(name: 'note'),
  304. updated_by_id: 1,
  305. created_by_id: 1,
  306. )
  307. Observer::Transaction.commit
  308. ticket3.reload
  309. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  310. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  311. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  312. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  313. assert_equal(4, ticket3.articles.count, 'ticket3.articles verify')
  314. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  315. Ticket::Article.create!(
  316. ticket_id: ticket3.id,
  317. from: 'some_sender@example.com',
  318. to: 'some_recipient@example.com',
  319. subject: 'some subject NOT 1234',
  320. message_id: 'some@id',
  321. content_type: 'text/html',
  322. body: 'some message <b>note</b><br>new line',
  323. internal: false,
  324. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  325. type: Ticket::Article::Type.find_by(name: 'note'),
  326. updated_by_id: 1,
  327. created_by_id: 1,
  328. )
  329. Observer::Transaction.commit
  330. ticket3.reload
  331. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  332. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  333. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  334. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  335. assert_equal(5, ticket3.articles.count, 'ticket3.articles verify')
  336. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  337. Ticket::Article.create!(
  338. ticket_id: ticket3.id,
  339. from: 'some_sender@example.com',
  340. to: 'some_recipient@example.com',
  341. subject: 'some subject 1234',
  342. message_id: 'some@id',
  343. content_type: 'text/html',
  344. body: 'some message <b>note</b><br>new line',
  345. internal: false,
  346. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  347. type: Ticket::Article::Type.find_by(name: 'note'),
  348. updated_by_id: 1,
  349. created_by_id: 1,
  350. )
  351. Observer::Transaction.commit
  352. ticket3.reload
  353. assert_equal('some <b>title</b> äöüß3', ticket3.title, 'ticket3.title verify')
  354. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  355. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  356. assert_equal('3 high', ticket3.priority.name, 'ticket3.priority verify')
  357. assert_equal(7, ticket3.articles.count, 'ticket3.articles verify')
  358. assert_equal(%w[aa abc article_create_trigger], ticket3.tag_list)
  359. end
  360. test '2 actions - create' do
  361. Trigger.create_or_update(
  362. name: 'auto reply',
  363. condition: {
  364. 'ticket.action' => {
  365. 'operator' => 'is',
  366. 'value' => 'create',
  367. },
  368. 'ticket.state_id' => {
  369. 'operator' => 'is',
  370. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  371. }
  372. },
  373. perform: {
  374. 'notification.email' => {
  375. 'body' => 'dasdasdasd',
  376. 'recipient' => 'ticket_customer',
  377. 'subject' => 'asdasdas',
  378. },
  379. 'ticket.priority_id' => {
  380. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  381. },
  382. },
  383. disable_notification: true,
  384. active: true,
  385. created_by_id: 1,
  386. updated_by_id: 1,
  387. )
  388. ticket1 = Ticket.create!(
  389. title: "some title\n äöüß",
  390. group: Group.lookup(name: 'Users'),
  391. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  392. updated_by_id: 1,
  393. created_by_id: 1,
  394. )
  395. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  396. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  397. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  398. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  399. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  400. Observer::Transaction.commit
  401. ticket1.reload
  402. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  403. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  404. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  405. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  406. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  407. article1 = ticket1.articles.last
  408. assert_match('Zammad <zammad@localhost>', article1.from)
  409. assert_match('nicole.braun@zammad.org', article1.to)
  410. assert_match('asdasdas', article1.subject)
  411. assert_match('dasdasdasd', article1.body)
  412. assert_equal('text/html', article1.content_type)
  413. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  414. ticket1.save!
  415. Observer::Transaction.commit
  416. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  417. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  418. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  419. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  420. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  421. ticket1.state = Ticket::State.lookup(name: 'open')
  422. ticket1.save!
  423. Observer::Transaction.commit
  424. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  425. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  426. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  427. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  428. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  429. ticket1.state = Ticket::State.lookup(name: 'new')
  430. ticket1.save!
  431. Observer::Transaction.commit
  432. ticket1.reload
  433. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  434. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  435. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  436. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  437. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  438. end
  439. test '2 actions - update' do
  440. Trigger.create_or_update(
  441. name: 'auto reply',
  442. condition: {
  443. 'ticket.action' => {
  444. 'operator' => 'is',
  445. 'value' => 'update',
  446. },
  447. 'ticket.state_id' => {
  448. 'operator' => 'is',
  449. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  450. }
  451. },
  452. perform: {
  453. 'notification.email' => {
  454. 'body' => 'dasdasdasd',
  455. 'recipient' => 'ticket_customer',
  456. 'subject' => 'asdasdas',
  457. },
  458. 'ticket.priority_id' => {
  459. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  460. },
  461. },
  462. disable_notification: true,
  463. active: true,
  464. created_by_id: 1,
  465. updated_by_id: 1,
  466. )
  467. ticket1 = Ticket.create!(
  468. title: "some title\n äöüß",
  469. group: Group.lookup(name: 'Users'),
  470. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  471. updated_by_id: 1,
  472. created_by_id: 1,
  473. )
  474. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  475. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  476. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  477. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  478. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  479. Observer::Transaction.commit
  480. ticket1.reload
  481. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  482. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  483. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  484. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  485. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  486. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  487. ticket1.save!
  488. Observer::Transaction.commit
  489. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  490. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  491. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  492. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  493. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  494. ticket1.state = Ticket::State.lookup(name: 'open')
  495. ticket1.save!
  496. Observer::Transaction.commit
  497. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  498. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  499. assert_equal('open', ticket1.state.name, 'ticket1.state verify')
  500. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  501. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  502. ticket1.state = Ticket::State.lookup(name: 'new')
  503. ticket1.save!
  504. Observer::Transaction.commit
  505. ticket1.reload
  506. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  507. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  508. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  509. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  510. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  511. end
  512. test '3 auto replys' do
  513. roles = Role.where(name: 'Customer')
  514. User.create_or_update(
  515. login: 'postmaster@example.com',
  516. firstname: 'Trigger',
  517. lastname: 'Customer1',
  518. email: 'postmaster@example.com',
  519. password: 'customerpw',
  520. active: true,
  521. roles: roles,
  522. updated_at: '2015-02-05 16:37:00',
  523. updated_by_id: 1,
  524. created_by_id: 1,
  525. )
  526. User.create_or_update(
  527. login: 'ticket-auto-reply-customer2@example.com',
  528. firstname: 'Trigger',
  529. lastname: 'Customer2',
  530. email: 'ticket-auto-reply-customer2@example.com',
  531. password: 'customerpw',
  532. active: true,
  533. organization_id: nil,
  534. roles: roles,
  535. updated_at: '2015-02-05 16:37:00',
  536. updated_by_id: 1,
  537. created_by_id: 1,
  538. )
  539. Trigger.create_or_update(
  540. name: 'auto reply - new ticket',
  541. condition: {
  542. 'ticket.action' => {
  543. 'operator' => 'is',
  544. 'value' => 'create',
  545. },
  546. 'ticket.state_id' => {
  547. 'operator' => 'is not',
  548. 'value' => Ticket::State.lookup(name: 'closed').id,
  549. },
  550. 'article.type_id' => {
  551. 'operator' => 'is',
  552. 'value' => [
  553. Ticket::Article::Type.lookup(name: 'email').id,
  554. Ticket::Article::Type.lookup(name: 'phone').id,
  555. Ticket::Article::Type.lookup(name: 'web').id,
  556. ],
  557. },
  558. },
  559. perform: {
  560. 'notification.email' => {
  561. 'body' => '<p>Your request (Ticket##{ticket.number}) has been received and will be reviewed by our support staff.<p>
  562. <br/>
  563. <p>To provide additional information, please reply to this email or click on the following link:
  564. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  565. </p>
  566. <br/>
  567. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  568. 'recipient' => 'ticket_customer',
  569. 'subject' => 'Thanks for your inquiry (#{ticket.title})',
  570. },
  571. },
  572. disable_notification: true,
  573. active: true,
  574. created_by_id: 1,
  575. updated_by_id: 1,
  576. )
  577. Trigger.create_or_update(
  578. name: 'auto reply (on follow-up of tickets)',
  579. condition: {
  580. 'ticket.action' => {
  581. 'operator' => 'is',
  582. 'value' => 'update',
  583. },
  584. 'article.sender_id' => {
  585. 'operator' => 'is',
  586. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  587. },
  588. 'article.type_id' => {
  589. 'operator' => 'is',
  590. 'value' => [
  591. Ticket::Article::Type.lookup(name: 'email').id,
  592. Ticket::Article::Type.lookup(name: 'phone').id,
  593. Ticket::Article::Type.lookup(name: 'web').id,
  594. ],
  595. },
  596. },
  597. perform: {
  598. 'notification.email' => {
  599. 'body' => '<p>Your follow-up for (#{config.ticket_hook}##{ticket.number}) has been received and will be reviewed by our support staff.<p>
  600. <br/>
  601. <p>To provide additional information, please reply to this email or click on the following link:
  602. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  603. </p>
  604. <br/>
  605. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  606. 'recipient' => 'ticket_customer',
  607. 'subject' => 'Thanks for your follow-up (#{ticket.title})',
  608. },
  609. },
  610. active: true,
  611. created_by_id: 1,
  612. updated_by_id: 1,
  613. )
  614. Trigger.create_or_update(
  615. name: 'not matching',
  616. condition: {
  617. 'ticket.action' => {
  618. 'operator' => 'is',
  619. 'value' => 'create',
  620. },
  621. 'ticket.state_id' => {
  622. 'operator' => 'is',
  623. 'value' => Ticket::State.lookup(name: 'closed').id.to_s,
  624. }
  625. },
  626. perform: {
  627. 'notification.email' => {
  628. 'body' => '2some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  629. 'recipient' => 'ticket_customer',
  630. 'subject' => '2Thanks for your inquiry (#{ticket.title})!',
  631. },
  632. },
  633. disable_notification: true,
  634. active: true,
  635. created_by_id: 1,
  636. updated_by_id: 1,
  637. )
  638. # process mail without Precedence header
  639. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  640. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  641. assert_equal('aaäöüßad asd', ticket_p.title)
  642. assert_equal('Users', ticket_p.group.name)
  643. assert_equal('new', ticket_p.state.name)
  644. assert_equal(2, ticket_p.articles.count)
  645. article_p = ticket_p.articles.last
  646. assert_match('Thanks for your inquiry (aaäöüßad asd)', article_p.subject)
  647. assert_match('Zammad <zammad@localhost>', article_p.from)
  648. assert_no_match('config\.', article_p.body)
  649. assert_match('http://zammad.example.com', article_p.body)
  650. assert_no_match('ticket.', article_p.body)
  651. assert_match(ticket_p.number, article_p.body)
  652. assert_equal('text/html', article_p.content_type)
  653. ticket_p.priority = Ticket::Priority.lookup(name: '2 normal')
  654. ticket_p.save!
  655. Observer::Transaction.commit
  656. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  657. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  658. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  659. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  660. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  661. Ticket::Article.create!(
  662. ticket_id: ticket_p.id,
  663. from: 'some_sender@example.com',
  664. to: 'some_recipient@example.com',
  665. subject: 'some subject',
  666. message_id: 'some@id',
  667. body: 'some message note',
  668. internal: false,
  669. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  670. type: Ticket::Article::Type.find_by(name: 'note'),
  671. updated_by_id: 1,
  672. created_by_id: 1,
  673. )
  674. Observer::Transaction.commit
  675. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  676. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  677. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  678. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  679. assert_equal(3, ticket_p.articles.count, 'ticket_p.articles verify')
  680. Ticket::Article.create!(
  681. ticket_id: ticket_p.id,
  682. from: 'some_sender@example.com',
  683. to: 'some_recipient@example.com',
  684. subject: 'some subject',
  685. message_id: 'some@id',
  686. body: 'some message note',
  687. internal: false,
  688. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  689. type: Ticket::Article::Type.find_by(name: 'email'),
  690. updated_by_id: 1,
  691. created_by_id: 1,
  692. )
  693. Observer::Transaction.commit
  694. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  695. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  696. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  697. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  698. assert_equal(4, ticket_p.articles.count, 'ticket_p.articles verify')
  699. Ticket::Article.create!(
  700. ticket_id: ticket_p.id,
  701. from: 'some_sender@example.com',
  702. to: 'some_recipient@example.com',
  703. subject: 'some subject',
  704. message_id: 'some@id',
  705. body: 'some message note',
  706. internal: false,
  707. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  708. type: Ticket::Article::Type.find_by(name: 'email'),
  709. updated_by_id: 1,
  710. created_by_id: 1,
  711. )
  712. Observer::Transaction.commit
  713. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  714. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  715. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  716. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  717. assert_equal(6, ticket_p.articles.count, 'ticket_p.articles verify')
  718. article_p = ticket_p.articles.last
  719. assert_match('Thanks for your follow-up (aaäöüßad asd)', article_p.subject)
  720. assert_match('Zammad <zammad@localhost>', article_p.from)
  721. assert_no_match('config\.', article_p.body)
  722. assert_match('http://zammad.example.com', article_p.body)
  723. assert_no_match('ticket.', article_p.body)
  724. assert_match(ticket_p.number, article_p.body)
  725. assert_equal('text/html', article_p.content_type)
  726. ticket_p.state = Ticket::State.lookup(name: 'open')
  727. ticket_p.save!
  728. Ticket::Article.create!(
  729. ticket_id: ticket_p.id,
  730. from: 'some_sender@example.com',
  731. to: 'some_recipient@example.com',
  732. subject: 'some subject',
  733. message_id: 'some@id',
  734. body: 'some message note',
  735. internal: false,
  736. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  737. type: Ticket::Article::Type.find_by(name: 'email'),
  738. updated_by_id: 1,
  739. created_by_id: 1,
  740. )
  741. Observer::Transaction.commit
  742. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  743. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  744. assert_equal('open', ticket_p.state.name, 'ticket_p.state verify')
  745. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  746. assert_equal(8, ticket_p.articles.count, 'ticket_p.articles verify')
  747. article_p = ticket_p.articles.last
  748. assert_match('Thanks for your follow-up (aaäöüßad asd)', article_p.subject)
  749. assert_match('Zammad <zammad@localhost>', article_p.from)
  750. assert_no_match('config\.', article_p.body)
  751. assert_match('http://zammad.example.com', article_p.body)
  752. assert_no_match('ticket.', article_p.body)
  753. assert_match(ticket_p.number, article_p.body)
  754. assert_equal('text/html', article_p.content_type)
  755. # process mail without Precedence header
  756. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  757. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  758. assert_equal('new', ticket_p.state.name)
  759. assert_equal(2, ticket_p.articles.count)
  760. # process mail with Precedence header (no auto response)
  761. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail2.box'))
  762. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  763. assert_equal('new', ticket_p.state.name)
  764. assert_equal(1, ticket_p.articles.count)
  765. # process mail with abuse@ (no auto response)
  766. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail3.box'))
  767. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  768. assert_equal('new', ticket_p.state.name)
  769. assert_equal(1, ticket_p.articles.count)
  770. end
  771. test '4 has changed' do
  772. roles = Role.where(name: 'Customer')
  773. User.create_or_update(
  774. login: 'postmaster@example.com',
  775. firstname: 'Trigger',
  776. lastname: 'Customer1',
  777. email: 'postmaster@example.com',
  778. password: 'customerpw',
  779. active: true,
  780. roles: roles,
  781. updated_at: '2015-02-05 16:37:00',
  782. updated_by_id: 1,
  783. created_by_id: 1,
  784. )
  785. User.create_or_update(
  786. login: 'ticket-has-changed-customer2@example.com',
  787. firstname: 'Trigger',
  788. lastname: 'Customer2',
  789. email: 'ticket-has-changed-customer2@example.com',
  790. password: 'customerpw',
  791. active: true,
  792. organization_id: nil,
  793. roles: roles,
  794. updated_at: '2015-02-05 16:37:00',
  795. updated_by_id: 1,
  796. created_by_id: 1,
  797. )
  798. groups = Group.where(name: 'Users')
  799. roles = Role.where(name: 'Agent')
  800. agent1 = User.create_or_update(
  801. login: 'agent-has-changed@example.com',
  802. firstname: 'Has Changed',
  803. lastname: 'Agent1',
  804. email: 'agent-has-changed@example.com',
  805. password: 'agentpw',
  806. active: true,
  807. roles: roles,
  808. groups: groups,
  809. updated_at: '2015-02-05 16:37:00',
  810. updated_by_id: 1,
  811. created_by_id: 1,
  812. )
  813. Trigger.create_or_update(
  814. name: 'owner update - to customer',
  815. condition: {
  816. 'ticket.owner_id' => {
  817. 'operator' => 'has changed',
  818. 'pre_condition' => 'current_user.id',
  819. 'value' => '',
  820. 'value_completion' => '',
  821. }
  822. },
  823. perform: {
  824. 'notification.email' => {
  825. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  826. <br/>
  827. <p>To provide additional information, please reply to this email or click on the following link:
  828. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  829. </p>
  830. <br/>
  831. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  832. 'recipient' => 'ticket_customer',
  833. 'subject' => 'Owner has changed (#{ticket.title})',
  834. },
  835. },
  836. disable_notification: true,
  837. active: true,
  838. created_by_id: 1,
  839. updated_by_id: 1,
  840. )
  841. # process mail without Precedence header
  842. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  843. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  844. assert_equal('aaäöüßad asd', ticket_p.title)
  845. assert_equal('Users', ticket_p.group.name)
  846. assert_equal('new', ticket_p.state.name)
  847. assert_equal(1, ticket_p.articles.count)
  848. Observer::Transaction.commit
  849. ticket_p.owner = agent1
  850. ticket_p.save!
  851. Observer::Transaction.commit
  852. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  853. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  854. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  855. assert_equal('2 normal', ticket_p.priority.name, 'ticket_p.priority verify')
  856. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  857. #p ticket_p.articles.last.inspect
  858. article_p = ticket_p.articles.last
  859. assert_match('Owner has changed', article_p.subject)
  860. assert_match('Zammad <zammad@localhost>', article_p.from)
  861. assert_match('martin@example.com', article_p.to)
  862. assert_no_match('config\.', article_p.body)
  863. assert_match('http://zammad.example.com', article_p.body)
  864. assert_no_match('ticket.', article_p.body)
  865. assert_match(ticket_p.number, article_p.body)
  866. assert_equal('text/html', article_p.content_type)
  867. Trigger.create_or_update(
  868. name: 'owner update - to customer',
  869. condition: {
  870. 'ticket.owner_id' => {
  871. 'operator' => 'has changed',
  872. 'pre_condition' => 'current_user.id',
  873. 'value' => '',
  874. 'value_completion' => '',
  875. },
  876. 'ticket.priority_id' => {
  877. 'operator' => 'is',
  878. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  879. },
  880. },
  881. perform: {
  882. 'notification.email' => {
  883. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  884. <br/>
  885. <p>To provide additional information, please reply to this email or click on the following link:
  886. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  887. </p>
  888. <br/>
  889. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  890. 'recipient' => 'ticket_customer',
  891. 'subject' => 'Owner has changed (#{ticket.title})',
  892. },
  893. },
  894. disable_notification: true,
  895. active: true,
  896. created_by_id: 1,
  897. updated_by_id: 1,
  898. )
  899. # process mail without Precedence header
  900. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  901. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  902. assert_equal('aaäöüßad asd', ticket_p.title)
  903. assert_equal('Users', ticket_p.group.name)
  904. assert_equal('new', ticket_p.state.name)
  905. assert_equal(1, ticket_p.articles.count)
  906. Observer::Transaction.commit
  907. assert_equal(1, ticket_p.articles.count)
  908. ticket_p.priority = Ticket::Priority.lookup(name: '1 low')
  909. ticket_p.save!
  910. Observer::Transaction.commit
  911. assert_equal(1, ticket_p.articles.count)
  912. ticket_p.priority = Ticket::Priority.lookup(name: '3 high')
  913. ticket_p.save!
  914. Observer::Transaction.commit
  915. assert_equal(1, ticket_p.articles.count)
  916. ticket_p.owner = agent1
  917. ticket_p.save!
  918. Observer::Transaction.commit
  919. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  920. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  921. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  922. assert_equal('3 high', ticket_p.priority.name, 'ticket_p.priority verify')
  923. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  924. #p ticket_p.articles.last.inspect
  925. article_p = ticket_p.articles.last
  926. assert_match('Owner has changed', article_p.subject)
  927. assert_match('Zammad <zammad@localhost>', article_p.from)
  928. assert_match('martin@example.com', article_p.to)
  929. assert_no_match('config\.', article_p.body)
  930. assert_match('http://zammad.example.com', article_p.body)
  931. assert_no_match('ticket.', article_p.body)
  932. assert_match(ticket_p.number, article_p.body)
  933. assert_equal('text/html', article_p.content_type)
  934. # should trigger
  935. Trigger.create_or_update(
  936. name: 'owner update - to customer',
  937. condition: {
  938. 'ticket.owner_id' => {
  939. 'operator' => 'has changed',
  940. 'pre_condition' => 'current_user.id',
  941. 'value' => '',
  942. 'value_completion' => '',
  943. },
  944. 'ticket.priority_id' => {
  945. 'operator' => 'is',
  946. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  947. },
  948. 'ticket.action' => {
  949. 'operator' => 'is not',
  950. 'value' => 'create',
  951. },
  952. },
  953. perform: {
  954. 'notification.email' => {
  955. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  956. <br/>
  957. <p>To provide additional information, please reply to this email or click on the following link:
  958. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  959. </p>
  960. <br/>
  961. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  962. 'recipient' => 'ticket_customer',
  963. 'subject' => 'Owner has changed (#{ticket.title})',
  964. },
  965. },
  966. disable_notification: true,
  967. active: true,
  968. created_by_id: 1,
  969. updated_by_id: 1,
  970. )
  971. # process mail without Precedence header
  972. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  973. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  974. assert_equal('aaäöüßad asd', ticket_p.title)
  975. assert_equal('Users', ticket_p.group.name)
  976. assert_equal('new', ticket_p.state.name)
  977. assert_equal(1, ticket_p.articles.count)
  978. Observer::Transaction.commit
  979. assert_equal(1, ticket_p.articles.count)
  980. ticket_p.priority = Ticket::Priority.lookup(name: '1 low')
  981. ticket_p.save!
  982. Observer::Transaction.commit
  983. assert_equal(1, ticket_p.articles.count)
  984. ticket_p.priority = Ticket::Priority.lookup(name: '3 high')
  985. ticket_p.save!
  986. Observer::Transaction.commit
  987. assert_equal(1, ticket_p.articles.count)
  988. ticket_p.owner = agent1
  989. ticket_p.save!
  990. Observer::Transaction.commit
  991. assert_equal('aaäöüßad asd', ticket_p.title, 'ticket_p.title verify')
  992. assert_equal('Users', ticket_p.group.name, 'ticket_p.group verify')
  993. assert_equal('new', ticket_p.state.name, 'ticket_p.state verify')
  994. assert_equal('3 high', ticket_p.priority.name, 'ticket_p.priority verify')
  995. assert_equal(2, ticket_p.articles.count, 'ticket_p.articles verify')
  996. #p ticket_p.articles.last.inspect
  997. article_p = ticket_p.articles.last
  998. assert_match('Owner has changed', article_p.subject)
  999. assert_match('Zammad <zammad@localhost>', article_p.from)
  1000. assert_match('martin@example.com', article_p.to)
  1001. assert_no_match('config\.', article_p.body)
  1002. assert_match('http://zammad.example.com', article_p.body)
  1003. assert_no_match('ticket.', article_p.body)
  1004. assert_match(ticket_p.number, article_p.body)
  1005. assert_equal('text/html', article_p.content_type)
  1006. # should not trigger
  1007. Trigger.create_or_update(
  1008. name: 'owner update - to customer',
  1009. condition: {
  1010. 'ticket.owner_id' => {
  1011. 'operator' => 'has changed',
  1012. 'pre_condition' => 'current_user.id',
  1013. 'value' => '',
  1014. 'value_completion' => '',
  1015. },
  1016. 'ticket.action' => {
  1017. 'operator' => 'is',
  1018. 'value' => 'create',
  1019. },
  1020. },
  1021. perform: {
  1022. 'notification.email' => {
  1023. 'body' => '<p>The owner of ticket (Ticket##{ticket.number}) has changed.<p>
  1024. <br/>
  1025. <p>To provide additional information, please reply to this email or click on the following link:
  1026. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  1027. </p>
  1028. <br/>
  1029. <p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
  1030. 'recipient' => 'ticket_customer',
  1031. 'subject' => 'Owner has changed (#{ticket.title})',
  1032. },
  1033. },
  1034. disable_notification: true,
  1035. active: true,
  1036. created_by_id: 1,
  1037. updated_by_id: 1,
  1038. )
  1039. # process mail without Precedence header
  1040. content = File.read(Rails.root.join('test', 'data', 'ticket_trigger', 'mail1.box'))
  1041. ticket_p, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, content)
  1042. assert_equal(1, ticket_p.articles.count)
  1043. Observer::Transaction.commit
  1044. assert_equal(1, ticket_p.articles.count)
  1045. ticket_p.owner = agent1
  1046. ticket_p.save!
  1047. Observer::Transaction.commit
  1048. assert_equal(1, ticket_p.articles.count)
  1049. end
  1050. test '5 notify owner' do
  1051. Trigger.create_or_update(
  1052. name: 'aaa notify mail',
  1053. condition: {
  1054. 'ticket.state_id' => {
  1055. 'operator' => 'is',
  1056. 'value' => Ticket::State.all.pluck(:id),
  1057. },
  1058. 'ticket.action' => {
  1059. 'operator' => 'is',
  1060. 'value' => 'update',
  1061. },
  1062. },
  1063. perform: {
  1064. 'notification.email' => {
  1065. 'body' => 'some lala',
  1066. 'recipient' => 'ticket_owner',
  1067. 'subject' => 'CC NOTE (#{ticket.title})!',
  1068. },
  1069. },
  1070. disable_notification: true,
  1071. active: true,
  1072. created_by_id: 1,
  1073. updated_by_id: 1,
  1074. )
  1075. groups = Group.where(name: 'Users')
  1076. roles = Role.where(name: 'Agent')
  1077. agent = User.create_or_update(
  1078. login: 'agent@example.com',
  1079. firstname: 'Trigger',
  1080. lastname: 'Agent1',
  1081. email: 'agent@example.com',
  1082. password: 'agentpw',
  1083. active: true,
  1084. roles: roles,
  1085. groups: groups,
  1086. updated_by_id: 1,
  1087. created_by_id: 1,
  1088. )
  1089. ticket1 = Ticket.create!(
  1090. title: 'test 123',
  1091. owner: agent,
  1092. group: Group.lookup(name: 'Users'),
  1093. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1094. updated_by_id: 1,
  1095. created_by_id: 1,
  1096. )
  1097. Ticket::Article.create!(
  1098. ticket_id: ticket1.id,
  1099. from: 'some_sender@example.com',
  1100. to: 'some_recipient@example.com',
  1101. subject: 'some subject',
  1102. message_id: 'some@id',
  1103. body: "some message <b>note</b>\nnew line",
  1104. internal: false,
  1105. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1106. type: Ticket::Article::Type.find_by(name: 'note'),
  1107. updated_by_id: 1,
  1108. created_by_id: 1,
  1109. )
  1110. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1111. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1112. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1113. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1114. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1115. assert_equal([], ticket1.tag_list)
  1116. Observer::Transaction.commit
  1117. assert_equal(1, ticket1.articles.count)
  1118. Ticket::Article.create!(
  1119. ticket_id: ticket1.id,
  1120. from: 'some_sender@example.com',
  1121. to: 'some_recipient@example.com',
  1122. subject: 'update',
  1123. message_id: 'some@id',
  1124. content_type: 'text/html',
  1125. body: 'update',
  1126. internal: false,
  1127. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1128. type: Ticket::Article::Type.find_by(name: 'note'),
  1129. updated_by_id: 1,
  1130. created_by_id: 1,
  1131. )
  1132. Observer::Transaction.commit
  1133. assert_equal(3, ticket1.articles.count)
  1134. Trigger.create_or_update(
  1135. name: 'aaa notify mail 2',
  1136. condition: {
  1137. 'ticket.state_id' => {
  1138. 'operator' => 'is',
  1139. 'value' => Ticket::State.all.pluck(:id),
  1140. },
  1141. 'ticket.action' => {
  1142. 'operator' => 'is',
  1143. 'value' => 'update',
  1144. },
  1145. },
  1146. perform: {
  1147. 'notification.email' => {
  1148. 'body' => 'some lala',
  1149. 'recipient' => 'ticket_owner',
  1150. 'subject' => 'CC NOTE (#{ticket.title})!',
  1151. },
  1152. },
  1153. disable_notification: true,
  1154. active: true,
  1155. created_by_id: 1,
  1156. updated_by_id: 1,
  1157. )
  1158. Ticket::Article.create!(
  1159. ticket_id: ticket1.id,
  1160. from: 'some_sender@example.com',
  1161. to: 'some_recipient@example.com',
  1162. subject: 'update',
  1163. message_id: 'some@id',
  1164. content_type: 'text/html',
  1165. body: 'update',
  1166. internal: false,
  1167. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1168. type: Ticket::Article::Type.find_by(name: 'note'),
  1169. updated_by_id: 1,
  1170. created_by_id: 1,
  1171. )
  1172. Observer::Transaction.commit
  1173. assert_equal(6, ticket1.articles.count)
  1174. end
  1175. test '6 owner auto assignment' do
  1176. Trigger.create_or_update(
  1177. name: 'aaa auto assignment',
  1178. condition: {
  1179. 'ticket.owner_id' => {
  1180. 'operator' => 'is',
  1181. 'pre_condition' => 'not_set',
  1182. 'value' => '',
  1183. 'value_completion' => '',
  1184. },
  1185. 'ticket.action' => {
  1186. 'operator' => 'is',
  1187. 'value' => 'update',
  1188. },
  1189. },
  1190. perform: {
  1191. 'ticket.owner_id' => {
  1192. 'pre_condition' => 'current_user.id',
  1193. 'value' => '',
  1194. 'value_completion' => '',
  1195. },
  1196. },
  1197. disable_notification: true,
  1198. active: true,
  1199. created_by_id: 1,
  1200. updated_by_id: 1,
  1201. )
  1202. groups = Group.where(name: 'Users')
  1203. roles = Role.where(name: 'Agent')
  1204. agent = User.create_or_update(
  1205. login: 'agent@example.com',
  1206. firstname: 'Trigger',
  1207. lastname: 'Agent1',
  1208. email: 'agent@example.com',
  1209. password: 'agentpw',
  1210. active: true,
  1211. roles: roles,
  1212. groups: groups,
  1213. updated_by_id: 1,
  1214. created_by_id: 1,
  1215. )
  1216. ticket1 = Ticket.create!(
  1217. title: 'test 123',
  1218. #owner: agent,
  1219. group: Group.lookup(name: 'Users'),
  1220. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1221. updated_by_id: 1,
  1222. created_by_id: 1,
  1223. )
  1224. Ticket::Article.create!(
  1225. ticket_id: ticket1.id,
  1226. from: 'some_sender@example.com',
  1227. to: 'some_recipient@example.com',
  1228. subject: 'some subject',
  1229. message_id: 'some@id',
  1230. body: "some message <b>note</b>\nnew line",
  1231. internal: false,
  1232. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1233. type: Ticket::Article::Type.find_by(name: 'note'),
  1234. updated_by_id: 1,
  1235. created_by_id: 1,
  1236. )
  1237. Observer::Transaction.commit
  1238. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1239. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1240. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1241. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1242. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1243. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1244. assert_equal([], ticket1.tag_list)
  1245. UserInfo.current_user_id = agent.id
  1246. Ticket::Article.create!(
  1247. ticket_id: ticket1.id,
  1248. from: 'some_sender@example.com',
  1249. to: 'some_recipient@example.com',
  1250. subject: 'update',
  1251. message_id: 'some@id',
  1252. content_type: 'text/html',
  1253. body: 'update',
  1254. internal: false,
  1255. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1256. type: Ticket::Article::Type.find_by(name: 'note'),
  1257. )
  1258. Observer::Transaction.commit
  1259. UserInfo.current_user_id = nil
  1260. ticket1.reload
  1261. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1262. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1263. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1264. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1265. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1266. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1267. assert_equal([], ticket1.tag_list)
  1268. UserInfo.current_user_id = agent.id
  1269. ticket1.owner_id = 1
  1270. ticket1.save!
  1271. Observer::Transaction.commit
  1272. UserInfo.current_user_id = nil
  1273. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1274. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1275. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1276. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1277. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1278. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1279. assert_equal([], ticket1.tag_list)
  1280. end
  1281. test '6.1 owner auto assignment based on organization' do
  1282. Trigger.create_or_update(
  1283. name: 'aaa auto assignment',
  1284. condition: {
  1285. 'ticket.organization_id' => {
  1286. 'operator' => 'is not',
  1287. 'pre_condition' => 'not_set',
  1288. 'value' => '',
  1289. 'value_completion' => '',
  1290. },
  1291. 'ticket.action' => {
  1292. 'operator' => 'is',
  1293. 'value' => 'update',
  1294. },
  1295. },
  1296. perform: {
  1297. 'ticket.owner_id' => {
  1298. 'pre_condition' => 'current_user.id',
  1299. 'value' => '',
  1300. 'value_completion' => '',
  1301. },
  1302. },
  1303. disable_notification: true,
  1304. active: true,
  1305. created_by_id: 1,
  1306. updated_by_id: 1,
  1307. )
  1308. roles = Role.where(name: 'Agent')
  1309. groups = Group.where(name: 'Users')
  1310. agent = User.create_or_update(
  1311. login: 'agent@example.com',
  1312. firstname: 'Trigger',
  1313. lastname: 'Agent1',
  1314. email: 'agent@example.com',
  1315. password: 'agentpw',
  1316. active: true,
  1317. roles: roles,
  1318. groups: groups,
  1319. updated_by_id: 1,
  1320. created_by_id: 1,
  1321. )
  1322. roles = Role.where(name: 'Customer')
  1323. customer = User.create_or_update(
  1324. login: 'customer@example.com',
  1325. firstname: 'Trigger',
  1326. lastname: 'Customer1',
  1327. email: 'customer@example.com',
  1328. password: 'customerpw',
  1329. vip: true,
  1330. active: true,
  1331. roles: roles,
  1332. updated_by_id: 1,
  1333. created_by_id: 1,
  1334. )
  1335. ticket1 = Ticket.create!(
  1336. title: 'test 123',
  1337. group: Group.lookup(name: 'Users'),
  1338. customer: customer,
  1339. updated_by_id: 1,
  1340. created_by_id: 1,
  1341. )
  1342. Ticket::Article.create!(
  1343. ticket_id: ticket1.id,
  1344. from: 'some_sender@example.com',
  1345. to: 'some_recipient@example.com',
  1346. subject: 'some subject',
  1347. message_id: 'some@id',
  1348. body: "some message <b>note</b>\nnew line",
  1349. internal: false,
  1350. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1351. type: Ticket::Article::Type.find_by(name: 'note'),
  1352. updated_by_id: 1,
  1353. created_by_id: 1,
  1354. )
  1355. Observer::Transaction.commit
  1356. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1357. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1358. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1359. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1360. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1361. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1362. assert_equal([], ticket1.tag_list)
  1363. ticket1.update!(customer: User.lookup(email: 'nicole.braun@zammad.org') )
  1364. UserInfo.current_user_id = agent.id
  1365. Ticket::Article.create!(
  1366. ticket_id: ticket1.id,
  1367. from: 'some_sender@example.com',
  1368. to: 'some_recipient@example.com',
  1369. subject: 'update',
  1370. message_id: 'some@id',
  1371. content_type: 'text/html',
  1372. body: 'update',
  1373. internal: false,
  1374. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1375. type: Ticket::Article::Type.find_by(name: 'note'),
  1376. )
  1377. Observer::Transaction.commit
  1378. UserInfo.current_user_id = nil
  1379. ticket1.reload
  1380. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1381. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1382. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1383. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1384. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1385. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1386. assert_equal([], ticket1.tag_list)
  1387. end
  1388. test '6.2 owner auto assignment based on organization' do
  1389. Trigger.create_or_update(
  1390. name: 'aaa auto assignment',
  1391. condition: {
  1392. 'ticket.organization_id' => {
  1393. 'operator' => 'is',
  1394. 'pre_condition' => 'not_set',
  1395. 'value' => '',
  1396. 'value_completion' => '',
  1397. },
  1398. 'ticket.action' => {
  1399. 'operator' => 'is',
  1400. 'value' => 'update',
  1401. },
  1402. },
  1403. perform: {
  1404. 'ticket.owner_id' => {
  1405. 'pre_condition' => 'current_user.id',
  1406. 'value' => '',
  1407. 'value_completion' => '',
  1408. },
  1409. },
  1410. disable_notification: true,
  1411. active: true,
  1412. created_by_id: 1,
  1413. updated_by_id: 1,
  1414. )
  1415. groups = Group.where(name: 'Users')
  1416. roles = Role.where(name: 'Agent')
  1417. agent = User.create_or_update(
  1418. login: 'agent@example.com',
  1419. firstname: 'Trigger',
  1420. lastname: 'Agent1',
  1421. email: 'agent@example.com',
  1422. password: 'agentpw',
  1423. active: true,
  1424. roles: roles,
  1425. groups: groups,
  1426. updated_by_id: 1,
  1427. created_by_id: 1,
  1428. )
  1429. roles = Role.where(name: 'Customer')
  1430. customer = User.create_or_update(
  1431. login: 'customer@example.com',
  1432. firstname: 'Trigger',
  1433. lastname: 'Customer1',
  1434. email: 'customer@example.com',
  1435. password: 'customerpw',
  1436. vip: true,
  1437. active: true,
  1438. roles: roles,
  1439. updated_by_id: 1,
  1440. created_by_id: 1,
  1441. )
  1442. ticket1 = Ticket.create!(
  1443. title: 'test 123',
  1444. group: Group.lookup(name: 'Users'),
  1445. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1446. updated_by_id: 1,
  1447. created_by_id: 1,
  1448. )
  1449. Ticket::Article.create!(
  1450. ticket_id: ticket1.id,
  1451. from: 'some_sender@example.com',
  1452. to: 'some_recipient@example.com',
  1453. subject: 'some subject',
  1454. message_id: 'some@id',
  1455. body: "some message <b>note</b>\nnew line",
  1456. internal: false,
  1457. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1458. type: Ticket::Article::Type.find_by(name: 'note'),
  1459. updated_by_id: 1,
  1460. created_by_id: 1,
  1461. )
  1462. Observer::Transaction.commit
  1463. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1464. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1465. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1466. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1467. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1468. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1469. assert_equal([], ticket1.tag_list)
  1470. ticket1.update!(customer: customer )
  1471. UserInfo.current_user_id = agent.id
  1472. Ticket::Article.create!(
  1473. ticket_id: ticket1.id,
  1474. from: 'some_sender@example.com',
  1475. to: 'some_recipient@example.com',
  1476. subject: 'update',
  1477. message_id: 'some@id',
  1478. content_type: 'text/html',
  1479. body: 'update',
  1480. internal: false,
  1481. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1482. type: Ticket::Article::Type.find_by(name: 'note'),
  1483. )
  1484. Observer::Transaction.commit
  1485. UserInfo.current_user_id = nil
  1486. ticket1.reload
  1487. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1488. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1489. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1490. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1491. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1492. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1493. assert_equal([], ticket1.tag_list)
  1494. end
  1495. test '7 owner auto assignment' do
  1496. Trigger.create_or_update(
  1497. name: 'aaa auto assignment',
  1498. condition: {
  1499. 'ticket.owner_id' => {
  1500. 'operator' => 'is',
  1501. 'pre_condition' => 'not_set',
  1502. 'value' => '',
  1503. 'value_completion' => '',
  1504. },
  1505. 'article.type_id' => {
  1506. 'operator' => 'is',
  1507. 'value' => Ticket::Article::Type.find_by(name: 'note'),
  1508. },
  1509. 'article.sender_id' => {
  1510. 'operator' => 'is',
  1511. 'value' => Ticket::Article::Sender.find_by(name: 'Agent'),
  1512. },
  1513. },
  1514. perform: {
  1515. 'ticket.owner_id' => {
  1516. 'pre_condition' => 'current_user.id',
  1517. 'value' => '',
  1518. 'value_completion' => '',
  1519. },
  1520. },
  1521. disable_notification: true,
  1522. active: true,
  1523. created_by_id: 1,
  1524. updated_by_id: 1,
  1525. )
  1526. groups = Group.where(name: 'Users')
  1527. roles = Role.where(name: 'Agent')
  1528. agent1 = User.create_or_update(
  1529. login: 'agent@example.com',
  1530. firstname: 'Trigger',
  1531. lastname: 'Agent1',
  1532. email: 'agent@example.com',
  1533. password: 'agentpw',
  1534. active: true,
  1535. roles: roles,
  1536. groups: groups,
  1537. updated_by_id: 1,
  1538. created_by_id: 1,
  1539. )
  1540. agent2 = User.create_or_update(
  1541. login: 'agent@example.com',
  1542. firstname: 'Trigger',
  1543. lastname: 'Agent2',
  1544. email: 'agent@example.com',
  1545. password: 'agentpw',
  1546. active: true,
  1547. roles: roles,
  1548. groups: groups,
  1549. updated_by_id: 1,
  1550. created_by_id: 1,
  1551. )
  1552. ticket1 = Ticket.create!(
  1553. title: 'test 123',
  1554. #owner: agent,
  1555. group: Group.lookup(name: 'Users'),
  1556. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1557. updated_by_id: 1,
  1558. created_by_id: 1,
  1559. )
  1560. Ticket::Article.create!(
  1561. ticket_id: ticket1.id,
  1562. from: 'some_sender@example.com',
  1563. to: 'some_recipient@example.com',
  1564. subject: 'some subject',
  1565. message_id: 'some@id',
  1566. body: "some message <b>note</b>\nnew line",
  1567. internal: false,
  1568. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1569. type: Ticket::Article::Type.find_by(name: 'note'),
  1570. updated_by_id: 1,
  1571. created_by_id: 1,
  1572. )
  1573. Observer::Transaction.commit
  1574. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1575. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1576. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1577. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1578. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1579. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1580. assert_equal([], ticket1.tag_list)
  1581. UserInfo.current_user_id = agent1.id
  1582. Ticket::Article.create!(
  1583. ticket_id: ticket1.id,
  1584. from: 'some_sender@example.com',
  1585. to: 'some_recipient@example.com',
  1586. subject: 'update',
  1587. message_id: 'some@id',
  1588. content_type: 'text/html',
  1589. body: 'update',
  1590. internal: false,
  1591. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1592. type: Ticket::Article::Type.find_by(name: 'note'),
  1593. )
  1594. Observer::Transaction.commit
  1595. UserInfo.current_user_id = nil
  1596. ticket1.reload
  1597. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1598. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1599. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1600. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1601. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1602. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1603. assert_equal([], ticket1.tag_list)
  1604. UserInfo.current_user_id = agent1.id
  1605. ticket1.owner_id = 1
  1606. ticket1.save!
  1607. Observer::Transaction.commit
  1608. UserInfo.current_user_id = nil
  1609. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1610. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1611. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1612. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1613. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1614. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1615. assert_equal([], ticket1.tag_list)
  1616. UserInfo.current_user_id = agent1.id
  1617. Ticket::Article.create!(
  1618. ticket_id: ticket1.id,
  1619. from: 'some_sender@example.com',
  1620. to: 'some_recipient@example.com',
  1621. subject: 'update',
  1622. message_id: 'some@id',
  1623. content_type: 'text/html',
  1624. body: 'update',
  1625. internal: false,
  1626. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  1627. type: Ticket::Article::Type.find_by(name: 'note'),
  1628. )
  1629. Observer::Transaction.commit
  1630. UserInfo.current_user_id = nil
  1631. ticket1.reload
  1632. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1633. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1634. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1635. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1636. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1637. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  1638. assert_equal([], ticket1.tag_list)
  1639. UserInfo.current_user_id = agent2.id
  1640. ticket1.owner_id = agent2.id
  1641. ticket1.save!
  1642. Observer::Transaction.commit
  1643. UserInfo.current_user_id = nil
  1644. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1645. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1646. assert_equal(agent2.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1647. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1648. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1649. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  1650. assert_equal([], ticket1.tag_list)
  1651. UserInfo.current_user_id = agent1.id
  1652. Ticket::Article.create!(
  1653. ticket_id: ticket1.id,
  1654. from: 'some_sender@example.com',
  1655. to: 'some_recipient@example.com',
  1656. subject: 'update',
  1657. message_id: 'some@id',
  1658. content_type: 'text/html',
  1659. body: 'update',
  1660. internal: false,
  1661. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1662. type: Ticket::Article::Type.find_by(name: 'note'),
  1663. )
  1664. Observer::Transaction.commit
  1665. UserInfo.current_user_id = nil
  1666. ticket1.reload
  1667. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1668. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1669. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1670. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1671. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1672. assert_equal(4, ticket1.articles.count, 'ticket1.articles verify')
  1673. assert_equal([], ticket1.tag_list)
  1674. end
  1675. test '8 owner auto assignment' do
  1676. Trigger.create_or_update(
  1677. name: 'aaa auto assignment',
  1678. condition: {
  1679. 'ticket.owner_id' => {
  1680. 'operator' => 'is',
  1681. 'pre_condition' => 'not_set',
  1682. 'value' => '',
  1683. 'value_completion' => '',
  1684. },
  1685. 'ticket.priority_id' => {
  1686. 'operator' => 'has changed',
  1687. 'pre_condition' => '',
  1688. 'value' => '2',
  1689. 'value_completion' => '',
  1690. },
  1691. 'ticket.action' => {
  1692. 'operator' => 'is',
  1693. 'value' => 'update',
  1694. },
  1695. },
  1696. perform: {
  1697. 'ticket.owner_id' => {
  1698. 'pre_condition' => 'current_user.id',
  1699. 'value' => '',
  1700. 'value_completion' => '',
  1701. },
  1702. },
  1703. disable_notification: true,
  1704. active: true,
  1705. created_by_id: 1,
  1706. updated_by_id: 1,
  1707. )
  1708. groups = Group.where(name: 'Users')
  1709. roles = Role.where(name: 'Agent')
  1710. agent = User.create_or_update(
  1711. login: 'agent@example.com',
  1712. firstname: 'Trigger',
  1713. lastname: 'Agent1',
  1714. email: 'agent@example.com',
  1715. password: 'agentpw',
  1716. active: true,
  1717. roles: roles,
  1718. groups: groups,
  1719. updated_by_id: 1,
  1720. created_by_id: 1,
  1721. )
  1722. ticket1 = Ticket.create!(
  1723. title: 'test 123',
  1724. #owner: agent,
  1725. group: Group.lookup(name: 'Users'),
  1726. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1727. updated_by_id: 1,
  1728. created_by_id: 1,
  1729. )
  1730. Ticket::Article.create!(
  1731. ticket_id: ticket1.id,
  1732. from: 'some_sender@example.com',
  1733. to: 'some_recipient@example.com',
  1734. subject: 'some subject',
  1735. message_id: 'some@id',
  1736. body: "some message <b>note</b>\nnew line",
  1737. internal: false,
  1738. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1739. type: Ticket::Article::Type.find_by(name: 'note'),
  1740. updated_by_id: 1,
  1741. created_by_id: 1,
  1742. )
  1743. Observer::Transaction.commit
  1744. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1745. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1746. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1747. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1748. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1749. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1750. assert_equal([], ticket1.tag_list)
  1751. UserInfo.current_user_id = agent.id
  1752. Ticket::Article.create!(
  1753. ticket_id: ticket1.id,
  1754. from: 'some_sender@example.com',
  1755. to: 'some_recipient@example.com',
  1756. subject: 'update',
  1757. message_id: 'some@id',
  1758. content_type: 'text/html',
  1759. body: 'update',
  1760. internal: false,
  1761. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1762. type: Ticket::Article::Type.find_by(name: 'note'),
  1763. )
  1764. Observer::Transaction.commit
  1765. UserInfo.current_user_id = nil
  1766. ticket1.reload
  1767. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1768. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1769. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1770. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1771. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1772. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1773. assert_equal([], ticket1.tag_list)
  1774. UserInfo.current_user_id = agent.id
  1775. ticket1.priority = Ticket::Priority.find_by(name: '1 low')
  1776. ticket1.save!
  1777. Observer::Transaction.commit
  1778. UserInfo.current_user_id = nil
  1779. ticket1.reload
  1780. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1781. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1782. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1783. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1784. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1785. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1786. assert_equal([], ticket1.tag_list)
  1787. UserInfo.current_user_id = agent.id
  1788. ticket1.owner_id = 1
  1789. ticket1.save!
  1790. Observer::Transaction.commit
  1791. UserInfo.current_user_id = nil
  1792. ticket1.reload
  1793. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1794. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1795. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  1796. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1797. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1798. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1799. assert_equal([], ticket1.tag_list)
  1800. UserInfo.current_user_id = agent.id
  1801. ticket1.owner_id = agent.id
  1802. ticket1.save!
  1803. Observer::Transaction.commit
  1804. UserInfo.current_user_id = nil
  1805. ticket1.reload
  1806. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1807. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1808. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1809. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1810. assert_equal('1 low', ticket1.priority.name, 'ticket1.priority verify')
  1811. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  1812. assert_equal([], ticket1.tag_list)
  1813. end
  1814. test '9 vip priority set' do
  1815. Trigger.create_or_update(
  1816. name: 'aaa vip priority',
  1817. condition: {
  1818. 'customer.vip' => {
  1819. 'operator' => 'is',
  1820. 'value' => true,
  1821. },
  1822. },
  1823. perform: {
  1824. 'ticket.priority_id' => {
  1825. 'value' => Ticket::Priority.find_by(name: '3 high').id,
  1826. },
  1827. },
  1828. disable_notification: true,
  1829. active: true,
  1830. created_by_id: 1,
  1831. updated_by_id: 1,
  1832. )
  1833. groups = Group.where(name: 'Users')
  1834. roles = Role.where(name: 'Agent')
  1835. agent = User.create_or_update(
  1836. login: 'agent@example.com',
  1837. firstname: 'Trigger',
  1838. lastname: 'Agent1',
  1839. email: 'agent@example.com',
  1840. password: 'agentpw',
  1841. active: true,
  1842. roles: roles,
  1843. groups: groups,
  1844. updated_by_id: 1,
  1845. created_by_id: 1,
  1846. )
  1847. roles = Role.where(name: 'Customer')
  1848. customer = User.create_or_update(
  1849. login: 'customer@example.com',
  1850. firstname: 'Trigger',
  1851. lastname: 'Customer1',
  1852. email: 'customer@example.com',
  1853. password: 'customerpw',
  1854. vip: true,
  1855. active: true,
  1856. roles: roles,
  1857. updated_by_id: 1,
  1858. created_by_id: 1,
  1859. )
  1860. ticket1 = Ticket.create!(
  1861. title: 'test 123',
  1862. owner: agent,
  1863. customer: customer,
  1864. group: Group.lookup(name: 'Users'),
  1865. updated_by_id: 1,
  1866. created_by_id: 1,
  1867. )
  1868. Ticket::Article.create!(
  1869. ticket_id: ticket1.id,
  1870. from: 'some_sender@example.com',
  1871. to: 'some_recipient@example.com',
  1872. subject: 'some subject',
  1873. message_id: 'some@id',
  1874. body: "some message <b>note</b>\nnew line",
  1875. internal: false,
  1876. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1877. type: Ticket::Article::Type.find_by(name: 'note'),
  1878. updated_by_id: 1,
  1879. created_by_id: 1,
  1880. )
  1881. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1882. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1883. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1884. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  1885. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1886. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  1887. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1888. assert_equal([], ticket1.tag_list)
  1889. Observer::Transaction.commit
  1890. ticket1.reload
  1891. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  1892. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  1893. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  1894. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  1895. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  1896. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  1897. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  1898. assert_equal([], ticket1.tag_list)
  1899. customer.vip = false
  1900. customer.save!
  1901. ticket2 = Ticket.create!(
  1902. title: 'test 123',
  1903. owner: agent,
  1904. customer: customer,
  1905. group: Group.lookup(name: 'Users'),
  1906. updated_by_id: 1,
  1907. created_by_id: 1,
  1908. )
  1909. Ticket::Article.create!(
  1910. ticket_id: ticket2.id,
  1911. from: 'some_sender@example.com',
  1912. to: 'some_recipient@example.com',
  1913. subject: 'some subject',
  1914. message_id: 'some@id',
  1915. body: "some message <b>note</b>\nnew line",
  1916. internal: false,
  1917. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  1918. type: Ticket::Article::Type.find_by(name: 'note'),
  1919. updated_by_id: 1,
  1920. created_by_id: 1,
  1921. )
  1922. assert_equal('test 123', ticket2.title, 'ticket2.title verify')
  1923. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  1924. assert_equal(agent.id, ticket2.owner_id, 'ticket2.owner_id verify')
  1925. assert_equal(customer.id, ticket2.customer_id, 'ticket2.customer_id verify')
  1926. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  1927. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  1928. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  1929. assert_equal([], ticket2.tag_list)
  1930. Observer::Transaction.commit
  1931. ticket2.reload
  1932. assert_equal('test 123', ticket2.title, 'ticket2.title verify')
  1933. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  1934. assert_equal(agent.id, ticket2.owner_id, 'ticket2.owner_id verify')
  1935. assert_equal(customer.id, ticket2.customer_id, 'ticket2.customer_id verify')
  1936. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  1937. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  1938. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  1939. assert_equal([], ticket2.tag_list)
  1940. end
  1941. test '10 owner auto assignment notify to customer' do
  1942. Trigger.create_or_update(
  1943. name: 'aaa auto assignment',
  1944. condition: {
  1945. 'ticket.owner_id' => {
  1946. 'operator' => 'has changed',
  1947. 'pre_condition' => '',
  1948. 'value' => '2',
  1949. 'value_completion' => '',
  1950. },
  1951. },
  1952. perform: {
  1953. 'notification.email' => {
  1954. 'body' => 'some lala',
  1955. 'recipient' => 'ticket_customer',
  1956. 'subject' => 'NEW OWNER (#{ticket.title})!',
  1957. },
  1958. },
  1959. disable_notification: true,
  1960. active: true,
  1961. created_by_id: 1,
  1962. updated_by_id: 1,
  1963. )
  1964. groups = Group.where(name: 'Users')
  1965. roles = Role.where(name: 'Agent')
  1966. agent1 = User.create_or_update(
  1967. login: 'agent1@example.com',
  1968. firstname: 'Trigger',
  1969. lastname: 'Agent1',
  1970. email: 'agent1@example.com',
  1971. password: 'agentpw',
  1972. active: true,
  1973. roles: roles,
  1974. groups: groups,
  1975. updated_by_id: 1,
  1976. created_by_id: 1,
  1977. )
  1978. agent2 = User.create_or_update(
  1979. login: 'agent2@example.com',
  1980. firstname: 'Trigger',
  1981. lastname: 'Agent2',
  1982. email: 'agent2@example.com',
  1983. password: 'agentpw',
  1984. active: true,
  1985. roles: roles,
  1986. groups: groups,
  1987. updated_by_id: 1,
  1988. created_by_id: 1,
  1989. )
  1990. ticket1 = Ticket.create!(
  1991. title: 'test 123',
  1992. group: Group.lookup(name: 'Users'),
  1993. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  1994. updated_by_id: 1,
  1995. created_by_id: 1,
  1996. )
  1997. Ticket::Article.create!(
  1998. ticket_id: ticket1.id,
  1999. from: 'some_sender@example.com',
  2000. to: 'some_recipient@example.com',
  2001. subject: 'some subject',
  2002. message_id: 'some@id',
  2003. body: "some message <b>note</b>\nnew line",
  2004. internal: false,
  2005. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2006. type: Ticket::Article::Type.find_by(name: 'note'),
  2007. updated_by_id: 1,
  2008. created_by_id: 1,
  2009. )
  2010. Observer::Transaction.commit
  2011. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2012. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2013. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2014. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2015. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2016. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  2017. assert_equal([], ticket1.tag_list)
  2018. UserInfo.current_user_id = agent1.id
  2019. ticket1.owner_id = agent1.id
  2020. ticket1.save!
  2021. Observer::Transaction.commit
  2022. UserInfo.current_user_id = nil
  2023. ticket1.reload
  2024. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2025. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2026. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2027. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2028. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2029. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2030. assert_equal([], ticket1.tag_list)
  2031. UserInfo.current_user_id = agent1.id
  2032. ticket1.owner_id = agent1.id
  2033. ticket1.save!
  2034. Observer::Transaction.commit
  2035. UserInfo.current_user_id = nil
  2036. ticket1.reload
  2037. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2038. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2039. assert_equal(agent1.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2040. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2041. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2042. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2043. assert_equal([], ticket1.tag_list)
  2044. UserInfo.current_user_id = agent1.id
  2045. ticket1.owner_id = agent2.id
  2046. ticket1.save!
  2047. Observer::Transaction.commit
  2048. UserInfo.current_user_id = nil
  2049. ticket1.reload
  2050. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2051. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2052. assert_equal(agent2.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2053. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2054. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2055. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2056. assert_equal([], ticket1.tag_list)
  2057. end
  2058. test '11 notify to customer on public note' do
  2059. Trigger.create_or_update(
  2060. name: 'aaa notify to customer on public note',
  2061. condition: {
  2062. 'article.internal' => {
  2063. 'operator' => 'is',
  2064. 'value' => 'false',
  2065. },
  2066. 'article.sender_id' => {
  2067. 'operator' => 'is',
  2068. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  2069. },
  2070. 'article.type_id' => {
  2071. 'operator' => 'is',
  2072. 'value' => [
  2073. Ticket::Article::Type.lookup(name: 'note').id,
  2074. ],
  2075. },
  2076. },
  2077. perform: {
  2078. 'notification.email' => {
  2079. 'body' => 'some lala',
  2080. 'recipient' => 'ticket_customer',
  2081. 'subject' => 'UPDATE (#{ticket.title})!',
  2082. },
  2083. },
  2084. disable_notification: true,
  2085. active: true,
  2086. created_by_id: 1,
  2087. updated_by_id: 1,
  2088. )
  2089. groups = Group.where(name: 'Users')
  2090. roles = Role.where(name: 'Agent')
  2091. agent = User.create_or_update(
  2092. login: 'agent@example.com',
  2093. firstname: 'Trigger',
  2094. lastname: 'Agent1',
  2095. email: 'agent@example.com',
  2096. password: 'agentpw',
  2097. active: true,
  2098. roles: roles,
  2099. groups: groups,
  2100. updated_by_id: 1,
  2101. created_by_id: 1,
  2102. )
  2103. roles = Role.where(name: 'Customer')
  2104. customer = User.create_or_update(
  2105. login: 'customer@example.com',
  2106. firstname: 'Trigger',
  2107. lastname: 'Customer1',
  2108. email: 'customer@example.com',
  2109. password: 'customerpw',
  2110. vip: true,
  2111. active: true,
  2112. roles: roles,
  2113. updated_by_id: 1,
  2114. created_by_id: 1,
  2115. )
  2116. ticket1 = Ticket.create!(
  2117. title: 'test 123',
  2118. owner: agent,
  2119. customer: customer,
  2120. group: Group.lookup(name: 'Users'),
  2121. updated_by_id: 1,
  2122. created_by_id: 1,
  2123. )
  2124. Ticket::Article.create!(
  2125. ticket_id: ticket1.id,
  2126. from: 'some_sender@example.com',
  2127. to: 'some_recipient@example.com',
  2128. subject: 'some subject',
  2129. message_id: 'some@id',
  2130. body: "some message <b>note</b>\nnew line",
  2131. internal: false,
  2132. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2133. type: Ticket::Article::Type.find_by(name: 'note'),
  2134. updated_by_id: 1,
  2135. created_by_id: 1,
  2136. )
  2137. Observer::Transaction.commit
  2138. ticket1.reload
  2139. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2140. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2141. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2142. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2143. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2144. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2145. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2146. assert_equal([], ticket1.tag_list)
  2147. Ticket::Article.create!(
  2148. ticket_id: ticket1.id,
  2149. from: 'some_sender@example.com',
  2150. to: 'some_recipient@example.com',
  2151. subject: 'some subject',
  2152. message_id: 'some@id',
  2153. body: "some message <b>note</b>\nnew line",
  2154. internal: true,
  2155. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2156. type: Ticket::Article::Type.find_by(name: 'note'),
  2157. updated_by_id: 1,
  2158. created_by_id: 1,
  2159. )
  2160. Observer::Transaction.commit
  2161. ticket1.reload
  2162. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2163. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2164. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2165. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2166. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2167. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2168. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2169. assert_equal([], ticket1.tag_list)
  2170. Ticket::Article.create!(
  2171. ticket_id: ticket1.id,
  2172. from: 'some_sender@example.com',
  2173. to: 'some_recipient@example.com',
  2174. subject: 'some subject',
  2175. message_id: 'some@id',
  2176. body: "some message <b>note</b>\nnew line",
  2177. internal: false,
  2178. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2179. type: Ticket::Article::Type.find_by(name: 'note'),
  2180. updated_by_id: 1,
  2181. created_by_id: 1,
  2182. )
  2183. Observer::Transaction.commit
  2184. ticket1.reload
  2185. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2186. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2187. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2188. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2189. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2190. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2191. assert_equal(5, ticket1.articles.count, 'ticket1.articles verify')
  2192. assert_equal([], ticket1.tag_list)
  2193. ticket1.priority = Ticket::Priority.find_by(name: '3 high')
  2194. ticket1.save!
  2195. article = Ticket::Article.create!(
  2196. ticket_id: ticket1.id,
  2197. from: 'some_sender@example.com',
  2198. to: 'some_recipient@example.com',
  2199. subject: 'some subject',
  2200. message_id: 'some@id',
  2201. body: "some message <b>note</b>\nnew line",
  2202. internal: true,
  2203. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2204. type: Ticket::Article::Type.find_by(name: 'note'),
  2205. updated_by_id: 1,
  2206. created_by_id: 1,
  2207. )
  2208. Observer::Transaction.commit
  2209. ticket1.reload
  2210. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2211. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2212. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2213. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2214. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2215. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2216. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2217. assert_equal([], ticket1.tag_list)
  2218. article.internal = false
  2219. article.save!
  2220. Observer::Transaction.commit
  2221. ticket1.reload
  2222. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2223. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2224. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2225. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2226. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2227. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2228. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2229. assert_equal([], ticket1.tag_list)
  2230. Ticket::Article.create!(
  2231. ticket_id: ticket1.id,
  2232. from: 'some_sender@example.com',
  2233. to: 'some_recipient@example.com',
  2234. subject: 'some subject',
  2235. message_id: 'some@id',
  2236. body: "some message <b>note</b>\nnew line",
  2237. internal: true,
  2238. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2239. type: Ticket::Article::Type.find_by(name: 'note'),
  2240. updated_by_id: 1,
  2241. created_by_id: 1,
  2242. )
  2243. Observer::Transaction.commit
  2244. ticket1.reload
  2245. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2246. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2247. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2248. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2249. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2250. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  2251. assert_equal(7, ticket1.articles.count, 'ticket1.articles verify')
  2252. assert_equal([], ticket1.tag_list)
  2253. end
  2254. test '12 notify on owner change' do
  2255. Trigger.create_or_update(
  2256. name: 'aaa notify to customer on public note',
  2257. condition: {
  2258. 'ticket.owner_id' => {
  2259. 'operator' => 'has changed',
  2260. 'pre_condition' => 'current_user.id',
  2261. 'value' => '',
  2262. 'value_completion' => '',
  2263. }
  2264. },
  2265. perform: {
  2266. 'notification.email' => {
  2267. 'body' => 'some lala',
  2268. 'recipient' => 'ticket_customer',
  2269. 'subject' => 'UPDATE (#{ticket.title})!',
  2270. },
  2271. },
  2272. disable_notification: true,
  2273. active: true,
  2274. created_by_id: 1,
  2275. updated_by_id: 1,
  2276. )
  2277. Trigger.create_or_update(
  2278. name: 'auto reply (on new tickets)',
  2279. condition: {
  2280. 'ticket.action' => {
  2281. 'operator' => 'is',
  2282. 'value' => 'create',
  2283. },
  2284. 'ticket.state_id' => {
  2285. 'operator' => 'is not',
  2286. 'value' => Ticket::State.lookup(name: 'closed').id,
  2287. },
  2288. 'article.type_id' => {
  2289. 'operator' => 'is',
  2290. 'value' => [
  2291. Ticket::Article::Type.lookup(name: 'email').id,
  2292. Ticket::Article::Type.lookup(name: 'phone').id,
  2293. Ticket::Article::Type.lookup(name: 'web').id,
  2294. ],
  2295. },
  2296. 'article.sender_id' => {
  2297. 'operator' => 'is',
  2298. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2299. },
  2300. },
  2301. perform: {
  2302. 'notification.email' => {
  2303. 'body' => '<div>Your request <b>(#{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
  2304. <br/>
  2305. <div>To provide additional information, please reply to this email or click on the following link (for initial login, please request a new password):
  2306. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  2307. </div>
  2308. <br/>
  2309. <div>Your #{config.product_name} Team</div>
  2310. <br/>
  2311. <div><i><a href="https://zammad.com">Zammad</a>, your customer support system</i></div>',
  2312. 'recipient' => 'ticket_customer',
  2313. 'subject' => 'Thanks for your inquiry (#{ticket.title})',
  2314. },
  2315. },
  2316. active: true,
  2317. created_by_id: 1,
  2318. updated_by_id: 1,
  2319. )
  2320. Trigger.create_or_update(
  2321. name: 'auto reply (on follow-up of tickets)',
  2322. condition: {
  2323. 'ticket.action' => {
  2324. 'operator' => 'is',
  2325. 'value' => 'update',
  2326. },
  2327. 'article.sender_id' => {
  2328. 'operator' => 'is',
  2329. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2330. },
  2331. 'article.type_id' => {
  2332. 'operator' => 'is',
  2333. 'value' => [
  2334. Ticket::Article::Type.lookup(name: 'email').id,
  2335. Ticket::Article::Type.lookup(name: 'phone').id,
  2336. Ticket::Article::Type.lookup(name: 'web').id,
  2337. ],
  2338. },
  2339. },
  2340. perform: {
  2341. 'notification.email' => {
  2342. 'body' => '<div>Your follow-up for <b>(#{config.ticket_hook}#{ticket.number})</b> has been received and will be reviewed by our support staff.</div>
  2343. <br/>
  2344. <div>To provide additional information, please reply to this email or click on the following link:
  2345. <a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
  2346. </div>
  2347. <br/>
  2348. <div>Your #{config.product_name} Team</div>
  2349. <br/>
  2350. <div><i><a href="https://zammad.com">Zammad</a>, your customer support system</i></div>',
  2351. 'recipient' => 'ticket_customer',
  2352. 'subject' => 'Thanks for your follow-up (#{ticket.title})',
  2353. },
  2354. },
  2355. active: true,
  2356. created_by_id: 1,
  2357. updated_by_id: 1,
  2358. )
  2359. groups = Group.where(name: 'Users')
  2360. roles = Role.where(name: 'Agent')
  2361. agent = User.create_or_update(
  2362. login: 'agent@example.com',
  2363. firstname: 'Trigger',
  2364. lastname: 'Agent1',
  2365. email: 'agent@example.com',
  2366. password: 'agentpw',
  2367. active: true,
  2368. roles: roles,
  2369. groups: groups,
  2370. updated_by_id: 1,
  2371. created_by_id: 1,
  2372. )
  2373. roles = Role.where(name: 'Customer')
  2374. customer = User.create_or_update(
  2375. login: 'customer@example.com',
  2376. firstname: 'Trigger',
  2377. lastname: 'Customer1',
  2378. email: 'customer@example.com',
  2379. password: 'customerpw',
  2380. vip: true,
  2381. active: true,
  2382. roles: roles,
  2383. updated_by_id: 1,
  2384. created_by_id: 1,
  2385. )
  2386. ticket1 = Ticket.create!(
  2387. title: 'test 123',
  2388. #owner: agent,
  2389. customer: customer,
  2390. group: Group.lookup(name: 'Users'),
  2391. updated_by_id: 1,
  2392. created_by_id: 1,
  2393. )
  2394. Ticket::Article.create!(
  2395. ticket_id: ticket1.id,
  2396. from: 'some_sender@example.com',
  2397. to: 'some_recipient@example.com',
  2398. subject: 'some subject',
  2399. message_id: 'some@id',
  2400. body: "some message <b>note</b>\nnew line",
  2401. internal: false,
  2402. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2403. type: Ticket::Article::Type.find_by(name: 'web'),
  2404. updated_by_id: 1,
  2405. created_by_id: 1,
  2406. )
  2407. Observer::Transaction.commit
  2408. ticket1.reload
  2409. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2410. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2411. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2412. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2413. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2414. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2415. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2416. assert_equal([], ticket1.tag_list)
  2417. UserInfo.current_user_id = agent.id
  2418. ticket1.owner_id = agent.id
  2419. ticket1.save!
  2420. Observer::Transaction.commit
  2421. UserInfo.current_user_id = nil
  2422. ticket1.reload
  2423. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2424. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2425. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2426. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2427. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2428. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2429. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify')
  2430. assert_equal([], ticket1.tag_list)
  2431. Ticket::Article.create!(
  2432. ticket_id: ticket1.id,
  2433. from: 'some_sender@example.com',
  2434. to: 'some_recipient@example.com',
  2435. subject: 'some subject',
  2436. message_id: 'some@id',
  2437. body: "some message <b>note</b>\nnew line",
  2438. internal: false,
  2439. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2440. type: Ticket::Article::Type.find_by(name: 'web'),
  2441. updated_by_id: 1,
  2442. created_by_id: 1,
  2443. )
  2444. Observer::Transaction.commit
  2445. ticket1.reload
  2446. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2447. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2448. assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
  2449. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2450. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2451. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2452. assert_equal(5, ticket1.articles.count, 'ticket1.articles verify')
  2453. assert_equal([], ticket1.tag_list)
  2454. UserInfo.current_user_id = agent.id
  2455. ticket1.owner_id = 1
  2456. ticket1.save!
  2457. Observer::Transaction.commit
  2458. UserInfo.current_user_id = nil
  2459. ticket1.reload
  2460. assert_equal('test 123', ticket1.title, 'ticket1.title verify')
  2461. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  2462. assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
  2463. assert_equal(customer.id, ticket1.customer_id, 'ticket1.customer_id verify')
  2464. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  2465. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  2466. assert_equal(6, ticket1.articles.count, 'ticket1.articles verify')
  2467. assert_equal([], ticket1.tag_list)
  2468. end
  2469. test '1 empty condition should not create errors' do
  2470. assert_raises(Exception) do
  2471. Trigger.create_or_update(
  2472. name: 'aaa loop check',
  2473. condition: {
  2474. 'ticket.number' => {
  2475. 'operator' => 'contains',
  2476. 'value' => '',
  2477. },
  2478. },
  2479. perform: {
  2480. 'notification.email' => {
  2481. 'body' => 'some lala',
  2482. 'recipient' => 'ticket_customer',
  2483. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  2484. },
  2485. },
  2486. disable_notification: true,
  2487. active: true,
  2488. created_by_id: 1,
  2489. updated_by_id: 1,
  2490. )
  2491. end
  2492. end
  2493. test 'article_last_sender trigger -> reply_to' do
  2494. Trigger.create_or_update(
  2495. name: 'auto reply',
  2496. condition: {
  2497. 'ticket.action' => {
  2498. 'operator' => 'is',
  2499. 'value' => 'create',
  2500. },
  2501. 'ticket.state_id' => {
  2502. 'operator' => 'is',
  2503. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2504. }
  2505. },
  2506. perform: {
  2507. 'notification.email' => {
  2508. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2509. 'recipient' => 'article_last_sender',
  2510. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2511. },
  2512. },
  2513. disable_notification: true,
  2514. active: true,
  2515. created_by_id: 1,
  2516. updated_by_id: 1,
  2517. )
  2518. ticket1 = Ticket.create!(
  2519. title: "some <b>title</b>\n äöüß",
  2520. group: Group.lookup(name: 'Users'),
  2521. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2522. updated_by_id: 1,
  2523. created_by_id: 1,
  2524. )
  2525. Ticket::Article.create!(
  2526. ticket_id: ticket1.id,
  2527. from: 'some_sender@example.com',
  2528. to: 'some_recipient+from@example.com',
  2529. reply_to: 'some_recipient+reply_to@example.com',
  2530. subject: 'some subject',
  2531. message_id: 'some@id',
  2532. body: "some message <b>note</b>\nnew line",
  2533. internal: false,
  2534. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2535. type: Ticket::Article::Type.find_by(name: 'note'),
  2536. updated_by_id: 1,
  2537. created_by_id: 1,
  2538. )
  2539. Observer::Transaction.commit
  2540. ticket1.reload
  2541. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2542. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2543. auto_response = ticket1.articles.last
  2544. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2545. assert_match('some_recipient+reply_to@example.com', auto_response.to)
  2546. end
  2547. test 'article_last_sender trigger -> from' do
  2548. Trigger.create_or_update(
  2549. name: 'auto reply',
  2550. condition: {
  2551. 'ticket.action' => {
  2552. 'operator' => 'is',
  2553. 'value' => 'create',
  2554. },
  2555. 'ticket.state_id' => {
  2556. 'operator' => 'is',
  2557. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2558. }
  2559. },
  2560. perform: {
  2561. 'notification.email' => {
  2562. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2563. 'recipient' => 'article_last_sender',
  2564. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2565. },
  2566. },
  2567. disable_notification: true,
  2568. active: true,
  2569. created_by_id: 1,
  2570. updated_by_id: 1,
  2571. )
  2572. ticket1 = Ticket.create!(
  2573. title: "some <b>title</b>\n äöüß",
  2574. group: Group.lookup(name: 'Users'),
  2575. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2576. updated_by_id: 1,
  2577. created_by_id: 1,
  2578. )
  2579. Ticket::Article.create!(
  2580. ticket_id: ticket1.id,
  2581. from: 'some_sender+from@example.com',
  2582. to: 'some_recipient@example.com',
  2583. subject: 'some subject',
  2584. message_id: 'some@id',
  2585. body: "some message <b>note</b>\nnew line",
  2586. internal: false,
  2587. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2588. type: Ticket::Article::Type.find_by(name: 'email'),
  2589. updated_by_id: 1,
  2590. created_by_id: 1,
  2591. )
  2592. Observer::Transaction.commit
  2593. ticket1.reload
  2594. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2595. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2596. auto_response = ticket1.articles.last
  2597. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2598. assert_match('some_sender+from@example.com', auto_response.to)
  2599. end
  2600. test 'article_last_sender trigger -> origin_by_id' do
  2601. Trigger.create_or_update(
  2602. name: 'auto reply',
  2603. condition: {
  2604. 'ticket.action' => {
  2605. 'operator' => 'is',
  2606. 'value' => 'create',
  2607. },
  2608. 'ticket.state_id' => {
  2609. 'operator' => 'is',
  2610. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2611. }
  2612. },
  2613. perform: {
  2614. 'notification.email' => {
  2615. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2616. 'recipient' => 'article_last_sender',
  2617. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2618. },
  2619. },
  2620. disable_notification: true,
  2621. active: true,
  2622. created_by_id: 1,
  2623. updated_by_id: 1,
  2624. )
  2625. roles = Role.where(name: 'Customer')
  2626. customer1 = User.create_or_update(
  2627. login: 'customer+origin_by_id@example.com',
  2628. firstname: 'Trigger',
  2629. lastname: 'Customer1',
  2630. email: 'customer+origin_by_id@example.com',
  2631. password: 'customerpw',
  2632. active: true,
  2633. roles: roles,
  2634. updated_at: '2015-02-05 16:37:00',
  2635. updated_by_id: 1,
  2636. created_by_id: 1,
  2637. )
  2638. ticket1 = Ticket.create!(
  2639. title: "some <b>title</b>\n äöüß",
  2640. group: Group.lookup(name: 'Users'),
  2641. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2642. updated_by_id: 1,
  2643. created_by_id: 1,
  2644. )
  2645. Ticket::Article.create!(
  2646. ticket_id: ticket1.id,
  2647. to: 'some_recipient@example.com',
  2648. subject: 'some subject',
  2649. message_id: 'some@id',
  2650. body: "some message <b>note</b>\nnew line",
  2651. internal: false,
  2652. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2653. type: Ticket::Article::Type.find_by(name: 'email'),
  2654. origin_by_id: customer1.id,
  2655. updated_by_id: 1,
  2656. created_by_id: 1,
  2657. )
  2658. Observer::Transaction.commit
  2659. ticket1.reload
  2660. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2661. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2662. auto_response = ticket1.articles.last
  2663. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2664. assert_match('customer+origin_by_id@example.com', auto_response.to)
  2665. end
  2666. test 'article_last_sender trigger -> created_by_id' do
  2667. Trigger.create_or_update(
  2668. name: 'auto reply',
  2669. condition: {
  2670. 'ticket.action' => {
  2671. 'operator' => 'is',
  2672. 'value' => 'create',
  2673. },
  2674. 'ticket.state_id' => {
  2675. 'operator' => 'is',
  2676. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2677. }
  2678. },
  2679. perform: {
  2680. 'notification.email' => {
  2681. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2682. 'recipient' => 'article_last_sender',
  2683. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2684. },
  2685. },
  2686. disable_notification: true,
  2687. active: true,
  2688. created_by_id: 1,
  2689. updated_by_id: 1,
  2690. )
  2691. roles = Role.where(name: 'Customer')
  2692. customer1 = User.create_or_update(
  2693. login: 'customer+created_by_id@example.com',
  2694. firstname: 'Trigger',
  2695. lastname: 'Customer1',
  2696. email: 'customer+created_by_id@example.com',
  2697. password: 'customerpw',
  2698. active: true,
  2699. roles: roles,
  2700. updated_at: '2015-02-05 16:37:00',
  2701. updated_by_id: 1,
  2702. created_by_id: 1,
  2703. )
  2704. ticket1 = Ticket.create!(
  2705. title: "some <b>title</b>\n äöüß",
  2706. group: Group.lookup(name: 'Users'),
  2707. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2708. updated_by_id: 1,
  2709. created_by_id: 1,
  2710. )
  2711. Ticket::Article.create!(
  2712. ticket_id: ticket1.id,
  2713. to: 'some_recipient@example.com',
  2714. subject: 'some subject',
  2715. message_id: 'some@id',
  2716. body: "some message <b>note</b>\nnew line",
  2717. internal: false,
  2718. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2719. type: Ticket::Article::Type.find_by(name: 'email'),
  2720. updated_by_id: customer1.id,
  2721. created_by_id: customer1.id,
  2722. )
  2723. Observer::Transaction.commit
  2724. ticket1.reload
  2725. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2726. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2727. auto_response = ticket1.articles.last
  2728. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2729. assert_match('customer+created_by_id@example.com', auto_response.to)
  2730. end
  2731. test 'multiple recipients owner_id, article_last_sender(reply_to) trigger' do
  2732. Trigger.create_or_update(
  2733. name: 'auto reply',
  2734. condition: {
  2735. 'ticket.action' => {
  2736. 'operator' => 'is',
  2737. 'value' => 'create',
  2738. },
  2739. 'ticket.state_id' => {
  2740. 'operator' => 'is',
  2741. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2742. }
  2743. },
  2744. perform: {
  2745. 'notification.email' => {
  2746. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2747. 'recipient' => %w[ticket_owner article_last_sender],
  2748. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2749. },
  2750. },
  2751. disable_notification: true,
  2752. active: true,
  2753. created_by_id: 1,
  2754. updated_by_id: 1,
  2755. )
  2756. admin = User.create_or_update(
  2757. login: 'admin+owner_recipient@example.com',
  2758. firstname: 'Role',
  2759. lastname: "Admin#{name}",
  2760. email: 'admin+owner_recipient@example.com',
  2761. password: 'adminpw',
  2762. active: true,
  2763. roles: Role.where(name: %w[Admin Agent]),
  2764. groups: Group.where(name: 'Users'),
  2765. updated_by_id: 1,
  2766. created_by_id: 1,
  2767. )
  2768. ticket1 = Ticket.create!(
  2769. title: "some <b>title</b>\n äöüß",
  2770. group: Group.lookup(name: 'Users'),
  2771. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2772. owner_id: admin.id,
  2773. updated_by_id: 1,
  2774. created_by_id: 1,
  2775. )
  2776. Ticket::Article.create!(
  2777. ticket_id: ticket1.id,
  2778. from: 'some_sender@example.com',
  2779. to: 'some_recipient+from@example.com',
  2780. reply_to: 'some_recipient+reply_to@example.com',
  2781. subject: 'some subject',
  2782. message_id: 'some@id',
  2783. body: "some message <b>note</b>\nnew line",
  2784. internal: false,
  2785. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2786. type: Ticket::Article::Type.find_by(name: 'note'),
  2787. updated_by_id: 1,
  2788. created_by_id: 1,
  2789. )
  2790. Observer::Transaction.commit
  2791. ticket1.reload
  2792. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2793. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  2794. auto_response = ticket1.articles.last
  2795. assert_match('Zammad <zammad@localhost>', auto_response.from)
  2796. assert_match('some_recipient+reply_to@example.com', auto_response.to)
  2797. assert_match('admin+owner_recipient@example.com', auto_response.to)
  2798. end
  2799. test 'article_last_sender trigger -> invalid reply_to' do
  2800. Trigger.create_or_update(
  2801. name: 'auto reply',
  2802. condition: {
  2803. 'ticket.action' => {
  2804. 'operator' => 'is',
  2805. 'value' => 'create',
  2806. },
  2807. 'ticket.state_id' => {
  2808. 'operator' => 'is',
  2809. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  2810. }
  2811. },
  2812. perform: {
  2813. 'notification.email' => {
  2814. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  2815. 'recipient' => 'article_last_sender',
  2816. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  2817. },
  2818. },
  2819. disable_notification: true,
  2820. active: true,
  2821. created_by_id: 1,
  2822. updated_by_id: 1,
  2823. )
  2824. ticket1 = Ticket.create!(
  2825. title: "some <b>title</b>\n äöüß",
  2826. group: Group.lookup(name: 'Users'),
  2827. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2828. updated_by_id: 1,
  2829. created_by_id: 1,
  2830. )
  2831. Ticket::Article.create!(
  2832. ticket_id: ticket1.id,
  2833. from: 'some_sender@example.com',
  2834. to: 'some_recipient+from@example.com',
  2835. reply_to: 'Blub blub blub some_recipient+reply_to@example',
  2836. subject: 'some subject',
  2837. message_id: 'some@id',
  2838. body: "some message <b>note</b>\nnew line",
  2839. internal: false,
  2840. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  2841. type: Ticket::Article::Type.find_by(name: 'note'),
  2842. updated_by_id: 1,
  2843. created_by_id: 1,
  2844. )
  2845. Observer::Transaction.commit
  2846. ticket1.reload
  2847. assert_equal('new', ticket1.state.name, 'ticket1.state new')
  2848. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  2849. end
  2850. test '2 loop check' do
  2851. Trigger.create_or_update(
  2852. name: 'aaa loop check',
  2853. condition: {
  2854. 'ticket.state_id' => {
  2855. 'operator' => 'is',
  2856. 'value' => Ticket::State.all.pluck(:id),
  2857. },
  2858. 'article.sender_id' => {
  2859. 'operator' => 'is',
  2860. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  2861. },
  2862. 'article.type_id' => {
  2863. 'operator' => 'is',
  2864. 'value' => [
  2865. Ticket::Article::Type.lookup(name: 'email').id,
  2866. Ticket::Article::Type.lookup(name: 'phone').id,
  2867. Ticket::Article::Type.lookup(name: 'web').id,
  2868. ],
  2869. },
  2870. },
  2871. perform: {
  2872. 'notification.email' => {
  2873. 'body' => 'some lala',
  2874. 'recipient' => 'ticket_customer',
  2875. 'subject' => 'Thanks for your inquiry - loop check (#{ticket.title})!',
  2876. },
  2877. },
  2878. disable_notification: true,
  2879. active: true,
  2880. created_by_id: 1,
  2881. updated_by_id: 1,
  2882. )
  2883. ticket1 = Ticket.create!(
  2884. title: 'loop try 1',
  2885. group: Group.lookup(name: 'Users'),
  2886. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  2887. updated_by_id: 1,
  2888. created_by_id: 1,
  2889. )
  2890. Ticket::Article.create!(
  2891. ticket_id: ticket1.id,
  2892. from: 'some_loop_sender@example.com',
  2893. to: 'some_loop_recipient@example.com',
  2894. subject: 'some subject',
  2895. message_id: 'some@id',
  2896. body: "some message <b>note</b>\nnew line",
  2897. internal: false,
  2898. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2899. type: Ticket::Article::Type.find_by(name: 'email'),
  2900. updated_by_id: 1,
  2901. created_by_id: 1,
  2902. )
  2903. ticket1.reload
  2904. assert_equal(1, ticket1.articles.count)
  2905. Observer::Transaction.commit
  2906. ticket1.reload
  2907. assert_equal(2, ticket1.articles.count)
  2908. ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
  2909. ticket1.save!
  2910. Observer::Transaction.commit
  2911. ticket1.reload
  2912. assert_equal(2, ticket1.articles.count)
  2913. Ticket::Article.create!(
  2914. ticket_id: ticket1.id,
  2915. from: 'some_loop_sender@example.com',
  2916. to: 'some_loop_recipient@example.com',
  2917. subject: 'some subject 1234',
  2918. message_id: 'some@id',
  2919. content_type: 'text/html',
  2920. body: 'some message <b>note</b><br>new line',
  2921. internal: false,
  2922. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2923. type: Ticket::Article::Type.find_by(name: 'email'),
  2924. updated_by_id: 1,
  2925. created_by_id: 1,
  2926. )
  2927. Observer::Transaction.commit
  2928. ticket1.reload
  2929. assert_equal(4, ticket1.articles.count)
  2930. assert_equal('some_loop_sender@example.com', ticket1.articles[2].from)
  2931. assert_equal('nicole.braun@zammad.org', ticket1.articles[3].to)
  2932. Ticket::Article.create!(
  2933. ticket_id: ticket1.id,
  2934. from: 'some_loop_sender@example.com',
  2935. to: 'some_loop_recipient@example.com',
  2936. subject: 'some subject 1234',
  2937. message_id: 'some@id',
  2938. content_type: 'text/html',
  2939. body: 'some message <b>note</b><br>new line',
  2940. internal: false,
  2941. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2942. type: Ticket::Article::Type.find_by(name: 'email'),
  2943. updated_by_id: 1,
  2944. created_by_id: 1,
  2945. )
  2946. Observer::Transaction.commit
  2947. ticket1.reload
  2948. assert_equal(6, ticket1.articles.count)
  2949. assert_equal('some_loop_sender@example.com', ticket1.articles[4].from)
  2950. assert_equal('nicole.braun@zammad.org', ticket1.articles[5].to)
  2951. Ticket::Article.create!(
  2952. ticket_id: ticket1.id,
  2953. from: 'some_loop_sender@example.com',
  2954. to: 'some_loop_recipient@example.com',
  2955. subject: 'some subject 1234',
  2956. message_id: 'some@id',
  2957. content_type: 'text/html',
  2958. body: 'some message <b>note</b><br>new line',
  2959. internal: false,
  2960. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2961. type: Ticket::Article::Type.find_by(name: 'email'),
  2962. updated_by_id: 1,
  2963. created_by_id: 1,
  2964. )
  2965. Observer::Transaction.commit
  2966. ticket1.reload
  2967. assert_equal(8, ticket1.articles.count)
  2968. assert_equal('some_loop_sender@example.com', ticket1.articles[6].from)
  2969. assert_equal('nicole.braun@zammad.org', ticket1.articles[7].to)
  2970. Ticket::Article.create!(
  2971. ticket_id: ticket1.id,
  2972. from: 'some_loop_sender@example.com',
  2973. to: 'some_loop_recipient@example.com',
  2974. subject: 'some subject 1234',
  2975. message_id: 'some@id',
  2976. content_type: 'text/html',
  2977. body: 'some message <b>note</b><br>new line',
  2978. internal: false,
  2979. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2980. type: Ticket::Article::Type.find_by(name: 'email'),
  2981. updated_by_id: 1,
  2982. created_by_id: 1,
  2983. )
  2984. Observer::Transaction.commit
  2985. ticket1.reload
  2986. assert_equal(10, ticket1.articles.count)
  2987. assert_equal('some_loop_sender@example.com', ticket1.articles[8].from)
  2988. assert_equal('nicole.braun@zammad.org', ticket1.articles[9].to)
  2989. Ticket::Article.create!(
  2990. ticket_id: ticket1.id,
  2991. from: 'some_loop_sender@example.com',
  2992. to: 'some_loop_recipient@example.com',
  2993. subject: 'some subject 1234',
  2994. message_id: 'some@id',
  2995. content_type: 'text/html',
  2996. body: 'some message <b>note</b><br>new line',
  2997. internal: false,
  2998. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  2999. type: Ticket::Article::Type.find_by(name: 'email'),
  3000. updated_by_id: 1,
  3001. created_by_id: 1,
  3002. )
  3003. Observer::Transaction.commit
  3004. ticket1.reload
  3005. assert_equal(12, ticket1.articles.count)
  3006. assert_equal('some_loop_sender@example.com', ticket1.articles[10].from)
  3007. assert_equal('nicole.braun@zammad.org', ticket1.articles[11].to)
  3008. Ticket::Article.create!(
  3009. ticket_id: ticket1.id,
  3010. from: 'some_loop_sender@example.com',
  3011. to: 'some_loop_recipient@example.com',
  3012. subject: 'some subject 1234',
  3013. message_id: 'some@id',
  3014. content_type: 'text/html',
  3015. body: 'some message <b>note</b><br>new line',
  3016. internal: false,
  3017. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3018. type: Ticket::Article::Type.find_by(name: 'email'),
  3019. updated_by_id: 1,
  3020. created_by_id: 1,
  3021. )
  3022. Observer::Transaction.commit
  3023. ticket1.reload
  3024. assert_equal(14, ticket1.articles.count)
  3025. assert_equal('some_loop_sender@example.com', ticket1.articles[12].from)
  3026. assert_equal('nicole.braun@zammad.org', ticket1.articles[13].to)
  3027. Ticket::Article.create!(
  3028. ticket_id: ticket1.id,
  3029. from: 'some_loop_sender@example.com',
  3030. to: 'some_loop_recipient@example.com',
  3031. subject: 'some subject 1234',
  3032. message_id: 'some@id',
  3033. content_type: 'text/html',
  3034. body: 'some message <b>note</b><br>new line',
  3035. internal: false,
  3036. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3037. type: Ticket::Article::Type.find_by(name: 'email'),
  3038. updated_by_id: 1,
  3039. created_by_id: 1,
  3040. )
  3041. Observer::Transaction.commit
  3042. ticket1.reload
  3043. assert_equal(16, ticket1.articles.count)
  3044. assert_equal('some_loop_sender@example.com', ticket1.articles[14].from)
  3045. assert_equal('nicole.braun@zammad.org', ticket1.articles[15].to)
  3046. Ticket::Article.create!(
  3047. ticket_id: ticket1.id,
  3048. from: 'some_loop_sender@example.com',
  3049. to: 'some_loop_recipient@example.com',
  3050. subject: 'some subject 1234',
  3051. message_id: 'some@id',
  3052. content_type: 'text/html',
  3053. body: 'some message <b>note</b><br>new line',
  3054. internal: false,
  3055. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3056. type: Ticket::Article::Type.find_by(name: 'email'),
  3057. updated_by_id: 1,
  3058. created_by_id: 1,
  3059. )
  3060. Observer::Transaction.commit
  3061. ticket1.reload
  3062. assert_equal(18, ticket1.articles.count)
  3063. assert_equal('some_loop_sender@example.com', ticket1.articles[16].from)
  3064. assert_equal('nicole.braun@zammad.org', ticket1.articles[17].to)
  3065. Ticket::Article.create!(
  3066. ticket_id: ticket1.id,
  3067. from: 'some_loop_sender@example.com',
  3068. to: 'some_loop_recipient@example.com',
  3069. subject: 'some subject 1234',
  3070. message_id: 'some@id',
  3071. content_type: 'text/html',
  3072. body: 'some message <b>note</b><br>new line',
  3073. internal: false,
  3074. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3075. type: Ticket::Article::Type.find_by(name: 'email'),
  3076. updated_by_id: 1,
  3077. created_by_id: 1,
  3078. )
  3079. Observer::Transaction.commit
  3080. ticket1.reload
  3081. assert_equal(20, ticket1.articles.count)
  3082. assert_equal('some_loop_sender@example.com', ticket1.articles[18].from)
  3083. assert_equal('nicole.braun@zammad.org', ticket1.articles[19].to)
  3084. Ticket::Article.create!(
  3085. ticket_id: ticket1.id,
  3086. from: 'some_loop_sender@example.com',
  3087. to: 'some_loop_recipient@example.com',
  3088. subject: 'some subject 1234',
  3089. message_id: 'some@id',
  3090. content_type: 'text/html',
  3091. body: 'some message <b>note</b><br>new line',
  3092. internal: false,
  3093. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3094. type: Ticket::Article::Type.find_by(name: 'email'),
  3095. updated_by_id: 1,
  3096. created_by_id: 1,
  3097. )
  3098. Observer::Transaction.commit
  3099. ticket1.reload
  3100. assert_equal(21, ticket1.articles.count)
  3101. assert_equal('some_loop_sender@example.com', ticket1.articles[20].from)
  3102. Ticket::Article.create!(
  3103. ticket_id: ticket1.id,
  3104. from: 'some_loop_sender@example.com',
  3105. to: 'some_loop_recipient@example.com',
  3106. subject: 'some subject 1234',
  3107. message_id: 'some@id',
  3108. content_type: 'text/html',
  3109. body: 'some message <b>note</b><br>new line',
  3110. internal: false,
  3111. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3112. type: Ticket::Article::Type.find_by(name: 'email'),
  3113. updated_by_id: 1,
  3114. created_by_id: 1,
  3115. )
  3116. Observer::Transaction.commit
  3117. ticket1.reload
  3118. assert_equal(22, ticket1.articles.count)
  3119. assert_equal('some_loop_sender@example.com', ticket1.articles[21].from)
  3120. end
  3121. test '3 invalid condition' do
  3122. trigger1 = Trigger.create_or_update(
  3123. name: 'aaa loop check',
  3124. condition: {
  3125. 'ticket.action' => {
  3126. 'operator' => 'is',
  3127. 'value' => 'create',
  3128. },
  3129. },
  3130. perform: {
  3131. 'ticket.tags' => {
  3132. 'operator' => 'add',
  3133. 'value' => 'xxx',
  3134. },
  3135. },
  3136. disable_notification: true,
  3137. active: true,
  3138. created_by_id: 1,
  3139. updated_by_id: 1,
  3140. )
  3141. trigger1.update_column(:condition, {
  3142. 'ticket.action' => {
  3143. 'operator' => 'is',
  3144. 'value' => 'create',
  3145. },
  3146. 'ticket.first_response_at' => {
  3147. 'operator' => 'before (absolute)',
  3148. 'value' => 'invalid invalid 4',
  3149. },
  3150. })
  3151. assert_equal('invalid invalid 4', trigger1.condition['ticket.first_response_at']['value'])
  3152. Trigger.create_or_update(
  3153. name: 'auto reply',
  3154. condition: {
  3155. 'ticket.action' => {
  3156. 'operator' => 'is',
  3157. 'value' => 'create',
  3158. },
  3159. 'ticket.state_id' => {
  3160. 'operator' => 'is',
  3161. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3162. }
  3163. },
  3164. perform: {
  3165. 'notification.email' => {
  3166. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3167. 'recipient' => 'ticket_customer',
  3168. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3169. },
  3170. 'ticket.priority_id' => {
  3171. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  3172. },
  3173. 'ticket.tags' => {
  3174. 'operator' => 'add',
  3175. 'value' => 'aa, kk',
  3176. },
  3177. },
  3178. disable_notification: true,
  3179. active: true,
  3180. created_by_id: 1,
  3181. updated_by_id: 1,
  3182. )
  3183. ticket1 = Ticket.create!(
  3184. title: "some <b>title</b>\n äöüß",
  3185. group: Group.lookup(name: 'Users'),
  3186. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3187. updated_by_id: 1,
  3188. created_by_id: 1,
  3189. )
  3190. Ticket::Article.create!(
  3191. ticket_id: ticket1.id,
  3192. from: 'some_sender@example.com',
  3193. to: 'some_recipient@example.com',
  3194. subject: 'some subject',
  3195. message_id: 'some@id',
  3196. body: "some message <b>note</b>\nnew line",
  3197. internal: false,
  3198. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3199. type: Ticket::Article::Type.find_by(name: 'note'),
  3200. updated_by_id: 1,
  3201. created_by_id: 1,
  3202. )
  3203. ticket1.reload
  3204. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  3205. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3206. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3207. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3208. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3209. assert_equal([], ticket1.tag_list)
  3210. Observer::Transaction.commit
  3211. ticket1.reload
  3212. assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
  3213. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3214. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3215. assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
  3216. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3217. assert_equal(%w[aa kk], ticket1.tag_list)
  3218. article1 = ticket1.articles.last
  3219. assert_match('Zammad <zammad@localhost>', article1.from)
  3220. assert_match('nicole.braun@zammad.org', article1.to)
  3221. assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
  3222. assert_match('Braun<br>some &lt;b&gt;title&lt;/b&gt;', article1.body)
  3223. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt;<br>&gt; new line', article1.body)
  3224. assert_equal('text/html', article1.content_type)
  3225. end
  3226. test '4 tag based auto response' do
  3227. Trigger.create_or_update(
  3228. name: '100 add tag if sender 1',
  3229. condition: {
  3230. 'ticket.action' => {
  3231. 'operator' => 'is',
  3232. 'value' => 'create',
  3233. },
  3234. 'article.from' => {
  3235. 'operator' => 'contains',
  3236. 'value' => 'sender1',
  3237. },
  3238. },
  3239. perform: {
  3240. 'ticket.tags' => {
  3241. 'operator' => 'add',
  3242. 'value' => 'sender1',
  3243. },
  3244. },
  3245. disable_notification: true,
  3246. active: true,
  3247. created_by_id: 1,
  3248. updated_by_id: 1,
  3249. )
  3250. Trigger.create_or_update(
  3251. name: '200 add tag if sender 2',
  3252. condition: {
  3253. 'ticket.action' => {
  3254. 'operator' => 'is',
  3255. 'value' => 'create',
  3256. },
  3257. 'article.from' => {
  3258. 'operator' => 'contains',
  3259. 'value' => 'sender2',
  3260. },
  3261. },
  3262. perform: {
  3263. 'ticket.tags' => {
  3264. 'operator' => 'add',
  3265. 'value' => 'sender2',
  3266. },
  3267. },
  3268. disable_notification: true,
  3269. active: true,
  3270. created_by_id: 1,
  3271. updated_by_id: 1,
  3272. )
  3273. Trigger.create_or_update(
  3274. name: '300 auto reply',
  3275. condition: {
  3276. 'ticket.action' => {
  3277. 'operator' => 'is',
  3278. 'value' => 'create',
  3279. },
  3280. 'ticket.state_id' => {
  3281. 'operator' => 'is',
  3282. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3283. },
  3284. 'ticket.tags' => {
  3285. #'operator' => 'contains one not',
  3286. 'operator' => 'contains all not',
  3287. 'value' => 'sender1, sender2',
  3288. },
  3289. },
  3290. perform: {
  3291. 'notification.email' => {
  3292. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3293. 'recipient' => 'ticket_customer',
  3294. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3295. },
  3296. },
  3297. disable_notification: true,
  3298. active: true,
  3299. created_by_id: 1,
  3300. updated_by_id: 1,
  3301. )
  3302. ticket1 = Ticket.create!(
  3303. title: 'test 1',
  3304. group: Group.lookup(name: 'Users'),
  3305. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3306. updated_by_id: 1,
  3307. created_by_id: 1,
  3308. )
  3309. Ticket::Article.create!(
  3310. ticket_id: ticket1.id,
  3311. from: 'sender1@example.com',
  3312. to: 'some_recipient@example.com',
  3313. subject: 'some subject',
  3314. message_id: 'some@id',
  3315. body: "some message <b>note</b>\nnew line",
  3316. internal: false,
  3317. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3318. type: Ticket::Article::Type.find_by(name: 'email'),
  3319. updated_by_id: 1,
  3320. created_by_id: 1,
  3321. )
  3322. ticket1.reload
  3323. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3324. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3325. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3326. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3327. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3328. assert_equal([], ticket1.tag_list)
  3329. Observer::Transaction.commit
  3330. ticket1.reload
  3331. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3332. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3333. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3334. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3335. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3336. assert_equal(%w[sender1], ticket1.tag_list)
  3337. ticket2 = Ticket.create!(
  3338. title: 'test 2',
  3339. group: Group.lookup(name: 'Users'),
  3340. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3341. updated_by_id: 1,
  3342. created_by_id: 1,
  3343. )
  3344. Ticket::Article.create!(
  3345. ticket_id: ticket2.id,
  3346. from: 'sender2@example.com',
  3347. to: 'some_recipient@example.com',
  3348. subject: 'some subject',
  3349. message_id: 'some@id',
  3350. body: "some message <b>note</b>\nnew line",
  3351. internal: false,
  3352. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3353. type: Ticket::Article::Type.find_by(name: 'email'),
  3354. updated_by_id: 1,
  3355. created_by_id: 1,
  3356. )
  3357. ticket2.reload
  3358. assert_equal('test 2', ticket2.title, 'ticket2.title verify')
  3359. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3360. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3361. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3362. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3363. assert_equal([], ticket2.tag_list)
  3364. Observer::Transaction.commit
  3365. ticket2.reload
  3366. assert_equal('test 2', ticket2.title, 'ticket2.title verify')
  3367. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3368. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3369. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3370. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3371. assert_equal(%w[sender2], ticket2.tag_list)
  3372. ticket3 = Ticket.create!(
  3373. title: 'test 3',
  3374. group: Group.lookup(name: 'Users'),
  3375. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3376. updated_by_id: 1,
  3377. created_by_id: 1,
  3378. )
  3379. assert(ticket3, 'ticket3 created')
  3380. Ticket::Article.create!(
  3381. ticket_id: ticket3.id,
  3382. from: 'sender0@example.com',
  3383. to: 'some_recipient@example.com',
  3384. subject: 'some subject',
  3385. message_id: 'some@id',
  3386. body: "some message <b>note</b>\nnew line",
  3387. internal: false,
  3388. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3389. type: Ticket::Article::Type.find_by(name: 'email'),
  3390. updated_by_id: 1,
  3391. created_by_id: 1,
  3392. )
  3393. ticket3.reload
  3394. assert_equal('test 3', ticket3.title, 'ticket3.title verify')
  3395. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3396. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3397. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3398. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3399. assert_equal([], ticket3.tag_list)
  3400. Observer::Transaction.commit
  3401. ticket3.reload
  3402. assert_equal('test 3', ticket3.title, 'ticket3.title verify')
  3403. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3404. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3405. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3406. assert_equal(2, ticket3.articles.count, 'ticket3.articles verify')
  3407. assert_equal([], ticket3.tag_list)
  3408. ticket3.articles.last
  3409. end
  3410. test 'article.body' do
  3411. Trigger.create_or_update(
  3412. name: 'auto reply',
  3413. condition: {
  3414. 'ticket.action' => {
  3415. 'operator' => 'is',
  3416. 'value' => 'create',
  3417. },
  3418. 'ticket.state_id' => {
  3419. 'operator' => 'is',
  3420. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3421. },
  3422. 'article.body' => {
  3423. 'operator' => 'contains',
  3424. 'value' => 'hello',
  3425. },
  3426. },
  3427. perform: {
  3428. 'notification.email' => {
  3429. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3430. 'recipient' => 'ticket_customer',
  3431. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3432. },
  3433. 'ticket.tags' => {
  3434. 'operator' => 'add',
  3435. 'value' => 'aa, kk',
  3436. },
  3437. },
  3438. disable_notification: true,
  3439. active: true,
  3440. created_by_id: 1,
  3441. updated_by_id: 1,
  3442. )
  3443. ticket1 = Ticket.create!(
  3444. title: 'test 1',
  3445. group: Group.lookup(name: 'Users'),
  3446. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3447. updated_by_id: 1,
  3448. created_by_id: 1,
  3449. )
  3450. Ticket::Article.create!(
  3451. ticket_id: ticket1.id,
  3452. from: 'some_sender@example.com',
  3453. to: 'some_recipient@example.com',
  3454. subject: 'some subject',
  3455. message_id: 'some@id',
  3456. body: 'some message <b>note</b> hello ',
  3457. internal: false,
  3458. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3459. type: Ticket::Article::Type.find_by(name: 'note'),
  3460. updated_by_id: 1,
  3461. created_by_id: 1,
  3462. )
  3463. ticket1.reload
  3464. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3465. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3466. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3467. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3468. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3469. assert_equal([], ticket1.tag_list)
  3470. Observer::Transaction.commit
  3471. ticket1.reload
  3472. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3473. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3474. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3475. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3476. assert_equal(%w[aa kk], ticket1.tag_list)
  3477. article1 = ticket1.articles.last
  3478. assert_match('Zammad <zammad@localhost>', article1.from)
  3479. assert_match('nicole.braun@zammad.org', article1.to)
  3480. assert_match('Thanks for your inquiry (test 1)!', article1.subject)
  3481. assert_match('some message', article1.body)
  3482. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; hello', article1.body)
  3483. assert_equal('text/html', article1.content_type)
  3484. ticket2 = Ticket.create!(
  3485. title: 'test 1',
  3486. group: Group.lookup(name: 'Users'),
  3487. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3488. updated_by_id: 1,
  3489. created_by_id: 1,
  3490. )
  3491. Ticket::Article.create!(
  3492. ticket_id: ticket2.id,
  3493. from: 'some_sender@example.com',
  3494. to: 'some_recipient@example.com',
  3495. subject: 'some subject',
  3496. message_id: 'some@id',
  3497. body: 'some message <b>note</b>',
  3498. internal: false,
  3499. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3500. type: Ticket::Article::Type.find_by(name: 'note'),
  3501. updated_by_id: 1,
  3502. created_by_id: 1,
  3503. )
  3504. ticket2.reload
  3505. assert_equal('test 1', ticket2.title, 'ticket2.title verify')
  3506. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3507. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3508. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3509. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3510. assert_equal([], ticket2.tag_list)
  3511. Observer::Transaction.commit
  3512. ticket2.reload
  3513. assert_equal('test 1', ticket2.title, 'ticket2.title verify')
  3514. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3515. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3516. assert_equal(1, ticket2.articles.count, 'ticket2.articles verify')
  3517. assert_equal(%w[], ticket2.tag_list)
  3518. Trigger.create_or_update(
  3519. name: 'auto reply',
  3520. condition: {
  3521. 'ticket.action' => {
  3522. 'operator' => 'is',
  3523. 'value' => 'create',
  3524. },
  3525. 'ticket.state_id' => {
  3526. 'operator' => 'is',
  3527. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3528. },
  3529. 'article.body' => {
  3530. 'operator' => 'contains not',
  3531. 'value' => 'hello',
  3532. },
  3533. },
  3534. perform: {
  3535. 'notification.email' => {
  3536. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3537. 'recipient' => 'ticket_customer',
  3538. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3539. },
  3540. 'ticket.tags' => {
  3541. 'operator' => 'add',
  3542. 'value' => 'aa, kk',
  3543. },
  3544. },
  3545. disable_notification: true,
  3546. active: true,
  3547. created_by_id: 1,
  3548. updated_by_id: 1,
  3549. )
  3550. ticket3 = Ticket.create!(
  3551. title: 'test 1',
  3552. group: Group.lookup(name: 'Users'),
  3553. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3554. updated_by_id: 1,
  3555. created_by_id: 1,
  3556. )
  3557. Ticket::Article.create!(
  3558. ticket_id: ticket3.id,
  3559. from: 'some_sender@example.com',
  3560. to: 'some_recipient@example.com',
  3561. subject: 'some subject',
  3562. message_id: 'some@id',
  3563. body: 'some message <b>note</b> hello ',
  3564. internal: false,
  3565. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3566. type: Ticket::Article::Type.find_by(name: 'note'),
  3567. updated_by_id: 1,
  3568. created_by_id: 1,
  3569. )
  3570. ticket3.reload
  3571. assert_equal('test 1', ticket3.title, 'ticket3.title verify')
  3572. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3573. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3574. assert_equal('2 normal', ticket3.priority.name, 'ticket3.priority verify')
  3575. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3576. assert_equal([], ticket3.tag_list)
  3577. Observer::Transaction.commit
  3578. ticket3.reload
  3579. assert_equal('test 1', ticket3.title, 'ticket3.title verify')
  3580. assert_equal('Users', ticket3.group.name, 'ticket3.group verify')
  3581. assert_equal('new', ticket3.state.name, 'ticket3.state verify')
  3582. assert_equal(1, ticket3.articles.count, 'ticket3.articles verify')
  3583. assert_equal(%w[], ticket3.tag_list)
  3584. ticket4 = Ticket.create!(
  3585. title: 'test 1',
  3586. group: Group.lookup(name: 'Users'),
  3587. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3588. updated_by_id: 1,
  3589. created_by_id: 1,
  3590. )
  3591. Ticket::Article.create!(
  3592. ticket_id: ticket4.id,
  3593. from: 'some_sender@example.com',
  3594. to: 'some_recipient@example.com',
  3595. subject: 'some subject',
  3596. message_id: 'some@id',
  3597. body: 'some message <b>note</b> 2',
  3598. internal: false,
  3599. sender: Ticket::Article::Sender.find_by(name: 'Agent'),
  3600. type: Ticket::Article::Type.find_by(name: 'note'),
  3601. updated_by_id: 1,
  3602. created_by_id: 1,
  3603. )
  3604. ticket4.reload
  3605. assert_equal('test 1', ticket4.title, 'ticket4.title verify')
  3606. assert_equal('Users', ticket4.group.name, 'ticket4.group verify')
  3607. assert_equal('new', ticket4.state.name, 'ticket4.state verify')
  3608. assert_equal('2 normal', ticket4.priority.name, 'ticket4.priority verify')
  3609. assert_equal(1, ticket4.articles.count, 'ticket4.articles verify')
  3610. assert_equal([], ticket4.tag_list)
  3611. Observer::Transaction.commit
  3612. ticket4.reload
  3613. assert_equal('test 1', ticket4.title, 'ticket4.title verify')
  3614. assert_equal('Users', ticket4.group.name, 'ticket4.group verify')
  3615. assert_equal('new', ticket4.state.name, 'ticket4.state verify')
  3616. assert_equal(2, ticket4.articles.count, 'ticket4.articles verify')
  3617. assert_equal(%w[aa kk], ticket4.tag_list)
  3618. article4 = ticket4.articles.last
  3619. assert_match('Zammad <zammad@localhost>', article4.from)
  3620. assert_match('nicole.braun@zammad.org', article4.to)
  3621. assert_match('Thanks for your inquiry (test 1)!', article4.subject)
  3622. assert_match('some message', article4.body)
  3623. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; 2', article4.body)
  3624. assert_equal('text/html', article4.content_type)
  3625. end
  3626. test 'change owner' do
  3627. roles = Role.where(name: 'Agent')
  3628. groups = Group.where(name: 'Users')
  3629. agent1 = User.create_or_update(
  3630. login: 'agent-has-changed@example.com',
  3631. firstname: 'Has Changed',
  3632. lastname: 'Agent1',
  3633. email: 'agent-has-changed@example.com',
  3634. password: 'agentpw',
  3635. active: true,
  3636. roles: roles,
  3637. groups: groups,
  3638. updated_at: '2015-02-05 16:37:00',
  3639. updated_by_id: 1,
  3640. created_by_id: 1,
  3641. )
  3642. agent2 = User.create_or_update(
  3643. login: 'agent-has-changed2@example.com',
  3644. firstname: 'Has Changed',
  3645. lastname: 'Agent2',
  3646. email: 'agent-has-changed2@example.com',
  3647. password: 'agentpw',
  3648. active: true,
  3649. roles: roles,
  3650. groups: groups,
  3651. updated_at: '2015-02-05 16:37:00',
  3652. updated_by_id: 1,
  3653. created_by_id: 1,
  3654. )
  3655. # multi tag trigger with changed owner
  3656. Trigger.create_or_update(
  3657. name: 'change owner',
  3658. condition: {
  3659. 'ticket.owner_id' => {
  3660. 'operator' => 'has changed',
  3661. },
  3662. 'ticket.tags' => {
  3663. 'operator' => 'contains one not',
  3664. 'value' => 'nosendmail test123'
  3665. }
  3666. },
  3667. perform: {
  3668. 'ticket.tags' => {
  3669. 'operator' => 'add',
  3670. 'value' => '123'
  3671. },
  3672. 'notification.email' => {
  3673. 'body' => 'some lala',
  3674. 'recipient' => 'ticket_customer',
  3675. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  3676. },
  3677. },
  3678. disable_notification: true,
  3679. active: true,
  3680. created_by_id: 1,
  3681. updated_by_id: 1,
  3682. )
  3683. # single tag trigger with changed owner
  3684. Trigger.create_or_update(
  3685. name: 'change owner',
  3686. condition: {
  3687. 'ticket.owner_id' => {
  3688. 'operator' => 'has changed',
  3689. },
  3690. 'ticket.tags' => {
  3691. 'operator' => 'contains one not',
  3692. 'value' => 'nosendmail2',
  3693. }
  3694. },
  3695. perform: {
  3696. 'ticket.tags' => {
  3697. 'operator' => 'add',
  3698. 'value' => '123'
  3699. },
  3700. 'notification.email' => {
  3701. 'body' => 'some lala',
  3702. 'recipient' => 'ticket_customer',
  3703. 'subject' => 'Thanks for your inquiry - 1234 check (#{ticket.title})!',
  3704. },
  3705. },
  3706. disable_notification: true,
  3707. active: true,
  3708. created_by_id: 1,
  3709. updated_by_id: 1,
  3710. )
  3711. ticket1 = Ticket.create!(
  3712. title: "some title\n äöüß",
  3713. group: Group.lookup(name: 'Users'),
  3714. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3715. updated_by_id: 1,
  3716. created_by_id: 1,
  3717. )
  3718. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3719. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3720. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3721. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3722. assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
  3723. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3724. assert_equal([], ticket1.tag_list, 'ticket1.tag_list')
  3725. ticket2 = Ticket.create!(
  3726. title: "some title\n äöüß",
  3727. group: Group.lookup(name: 'Users'),
  3728. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3729. updated_by_id: 1,
  3730. created_by_id: 1,
  3731. )
  3732. assert_equal('some title äöüß', ticket2.title, 'ticket1.title verify')
  3733. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3734. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3735. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3736. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
  3737. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3738. assert_equal([], ticket1.tag_list, 'ticket2.tag_list')
  3739. # control test - should pass
  3740. # create common object tag
  3741. Tag::Object.create_or_update(name: 'Ticket')
  3742. # add tag
  3743. ticket1.tag_add('thisisthebestjob', agent1.id)
  3744. # change owner
  3745. ticket1.owner_id = agent1.id
  3746. ticket1.save!
  3747. Observer::Transaction.commit
  3748. # this will add a tag by trigger
  3749. ticket1.reload
  3750. assert_equal('some title äöüß', ticket1.title, 'ticket2.title verify')
  3751. assert_equal('Users', ticket1.group.name, 'ticket2.group verify')
  3752. assert_equal('new', ticket1.state.name, 'ticket2.state verify')
  3753. assert_equal('2 normal', ticket1.priority.name, 'ticket2.priority verify')
  3754. assert_equal(1, ticket1.articles.count, 'ticket2.articles verify') # articles.count must be 1 if the tag is added
  3755. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3756. assert_equal(%w[thisisthebestjob 123], ticket1.tag_list, 'ticket2.tag_list')
  3757. # add tag nosendmail (to test the bug)
  3758. ticket1.tag_add('nosendmail', agent2.id)
  3759. # change owner
  3760. ticket1.owner_id = agent2.id
  3761. ticket1.save!
  3762. Observer::Transaction.commit
  3763. ticket1.reload
  3764. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3765. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3766. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3767. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3768. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify') # articles.count must be 0 if adding tag is skipped
  3769. assert_equal('agent-has-changed2@example.com', agent2.login, 'verify agent')
  3770. assert_equal(%w[thisisthebestjob 123 nosendmail], ticket1.tag_list, 'ticket1.tag_list')
  3771. # add tag (to test the bug)
  3772. ticket1.tag_add('test123', agent2.id)
  3773. # change owner
  3774. ticket1.owner_id = agent1.id
  3775. ticket1.save!
  3776. Observer::Transaction.commit
  3777. ticket1.reload
  3778. assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
  3779. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3780. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3781. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3782. assert_equal(3, ticket1.articles.count, 'ticket1.articles verify') # articles.count must be 0 if adding tag is skipped
  3783. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3784. assert_equal(%w[thisisthebestjob 123 nosendmail test123], ticket1.tag_list, 'ticket1.tag_list')
  3785. # add tag single tag 'nosendmail2' (to test the bug)
  3786. ticket2.tag_add('nosendmail2', agent1.id)
  3787. # change owner
  3788. ticket2.owner_id = agent1.id
  3789. ticket2.save!
  3790. Observer::Transaction.commit
  3791. ticket2.reload
  3792. assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
  3793. assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
  3794. assert_equal('new', ticket2.state.name, 'ticket2.state verify')
  3795. assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
  3796. assert_equal(0, ticket2.articles.count, 'ticket2.articles verify') # articles.count must be 0 if adding tag is skipped
  3797. assert_equal('agent-has-changed@example.com', agent1.login, 'verify agent')
  3798. assert_equal(['nosendmail2'], ticket2.tag_list, 'ticket2.tag_list')
  3799. end
  3800. test 'trigger auto reply with umlaut in form' do
  3801. Trigger.create_or_update(
  3802. name: 'auto reply',
  3803. condition: {
  3804. 'ticket.action' => {
  3805. 'operator' => 'is',
  3806. 'value' => 'create',
  3807. },
  3808. 'ticket.state_id' => {
  3809. 'operator' => 'is',
  3810. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3811. },
  3812. },
  3813. perform: {
  3814. 'notification.email' => {
  3815. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3816. 'recipient' => 'article_last_sender',
  3817. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3818. },
  3819. },
  3820. disable_notification: true,
  3821. active: true,
  3822. created_by_id: 1,
  3823. updated_by_id: 1,
  3824. )
  3825. ticket1 = Ticket.create!(
  3826. title: 'test 1',
  3827. group: Group.lookup(name: 'Users'),
  3828. customer: User.lookup(email: 'nicole.braun@zammad.org'),
  3829. updated_by_id: 1,
  3830. created_by_id: 1,
  3831. )
  3832. Ticket::Article.create!(
  3833. ticket_id: ticket1.id,
  3834. from: 'Sabine Schütz <some_sender@example.com>',
  3835. to: 'some_recipient@example.com',
  3836. subject: 'some subject',
  3837. message_id: 'some@id',
  3838. body: 'some message <b>note</b> hello ',
  3839. internal: false,
  3840. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  3841. type: Ticket::Article::Type.find_by(name: 'email'),
  3842. updated_by_id: 1,
  3843. created_by_id: 1,
  3844. )
  3845. ticket1.reload
  3846. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3847. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3848. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3849. assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
  3850. assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
  3851. assert_equal('Sabine Schütz <some_sender@example.com>', ticket1.articles.first.from, 'ticket1.articles.first.from verify')
  3852. assert_equal([], ticket1.tag_list)
  3853. Observer::Transaction.commit
  3854. ticket1.reload
  3855. assert_equal('test 1', ticket1.title, 'ticket1.title verify')
  3856. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3857. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3858. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3859. article1 = ticket1.articles.last
  3860. assert_match('Zammad <zammad@localhost>', article1.from)
  3861. assert_match('some_sender@example.com', article1.to)
  3862. assert_match('Thanks for your inquiry (test 1)!', article1.subject)
  3863. assert_match('some message', article1.body)
  3864. assert_match('&gt; some message &lt;b&gt;note&lt;/b&gt; hello', article1.body)
  3865. assert_equal('text/html', article1.content_type)
  3866. end
  3867. test 'trigger auto reply with 2 sender addresses in form' do
  3868. Trigger.create_or_update(
  3869. name: 'auto reply',
  3870. condition: {
  3871. 'ticket.action' => {
  3872. 'operator' => 'is',
  3873. 'value' => 'create',
  3874. },
  3875. 'ticket.state_id' => {
  3876. 'operator' => 'is',
  3877. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3878. },
  3879. },
  3880. perform: {
  3881. 'notification.email' => {
  3882. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
  3883. 'recipient' => 'article_last_sender',
  3884. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3885. },
  3886. },
  3887. disable_notification: true,
  3888. active: true,
  3889. created_by_id: 1,
  3890. updated_by_id: 1,
  3891. )
  3892. ticket1, _article1, _user, _mail = Channel::EmailParser.new.process({}, File.read(Rails.root.join('test', 'data', 'mail', 'mail065.box')))
  3893. assert_equal('aaäöüßad asd', ticket1.title, 'ticket1.title verify')
  3894. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3895. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3896. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3897. article1 = ticket1.articles.last
  3898. assert_match('Zammad <zammad@localhost>', article1.from)
  3899. assert_match('smith@example.com', article1.to)
  3900. assert_match('Thanks for your inquiry (aaäöüßad asd)!', article1.subject)
  3901. assert_match('some text<br><br>aaäöüßad asd', article1.body)
  3902. assert_equal('text/html', article1.content_type)
  3903. end
  3904. test 'make sure attachments should be attached with content id' do
  3905. Trigger.create_or_update(
  3906. name: 'auto reply',
  3907. condition: {
  3908. 'ticket.action' => {
  3909. 'operator' => 'is',
  3910. 'value' => 'create',
  3911. },
  3912. 'ticket.state_id' => {
  3913. 'operator' => 'is',
  3914. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  3915. },
  3916. },
  3917. perform: {
  3918. 'notification.email' => {
  3919. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}<br><img tabindex="0" style="width: 192px; height: 192px" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCADAAMADAREAAhEBAxEB/8QAHgABAAICAwEBAQAAAAAAAAAAAAcICQoFBgsDAQT/xAA7EAAABwEAAQMCAgYJAgcAAAAAAQIDBAUGBwgJERITIQoUFRciMXa1FiMyNzg5QVF3JLIYGSc1QkVh/8QAHQEBAAICAwEBAAAAAAAAAAAAAAQFAwYCBwgBCf/EAEURAAICAgEDAgMEBAkLBAMAAAECAAMEEQUGEiETMQciQQgUMlEjYXF2FTM1QnJzgZGzFjY3OFJiobGytLUXGILBJTRD/9oADAMBAAIRAxEAPwDU/G4SPARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARARLM+HPi5uvNDyU5T4086cbiaXp+iTU/piTGflwM3TxYsiyv9PZx4xk+5WZ+nhzLSelk/qnGjLJslLNKT++Atjk6Wquy1z/uo">',
  3920. 'recipient' => 'article_last_sender',
  3921. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  3922. },
  3923. },
  3924. disable_notification: true,
  3925. active: true,
  3926. created_by_id: 1,
  3927. updated_by_id: 1,
  3928. )
  3929. ticket1, _article1, _user, _mail = Channel::EmailParser.new.process({}, File.read(Rails.root.join('test', 'data', 'mail', 'mail065.box')))
  3930. assert_equal('aaäöüßad asd', ticket1.title, 'ticket1.title verify')
  3931. assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
  3932. assert_equal('new', ticket1.state.name, 'ticket1.state verify')
  3933. assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
  3934. article1 = ticket1.articles.last
  3935. assert_match('Zammad <zammad@localhost>', article1.from)
  3936. assert_match('smith@example.com', article1.to)
  3937. assert_match('Thanks for your inquiry (aaäöüßad asd)!', article1.subject)
  3938. assert_match(/.+cid:.+?@zammad.example.com.+/, article1.body)
  3939. assert_equal(1, article1.attachments.count)
  3940. assert_equal('789', article1.attachments[0].size)
  3941. assert_equal('text/html', article1.content_type)
  3942. end
  3943. end