コード例 #1
0
ファイル: views.py プロジェクト: saltfun/eox-core
    def get(self, request, *args, **kwargs):
        """
        Retrieve an user from edxapp
        """
        query = self.get_user_query(request)
        user = get_edxapp_user(**query)
        admin_fields = getattr(settings, 'ACCOUNT_VISIBILITY_CONFIGURATION',
                               {}).get('admin_fields', {})
        serialized_user = EdxappUserReadOnlySerializer(
            user, custom_fields=admin_fields, context={'request': request})
        response_data = serialized_user.data
        # Show a warning if the request is providing email and username
        # to let the client know we're giving priority to the username
        if 'username' and 'email' in self.query_params:
            response_data[
                'warning'] = 'The username prevails over the email when both are provided to get the user.'

        return Response(response_data)
コード例 #2
0
ファイル: views.py プロジェクト: eduNEXT/eox-core
    def patch(self, request, *args, **kwargs):
        """
        Allows to safely update an Edxapp user's Username along with the
        forum associated User.

        For now users that have different signup sources cannot be updated.

        For example:

        **Requests**:
            PATCH <domain>/eox-core/support-api/v1/replace-username/

        **Request body**
            {
                "new_username": "******"
            }

        **Response values**
            User serialized.
        """
        query = self.get_user_query(request)
        user = get_edxapp_user(**query)
        data = request.data

        with transaction.atomic():
            serializer = WrittableEdxappUsernameSerializer(user, data=data)
            serializer.is_valid(raise_exception=True)
            serializer.save()

            data = serializer.validated_data
            data["user"] = user

            # Update user in cs_comments_service forums
            replace_username_cs_user(**data)

        admin_fields = getattr(settings, "ACCOUNT_VISIBILITY_CONFIGURATION", {}).get(
            "admin_fields", {}
        )
        serialized_user = EdxappUserReadOnlySerializer(
            user, custom_fields=admin_fields, context={"request": request}
        )
        return Response(serialized_user.data)
コード例 #3
0
ファイル: views.py プロジェクト: saltfun/eox-core
    def patch(self, request, *args, **kwargs):
        """
        Partially update a user from edxapp. Not all the fields can be updated, just the ones thought as `safe`.

        For example:

        **Requests**:
            PATCH <domain>/eox-core/api/v1/user/

        **Request body**
            {
                "email"=<USER_EMAIL>,
                "is_active": true,
                "password": "******"
            }

        **Response values**
            User serialized.
        """
        # Pop identification
        data = request.data.copy()
        query_params = {
            "email": data.pop("email", None),
        }
        query = self.get_user_query(request, query_params=query_params)
        user = get_edxapp_user(**query)

        serializer = WrittableEdxappUserSerializer(user,
                                                   data=data,
                                                   partial=True)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        admin_fields = getattr(settings, 'ACCOUNT_VISIBILITY_CONFIGURATION',
                               {}).get('admin_fields', {})
        serialized_user = EdxappUserReadOnlySerializer(
            user, custom_fields=admin_fields, context={'request': request})
        return Response(serialized_user.data)
