Changeset - b4749d02192d
[Not reviewed]
default
0 5 0
Thomas De Schampheleire - 5 years ago 2020-11-05 22:41:09
thomas.de_schampheleire@nokia.com
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.
5 files changed with 8 insertions and 40 deletions:
0 comments (0 inline, 0 general)
kallithea/model/comment.py
Show inline comments
 
@@ -28,8 +28,6 @@ Original author and date, and relevant c
 
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 @@ class ChangesetCommentsModel(object):
 
                                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 @@ class ChangesetCommentsModel(object):
 
                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 @@ class ChangesetCommentsModel(object):
 
        # 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 @@ class ChangesetCommentsModel(object):
 
                                                          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 @@ class ChangesetCommentsModel(object):
 
        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 @@ class ChangesetCommentsModel(object):
 
        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
kallithea/model/notification.py
Show inline comments
 
@@ -49,7 +49,7 @@ class NotificationModel(object):
 
    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 @@ class NotificationModel(object):
 

	
 
        :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 @@ class NotificationModel(object):
 
        # 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,
kallithea/model/pull_request.py
Show inline comments
 
@@ -78,12 +78,6 @@ class PullRequestModel(object):
 
        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 @@ class PullRequestModel(object):
 
            '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)
kallithea/model/user.py
Show inline comments
 
@@ -170,7 +170,6 @@ class UserModel(object):
 
        new_user = self.create(form_data)
 

	
 
        # notification to admins
 
        subject = _('New user registration')
 
        body = (
 
            'New user registration\n'
 
            '---------------------\n'
 
@@ -184,7 +183,7 @@ class UserModel(object):
 
            '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)
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -50,7 +50,7 @@ class TestNotifications(base.TestControl
 
                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 @@ class TestNotifications(base.TestControl
 
                    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:
0 comments (0 inline, 0 general)