ticket_trigger_recursive_disabled_test.rb 159 KB

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