Mercurial > kallithea
annotate rhodecode/controllers/admin/notifications.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | 13241a4075e9 |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
1 # -*- coding: utf-8 -*- |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
5 # (at your option) any later version. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
6 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
10 # GNU General Public License for more details. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
11 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
15 rhodecode.controllers.admin.notifications |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
18 notifications controller for RhodeCode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
20 :created_on: Nov 23, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
24 """ |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
25 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 import logging |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
27 import traceback |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 |
1791
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
29 from pylons import request |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
30 from pylons import tmpl_context as c, url |
3428
edb9a42def31
fix to strict permission check on notification messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3141
diff
changeset
|
31 from pylons.controllers.util import redirect, abort |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
32 from webob.exc import HTTPBadRequest |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 |
3776
13241a4075e9
Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents:
3745
diff
changeset
|
34 from rhodecode.model.db import Notification |
13241a4075e9
Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents:
3745
diff
changeset
|
35 from rhodecode.model.notification import NotificationModel |
13241a4075e9
Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents:
3745
diff
changeset
|
36 from rhodecode.model.meta import Session |
13241a4075e9
Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents:
3745
diff
changeset
|
37 from rhodecode.lib.auth import LoginRequired, NotAnonymous |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 from rhodecode.lib.base import BaseController, render |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 from rhodecode.lib import helpers as h |
3776
13241a4075e9
Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents:
3745
diff
changeset
|
40 from rhodecode.lib.helpers import Page |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
41 from rhodecode.lib.utils2 import safe_int |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
42 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 log = logging.getLogger(__name__) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
1791
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
46 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 class NotificationsController(BaseController): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 """REST Controller styled on the Atom Publishing Protocol""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 # To properly map this controller, ensure your config/routing.py |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 # file has a resource setup: |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1791
diff
changeset
|
51 # map.resource('notification', 'notifications', controller='_admin/notifications', |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 # path_prefix='/_admin', name_prefix='_admin_') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 @LoginRequired() |
1739
4a5b93b3bcdd
forbid notifications view for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
1723
diff
changeset
|
55 @NotAnonymous() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 def __before__(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 super(NotificationsController, self).__before__() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 def index(self, format='html'): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 """GET /_admin/notifications: All items in the collection""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 # url('notifications') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 c.user = self.rhodecode_user |
2433
74f2910f7ad9
Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents:
2190
diff
changeset
|
63 notif = NotificationModel().get_for_user(self.rhodecode_user.user_id, |
2503
d04243e932cc
Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2433
diff
changeset
|
64 filter_=request.GET.getall('type')) |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2662
diff
changeset
|
65 |
3745
7efc8dcc0dc4
usage of request.GET is now more consistent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
66 p = safe_int(request.GET.get('page', 1), 1) |
2190
64f7cf8f6a33
notification inbox improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
67 c.notifications = Page(notif, page=p, items_per_page=10) |
2433
74f2910f7ad9
Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents:
2190
diff
changeset
|
68 c.pull_request_type = Notification.TYPE_PULL_REQUEST |
2503
d04243e932cc
Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2433
diff
changeset
|
69 c.comment_type = [Notification.TYPE_CHANGESET_COMMENT, |
d04243e932cc
Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2433
diff
changeset
|
70 Notification.TYPE_PULL_REQUEST_COMMENT] |
2519
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
71 |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
72 _current_filter = request.GET.getall('type') |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
73 c.current_filter = 'all' |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
74 if _current_filter == [c.pull_request_type]: |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
75 c.current_filter = 'pull_request' |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
76 elif _current_filter == c.comment_type: |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
77 c.current_filter = 'comment' |
f8742e1acf08
add highlight of current filter in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2503
diff
changeset
|
78 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 return render('admin/notifications/notifications.html') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
1791
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
81 def mark_all_read(self): |
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
82 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
83 nm = NotificationModel() |
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
84 # mark all read |
2433
74f2910f7ad9
Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents:
2190
diff
changeset
|
85 nm.mark_all_read_for_user(self.rhodecode_user.user_id, |
2503
d04243e932cc
Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2433
diff
changeset
|
86 filter_=request.GET.getall('type')) |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2610
diff
changeset
|
87 Session().commit() |
1791
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
88 c.user = self.rhodecode_user |
2433
74f2910f7ad9
Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents:
2190
diff
changeset
|
89 notif = nm.get_for_user(self.rhodecode_user.user_id, |
2503
d04243e932cc
Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2433
diff
changeset
|
90 filter_=request.GET.getall('type')) |
2190
64f7cf8f6a33
notification inbox improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
91 c.notifications = Page(notif, page=1, items_per_page=10) |
1791
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
92 return render('admin/notifications/notifications_data.html') |
2aee0dc1784e
mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1739
diff
changeset
|
93 |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 def create(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 """POST /_admin/notifications: Create a new item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 # url('notifications') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 def new(self, format='html'): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 """GET /_admin/notifications/new: Form to create a new item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 # url('new_notification') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 def update(self, notification_id): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 """PUT /_admin/notifications/id: Update an existing item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 # Forms posted to this method should contain a hidden field: |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 # <input type="hidden" name="_method" value="PUT" /> |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 # Or using helpers: |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 # h.form(url('notification', notification_id=ID), |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 # method='put') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 # url('notification', notification_id=ID) |
2610
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
110 try: |
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
111 no = Notification.get(notification_id) |
3141
a45191e7c7bb
access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents:
2845
diff
changeset
|
112 owner = all(un.user.user_id == c.rhodecode_user.user_id |
a45191e7c7bb
access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents:
2845
diff
changeset
|
113 for un in no.notifications_to_users) |
2610
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
114 if h.HasPermissionAny('hg.admin')() or owner: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
115 # deletes only notification2user |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
116 NotificationModel().mark_read(c.rhodecode_user.user_id, no) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
117 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
118 return 'ok' |
2610
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
119 except Exception: |
3428
edb9a42def31
fix to strict permission check on notification messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3141
diff
changeset
|
120 Session().rollback() |
2610
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
121 log.error(traceback.format_exc()) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
122 raise HTTPBadRequest() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 def delete(self, notification_id): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 """DELETE /_admin/notifications/id: Delete an existing item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 # Forms posted to this method should contain a hidden field: |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 # <input type="hidden" name="_method" value="DELETE" /> |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 # Or using helpers: |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 # h.form(url('notification', notification_id=ID), |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 # method='delete') |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 # url('notification', notification_id=ID) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
132 try: |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
133 no = Notification.get(notification_id) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
134 owner = any(un.user.user_id == c.rhodecode_user.user_id |
3141
a45191e7c7bb
access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents:
2845
diff
changeset
|
135 for un in no.notifications_to_users) |
2610
3fdf7c3be2c9
added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
2519
diff
changeset
|
136 if h.HasPermissionAny('hg.admin')() or owner: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
137 # deletes only notification2user |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
138 NotificationModel().delete(c.rhodecode_user.user_id, no) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
139 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
140 return 'ok' |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
141 except Exception: |
3428
edb9a42def31
fix to strict permission check on notification messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3141
diff
changeset
|
142 Session().rollback() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
143 log.error(traceback.format_exc()) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
144 raise HTTPBadRequest() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 def show(self, notification_id, format='html'): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 """GET /_admin/notifications/id: Show a specific item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 # url('notification', notification_id=ID) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 c.user = self.rhodecode_user |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
150 no = Notification.get(notification_id) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
151 |
3428
edb9a42def31
fix to strict permission check on notification messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3141
diff
changeset
|
152 owner = any(un.user.user_id == c.rhodecode_user.user_id |
3141
a45191e7c7bb
access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents:
2845
diff
changeset
|
153 for un in no.notifications_to_users) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
154 repo_admin = h.HasRepoPermissionAny('repository.admin') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3776
diff
changeset
|
155 if no and (h.HasPermissionAny('hg.admin')() or repo_admin or owner): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
156 unotification = NotificationModel()\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
157 .get_user_notification(c.user.user_id, no) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
159 # if this association to user is not valid, we don't want to show |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
160 # this message |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
161 if unotification: |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3428
diff
changeset
|
162 if not unotification.read: |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
163 unotification.mark_as_read() |
2662
91c442a489bb
sqlalchemy sessions cleanup in admin
Marcin Kuzminski <marcin@python-works.com>
parents:
2610
diff
changeset
|
164 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
165 c.notification = no |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
167 return render('admin/notifications/show_notification.html') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 |
3428
edb9a42def31
fix to strict permission check on notification messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3141
diff
changeset
|
169 return abort(403) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 def edit(self, notification_id, format='html'): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 """GET /_admin/notifications/id/edit: Form to edit an existing item""" |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 # url('edit_notification', notification_id=ID) |