Re: [PATCH 0 of 9] remove UI notification feature

2018-12-06 Thread Mads Kiilerich

On 12/6/18 1:02 PM, Thomas De Schampheleire wrote:

And we have so much cruft in upgraded databases anyway. I think we
either should accept a bit more tech debt there and rely on a future
"only preserve schema things we use now" database migration option, or
just add a migration step now to drop these tables. I don't think the
comment helps - it is not a list that can be trusted anyway.

Dropping tables now means that people that upgrade then downgrade
(changed their mind) will have missing data.
I thought it was common to leave things if they don't hurt.



We will have to establish how we want to use database migrations. I 
guess it only will be possible to make the most simple migrations fully 
reversible. And even in that case, it is not necessarily clear if 
re-applying a migration step should do that migration "from scratch" 
(like create a new table, empty and fully correct) or pick it up where 
it was before (with old data).


I guess I just would expect the bi-directional migration steps to give a 
correct schema and consistent data. I would not expect the migration to 
"take a backup" just to allow a down-migration could "restore it".


Anyway: Ok to not drop the old unused tables and relational references. 
But I wonder how much value it has to maintain a catalogue of "backups" 
to delete later. And especially if it should be as comments spread out 
in db.py .




I would be fine with a "only preserve schema things we use now"
database migration option if it happens roughly once, but it would
imply we also fix any other problems in the database schema.



Yes, there is other tech debt. Unused stuff that not necessarily have 
been dropped. For example, I think there might be a need for ensuring 
the right field types, indices and constraints.




About the if condition indentation: I think we have the same deficiency
in many other places. Perhaps, when the number of outstanding patches
are at a low, we should just start using
https://black.readthedocs.io/en/stable/the_black_code_style.html .

Have you used this in practice somewhere?
I did a quick run on our controllers, and while it has the benefit of
consistency, some of the long-line wrapping principles are not how I
would write it naturally. So in order to make it effective I'd need a
commit hook that fixes my code on the fly. In general, I would prefer
a style that we can reasonably adopt naturally without any hook
needing to do fixups.



I don't like it's formatting very much, so it's not about advocating my 
preference. I mainly like that it leaves very little to discuss.


Yes, it would perhaps require some kind of hook. But also, formatting 
can always be applied later, like when landing the changes. We already 
have `scripts/run-all-cleanup` which I sometimes remember to run ;-)


/Mads

___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


Re: [PATCH 0 of 9] remove UI notification feature

2018-12-06 Thread Thomas De Schampheleire
El jue., 6 dic. 2018 a las 12:26, Mads Kiilerich
() escribió:
>
> Thanks.

Thanks for pushing so quickly.

>
> I wonder if some css also could be cleaned up?

Do you have specific examples or details? I searched for 'notif' but
found nothing.

>
> And we have so much cruft in upgraded databases anyway. I think we
> either should accept a bit more tech debt there and rely on a future
> "only preserve schema things we use now" database migration option, or
> just add a migration step now to drop these tables. I don't think the
> comment helps - it is not a list that can be trusted anyway.

Dropping tables now means that people that upgrade then downgrade
(changed their mind) will have missing data.
I thought it was common to leave things if they don't hurt.

I would be fine with a "only preserve schema things we use now"
database migration option if it happens roughly once, but it would
imply we also fix any other problems in the database schema.

>
> About the if condition indentation: I think we have the same deficiency
> in many other places. Perhaps, when the number of outstanding patches
> are at a low, we should just start using
> https://black.readthedocs.io/en/stable/the_black_code_style.html .

Have you used this in practice somewhere?
I did a quick run on our controllers, and while it has the benefit of
consistency, some of the long-line wrapping principles are not how I
would write it naturally. So in order to make it effective I'd need a
commit hook that fixes my code on the fly. In general, I would prefer
a style that we can reasonably adopt naturally without any hook
needing to do fixups.
But, I'm not making any vetos right now.

Best regards,
Thomas
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


Re: [PATCH 0 of 9] remove UI notification feature

2018-12-06 Thread Mads Kiilerich

Thanks.

I wonder if some css also could be cleaned up?

And we have so much cruft in upgraded databases anyway. I think we 
either should accept a bit more tech debt there and rely on a future 
"only preserve schema things we use now" database migration option, or 
just add a migration step now to drop these tables. I don't think the 
comment helps - it is not a list that can be trusted anyway.


About the if condition indentation: I think we have the same deficiency 
in many other places. Perhaps, when the number of outstanding patches 
are at a low, we should just start using 
https://black.readthedocs.io/en/stable/the_black_code_style.html .


