Beispiel #1
0
 def on_head(self, req, resp, user_id, session, actor):
     """
     description:
         Check if a user exists by id
     url_params:
         user_id: check if the user with `user_id` exists
     responses:
         - status_code: 204
           description: The requested user exists
         - status_code: 404
           description: The requested user does not exist
         - status_code: 401
           description: Unauthorized request
         - status_code: 403
           description: User is not permitted to access this user
     """
     try:
         head_entity(resp, session, User.active_user_query(user_id))
     except falcon.HTTPNotFound:
         # try to fetch by user name
         user_name = user_id
         head_entity(resp, session, User.active_username_query(user_name))
Beispiel #2
0
    def on_get(self, req, resp, user_id, session, actor):
        """
        description:
            Fetch an individual user by id.  Some details, such as email, are
            only included when users fetch their own record
        url_params:
            user_id: the identifier of the user to fetch
        responses:
            - status_code: 200
              description: Successfully fetched a user
              example:
                python: get_model_example
            - status_code: 404
              description: Provided an invalid user id
            - status_code: 401
              description: Unauthorized request
            - status_code: 403
              description: User is not permitted to access this user
        """
        try:
            user = get_entity(
                resp,
                session,
                actor,
                User.active_user_query(user_id),
                add_links=self.add_links)
        except EntityNotFoundError:
            # try to fetch by user name
            user_name = user_id
            user = get_entity(
                resp,
                session,
                actor,
                User.active_username_query(user_name),
                add_links=self.add_links)

        resp.set_header('Location', '/users/{id}'.format(**user))