ticket_trigger_test.rb 155 KB

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