/Mads

___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


[PATCH 9 of 9] model: comment out but retain Notification and UserNotification classes

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1544042393 -3600
#  Wed Dec 05 21:39:53 2018 +0100
# Node ID a6e7e098056c78e54d541c9cc410a5c94b320c74
# Parent  7e14c85c74fc6726ea46f41a98eba68093495d6f
model: comment out but retain Notification and UserNotification classes

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.

Retain the class and tablename in comments, as database migration will be
required if ever we reintroduce a database-hosted notification feature and
would use the same table names.

diff --git a/kallithea/model/db.py b/kallithea/model/db.py
--- a/kallithea/model/db.py
+++ b/kallithea/model/db.py
@@ -2475,11 +2475,15 @@ class PullRequestReviewer(Base, BaseDbMo
 )
 
 
-class Notification(object):
-__tablename__ = 'notifications'
-
-class UserNotification(object):
-__tablename__ = 'user_to_notification'
+# Notification and UserNotification are no longer used.
+# The below lines are preserved below as a reminder for the future: if ever we
+# reintroduce db tables with below names, the necessary alembic migration
+# script needs to be written to migrate from the old definition.
+#class Notification(object):
+#__tablename__ = 'notifications'
+#
+#class UserNotification(object):
+#__tablename__ = 'user_to_notification'
 
 
 class Gist(Base, BaseDbModel):
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


[PATCH 5 of 9] tests: remove tests of UI notifications

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1543992000 -3600
#  Wed Dec 05 07:40:00 2018 +0100
# Node ID c8c333e621e32f8f6f09fb45ce43cc57c38a
# Parent  4473f2fb4f7e34ee0d842d163b4412ba6a04e7cb
tests: remove tests of UI notifications

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.

diff --git a/kallithea/tests/base.py b/kallithea/tests/base.py
--- a/kallithea/tests/base.py
+++ b/kallithea/tests/base.py
@@ -24,7 +24,7 @@ from tg import config
 from webtest import TestApp
 
 from kallithea import model
-from kallithea.model.db import Notification, User, UserNotification
+from kallithea.model.db import User
 from kallithea.model.meta import Session
 from kallithea.lib.utils2 import safe_str
 
@@ -149,15 +149,6 @@ class TestController(object):
 self.app = TestApp(testapp)
 return self.app
 
-def remove_all_notifications(self):
-# query().delete() does not (by default) trigger cascades
-# ( 
http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes )
-# so delete the UserNotification first to ensure referential integrity.
-UserNotification.query().delete()
-
-Notification.query().delete()
-Session().commit()
-
 def log_user(self, username=TEST_USER_ADMIN_LOGIN,
  password=TEST_USER_ADMIN_PASS):
 self._logged_username = username
diff --git a/kallithea/tests/functional/test_admin_notifications.py 
b/kallithea/tests/functional/test_admin_notifications.py
deleted file mode 100644
--- a/kallithea/tests/functional/test_admin_notifications.py
+++ /dev/null
@@ -1,172 +0,0 @@
-from kallithea.tests.base import *
-from kallithea.model.db import User
-
-from kallithea.model.user import UserModel
-from kallithea.model.notification import NotificationModel
-from kallithea.model.meta import Session
-from kallithea.lib import helpers as h
-
-from tg.util.webtest import test_context
-
-
-class TestNotificationsController(TestController):
-def setup_method(self, method):
-self.remove_all_notifications()
-
-def test_index(self, create_test_user):
-self.log_user()
-
-u1 = create_test_user(dict(username='u1', password='qweqwe',
-   email='u...@example.com',
-   firstname=u'u1', lastname=u'u1',
-   active=True))
-u1 = u1.user_id
-Session().commit()
-
-response = self.app.get(url('notifications'))
-response.mustcontain('No notifications here yet')
-
-with test_context(self.app):
-cur_user = self._get_logged_user()
-notif = NotificationModel().create(created_by=u1, 
subject=u'test_notification_1',
-   body=u'notification_1', 
recipients=[cur_user])
-Session().commit()
-
-response = self.app.get(url('notifications'))
-response.mustcontain('id="notification_%s"' % notif.notification_id)
-
-def test_delete(self, create_test_user):
-self.log_user()
-cur_user = self._get_logged_user()
-
-with test_context(self.app):
-u1 = create_test_user(dict(username='u1', password='qweqwe',
-   email='u...@example.com',
-   firstname=u'u1', lastname=u'u1',
-   active=True))
-u2 = create_test_user(dict(username='u2', password='qweqwe',
-   email='u...@example.com',
-   firstname=u'u2', lastname=u'u2',
-   active=True))
-
-# make notifications
-notification = NotificationModel().create(created_by=cur_user,
-  subject=u'test',
-  body=u'hi there',
-  recipients=[cur_user, 
u1, u2])
-Session().commit()
-u1 = User.get(u1.user_id)
-u2 = User.get(u2.user_id)
-
-# check DB
-get_notif = lambda un: [x.notification for x in un]
-assert get_notif(cur_user.notifications) == [notification]
-assert get_notif(u1.notifications) == [notification]
-assert get_notif(u2.notifications) == [notification]
-cur_usr_id = cur_user.user_id
-
-response = self.app.post(
-url('notification_delete', 
notification_id=notification.notification_id),
-params={'_authentication_token': self.authentication_token()})
-assert response.body == 'ok'
-
-cur_user = User.get(cur_usr_id)
-assert cur_user.notifications == []
-
-def test_show(self, create_test_user):
-self.log_user()
-with te

