Esempio n. 1
0
    def flag_delete(self, request):
        """
        Exposes an API endpoint to delete an existing flag.
        """
        user = auth_user(self.request_state.headers)
        anno = None
        if request.id is None and request.anno_id is None:
            raise endpoints.BadRequestException('id or anno_id field is required.')
        if request.id is not None:
            flag = Flag.get_by_id(request.id)
            if flag is None:
                raise endpoints.NotFoundException('No flag entity with the id "%s" exists.' % request.id)

            anno = flag.anno_key.get()
            flag.key.delete()
            anno.flag_count -= 1
            anno.put()
        elif request.anno_id is not None:
            anno = Anno.get_by_id(request.anno_id)
            for key in Flag.query(Flag.anno_key == anno.key, Flag.creator == user.key).iter(keys_only=True):
                key.delete()
                anno.flag_count -= 1
                anno.put()
        put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)
        return message_types.VoidMessage()
Esempio n. 2
0
 def flag_get(self, request):
     """
     Exposes an API endpoint to get a flag.
     """
     if request.id is None:
         raise endpoints.BadRequestException('id field is required.')
     flag = Flag.get_by_id(request.id)
     if flag is None:
         raise endpoints.NotFoundException('No flag entity with the id "%s" exists.' % request.id)
     return flag.to_message()
Esempio n. 3
0
    def flag_delete(self, request):
        """
        Exposes an API endpoint to delete an existing flag.
        """
        if request.id is None and request.anno_id is None:
            raise endpoints.BadRequestException('id or anno_id field is required.')
        if request.id is not None:
            flag = Flag.get_by_id(request.id)
            if flag is None:
                raise endpoints.NotFoundException('No flag entity with the id "%s" exists.' % request.id)

            anno = flag.anno_key.get()
            flag.key.delete()
            anno.flag_count -= 1
            anno.put()
        elif request.anno_id is not None:
            user = User.find_user_by_email(get_endpoints_current_user().email())
            anno = Anno.get_by_id(request.anno_id)
            for key in Flag.query(Flag.anno_key == anno.key, Flag.creator == user.key).iter(keys_only=True):
                key.delete()
                anno.flag_count -= 1
                anno.put()
        return message_types.VoidMessage()