Exemplo n.º 1
0
    async def method_delete(self, request: Request, body: dict,
                            session: DBSession, user_id: int, token: dict,
                            *args, **kwargs) -> BaseHTTPResponse:

        if token.get('id') != user_id:
            return await self.make_response_json(status=403)

        try:
            user_queries.delete_user(session, user_id)
        except DBUserDeletedException:
            raise SanicUserDeletedException('User deleted')
        except DBUserNotFoundException:
            raise SanicUserNotFoundException('User not found')

        try:
            session.commit_session()
        except (DBIntegrityException, DBDataException) as error:
            raise SanicDBException(str(error))

        return await self.make_response_json(status=204)
Exemplo n.º 2
0
    async def method_delete(self, request: Request, body: dict,
                            session: DBSession, uid: int, *args,
                            **kwargs) -> BaseHTTPResponse:

        try:
            user = user_queries.delete_user(session, uid)
        except DBUserNotExistsException:
            raise SanicUserNotFound('User not found')

        try:
            session.commit_session()
        except (DBDataException, DBIntegrityException) as e:
            raise SanicDBException(str(e))

        return await self.make_response_json(status=204)
Exemplo n.º 3
0
    async def method_delete(self, request: Request, body: dict,
                            session: DBSession, user_id: int, token: dict,
                            *args, **kwargs) -> BaseHTTPResponse:
        if user_id != token["sub"]:
            raise Forbidden("user can delete only himself")

        try:
            _ = delete_user(session, user_id)
        except DBUserNotExists:
            raise SanicUserNotFound("User not found")

        try:
            session.commit_session()
        except (DBDataException, DBIntegrityException) as e:
            raise SanicDBException(str(e))

        return await self.make_response_json(status=204)
Exemplo n.º 4
0
    async def method_delete(self, request: Request, body: dict,
                            session: DBSession, uid: int, token: dict, *args,
                            **kwargs) -> BaseHTTPResponse:

        await self.check_uid_in_token(
            token,
            uid,
            response_error_message='You can only delete your own data')

        try:
            user = user_queries.delete_user(session, user_id=uid)
        except DBUserNotExistsException:
            raise SanicUserNotFound('User not found')

        try:
            session.commit_session()
        except (DBDataException, DBIntegrityException) as e:
            raise SanicDBException(str(e))

        return await self.make_response_json(status=204)