@@ -224,46 +224,61 @@ class Meta:
224
224
class PatchHistory (models .Model ):
225
225
patch = models .ForeignKey (Patch , blank = False , null = False , on_delete = models .CASCADE )
226
226
date = models .DateTimeField (blank = False , null = False , auto_now_add = True , db_index = True )
227
- by = models .ForeignKey (User , blank = False , null = False , on_delete = models .CASCADE )
227
+ by = models .ForeignKey (User , blank = True , null = True , on_delete = models .CASCADE )
228
+ by_cfbot = models .BooleanField (null = False , blank = False , default = False )
228
229
what = models .CharField (max_length = 500 , null = False , blank = False )
229
230
230
231
@property
231
232
def by_string (self ):
233
+ if (self .by_cfbot ):
234
+ return "CFbot"
235
+
232
236
return "%s %s (%s)" % (self .by .first_name , self .by .last_name , self .by .username )
233
237
234
238
def __str__ (self ):
235
239
return "%s - %s" % (self .patch .name , self .date )
236
240
237
241
class Meta :
238
242
ordering = ('-date' , )
243
+ constraints = [
244
+ models .CheckConstraint (
245
+ check = (
246
+ models .Q (by_cfbot = True ) & models .Q (by__isnull = True )
247
+ ) | (
248
+ models .Q (by_cfbot = False ) & models .Q (by__isnull = False )
249
+ ),
250
+ name = 'check_by' ,
251
+ ),
252
+ ]
239
253
240
254
def save_and_notify (self , prevcommitter = None ,
241
- prevreviewers = None , prevauthors = None ):
255
+ prevreviewers = None , prevauthors = None , authors_only = False ):
242
256
# Save this model, and then trigger notifications if there are any. There are
243
257
# many different things that can trigger notifications, so try them all.
244
258
self .save ()
245
259
246
260
recipients = []
247
- recipients .extend (self .patch .subscribers .all ())
248
-
249
- # Current or previous committer wants all notifications
250
- try :
251
- if self .patch .committer and self .patch .committer .user .userprofile .notify_all_committer :
252
- recipients .append (self .patch .committer .user )
253
- except UserProfile .DoesNotExist :
254
- pass
255
-
256
- try :
257
- if prevcommitter and prevcommitter .user .userprofile .notify_all_committer :
258
- recipients .append (prevcommitter .user )
259
- except UserProfile .DoesNotExist :
260
- pass
261
-
262
- # Current or previous reviewers wants all notifications
263
- recipients .extend (self .patch .reviewers .filter (userprofile__notify_all_reviewer = True ))
264
- if prevreviewers :
265
- # prevreviewers is a list
266
- recipients .extend (User .objects .filter (id__in = [p .id for p in prevreviewers ], userprofile__notify_all_reviewer = True ))
261
+ if not authors_only :
262
+ recipients .extend (self .patch .subscribers .all ())
263
+
264
+ # Current or previous committer wants all notifications
265
+ try :
266
+ if self .patch .committer and self .patch .committer .user .userprofile .notify_all_committer :
267
+ recipients .append (self .patch .committer .user )
268
+ except UserProfile .DoesNotExist :
269
+ pass
270
+
271
+ try :
272
+ if prevcommitter and prevcommitter .user .userprofile .notify_all_committer :
273
+ recipients .append (prevcommitter .user )
274
+ except UserProfile .DoesNotExist :
275
+ pass
276
+
277
+ # Current or previous reviewers wants all notifications
278
+ recipients .extend (self .patch .reviewers .filter (userprofile__notify_all_reviewer = True ))
279
+ if prevreviewers :
280
+ # prevreviewers is a list
281
+ recipients .extend (User .objects .filter (id__in = [p .id for p in prevreviewers ], userprofile__notify_all_reviewer = True ))
267
282
268
283
# Current or previous authors wants all notifications
269
284
recipients .extend (self .patch .authors .filter (userprofile__notify_all_author = True ))
@@ -358,6 +373,7 @@ class CfbotBranch(models.Model):
358
373
apply_url = models .TextField (null = False )
359
374
# Actually a postgres enum column
360
375
status = models .TextField (choices = STATUS_CHOICES , null = False )
376
+ needs_rebase_since = models .DateTimeField (null = True , blank = True )
361
377
created = models .DateTimeField (auto_now_add = True )
362
378
modified = models .DateTimeField (auto_now = True )
363
379
0 commit comments