changeset 8756:b4749d02192d

model: remove unused 'subject' parameter of NotificationModel.create() The subject of emails is determined with EmailNotificationModel._subj_map, based on the notification type. The 'subject' parameter passed to NotificationModel.create is completely unused. Remove this parameter and update its callers, removing code that is now no longer used.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Thu, 05 Nov 2020 22:41:09 +0100
parents d952e08eeb03
children 4cca6590f263
files kallithea/model/comment.py kallithea/model/notification.py kallithea/model/pull_request.py kallithea/model/user.py kallithea/tests/models/test_notifications.py
diffstat 5 files changed, 8 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/comment.py	Thu Nov 05 22:27:13 2020 +0100
+++ b/kallithea/model/comment.py	Thu Nov 05 22:41:09 2020 +0100
@@ -28,8 +28,6 @@
 import logging
 from collections import defaultdict
 
-from tg.i18n import ugettext as _
-
 from kallithea.lib import webutils
 from kallithea.lib.utils import extract_mentioned_users
 from kallithea.lib.utils2 import shorter
@@ -58,15 +56,10 @@
                                 line_no=None, revision=None, pull_request=None,
                                 status_change=None, closing_pr=False):
 
-        line = ''
-        if line_no:
-            line = _('on line %s') % line_no
-
         # changeset
         if revision:
             notification_type = notification.NotificationModel.TYPE_CHANGESET_COMMENT
             cs = repo.scm_instance.get_changeset(revision)
-            desc = cs.short_id
 
             threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, webutils.canonical_hostname())]
             if line_no: # TODO: url to file _and_ line number
@@ -76,10 +69,6 @@
                 repo_name=repo.repo_name,
                 revision=revision,
                 anchor='comment-%s' % comment.comment_id)
-            subj = webutils.link_to(
-                'Re changeset: %(desc)s %(line)s' %
-                          {'desc': desc, 'line': line},
-                 comment_url)
             # get the current participants of this changeset
             recipients = _list_changeset_commenters(revision)
             # add changeset author if it's known locally
@@ -110,7 +99,6 @@
         # pull request
         elif pull_request:
             notification_type = notification.NotificationModel.TYPE_PULL_REQUEST_COMMENT
-            desc = comment.pull_request.title
             _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
             _other_ref_type, other_ref_name, _other_rev = comment.pull_request.other_ref.split(':')
             threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
@@ -122,12 +110,6 @@
                                                           webutils.canonical_hostname()))
             comment_url = pull_request.url(canonical=True,
                 anchor='comment-%s' % comment.comment_id)
-            subj = webutils.link_to(
-                'Re pull request %(pr_nice_id)s: %(desc)s %(line)s' %
-                          {'desc': desc,
-                           'pr_nice_id': comment.pull_request.nice_id(),
-                           'line': line},
-                comment_url)
             # get the current participants of this pull request
             recipients = _list_pull_request_commenters(pull_request)
             recipients.append(pull_request.owner)
@@ -159,7 +141,7 @@
         email_kwargs['is_mention'] = False
         # create notification objects, and emails
         notification.NotificationModel().create(
-            created_by=author, subject=subj, body=comment_text,
+            created_by=author, body=comment_text,
             recipients=recipients, type_=notification_type,
             email_kwargs=email_kwargs,
         )
@@ -167,10 +149,8 @@
         mention_recipients = extract_mentioned_users(comment_text).difference(recipients)
         if mention_recipients:
             email_kwargs['is_mention'] = True