[PATCH 7 of 9] model: remove UI notification feature

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1544041678 -3600
#  Wed Dec 05 21:27:58 2018 +0100
# Node ID 97752bbee442057da88f03a75fc4dcf3945d90bb
# Parent  3ececf31e315c414f49a19ed0c5f7544d5c305bb
model: remove UI notification feature

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.

diff --git a/docs/api/models.rst b/docs/api/models.rst
--- a/docs/api/models.rst
+++ b/docs/api/models.rst
@@ -10,9 +10,6 @@ The :mod:`models` module
 .. automodule:: kallithea.model.comment
:members:
 
-.. automodule:: kallithea.model.notification
-   :members:
-
 .. automodule:: kallithea.model.permission
:members:
 
diff --git a/kallithea/model/db.py b/kallithea/model/db.py
--- a/kallithea/model/db.py
+++ b/kallithea/model/db.py
@@ -452,9 +452,6 @@ class User(Base, BaseDbModel):
 
 group_member = relationship('UserGroupMember', cascade='all')
 
-notifications = relationship('UserNotification', cascade='all')
-# notifications assigned to this user
-user_created_notifications = relationship('Notification', cascade='all')
 # comments created by this user
 user_comments = relationship('ChangesetComment', cascade='all')
 # extra emails for this user
@@ -2478,12 +2475,8 @@ class PullRequestReviewer(Base, BaseDbMo
 )
 
 
-class Notification(Base, BaseDbModel):
+class Notification(object):
 __tablename__ = 'notifications'
-__table_args__ = (
-Index('notification_type_idx', 'type'),
-_table_args_default_dict,
-)
 
 TYPE_CHANGESET_COMMENT = u'cs_comment'
 TYPE_MESSAGE = u'message'
@@ -2492,70 +2485,9 @@ class Notification(Base, BaseDbModel):
 TYPE_PULL_REQUEST = u'pull_request'
 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment'
 
