changeset 7448:f5841b61a582

model: move notification types from Notification to NotificationModel This commit is part of the removal of the UI notification feature from Kallithea, which is not deemed useful in its current form. Only email notifications are preserved. As there is no database storage of notifications anymore, the Notification class will be removed. However, the notification type definitions are still used for email notifications, and need to live somewhere. As creating notifications is always passing via NotificationModel, it makes sense to move the types there.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Wed, 05 Dec 2018 21:37:21 +0100
parents cd6c577ade97
children 7651f0cbca82
files kallithea/model/comment.py kallithea/model/db.py kallithea/model/notification.py kallithea/model/pull_request.py kallithea/model/user.py kallithea/tests/models/test_notifications.py
diffstat 6 files changed, 30 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/comment.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/model/comment.py	Wed Dec 05 21:37:21 2018 +0100
@@ -33,7 +33,7 @@
 from kallithea.lib.utils2 import extract_mentioned_users, safe_unicode
 from kallithea.lib import helpers as h
 from kallithea.model.db import ChangesetComment, User, \
-    Notification, PullRequest, Repository
+    PullRequest, Repository
 from kallithea.model.notification import NotificationModel
 from kallithea.model.meta import Session
 
@@ -69,7 +69,7 @@
 
         # changeset
         if revision:
-            notification_type = Notification.TYPE_CHANGESET_COMMENT
+            notification_type = NotificationModel.TYPE_CHANGESET_COMMENT
             cs = repo.scm_instance.get_changeset(revision)
             desc = cs.short_id
 
@@ -114,7 +114,7 @@
             }
         # pull request
         elif pull_request:
-            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
+            notification_type = 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(':')
--- a/kallithea/model/db.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/model/db.py	Wed Dec 05 21:37:21 2018 +0100
@@ -2478,14 +2478,6 @@
 class Notification(object):
     __tablename__ = 'notifications'
 
-    TYPE_CHANGESET_COMMENT = u'cs_comment'
-    TYPE_MESSAGE = u'message'
-    TYPE_MENTION = u'mention' # not used
-    TYPE_REGISTRATION = u'registration'
-    TYPE_PULL_REQUEST = u'pull_request'
-    TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
-
-
 class UserNotification(object):
     __tablename__ = 'user_to_notification'
 
--- a/kallithea/model/notification.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/model/notification.py	Wed Dec 05 21:37:21 2018 +0100
@@ -37,7 +37,7 @@
 import kallithea
 from kallithea.lib import helpers as h
 from kallithea.lib.utils2 import safe_unicode
-from kallithea.model.db import Notification, User
+from kallithea.model.db import User
 from kallithea.model.meta import Session
 
 log = logging.getLogger(__name__)
@@ -45,8 +45,15 @@
 
 class NotificationModel(object):
 
