diff --git a/rhodecode/controllers/admin/notifications.py b/rhodecode/controllers/admin/notifications.py --- a/rhodecode/controllers/admin/notifications.py +++ b/rhodecode/controllers/admin/notifications.py @@ -106,6 +106,18 @@ class NotificationsController(BaseContro # h.form(url('notification', notification_id=ID), # method='put') # url('notification', notification_id=ID) + try: + no = Notification.get(notification_id) + owner = lambda: (no.notifications_to_users.user.user_id + == c.rhodecode_user.user_id) + if h.HasPermissionAny('hg.admin')() or owner: + NotificationModel().mark_read(c.rhodecode_user.user_id, no) + Session.commit() + return 'ok' + except Exception: + Session.rollback() + log.error(traceback.format_exc()) + return 'fail' def delete(self, notification_id): """DELETE /_admin/notifications/id: Delete an existing item""" @@ -120,7 +132,7 @@ class NotificationsController(BaseContro no = Notification.get(notification_id) owner = lambda: (no.notifications_to_users.user.user_id == c.rhodecode_user.user_id) - if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: + if h.HasPermissionAny('hg.admin')() or owner: NotificationModel().delete(c.rhodecode_user.user_id, no) Session.commit() return 'ok' diff --git a/rhodecode/model/notification.py b/rhodecode/model/notification.py --- a/rhodecode/model/notification.py +++ b/rhodecode/model/notification.py @@ -156,6 +156,23 @@ class NotificationModel(BaseModel): return q.all() + def mark_read(self, user, notification): + try: + notification = self.__get_notification(notification) + user = self._get_user(user) + if notification and user: + obj = UserNotification.query()\ + .filter(UserNotification.user == user)\ + .filter(UserNotification.notification + == notification)\ + .one() + obj.read = True + self.sa.add(obj) + return True + except Exception: + log.error(traceback.format_exc()) + raise + def mark_all_read_for_user(self, user, filter_=None): user = self._get_user(user) q = UserNotification.query()\ diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -3002,6 +3002,13 @@ table.code-browser .submodule-dir { text-align: left; } +.accept_icon { + background: url("../images/icons/accept.png") no-repeat scroll 3px; + padding-left: 20px; + padding-top: 0px; + text-align: left; +} + .edit_icon { background: url("../images/icons/folder_edit.png") no-repeat scroll 3px; padding-left: 20px; @@ -4280,7 +4287,7 @@ form.comment-inline-form { background: none repeat scroll 0 0 transparent; padding: 0px 0px 0px 8px; } -.notification-header .desc.unread{ +.notification-list .container .notification-header .desc{ font-weight: bold; font-size: 17px; } @@ -4297,6 +4304,11 @@ form.comment-inline-form { padding-top: 8px; cursor: pointer; } +.notification-header .read-notifications{ + float: right; + padding-top: 8px; + cursor: pointer; +} .notification-subject{ clear:both; border-bottom: 1px solid #eee; diff --git a/rhodecode/public/js/rhodecode.js b/rhodecode/public/js/rhodecode.js --- a/rhodecode/public/js/rhodecode.js +++ b/rhodecode/public/js/rhodecode.js @@ -839,6 +839,27 @@ var deleteNotification = function(url, n callback, postData); }; +var readNotification = function(url, notification_id,callbacks){ + var callback = { + success:function(o){ + var obj = YUD.get(String("notification_"+notification_id)); + YUD.removeClass(obj, 'unread'); + var r_button = obj.children[0].getElementsByClassName('read-notification')[0] + + if(r_button.parentNode !== undefined){ + r_button.parentNode.removeChild(r_button); + } + _run_callbacks(callbacks); + }, + failure:function(o){ + alert("error"); + }, + }; + var postData = '_method=put'; + var sUrl = url.replace('__NOTIFICATION_ID__',notification_id); + var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, + callback, postData); +}; /** MEMBERS AUTOCOMPLETE WIDGET **/ diff --git a/rhodecode/templates/admin/notifications/notifications.html b/rhodecode/templates/admin/notifications/notifications.html --- a/rhodecode/templates/admin/notifications/notifications.html +++ b/rhodecode/templates/admin/notifications/notifications.html @@ -40,25 +40,26 @@ diff --git a/rhodecode/templates/admin/notifications/notifications_data.html b/rhodecode/templates/admin/notifications/notifications_data.html --- a/rhodecode/templates/admin/notifications/notifications_data.html +++ b/rhodecode/templates/admin/notifications/notifications_data.html @@ -18,6 +18,11 @@ unread = lambda n:{False:'unread'}.get(n
+ %if not notification.read: +
+ +
+ %endif
${h.literal(notification.notification.subject)}