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