+    TYPE_CHANGESET_COMMENT = u'cs_comment'
+    TYPE_MESSAGE = u'message'
+    TYPE_MENTION = u'mention' # not used
+    TYPE_REGISTRATION = u'registration'
+    TYPE_PULL_REQUEST = u'pull_request'
+    TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
+
     def create(self, created_by, subject, body, recipients=None,
-               type_=Notification.TYPE_MESSAGE, with_email=True,
+               type_=TYPE_MESSAGE, with_email=True,
                email_kwargs=None, repo_name=None):
         """
 
@@ -133,13 +140,13 @@
 
 class EmailNotificationModel(object):
 
-    TYPE_CHANGESET_COMMENT = Notification.TYPE_CHANGESET_COMMENT
-    TYPE_MESSAGE = Notification.TYPE_MESSAGE # only used for testing
-    # Notification.TYPE_MENTION is not used
+    TYPE_CHANGESET_COMMENT = NotificationModel.TYPE_CHANGESET_COMMENT
+    TYPE_MESSAGE = NotificationModel.TYPE_MESSAGE # only used for testing
+    # NotificationModel.TYPE_MENTION is not used
     TYPE_PASSWORD_RESET = 'password_link'
-    TYPE_REGISTRATION = Notification.TYPE_REGISTRATION
-    TYPE_PULL_REQUEST = Notification.TYPE_PULL_REQUEST
-    TYPE_PULL_REQUEST_COMMENT = Notification.TYPE_PULL_REQUEST_COMMENT
+    TYPE_REGISTRATION = NotificationModel.TYPE_REGISTRATION
+    TYPE_PULL_REQUEST = NotificationModel.TYPE_PULL_REQUEST
+    TYPE_PULL_REQUEST_COMMENT = NotificationModel.TYPE_PULL_REQUEST_COMMENT
     TYPE_DEFAULT = 'default'
 
     def __init__(self):
--- a/kallithea/model/pull_request.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/model/pull_request.py	Wed Dec 05 21:37:21 2018 +0100
@@ -36,7 +36,7 @@
 
 from kallithea.model.meta import Session
 from kallithea.lib import helpers as h
-from kallithea.model.db import PullRequest, PullRequestReviewer, Notification, \
+from kallithea.model.db import PullRequest, PullRequestReviewer, \
     ChangesetStatus, User
 from kallithea.model.notification import NotificationModel
 from kallithea.lib.utils2 import extract_mentioned_users, safe_str, safe_unicode
@@ -109,7 +109,7 @@
         if reviewers:
             NotificationModel().create(created_by=user, subject=subject, body=body,
                                        recipients=reviewers,
-                                       type_=Notification.TYPE_PULL_REQUEST,
+                                       type_=NotificationModel.TYPE_PULL_REQUEST,
                                        email_kwargs=email_kwargs)
 
         if mention_recipients:
@@ -118,7 +118,7 @@
             # FIXME: this subject is wrong and unused!
             NotificationModel().create(created_by=user, subject=subject, body=body,
                                        recipients=mention_recipients,
-                                       type_=Notification.TYPE_PULL_REQUEST,
+                                       type_=NotificationModel.TYPE_PULL_REQUEST,
                                        email_kwargs=email_kwargs)
 
     def mention_from_description(self, user, pr, old_description=''):
--- a/kallithea/model/user.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/model/user.py	Wed Dec 05 21:37:21 2018 +0100
@@ -39,7 +39,7 @@
 
 from kallithea.lib.utils2 import safe_str, generate_api_key, get_current_authuser
 from kallithea.lib.caching_query import FromCache
-from kallithea.model.db import Permission, User, UserToPerm, Notification, \
+from kallithea.model.db import Permission, User, UserToPerm, \
     UserEmailMap, UserIpMap
 from kallithea.lib.exceptions import DefaultUserException, \
     UserOwnsReposException
@@ -202,7 +202,7 @@
             'new_full_name': new_user.full_name}
         NotificationModel().create(created_by=new_user, subject=subject,
                                    body=body, recipients=None,
-                                   type_=Notification.TYPE_REGISTRATION,
+                                   type_=NotificationModel.TYPE_REGISTRATION,
                                    email_kwargs=email_kwargs)
 
     def update(self, user_id, form_data, skip_attrs=None):
--- a/kallithea/tests/models/test_notifications.py	Wed Dec 05 21:27:58 2018 +0100
+++ b/kallithea/tests/models/test_notifications.py	Wed Dec 05 21:37:21 2018 +0100
@@ -6,7 +6,7 @@
 
 from kallithea.tests.base import *
 from kallithea.lib import helpers as h
-from kallithea.model.db import User, Notification
+from kallithea.model.db import User
 from kallithea.model.user import UserModel
 from kallithea.model.meta import Session
 from kallithea.model.notification import NotificationModel, EmailNotificationModel
@@ -92,7 +92,7 @@
                     )
 
                 for type_, body, kwargs in [
-                        (Notification.TYPE_CHANGESET_COMMENT,
+                        (NotificationModel.TYPE_CHANGESET_COMMENT,
                          u'This is the new \'comment\'.\n\n - and here it ends indented.',
                          dict(
                             short_id='cafe1234',
@@ -107,18 +107,18 @@
                             cs_target_repo='http://example.com/repo_target',
                             cs_url='http://changeset.com',
                             cs_author=User.get(self.u2))),
-                        (Notification.TYPE_MESSAGE,
+                        (NotificationModel.TYPE_MESSAGE,
                          u'This is the \'body\' of the "test" message\n - nothing interesting here except indentation.',
                          dict()),
-                        #(Notification.TYPE_MENTION, '$body', None), # not used
-                        (Notification.TYPE_REGISTRATION,
+                        #(NotificationModel.TYPE_MENTION, '$body', None), # not used
+                        (NotificationModel.TYPE_REGISTRATION,
                          u'Registration body',
                          dict(
                             new_username='newbie',
                             registered_user_url='http://newbie.org',
                             new_email='new@email.com',
                             new_full_name='New Full Name')),
-                        (Notification.TYPE_PULL_REQUEST,
+                        (NotificationModel.TYPE_PULL_REQUEST,
                          u'This PR is \'awesome\' because it does <stuff>\n - please approve indented!',
                          dict(
                             pr_user_created='Requesting User (root)', # pr_owner should perhaps be used for @mention in description ...
@@ -126,7 +126,7 @@
                             pr_revisions=[('123abc'*7, "Introduce one and two\n\nand that's it"), ('567fed'*7, 'Make one plus two equal tree')],
                             org_repo_name='repo_org',
                             **pr_kwargs)),
-                        (Notification.TYPE_PULL_REQUEST_COMMENT,
+                        (NotificationModel.TYPE_PULL_REQUEST_COMMENT,
                          u'Me too!\n\n - and indented on second line',
                          dict(
                             closing_pr=[False, True],