コード例 #4
0
    def patch(self, request, *args, **kwargs):
        """
        Partially updates a user from edxapp.

        **Example Requests**

            PATCH /eox-core/api/v1/update-user/

            Request data: {
                "email": "*****@*****.**",
                "fullname": "John Doe R",
                "password": "******",
            }


        **Parameters**

        - `email` (**required**, string, _body_):
            The email used to identify the user. Use either username or email.

        - `username` (**required**, string, _body_):
            The username used to identify the user. Use either username or email.

        - `password` (**optional**, string, _body_):
            The new password of the user.

        - `fullname` (**optional**, string, _body_):
            The full name to be assigned.

        - `is_active` (**optional**, boolean, _body_):
            Flag indicating if the user is active on the platform.

        - Not all the fields can be updated, just the ones thought as 'safe', such as: "is_active", "password", "fullname"

        - By default, these are the 'safe' extra registration fields: "mailing_address", "year_of_birth", "gender", "level_of_education",
        "city", "country", "goals", "bio" and "phone_number".

        If you have extra registration fields configured in your settings or extended_profile fields, and you want to update them, you can send them along with the rest of the parameters.
        For example:

            {
                "email": "*****@*****.**",
                "fullname": "John Doe R",
                "password": "******",
                "gender": "f",
                "country": "US",
            }

        **Response details**

        - `username (str)`: Username of the edxapp user
        - `is_active (str)`: Indicates if the user is active on the platform
        - `email (str)`: Email of the user
        - `gender (str)`: Gender of the user
        - `date_joined (str)`: Date for when the user was registered in the platform
        - `name (str)`: Fullname of the user
        - `country (str)`: Country of the user
        - `level_of_education (str)`: Level of education of the user
        - `year_of_birth (int)`: Year of birth of the user
        - `bio (str)`: Bio of the user
        - `goals (str)`: Goals of the user
        - `extended_profile (list)`: List of dictionaries that contains the user-profile meta fields
            - `field_name (str)`: Name of the extended profile field
            - `field_value (str)`: Value of the extended profile field
        - `mailing_address (str)`
        - `social_links (List)`: List that contains the social links of the user, if any.
        - `account_privacy (str)`: Indicates the account privacy type
        - `state (str)`: State (only for US)
        - `secondary_email (str)`: Secondary email of the user
        - `profile_image (dictionary)`:
            - `has_image (Bool)`: Indicates if user has profile image
            - `image_url_medium (str)`: Url of the profile image in medium size
            - `image_url_small (str)`: Url of the profile image in small size
            - `image_url_full (str)`: Url of the profile image in full size,
            - `image_url_large (str)`: Url of the profile image in large size
        - `secondary_email_enabled (Bool)`: Indicates if the secondary email is enable
        - `phone_number (str)`: Phone number of the user
        - `requires_parental_consent (Bool)`: Indicates whether parental consent is required for the user

        **Returns**

        - 200: Success, user updated.
        - 400: Bad request, a required field is now null or has been entered with the wrong format.
        - 401: Unauthorized user to make the request.
        - 404: User not found
        """
        # Pop identification
        data = request.data.copy()
        query_params = {
            "email": data.pop("email", None),
            "username": data.pop("username", None),
        }
        query = self.get_user_query(request, query_params=query_params)
        user = get_edxapp_user(**query)

        serializer = WrittableEdxappUserSerializer(user,
                                                   data=data,
                                                   partial=True)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        admin_fields = getattr(settings, "ACCOUNT_VISIBILITY_CONFIGURATION",
                               {}).get("admin_fields", {})
        serialized_user = EdxappUserReadOnlySerializer(
            user, custom_fields=admin_fields, context={"request": request})
        return Response(serialized_user.data)
コード例 #5
0
    def get(self, request, *args, **kwargs):
        """
        Retrieves information about an edxapp user,
        given an email or a username.

        The username prevails over the email when both are provided to get the user.

        **Example Requests**

            GET /eox-core/api/v1/user/?username=johndoe

            Query parameters: {
              "username": "******",
            }

        **Response details**

        - `username (str)`: Username of the edxapp user
        - `is_active (str)`: Indicates if the user is active on the platform
        - `email (str)`: Email of the user
        - `gender (str)`: Gender of the user
        - `date_joined (str)`: Date for when the user was registered in the platform
        - `name (str)`: Fullname of the user
        - `country (str)`: Country of the user
        - `level_of_education (str)`: Level of education of the user
        - `year_of_birth (int)`: Year of birth of the user
        - `bio (str)`: Bio of the user
        - `goals (str)`: Goals of the user
        - `extended_profile (list)`: List of dictionaries that contains the user-profile meta fields
            - `field_name (str)`: Name of the extended profile field
            - `field_value (str)`: Value of the extended profile field
        - `mailing_address (str)`
        - `social_links (List)`: List that contains the social links of the user, if any.
        - `account_privacy (str)`: Indicates the account privacy type
        - `state (str)`: State (only for US)
        - `secondary_email (str)`: Secondary email of the user
        - `profile_image (dictionary)`:
            - `has_image (Bool)`: Indicates if user has profile image
            - `image_url_medium (str)`: Url of the profile image in medium size
            - `image_url_small (str)`: Url of the profile image in small size
            - `image_url_full (str)`: Url of the profile image in full size,
            - `image_url_large (str)`: Url of the profile image in large size
        - `secondary_email_enabled (Bool)`: Indicates if the secondary email is enable
        - `phone_number (str)`: Phone number of the user
        - `requires_parental_consent (Bool)`: Indicates whether parental consent is required for the user

        **Returns**

        - 200: Success, user found.
        - 400: Bad request, missing either email or username
        - 401: Unauthorized user to make the request.
        - 404: User not found
        """
        query = self.get_user_query(request)
        user = get_edxapp_user(**query)
        admin_fields = getattr(settings, "ACCOUNT_VISIBILITY_CONFIGURATION",
                               {}).get("admin_fields", {})
        serialized_user = EdxappUserReadOnlySerializer(
            user, custom_fields=admin_fields, context={"request": request})
        response_data = serialized_user.data
        # Show a warning if the request is providing email and username
        # to let the client know we're giving priority to the username
        if "username" and "email" in self.query_params:
            response_data[
                "warning"] = "The username prevails over the email when both are provided to get the user."

        return Response(response_data)