-notification_id = Column(Integer(), primary_key=True)
-subject = Column(Unicode(512), nullable=False)
-body = Column(UnicodeText(), nullable=False)
-created_by = Column(Integer(), ForeignKey('users.user_id'), nullable=False)
-created_on = Column(DateTime(timezone=False), nullable=False, 
default=datetime.datetime.now)
-type_ = Column('type', Unicode(255), nullable=False)
-
-created_by_user = relationship('User')
-notifications_to_users = relationship('UserNotification', cascade="all, 
delete-orphan")
-
-@property
-def recipients(self):
-return [x.user for x in UserNotification.query()
-.filter(UserNotification.notification == self)
-.order_by(UserNotification.user_id.asc()).all()]
-
-@classmethod
-def create(cls, created_by, subject, body, recipients, type_=None):
-if type_ is None:
-type_ = Notification.TYPE_MESSAGE
-
-notification = cls()
-notification.created_by_user = created_by
-notification.subject = subject
-notification.body = body
-notification.type_ = type_
-notification.created_on = datetime.datetime.now()
-
-for recipient in recipients:
-un = UserNotification()
-un.notification = notification
-un.user_id = recipient.user_id
-# Mark notifications to self "pre-read" - should perhaps just be 
skipped
-if recipient == created_by:
-un.read = True
-Session().add(un)
-
-Session().add(notification)
-Session().flush() # assign notification.notification_id
-return notification
-
-@property
-def description(self):
-from kallithea.model.notification import NotificationModel
-return NotificationModel().make_description(self)
-
-
-class UserNotification(Base, BaseDbModel):
+
+class UserNotification(object):
 __tablename__ = 'user_to_notification'
-__table_args__ = (
-UniqueConstraint('user_id', 'notification_id'),
-_table_args_default_dict,
-)
-
-user_id = Column(Integer(), ForeignKey('users.user_id'), primary_key=True)
-notification_id = Column(Integer(), 
ForeignKey('notifications.notification_id'), primary_key=True)
-read = Column(Boolean, nullable=False, default=False)
-sent_on = Column(DateTime(timezone=False), nullable=True) # FIXME: not 
nullable?
-
-user = relationship('User')
-notification = relationship('Notification')
-
-def mark_as_read(self):
-self.read = True
 
 
 class Gist(Base, BaseDbModel):
diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py
--- a/kallithea/model/notification.py
+++ b/kallithea/model/notification.py
@@ -26,6 +26,7 @@ Original author and date, and relevant c
 :license: GPLv3, see LICENSE.md for more details.
 """
 
+import datetime
 import logging
 import traceback
 
@@ -36,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 Notif

[PATCH 8 of 9] model: move notification types from Notification to NotificationModel

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# 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 jo

[PATCH 2 of 9] tests: notifications: increase indentation of multi-line for loop condition

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1543698298 -3600
#  Sat Dec 01 22:04:58 2018 +0100
# Node ID cf7e97eceeed93f74bf2db3b6ffaca4b55896a70
# Parent  d0eaee2ca6b205ad58b6e46723252e3e57bfa31c
tests: notifications: increase indentation of multi-line for loop condition

Code in question is:

for foo in [
item1,
item2,
item3]:
action1
action2

With the above indentation, a quick glance at the code does not show where
the actions start.

Using a double indentation for line continuation avoids this problem:

for foo in [
item1,
item2,
item3]:
action1
action2

There are no actual code changes in this commit.

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
@@ -208,50 +208,50 @@ class TestNotifications(TestController):
 )
 
 for type_, body, kwargs in [
-(Notification.TYPE_CHANGESET_COMMENT,
- u'This is the new \'comment\'.\n\n - and here it ends 
indented.',
- dict(
-short_id='cafe1234',
-raw_id='cafe1234c0ffeecafe',
-branch='brunch',
-cs_comment_user='Opinionated User (jsmith)',
-cs_comment_url='http://comment.org',
-is_mention=[False, True],
-message='This changeset did something clever which is 
hard to explain',
-message_short='This changeset did something cl...',
-status_change=[None, 'Approved'],
-cs_target_repo='http://example.com/repo_target',
-cs_url='http://changeset.com',
-cs_author=User.get(self.u2))),
-(Notification.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,
- 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,
- u'This PR is \'awesome\' because it does \n - 
please approve indented!',
- dict(
-pr_user_created='Requesting User (root)', # pr_owner 
should perhaps be used for @mention in description ...
-is_mention=[False, True],
-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,
- u'Me too!\n\n - and indented on second line',
- dict(
-closing_pr=[False, True],
-is_mention=[False, True],
-pr_comment_user='Opinionated User (jsmith)',
-pr_comment_url='http://pr.org/comment',
-status_change=[None, 'Under Review'],
-**pr_kwargs)),
-]:
+(Notification.TYPE_CHANGESET_COMMENT,
+ u'This is the new \'comment\'.\n\n - and here it ends 
indented.',
+ dict(
+short_id='cafe1234',
+raw_id='cafe1234c0ffeecafe',
+branch='brunch',
+cs_comment_user='Opinionated User (jsmith)',
+cs_comment_url='http://comment.org',
+is_mention=[False, True],
+message='This changeset did something clever which 
is hard to explain',
+message_short='This changeset did something cl...',
+status_change=[None, 'Approved'],
+cs_target_repo='http://example.com/repo_target',
+cs_url='http://changeset.com',
+cs_author=User.get(self.u2))),
+(Notification.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
+(Not

[PATCH 6 of 9] controllers/templates: remove UI notification feature

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1544041299 -3600
#  Wed Dec 05 21:21:39 2018 +0100
# Node ID 3ececf31e315c414f49a19ed0c5f7544d5c305bb
# Parent  c8c333e621e32f8f6f09fb45ce43cc57c38a
controllers/templates: remove UI notification feature

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.

diff --git a/kallithea/config/routing.py b/kallithea/config/routing.py
--- a/kallithea/config/routing.py
+++ b/kallithea/config/routing.py
@@ -361,24 +361,6 @@ def make_map(config):
 m.connect("my_account_api_keys_delete", "/my_account/api_keys/delete",
   action="my_account_api_keys_delete", 
conditions=dict(method=["POST"]))
 
-# NOTIFICATION REST ROUTES
-with rmap.submapper(path_prefix=ADMIN_PREFIX,
-controller='admin/notifications') as m:
-m.connect("notifications", "/notifications",
-  action="index", conditions=dict(method=["GET"]))
-m.connect("notifications_mark_all_read", 
"/notifications/mark_all_read",
-  action="mark_all_read", conditions=dict(method=["GET"]))
-m.connect("formatted_notifications", "/notifications.{format}",
-  action="index", conditions=dict(method=["GET"]))
-m.connect("notification_update", 
"/notifications/{notification_id}/update",
-  action="update", conditions=dict(method=["POST"]))
-m.connect("notification_delete", 
"/notifications/{notification_id}/delete",
-  action="delete", conditions=dict(method=["POST"]))
-m.connect("notification", "/notifications/{notification_id}",
-  action="show", conditions=dict(method=["GET"]))
-m.connect("formatted_notification", 
"/notifications/{notification_id}.{format}",
-  action="show", conditions=dict(method=["GET"]))
-
 # ADMIN GIST
 with rmap.submapper(path_prefix=ADMIN_PREFIX,
 controller='admin/gists') as m:
diff --git a/kallithea/controllers/admin/notifications.py 
b/kallithea/controllers/admin/notifications.py
deleted file mode 100644
--- a/kallithea/controllers/admin/notifications.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# -*- coding: utf-8 -*-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see .
-"""
-kallithea.controllers.admin.notifications
-~
-
-notifications controller for Kallithea
-
-This file was forked by the Kallithea project in July 2014.
-Original author and date, and relevant copyright and licensing information is 
below:
-:created_on: Nov 23, 2010
-:author: marcink
-:copyright: (c) 2013 RhodeCode GmbH, and others.
-:license: GPLv3, see LICENSE.md for more details.
-"""
-
-import logging
-import traceback
-
-from tg import request
-from tg import tmpl_context as c
-from webob.exc import HTTPBadRequest, HTTPForbidden
-
-from kallithea.model.db import Notification
-from kallithea.model.notification import NotificationModel
-from kallithea.model.meta import Session
-from kallithea.lib.auth import LoginRequired
-from kallithea.lib.base import BaseController, render
-from kallithea.lib import helpers as h
-from kallithea.lib.page import Page
-from kallithea.lib.utils2 import safe_int
-
-
-log = logging.getLogger(__name__)
-
-
-class NotificationsController(BaseController):
-"""REST Controller styled on the Atom Publishing Protocol"""
-# To properly map this controller, ensure your config/routing.py
-# file has a resource setup:
-# map.resource('notification', 'notifications', 
controller='_admin/notifications',
-# path_prefix='/_admin', name_prefix='_admin_')
-
-@LoginRequired()
-def _before(self, *args, **kwargs):
-super(NotificationsController, self)._before(*args, **kwargs)
-
-def index(self, format='html'):
-c.user = request.authuser
-notif = NotificationModel().query_for_user(request.authuser.user_id,
-filter_=request.GET.getall('type'))
-
-p = safe_int(request.GET.get('page'), 1)
-c.notifications = Page(notif, page=p, items_per_page=10)
-c.pull_request_type = Notification.TYPE_PULL_REQUEST
-c.comment_type = [Notification.TYPE_CHANGESET_COMMENT,
-  No

[PATCH 3 of 9] lib: remove unused method 'notify' from DbManage

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1543955255 -3600
#  Tue Dec 04 21:27:35 2018 +0100
# Node ID 7e7de9b59fb7af2f1926e628c88a50a0498d9dba
# Parent  cf7e97eceeed93f74bf2db3b6ffaca4b55896a70
lib: remove unused method 'notify' from DbManage

This method is no longer used.
Last usage was removed in 46db3368c2ae and previously c7ef77ab2f95.

diff --git a/kallithea/lib/db_manage.py b/kallithea/lib/db_manage.py
--- a/kallithea/lib/db_manage.py
+++ b/kallithea/lib/db_manage.py
@@ -54,14 +54,6 @@ from kallithea.model.permission import P
 log = logging.getLogger(__name__)
 
 
-def notify(msg):
-"""
-Notification for migrations messages
-"""
-ml = len(msg) + (4 * 2)
-print('\n%s\n*** %s ***\n%s' % ('*' * ml, msg, '*' * ml)).upper()
-
-
 class DbManage(object):
 def __init__(self, dbconf, root, tests=False, SESSION=None, cli_args=None):
 self.dbname = dbconf.split('/')[-1]
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


[PATCH 1 of 9] model: notification: don't round-trip via list if you want a set

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1543436548 -3600
#  Wed Nov 28 21:22:28 2018 +0100
# Node ID d0eaee2ca6b205ad58b6e46723252e3e57bfa31c
# Parent  2c54a82aeaed569ef27f7813d9537d4f1adcfb32
model: notification: don't round-trip via list if you want a set

'create' in NotificationModel starts from an empty list, appends entries to
it, then converts it to a set.
You could equally start with a set and add to it, avoiding the final
conversion.

diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py
--- a/kallithea/model/notification.py
+++ b/kallithea/model/notification.py
@@ -68,16 +68,15 @@ class NotificationModel(object):
 
 created_by_obj = User.guess_instance(created_by)
 
-recipients_objs = []
+recipients_objs = set()
 if recipients:
 for u in recipients:
 obj = User.guess_instance(u)
 if obj is not None:
-recipients_objs.append(obj)
+recipients_objs.add(obj)
 else:
 # TODO: inform user that requested operation couldn't be 
completed
 log.error('cannot email unknown user %r', u)
-recipients_objs = set(recipients_objs)
 log.debug('sending notifications %s to %s',
 type_, recipients_objs
 )
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


[PATCH 0 of 9] remove UI notification feature

2018-12-06 Thread Thomas De Schampheleire
Hello,

As discussed, this patch series removes the UI notification feature from
Kallithea. Notifications are now email-only.

This change simplifies the code base and will make later changes in the
email notifications easier.

The first three commits are not directly related to the removal, but are
small fixes noticed during the removal work.
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general


[PATCH 4 of 9] templates: remove notification count from user profile button

2018-12-06 Thread Thomas De Schampheleire
# HG changeset patch
# User Thomas De Schampheleire 
# Date 1543955577 -3600
#  Tue Dec 04 21:32:57 2018 +0100
# Node ID 4473f2fb4f7e34ee0d842d163b4412ba6a04e7cb
# Parent  7e7de9b59fb7af2f1926e628c88a50a0498d9dba
templates: remove notification count from user profile button

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.

This commit removes the notification count 'badge' next to the username
top-right, and the count in the expanded field when clicking that username.

diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py
--- a/kallithea/lib/base.py
+++ b/kallithea/lib/base.py
@@ -59,7 +59,6 @@ from kallithea.lib.vcs.exceptions import
 from kallithea.model import meta
 
 from kallithea.model.db import PullRequest, Repository, Ui, User, Setting
-from kallithea.model.notification import NotificationModel
 from kallithea.model.scm import ScmModel
 
 log = logging.getLogger(__name__)
@@ -418,8 +417,6 @@ class BaseController(TGController):
 
 c.repo_name = get_repo_slug(request)  # can be empty
 c.backends = BACKENDS.keys()
-c.unread_notifications = NotificationModel() \
-.get_unread_cnt_for_user(request.authuser.user_id)
 
 self.cut_off_limit = safe_int(config.get('cut_off_limit'))
 
diff --git a/kallithea/templates/base/base.html 
b/kallithea/templates/base/base.html
--- a/kallithea/templates/base/base.html
+++ b/kallithea/templates/base/base.html
@@ -354,19 +354,10 @@
 ## USER MENU
 
   
+aria-expanded="false" aria-controls="quick_login" href="#">
   ${h.gravatar_div(request.authuser.email, size=20, div_class="icon")}
   %if request.authuser.username != 'default':
 ${request.authuser.username}
-%if c.unread_notifications != 0:
-  ${c.unread_notifications}
-%endif
   %else:
   ${_('Not Logged In')}
   %endif
@@ -405,7 +396,6 @@
 ${request.authuser.email}
 
 
-  ${_('Notifications')}: 
${c.unread_notifications}
   ${h.link_to(_('My 
Account'),h.url('my_account'),class_='list-group-item')}
   %if not request.authuser.is_external_auth:
 ## Cannot log out if using external (container) authentication.
___
kallithea-general mailing list
kallithea-general@sfconservancy.org
https://lists.sfconservancy.org/mailman/listinfo/kallithea-general