Show More
@@ -459,9 +459,6 b' class CommentsModel(BaseModel):' | |||
|
459 | 459 | |
|
460 | 460 | if send_email: |
|
461 | 461 | recipients += [self._get_user(u) for u in (extra_recipients or [])] |
|
462 | # pre-generate the subject for notification itself | |
|
463 | (subject, _e, body_plaintext) = EmailNotificationModel().render_email( | |
|
464 | notification_type, **kwargs) | |
|
465 | 462 | |
|
466 | 463 | mention_recipients = set( |
|
467 | 464 | self._extract_mentions(text)).difference(recipients) |
@@ -469,8 +466,8 b' class CommentsModel(BaseModel):' | |||
|
469 | 466 | # create notification objects, and emails |
|
470 | 467 | NotificationModel().create( |
|
471 | 468 | created_by=user, |
|
472 |
notification_subject= |
|
|
473 |
notification_body= |
|
|
469 | notification_subject='', # Filled in based on the notification_type | |
|
470 | notification_body='', # Filled in based on the notification_type | |
|
474 | 471 | notification_type=notification_type, |
|
475 | 472 | recipients=recipients, |
|
476 | 473 | mention_recipients=mention_recipients, |
@@ -55,7 +55,7 b' class NotificationModel(BaseModel):' | |||
|
55 | 55 | ' of Notification got %s' % type(notification)) |
|
56 | 56 | |
|
57 | 57 | def create( |
|
58 | self, created_by, notification_subject, notification_body, | |
|
58 | self, created_by, notification_subject='', notification_body='', | |
|
59 | 59 | notification_type=Notification.TYPE_MESSAGE, recipients=None, |
|
60 | 60 | mention_recipients=None, with_email=True, email_kwargs=None): |
|
61 | 61 | """ |
@@ -64,11 +64,12 b' class NotificationModel(BaseModel):' | |||
|
64 | 64 | |
|
65 | 65 | :param created_by: int, str or User instance. User who created this |
|
66 | 66 | notification |
|
67 | :param notification_subject: subject of notification itself | |
|
67 | :param notification_subject: subject of notification itself, | |
|
68 | it will be generated automatically from notification_type if not specified | |
|
68 | 69 | :param notification_body: body of notification text |
|
70 | it will be generated automatically from notification_type if not specified | |
|
69 | 71 | :param notification_type: type of notification, based on that we |
|
70 | 72 | pick templates |
|
71 | ||
|
72 | 73 | :param recipients: list of int, str or User objects, when None |
|
73 | 74 | is given send to all admins |
|
74 | 75 | :param mention_recipients: list of int, str or User objects, |
@@ -82,14 +83,19 b' class NotificationModel(BaseModel):' | |||
|
82 | 83 | if recipients and not getattr(recipients, '__iter__', False): |
|
83 | 84 | raise Exception('recipients must be an iterable object') |
|
84 | 85 | |
|
86 | if not (notification_subject and notification_body) and not notification_type: | |
|
87 | raise ValueError('notification_subject, and notification_body ' | |
|
88 | 'cannot be empty when notification_type is not specified') | |
|
89 | ||
|
85 | 90 | created_by_obj = self._get_user(created_by) |
|
91 | ||
|
92 | if not created_by_obj: | |
|
93 | raise Exception('unknown user %s' % created_by) | |
|
94 | ||
|
86 | 95 | # default MAIN body if not given |
|
87 | 96 | email_kwargs = email_kwargs or {'body': notification_body} |
|
88 | 97 | mention_recipients = mention_recipients or set() |
|
89 | 98 | |
|
90 | if not created_by_obj: | |
|
91 | raise Exception('unknown user %s' % created_by) | |
|
92 | ||
|
93 | 99 | if recipients is None: |
|
94 | 100 | # recipients is None means to all admins |
|
95 | 101 | recipients_objs = User.query().filter(User.admin == true()).all() |
@@ -113,6 +119,15 b' class NotificationModel(BaseModel):' | |||
|
113 | 119 | # add mentioned users into recipients |
|
114 | 120 | final_recipients = set(recipients_objs).union(mention_recipients) |
|
115 | 121 | |
|
122 | (subject, email_body, email_body_plaintext) = \ | |
|
123 | EmailNotificationModel().render_email(notification_type, **email_kwargs) | |
|
124 | ||
|
125 | if not notification_subject: | |
|
126 | notification_subject = subject | |
|
127 | ||
|
128 | if not notification_body: | |
|
129 | notification_body = email_body_plaintext | |
|
130 | ||
|
116 | 131 | notification = Notification.create( |
|
117 | 132 | created_by=created_by_obj, subject=notification_subject, |
|
118 | 133 | body=notification_body, recipients=final_recipients, |
@@ -1502,15 +1502,11 b' class PullRequestModel(BaseModel):' | |||
|
1502 | 1502 | 'user_role': role |
|
1503 | 1503 | } |
|
1504 | 1504 | |
|
1505 | # pre-generate the subject for notification itself | |
|
1506 | (subject, _e, body_plaintext) = EmailNotificationModel().render_email( | |
|
1507 | notification_type, **kwargs) | |
|
1508 | ||
|
1509 | 1505 | # create notification objects, and emails |
|
1510 | 1506 | NotificationModel().create( |
|
1511 | 1507 | created_by=current_rhodecode_user, |
|
1512 |
notification_subject= |
|
|
1513 | notification_body=body_plaintext, | |
|
1508 | notification_subject='', # Filled in based on the notification_type | |
|
1509 | notification_body='', # Filled in based on the notification_type | |
|
1514 | 1510 | notification_type=notification_type, |
|
1515 | 1511 | recipients=recipients, |
|
1516 | 1512 | email_kwargs=kwargs, |
@@ -1579,14 +1575,11 b' class PullRequestModel(BaseModel):' | |||
|
1579 | 1575 | 'thread_ids': [pr_url], |
|
1580 | 1576 | } |
|
1581 | 1577 | |
|
1582 | (subject, _e, body_plaintext) = EmailNotificationModel().render_email( | |
|
1583 | EmailNotificationModel.TYPE_PULL_REQUEST_UPDATE, **email_kwargs) | |
|
1584 | ||
|
1585 | 1578 | # create notification objects, and emails |
|
1586 | 1579 | NotificationModel().create( |
|
1587 | 1580 | created_by=updating_user, |
|
1588 |
notification_subject= |
|
|
1589 | notification_body=body_plaintext, | |
|
1581 | notification_subject='', # Filled in based on the notification_type | |
|
1582 | notification_body='', # Filled in based on the notification_type | |
|
1590 | 1583 | notification_type=EmailNotificationModel.TYPE_PULL_REQUEST_UPDATE, |
|
1591 | 1584 | recipients=recipients, |
|
1592 | 1585 | email_kwargs=email_kwargs, |
@@ -425,15 +425,12 b' class UserModel(BaseModel):' | |||
|
425 | 425 | 'date': datetime.datetime.now() |
|
426 | 426 | } |
|
427 | 427 | notification_type = EmailNotificationModel.TYPE_REGISTRATION |
|
428 | # pre-generate the subject for notification itself | |
|
429 | (subject, _e, body_plaintext) = EmailNotificationModel().render_email( | |
|
430 | notification_type, **kwargs) | |
|
431 | 428 | |
|
432 | 429 | # create notification objects, and emails |
|
433 | 430 | NotificationModel().create( |
|
434 | 431 | created_by=new_user, |
|
435 |
notification_subject= |
|
|
436 |
notification_body= |
|
|
432 | notification_subject='', # Filled in based on the notification_type | |
|
433 | notification_body='', # Filled in based on the notification_type | |
|
437 | 434 | notification_type=notification_type, |
|
438 | 435 | recipients=None, # all admins |
|
439 | 436 | email_kwargs=kwargs, |
General Comments 0
You need to be logged in to leave comments.
Login now