-            subj = _('[Mention]') + ' ' + subj
-            # FIXME: this subject is wrong and unused!
             notification.NotificationModel().create(
-                created_by=author, subject=subj, body=comment_text,
+                created_by=author, body=comment_text,
                 recipients=mention_recipients,
                 type_=notification_type,
                 email_kwargs=email_kwargs
--- a/kallithea/model/notification.py	Thu Nov 05 22:27:13 2020 +0100
+++ b/kallithea/model/notification.py	Thu Nov 05 22:41:09 2020 +0100
@@ -49,7 +49,7 @@
     TYPE_PULL_REQUEST = 'pull_request'
     TYPE_PULL_REQUEST_COMMENT = 'pull_request_comment'
 
-    def create(self, created_by, subject, body, recipients=None,
+    def create(self, created_by, body, recipients=None,
                type_=TYPE_MESSAGE, with_email=True,
                email_kwargs=None, repo_name=None):
         """
@@ -58,7 +58,6 @@
 
         :param created_by: int, str or User instance. User who created this
             notification
-        :param subject:
         :param body:
         :param recipients: list of int, str or User objects, when None
             is given send to all admins
@@ -105,14 +104,12 @@
         # this is passed into template
         created_on = fmt_date(datetime.datetime.now())
         html_kwargs = {
-                  'subject': subject,
                   'body': h.render_w_mentions(body, repo_name),
                   'when': created_on,
                   'user': created_by_obj.username,
                   }
 
         txt_kwargs = {
-                  'subject': subject,
                   'body': body,
                   'when': created_on,
                   'user': created_by_obj.username,
--- a/kallithea/model/pull_request.py	Thu Nov 05 22:27:13 2020 +0100
+++ b/kallithea/model/pull_request.py	Thu Nov 05 22:41:09 2020 +0100
@@ -78,12 +78,6 @@
         threading = ['%s-pr-%s@%s' % (pr.other_repo.repo_name,
                                       pr.pull_request_id,
                                       webutils.canonical_hostname())]
-        subject = webutils.link_to(
-            _('%(user)s wants you to review pull request %(pr_nice_id)s: %(pr_title)s') %
-                {'user': user.username,
-                 'pr_title': pr.title,
-                 'pr_nice_id': pr.nice_id()},
-            pr_url)
         body = pr.description
         _org_ref_type, org_ref_name, _org_rev = pr.org_ref.split(':')
         _other_ref_type, other_ref_name, _other_rev = pr.other_ref.split(':')
@@ -112,16 +106,14 @@
             'is_mention': False,
             }
         if reviewers:
-            notification.NotificationModel().create(created_by=user, subject=subject, body=body,
+            notification.NotificationModel().create(created_by=user, body=body,
                                        recipients=reviewers,
                                        type_=notification.NotificationModel.TYPE_PULL_REQUEST,
                                        email_kwargs=email_kwargs)
 
         if mention_recipients:
             email_kwargs['is_mention'] = True
-            subject = _('[Mention]') + ' ' + subject
-            # FIXME: this subject is wrong and unused!
-            notification.NotificationModel().create(created_by=user, subject=subject, body=body,
+            notification.NotificationModel().create(created_by=user, body=body,
                                        recipients=mention_recipients,
                                        type_=notification.NotificationModel.TYPE_PULL_REQUEST,
                                        email_kwargs=email_kwargs)
--- a/kallithea/model/user.py	Thu Nov 05 22:27:13 2020 +0100
+++ b/kallithea/model/user.py	Thu Nov 05 22:41:09 2020 +0100
@@ -170,7 +170,6 @@
         new_user = self.create(form_data)
 
         # notification to admins
-        subject = _('New user registration')
         body = (
             'New user registration\n'
             '---------------------\n'
@@ -184,7 +183,7 @@
             'new_username': new_user.username,
             'new_email': new_user.email,
             'new_full_name': new_user.full_name}
-        notification.NotificationModel().create(created_by=new_user, subject=subject,
+        notification.NotificationModel().create(created_by=new_user,
                                    body=body, recipients=None,
                                    type_=notification.NotificationModel.TYPE_REGISTRATION,
                                    email_kwargs=email_kwargs)
--- a/kallithea/tests/models/test_notifications.py	Thu Nov 05 22:27:13 2020 +0100
+++ b/kallithea/tests/models/test_notifications.py	Thu Nov 05 22:41:09 2020 +0100
@@ -50,7 +50,7 @@
                 assert from_name == 'u1 u1'
             with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email):
                 NotificationModel().create(created_by=self.u1,
-                                                   subject='subj', body='hi there',
+                                                   body='hi there',
                                                    recipients=usrs)
 
     @mock.patch.object(h, 'canonical_url', (lambda arg, **kwargs: 'http://%s/?%s' % (arg, '&'.join('%s=%s' % (k, v) for (k, v) in sorted(kwargs.items())))))
@@ -149,7 +149,7 @@
                     for desc, type_, body, kwargs in params:
                         # desc is used as "global" variable
                         NotificationModel().create(created_by=self.u1,
-                                                           subject='unused', body=body, email_kwargs=kwargs,
+                                                           body=body, email_kwargs=kwargs,
                                                            recipients=[self.u2], type_=type_)
 
                 # Email type TYPE_PASSWORD_RESET has no corresponding notification type - test it directly: