def __get_notification(self, notification): if isinstance(notification, Notification): return notification elif isinstance(notification, (int, long)): return Notification.get(notification) else: if notification: raise Exception('notification must be int, long or Instance' ' of Notification got %s' % type(notification))
def delete(self, notification_id): """DELETE /_admin/notifications/id: Delete an existing item""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="DELETE" /> # Or using helpers: # h.form(url('notification', notification_id=ID), # method='delete') # url('notification', notification_id=ID) try: no = Notification.get(notification_id) if self._has_permissions(no): # deletes only notification2user NotificationModel().delete(c.rhodecode_user.user_id, no) Session().commit() return 'ok' except Exception: Session().rollback() log.exception("Exception deleting a notification item") raise HTTPBadRequest()
def update(self, notification_id): """PUT /_admin/notifications/id: Update an existing item""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="PUT" /> # Or using helpers: # h.form(url('notification', notification_id=ID), # method='put') # url('notification', notification_id=ID) try: no = Notification.get(notification_id) owner = all(un.user.user_id == c.rhodecode_user.user_id for un in no.notifications_to_users) 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""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="DELETE" /> # Or using helpers: # h.form(url('notification', notification_id=ID), # method='delete') # 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", "repository.admin")() or owner: NotificationModel().delete(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""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="DELETE" /> # Or using helpers: # h.form(url('notification', notification_id=ID), # method='delete') # 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', 'repository.admin')() or owner: NotificationModel().delete(c.rhodecode_user.user_id, no) Session.commit() return 'ok' except Exception: Session.rollback() log.error(traceback.format_exc()) return 'fail'
def show(self, notification_id): """GET /_admin/notifications/id: Show a specific item""" # url('notification', notification_id=ID) c.user = c.rhodecode_user no = Notification.get(notification_id) if no and self._has_permissions(no): unotification = NotificationModel()\ .get_user_notification(c.user.user_id, no) # if this association to user is not valid, we don't want to show # this message if unotification: if not unotification.read: unotification.mark_as_read() Session().commit() c.notification = no return render('admin/notifications/show_notification.html') return abort(403)
def show(self, notification_id, format="html"): """GET /_admin/notifications/id: Show a specific item""" # url('notification', notification_id=ID) c.user = self.rhodecode_user no = Notification.get(notification_id) owner = lambda: (no.notifications_to_users.user.user_id == c.user.user_id) if no and (h.HasPermissionAny("hg.admin", "repository.admin")() or owner): unotification = NotificationModel().get_user_notification(c.user.user_id, no) # if this association to user is not valid, we don't want to show # this message if unotification: if unotification.read is False: unotification.mark_as_read() Session.commit() c.notification = no return render("admin/notifications/show_notification.html") return redirect(url("notifications"))
def show(self, notification_id, format='html'): """GET /_admin/notifications/id: Show a specific item""" # url('notification', notification_id=ID) c.user = self.rhodecode_user no = Notification.get(notification_id) owner = lambda: (no.notifications_to_users.user.user_id == c.user. user_id) if no and (h.HasPermissionAny('hg.admin', 'repository.admin')() or owner): unotification = NotificationModel()\ .get_user_notification(c.user.user_id, no) # if this association to user is not valid, we don't want to show # this message if unotification: if unotification.read is False: unotification.mark_as_read() Session.commit() c.notification = no return render('admin/notifications/show_notification.html') return redirect(url('notifications'))
def show(self, notification_id, format='html'): """GET /_admin/notifications/id: Show a specific item""" # url('notification', notification_id=ID) c.user = self.rhodecode_user no = Notification.get(notification_id) owner = any(un.user.user_id == c.rhodecode_user.user_id for un in no.notifications_to_users) if no and (h.HasPermissionAny('hg.admin', 'repository.admin')() or owner): unotification = NotificationModel()\ .get_user_notification(c.user.user_id, no) # if this association to user is not valid, we don't want to show # this message if unotification: if not unotification.read: unotification.mark_as_read() Session().commit() c.notification = no return render('admin/notifications/show_notification.html') return abort(403)
def teardown_method(self, method): for n in Notification.query().all(): inst = Notification.get(n.notification_id) Session().delete(inst) Session().commit()
def tearDown(self): for n in Notification.query().all(): inst = Notification.get(n.notification_id) Session().delete(inst) Session().commit()
def tearDown(self): for n in Notification.query().all(): inst = Notification.get(n.notification_id) self.Session().delete(inst) self.Session().commit()