# HG changeset patch # User Thomas De Schampheleire <thomas.de_schamphele...@nokia.com> # Date 1544042241 -3600 # Wed Dec 05 21:37:21 2018 +0100 # Node ID 7e14c85c74fc6726ea46f41a98eba68093495d6f # Parent 97752bbee442057da88f03a75fc4dcf3945d90bb 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. diff --git a/kallithea/model/comment.py b/kallithea/model/comment.py --- a/kallithea/model/comment.py +++ b/kallithea/model/comment.py @@ -33,7 +33,7 @@ from collections import defaultdict 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 @@ class ChangesetCommentsModel(object): # 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 @@ class ChangesetCommentsModel(object): } # 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(':') diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -2478,14 +2478,6 @@ class PullRequestReviewer(Base, BaseDbMo 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' diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -37,7 +37,7 @@ from sqlalchemy.orm import joinedload, s 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 @@ log = logging.getLogger(__name__) 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 NotificationModel(object): 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): diff --git a/kallithea/model/pull_request.py b/kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py +++ b/kallithea/model/pull_request.py @@ -36,7 +36,7 @@ from sqlalchemy.orm import joinedload 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 @@ class PullRequestModel(object): 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 @@ class PullRequestModel(object): # 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=''): diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -39,7 +39,7 @@ from sqlalchemy.exc import DatabaseError 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 @@ class UserModel(object): '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): diff --git a/kallithea/tests/models/test_notifications.py b/kallithea/tests/models/test_notifications.py --- a/kallithea/tests/models/test_notifications.py +++ b/kallithea/tests/models/test_notifications.py @@ -6,7 +6,7 @@ import routes.util 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 @@ class TestNotifications(TestController): ) 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 @@ class TestNotifications(TestController): 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='n...@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 @@ class TestNotifications(TestController): 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], _______________________________________________ kallithea-general mailing list kallithea-general@sfconservancy.org https://lists.sfconservancy.org/mailman/listinfo/kallithea-general