Exemplo n.º 1
0
    def get(self, uid: str):
        """
        Login required. Returns a profile for the user specified. Will return
        reduced information if the profile specified is marked as private.

        Example:
        ```
        GET ->
        # If the profile is public
        (200 OK) <-
        {
            "_id": "string",
            "username": "******",
            "name": "string",
            "email": "string",
            "visibility": "string",
            "description": "string",
            "interests": ["string"],
            "programming_languages": ["string"],
            "languages": ["string"],
            "github": "string"
        }
        # If the profile is private
        (200 OK) <-
        {
            "_id": "string",
            "username": "******",
            "visibility": "string"
        }
        ```
        """
        try:
            uid = ObjectId(uid)
        except InvalidId:
            return {"message": f"invalid user_id: {uid}"}, 422

        data = self.user_manager.get_user_profile(uid)
        if data is None:
            return {"message": "user not found"}, 404

        # Project the items in the "profile" sub dictionary up. Could be done
        # on the database side as well but projection isn't very extensible.
        for k, v in data["profile"].items():
            data[k] = v

        # If the profile is private, return only a few select fields.
        if data["visibility"] == "private":
            reduced_fields = ("_id", "username", "visibility")
            reduced_profile = {
                k: v
                for k, v in data.items() if k in reduced_fields
            }
            return marshal(reduced_profile, profile_fields)

        return marshal(data, profile_fields)
Exemplo n.º 2
0
    def get(self):
        """
        Returns user profile information for an authenticated user.
        Will return 401/422 if user is not authenticated.

        Returns:
        ```json
            {
                "_id": string,
                "name": string,
                "email": string,
                "visibility": string,
                "description": string,
                "interests": string[],
                "programming_languages": string[],
                "languages": string[],
                "github": string
            }
        ```
        """
        # Hack to get proper type annotation working, casting doesn't do anything
        # at runtime. Should optimally create a proxy for current_user to annotate
        # the return of a User object.
        profile = cast(User, current_user).profile
        return marshal(profile, profile_fields)
Exemplo n.º 3
0
    def get(self, project_id: str):
        """
        Gets information about a specific project given its project_id. Returns 422 if
        the project_id is not in the correct format. 404 if project_id is not found.

        Example:
        ```
        GET /api/project/5dac029b8b819e584ff36f8d ->
        (200 OK) <-
            {
                "title": "Code Unity",
                "leader": "5dabfe830ddd57902efd2fa3",
                "max_people": 5,
                "cur_people": 1,
                "members": [
                    "5dabfe830ddd57902efd2fa3"
                ],
                "description": "Nice.",
                "course": "4920",
                "technologies": [
                    "assembly",
    projects              "python",
                    "mongoDB",
                    "react"
                ],
                "languages": [
                    "chinese",
                    "english"
                ],
                "tags": [
                    "wam booster",
                    "free hd",
                    "machine learning",
                    "blockchain"
                ]
            }
        # If project not found
        GET /api//project/ffffffffffffffffffffffff ->
        (404 NOT FOUND) <-
            {
                "message": "project_id ffffffffffffffffffffffff not found"
            }
        # If project_id isn't in the right format
        GET /api//project/ohno ->
        (422 UNPROCESSABLE ENTITY) <-
            {
                "message": "invalid project_id: ohno"
            }
        ```
        """
        try:
            id = ObjectId(project_id)
        except InvalidId:
            return {"message": f"invalid project_id: {project_id}"}, 422

        doc = self.project_manager.get_project(id)
        if doc is None:
            return {"message": f"project_id {project_id} not found"}, 404
        return marshal(doc, project_fields)
Exemplo n.º 4
0
    def get(self):
        """
        Allows a user to list the invites that they've sent out or the invites
        that other people have sent them if the incoming parameter is set to true.

        Example:
        ```
        # Gets invitations that the user has sent out
        GET ->
        (200 OK) <-
        [
            {
                "project_id": string,
                "project_title": string,
                "user_id": string,
                "user_name": "testuser"  # username of the user invited
            }
        ]

        # Gets invitations that the user has received from others
        GET ?incoming=true ->
        (200 OK) <- 
        [
            {
                "project_id": string,
                "project_title": string,
                "user_id": string,
                "user_name": "testuser"  # username of the user who invited the current user
            }
        ]
        ```
        """
        parser = RequestParser()
        parser.add_argument("incoming")
        incoming = parser.parse_args(strict=True)["incoming"]

        if incoming is not None and incoming.lower() == "true":
            result = current_user.get_incoming_invitations()
            return marshal(result, fields)

        result = current_user.get_outgoing_invitations()
        return marshal(result, fields)
Exemplo n.º 5
0
    def get(self):
        """
        Allows a user to get a list of pending join requests that they have sent,
        i.e., join requests that are outgoing. If the "incoming" parameter is set
        to true, then the endpoint will return a list of pending incoming join
        requests to the projects that they own. 

        Example:
        ```
        GET ->
        (200 OK) <-
        [
            {
                "project_id": string,
                "project_title": string,
                "message": string
            }
        ]

        GET ?incoming=true ->
        (200 OK) <-
        [
            {
                "project_id": string,
                "project_title": string,
                "user_id": string,
                "user_name": string,
                "message": string
            }
        ]
        ```
        """
        parser = RequestParser()
        parser.add_argument("incoming")
        incoming = parser.parse_args(strict=True)["incoming"]

        if incoming is not None and incoming.lower() == "true":
            result = current_user.get_incoming_join_requests()
            return marshal(result, incoming_fields)

        result = current_user.get_outgoing_join_requests()
        return marshal(result, outgoing_fields)
Exemplo n.º 6
0
    def get(self):
        """
        Returns a list of the current user's involved projects or
        every project's title and their project_id.

        Examples:
        ```
        GET ->
        (200 OK) <-
            [
                {
                    "project_id": "5dac029b8b819e584ff36f8d",
                    "title": "Code Unity",
                    "leader": {
                        "_id": "5dabfe830ddd57902efd2fa3",
                        "username": "******"
                    },
                    "cur_people": 1,
                    "members": [
                        {
                            "_id": "5daa6efd8805c462ef0d16e1",
                            "username": "******"
                        },
                        {
                            "_id": "5dabfe830ddd57902efd2fa3",
                            "username": "******"
                        }
                    ],
                    "description": "Nice.",
                    "course": "4920",
                    "tags": [
                        "wam booster",
                        "free hd",
                    ],
                    "languages": [
                        "chinese",
                        "english"
                    ],
                    "technologies": [
                        "python",
                        "mongoDB",
                        "react"
                    ]
                }
            ]
        ```
        """
        user_id = request.args.get("user_id")
        if user_id == None:
            ret = self.project_manager.get_project_listing()
        else:
            ret = self.project_manager.get_project_listing(user_id)

        return marshal(ret, project_fields)
Exemplo n.º 7
0
    def get(self):
        # assign the url encoded parameters into python variables
        title = request.args.get("title")
        courses = request.args.getlist("courses")
        languages = request.args.getlist("languages")
        programming_languages = request.args.getlist("programming_languages")
        group_crit = request.args.get("group_crit")

        # return resultant filtered projects
        ret = self.project_manager.search_project_listing(
            title, courses, languages, programming_languages, group_crit)

        return marshal(ret, project_fields)
Exemplo n.º 8
0
    def get(self):
        """
            Returns the account information for the currently logged in user.
            Will return 401/422 if user is not authenticated.

            Returns:
            ```json
                {
                    "_id": string,
                    "name": string,
                    "email": string,
                    "avatar": string
                }
            ```
        """
        account = cast(User, current_user).account
        return marshal(account, account_fields)