Adds preferences API and updates users to V1 with PEP8 fixes
This commit is contained in:
@@ -24,7 +24,8 @@ class AccountView(APIView):
|
||||
"""
|
||||
**Use Cases**
|
||||
|
||||
Get or update a user's account information. Updates are supported only through merge patch.
|
||||
Get or update a user's account information. Updates are supported
|
||||
only through merge patch.
|
||||
|
||||
**Example Requests**:
|
||||
|
||||
@@ -38,72 +39,74 @@ class AccountView(APIView):
|
||||
request for another account and has "is_staff" access, the response
|
||||
contains:
|
||||
|
||||
* username: The username associated with the account.
|
||||
* username: The username associated with the account.
|
||||
|
||||
* name: The full name of the user.
|
||||
* name: The full name of the user.
|
||||
|
||||
* email: email for the user (the new email address must be
|
||||
confirmed via a confirmation email, so GET will not reflect
|
||||
the change until the address has been confirmed).
|
||||
* email: email for the user (the new email address must be confirmed
|
||||
via a confirmation email, so GET will not reflect the change until
|
||||
the address has been confirmed).
|
||||
|
||||
* date_joined: The date the account was created, in the string
|
||||
format provided by datetime.
|
||||
For example, "2014-08-26T17:52:11Z".
|
||||
* date_joined: The date the account was created, in the string
|
||||
format provided by datetime. For example, "2014-08-26T17:52:11Z".
|
||||
|
||||
* gender: One of the following values:
|
||||
* "m"
|
||||
* "f"
|
||||
* "o"
|
||||
* null
|
||||
* gender: One of the following values:
|
||||
|
||||
* year_of_birth: The year the user was born, as an integer, or
|
||||
null.
|
||||
* "m"
|
||||
* "f"
|
||||
* "o"
|
||||
* null
|
||||
|
||||
* level_of_education: One of the following values:
|
||||
* "p": PhD or Doctorate
|
||||
* "m": Master's or professional degree
|
||||
* "b": Bachelor's degree
|
||||
* "a": Associate's degree
|
||||
* "hs": Secondary/high school
|
||||
* "jhs": Junior secondary/junior high/middle school
|
||||
* "el": Elementary/primary school
|
||||
* "none": "None"
|
||||
* "o": "Other"
|
||||
* null: The user did not enter a value.
|
||||
* year_of_birth: The year the user was born, as an integer, or null.
|
||||
|
||||
* language: The user's preferred language, or null.
|
||||
* level_of_education: One of the following values:
|
||||
|
||||
* country: null (not set), or a Country corresponding to one of
|
||||
the ISO 3166-1 countries.
|
||||
* "p": PhD or Doctorate
|
||||
* "m": Master's or professional degree
|
||||
* "b": Bachelor's degree
|
||||
* "a": Associate's degree
|
||||
* "hs": Secondary/high school
|
||||
* "jhs": Junior secondary/junior high/middle school
|
||||
* "el": Elementary/primary school
|
||||
* "none": None
|
||||
* "o": Other
|
||||
* null: The user did not enter a value.
|
||||
|
||||
* country: A ISO 3166 country code or null.
|
||||
* language: The user's preferred language, or null.
|
||||
|
||||
* mailing_address: The textual representation of the user's
|
||||
mailing address, or null.
|
||||
* country: null (not set), or a Country corresponding to one of the
|
||||
ISO 3166-1 countries.
|
||||
|
||||
* goals: The textual representation of the user's goals, or null.
|
||||
* country: A ISO 3166 country code or null.
|
||||
|
||||
* bio: null or textural representation of user biographical
|
||||
information ("about me").
|
||||
* mailing_address: The textual representation of the user's mailing
|
||||
address, or null.
|
||||
|
||||
* is_active: boolean representation of whether a user is active.
|
||||
* goals: The textual representation of the user's goals, or null.
|
||||
|
||||
* profile_image: JSON representation of a user's profile image
|
||||
information. The keys are:
|
||||
the user's profile image:
|
||||
* "has_image": boolean indicating whether the user has
|
||||
a profile image.
|
||||
* "image_url_*": absolute URL to various sizes of a user's
|
||||
profile image, where '*' matches a representation of
|
||||
the corresponding image size such as 'small', 'medium',
|
||||
'large', and 'full'. These are configurable via
|
||||
PROFILE_IMAGE_SIZES_MAP.
|
||||
* bio: null or textural representation of user biographical
|
||||
information ("about me").
|
||||
|
||||
* is_active: boolean representation of whether a user is active.
|
||||
|
||||
* profile_image: JSON representation of a user's profile image
|
||||
information. The keys are: the user's profile image:
|
||||
|
||||
* "has_image": boolean indicating whether the user has a profile
|
||||
image.
|
||||
|
||||
* "image_url_*": absolute URL to various sizes of a user's
|
||||
profile image, where '*' matches a representation of the
|
||||
corresponding image size such as 'small', 'medium', 'large',
|
||||
and 'full'. These are configurable via
|
||||
PROFILE_IMAGE_SIZES_MAP.
|
||||
|
||||
* requires_parental_consent: true if the user is a minor
|
||||
requiring parental consent.
|
||||
requiring parental consent.
|
||||
|
||||
* language_proficiencies: array of language preferences. Each
|
||||
preference is a JSON object with the following keys:
|
||||
|
||||
* language_proficiencies: array of language preferences.
|
||||
Each preference is a JSON object with the following keys:
|
||||
* "code": string ISO 639-1 language code e.g. "en".
|
||||
|
||||
For all text fields, clients rendering the values should take care
|
||||
@@ -114,8 +117,8 @@ class AccountView(APIView):
|
||||
If a user who does not have "is_staff" access requests account
|
||||
information for a different user, only a subset of these fields is
|
||||
returned. The fields returned depend on the configuration setting
|
||||
ACCOUNT_VISIBILITY_CONFIGURATION, and the visibility preference of
|
||||
the user for whom data is requested.
|
||||
ACCOUNT_VISIBILITY_CONFIGURATION, and the visibility preference of the
|
||||
user for whom data is requested.
|
||||
|
||||
Note that a user can view which account fields they have shared with
|
||||
other users by requesting their own username and providing the url
|
||||
@@ -126,10 +129,10 @@ class AccountView(APIView):
|
||||
|
||||
**Response Values for PATCH**
|
||||
|
||||
Users can only modify their own account information. If the requesting
|
||||
user does not have username "username", this method will return with
|
||||
a status of 403 for staff access but a 404 for ordinary users
|
||||
to avoid leaking the existence of the account.
|
||||
Users can only modify their own account information. If the
|
||||
requesting user does not have username "username", this method will
|
||||
return with a status of 403 for staff access but a 404 for ordinary
|
||||
users to avoid leaking the existence of the account.
|
||||
|
||||
If no user exists with the specified username, a 404 error is
|
||||
returned.
|
||||
|
||||
@@ -39,30 +39,48 @@ class PreferencesView(APIView):
|
||||
|
||||
**Response Value for GET**
|
||||
|
||||
A JSON dictionary will be returned with key/value pairs (all of type String).
|
||||
If the user makes the request for her own account, or makes a
|
||||
request for another account and has "is_staff" access, the response
|
||||
contains a JSON dictionary with a key/value pair (of type String)
|
||||
for each preference.
|
||||
|
||||
If a user without "is_staff" access has requested preferences for a different user,
|
||||
this method returns a 404.
|
||||
The list of preferences depends on your implementation. By default,
|
||||
preferences include:
|
||||
|
||||
If the specified username does not exist, this method returns a 404.
|
||||
* pref-lan: The user's preferred language, as set in account
|
||||
settings.
|
||||
|
||||
* account_privacy: The user's setting for sharing her personal
|
||||
profile. Possible values are ``all_users`` or ``private``.
|
||||
|
||||
If a user without "is_staff" access requests preferences for a
|
||||
different user, a 404 error is returned.
|
||||
|
||||
If the specified username does not exist, a 404 is returned.
|
||||
|
||||
**Response for PATCH**
|
||||
|
||||
Users can only modify their own preferences. If the requesting user does not have username
|
||||
"username", this method will return with a status of 403 for staff access but a 404 for ordinary
|
||||
Users can only modify their own preferences. If the requesting user
|
||||
does not have username "username", this method will return with a
|
||||
status of 403 for users with staff access but a 404 for ordinary
|
||||
users to avoid leaking the existence of the account.
|
||||
|
||||
This method will also return a 404 if no user exists with username "username".
|
||||
This method will also return a 404 if no user exists with username
|
||||
"username".
|
||||
|
||||
If "application/merge-patch+json" is not the specified content_type, this method returns a 415 status.
|
||||
If "application/merge-patch+json" is not the specified content_type,
|
||||
this method returns a 415 status.
|
||||
|
||||
If the update could not be completed due to validation errors, this method returns a 400 with all
|
||||
preference-specific error messages in the "field_errors" field of the returned JSON.
|
||||
If the update could not be completed due to validation errors, this
|
||||
method returns a 400 with all preference-specific error messages in
|
||||
the "field_errors" field of the returned JSON.
|
||||
|
||||
If the update could not be completed due to failure at the time of update, this method returns a 400 with
|
||||
specific errors in the returned JSON.
|
||||
If the update could not be completed due to failure at the time of
|
||||
update, this method returns a 400 with specific errors in the
|
||||
returned JSON.
|
||||
|
||||
If the update is successful, a 204 status is returned with no additional content.
|
||||
If the update is successful, a 204 status is returned with no
|
||||
additional content.
|
||||
|
||||
"""
|
||||
authentication_classes = (OAuth2AuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser)
|
||||
@@ -136,30 +154,35 @@ class PreferencesDetailView(APIView):
|
||||
|
||||
The preference value will be returned as a JSON string.
|
||||
|
||||
If a user without "is_staff" access has requested preferences for a different user,
|
||||
this method returns a 404.
|
||||
If a user without "is_staff" access has requested preferences for a
|
||||
different user, this method returns a 404.
|
||||
|
||||
If the specified username or preference does not exist, this method returns a 404.
|
||||
If the specified username or preference does not exist, this method
|
||||
returns a 404.
|
||||
|
||||
**Response Values for PUT**
|
||||
|
||||
A successful put returns a 204 and no content.
|
||||
|
||||
Users can only update their own preferences. If the requesting user does not have username
|
||||
"username", this method will return with a status of 403 for staff access but a 404 for ordinary
|
||||
Users can only modify their own preferences. If the requesting user
|
||||
does not have username "username", this method will return with a
|
||||
status of 403 for users with staff access but a 404 for ordinary
|
||||
users to avoid leaking the existence of the account.
|
||||
|
||||
If the specified preference does not exist, this method returns a 404.
|
||||
If the specified preference does not exist, this method returns a
|
||||
404.
|
||||
|
||||
**Response for DELETE**
|
||||
|
||||
A successful delete returns a 204 and no content.
|
||||
|
||||
Users can only delete their own preferences. If the requesting user does not have username
|
||||
"username", this method will return with a status of 403 for staff access but a 404 for ordinary
|
||||
Users can only delete their own preferences. If the requesting user
|
||||
does not have username "username", this method will return with a
|
||||
status of 403 for users with staff access but a 404 for ordinary
|
||||
users to avoid leaking the existence of the account.
|
||||
|
||||
If the specified preference does not exist, this method returns a 404.
|
||||
If the specified preference does not exist, this method returns a
|
||||
404.
|
||||
|
||||
"""
|
||||
authentication_classes = (OAuth2AuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser)
|
||||
|
||||
Reference in New Issue
Block a user