Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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'
Ejemplo n.º 5
0
    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"
Ejemplo n.º 6
0
    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'
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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"))
Ejemplo n.º 9
0
    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'))
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
 def teardown_method(self, method):
     for n in Notification.query().all():
         inst = Notification.get(n.notification_id)
         Session().delete(inst)
     Session().commit()
Ejemplo n.º 12
0
 def tearDown(self):
     for n in Notification.query().all():
         inst = Notification.get(n.notification_id)
         Session().delete(inst)
     Session().commit()
Ejemplo n.º 13
0
 def tearDown(self):
     for n in Notification.query().all():
         inst = Notification.get(n.notification_id)
         self.Session().delete(inst)
     self.Session().commit()