comparison rhodecode/controllers/admin/notifications.py @ 2610:3fdf7c3be2c9 beta

added mark as read for single notifications
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 15 Jul 2012 04:02:58 +0200
parents f8742e1acf08
children 91c442a489bb
comparison
equal deleted inserted replaced
2609:200a5b747e69 2610:3fdf7c3be2c9
104 # <input type="hidden" name="_method" value="PUT" /> 104 # <input type="hidden" name="_method" value="PUT" />
105 # Or using helpers: 105 # Or using helpers:
106 # h.form(url('notification', notification_id=ID), 106 # h.form(url('notification', notification_id=ID),
107 # method='put') 107 # method='put')
108 # url('notification', notification_id=ID) 108 # url('notification', notification_id=ID)
109 try:
110 no = Notification.get(notification_id)
111 owner = lambda: (no.notifications_to_users.user.user_id
112 == c.rhodecode_user.user_id)
113 if h.HasPermissionAny('hg.admin')() or owner:
114 NotificationModel().mark_read(c.rhodecode_user.user_id, no)
115 Session.commit()
116 return 'ok'
117 except Exception:
118 Session.rollback()
119 log.error(traceback.format_exc())
120 return 'fail'
109 121
110 def delete(self, notification_id): 122 def delete(self, notification_id):
111 """DELETE /_admin/notifications/id: Delete an existing item""" 123 """DELETE /_admin/notifications/id: Delete an existing item"""
112 # Forms posted to this method should contain a hidden field: 124 # Forms posted to this method should contain a hidden field:
113 # <input type="hidden" name="_method" value="DELETE" /> 125 # <input type="hidden" name="_method" value="DELETE" />
118 130
119 try: 131 try:
120 no = Notification.get(notification_id) 132 no = Notification.get(notification_id)
121 owner = lambda: (no.notifications_to_users.user.user_id 133 owner = lambda: (no.notifications_to_users.user.user_id
122 == c.rhodecode_user.user_id) 134 == c.rhodecode_user.user_id)
123 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: 135 if h.HasPermissionAny('hg.admin')() or owner:
124 NotificationModel().delete(c.rhodecode_user.user_id, no) 136 NotificationModel().delete(c.rhodecode_user.user_id, no)
125 Session.commit() 137 Session.commit()
126 return 'ok' 138 return 'ok'
127 except Exception: 139 except Exception:
128 Session.rollback() 140 Session.rollback()