@@ -270,7 +270,7 @@ class _Appt:
270
270
'lastfinishtime' ,
271
271
}
272
272
273
- def __init__ (self , stor , iden , recur , indx , storm , creator , recs , nexttime = None , view = None , created = None , pool = False , loglevel = None ):
273
+ def __init__ (self , stor , iden , recur , indx , storm , creator , user , recs , nexttime = None , view = None , created = None , pool = False , loglevel = None ):
274
274
self .doc = ''
275
275
self .name = ''
276
276
self .task = None
@@ -280,7 +280,8 @@ def __init__(self, stor, iden, recur, indx, storm, creator, recs, nexttime=None,
280
280
self .recur = recur # does this appointment repeat
281
281
self .indx = indx # incremented for each appt added ever. Used for nexttime tiebreaking for stable ordering
282
282
self .storm = storm # query to run
283
- self .creator = creator # user iden to run query as
283
+ self .user = user # user iden to run query as
284
+ self .creator = creator # user iden which created the appt
284
285
self .recs = recs # List[ApptRec] list of the individual entries to calculate next time from
285
286
self ._recidxnexttime = None # index of rec who is up next
286
287
self .view = view
@@ -326,6 +327,7 @@ def pack(self):
326
327
'view' : self .view ,
327
328
'indx' : self .indx ,
328
329
'storm' : self .storm ,
330
+ 'user' : self .user ,
329
331
'creator' : self .creator ,
330
332
'created' : self .created ,
331
333
'recs' : [d .pack () for d in self .recs ],
@@ -346,7 +348,7 @@ def unpack(cls, stor, val):
346
348
recs = [ApptRec .unpack (tupl ) for tupl in val ['recs' ]]
347
349
# TODO: MOAR INSANITY
348
350
loglevel = val .get ('loglevel' , 'WARNING' )
349
- appt = cls (stor , val ['iden' ], val ['recur' ], val ['indx' ], val ['storm' ], val ['creator' ], recs ,
351
+ appt = cls (stor , val ['iden' ], val ['recur' ], val ['indx' ], val ['storm' ], val ['creator' ], val [ 'user' ], recs ,
350
352
nexttime = val ['nexttime' ], view = val .get ('view' ), loglevel = loglevel )
351
353
appt .doc = val .get ('doc' , '' )
352
354
appt .name = val .get ('name' , '' )
@@ -512,7 +514,10 @@ async def add(self, cdef):
512
514
The cron definition may contain the following keys:
513
515
514
516
creator (str)
515
- Iden of the creating user.
517
+ Iden of the user which created the appointment.
518
+
519
+ user (str)
520
+ Iden of the user used to run the Storm query.
516
521
517
522
iden (str)
518
523
Iden of the appointment.
@@ -543,6 +548,7 @@ async def add(self, cdef):
543
548
reqs = cdef .get ('reqs' , {})
544
549
storm = cdef .get ('storm' )
545
550
creator = cdef .get ('creator' )
551
+ user = cdef .get ('user' )
546
552
view = cdef .get ('view' )
547
553
created = cdef .get ('created' )
548
554
loglevel = cdef .get ('loglevel' , 'WARNING' )
@@ -562,8 +568,8 @@ async def add(self, cdef):
562
568
563
569
await self .core .getStormQuery (storm )
564
570
565
- if not creator :
566
- raise ValueError ('"creator " key is cdef parameter is not present or empty' )
571
+ if not user :
572
+ raise ValueError ('"user " key is cdef parameter is not present or empty' )
567
573
568
574
if not reqs and incunit is None :
569
575
raise ValueError ('at least one of reqs and incunit must be non-empty' )
@@ -591,7 +597,7 @@ async def add(self, cdef):
591
597
recs .extend (ApptRec (rd , incunit , v ) for (rd , v ) in itertools .product (reqdicts , incvals ))
592
598
593
599
# TODO: this is insane. Make _Appt take the cdef directly...
594
- appt = _Appt (self , iden , recur , indx , storm , creator , recs , nexttime = nexttime , view = view ,
600
+ appt = _Appt (self , iden , recur , indx , storm , creator , user , recs , nexttime = nexttime , view = view ,
595
601
created = created , pool = pool , loglevel = loglevel )
596
602
self ._addappt (iden , appt )
597
603
@@ -704,8 +710,8 @@ async def runloop(self):
704
710
try :
705
711
await self ._execute (appt )
706
712
except Exception as e :
707
- extra = {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .creator , 'view' : appt .view }
708
- user = self .core .auth .user (appt .creator )
713
+ extra = {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .user , 'view' : appt .view }
714
+ user = self .core .auth .user (appt .user )
709
715
if user is not None :
710
716
extra ['username' ] = user .name
711
717
if isinstance (e , s_exc .SynErr ):
@@ -720,25 +726,25 @@ async def _execute(self, appt):
720
726
'''
721
727
Fire off the task to make the storm query
722
728
'''
723
- user = self .core .auth .user (appt .creator )
729
+ user = self .core .auth .user (appt .user )
724
730
if user is None :
725
- logger .warning (f'Unknown user { appt .creator } in stored appointment { appt .iden } { appt .name } ' ,
726
- extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .creator }})
731
+ logger .warning (f'Unknown user { appt .user } in stored appointment { appt .iden } { appt .name } ' ,
732
+ extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .user }})
727
733
await self ._markfailed (appt , 'unknown user' )
728
734
return
729
735
730
736
locked = user .info .get ('locked' )
731
737
if locked :
732
- logger .warning (f'Cron { appt .iden } { appt .name } failed because creator { user .name } is locked' ,
733
- extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .creator ,
738
+ logger .warning (f'Cron { appt .iden } { appt .name } failed because user { user .name } is locked' ,
739
+ extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .user ,
734
740
'username' : user .name }})
735
741
await self ._markfailed (appt , 'locked user' )
736
742
return
737
743
738
744
view = self .core .getView (iden = appt .view , user = user )
739
745
if view is None :
740
746
logger .warning (f'Unknown view { appt .view } in stored appointment { appt .iden } { appt .name } ' ,
741
- extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .creator ,
747
+ extra = {'synapse' : {'iden' : appt .iden , 'name' : appt .name , 'user' : appt .user ,
742
748
'username' : user .name , 'view' : appt .view }})
743
749
await self ._markfailed (appt , 'unknown view' )
744
750
return
0 commit comments