Add response schema validation (only when in TESTING mode) and add one schema. More will be added in a followup CL
This commit is contained in:
parent
4fd249589d
commit
6f1a4030b6
3 changed files with 78 additions and 4 deletions
|
@ -8,7 +8,8 @@ from flask.ext.principal import identity_changed, AnonymousIdentity
|
|||
from app import app, billing as stripe, authentication
|
||||
from endpoints.api import (ApiResource, nickname, resource, validate_json_request, request_error,
|
||||
log_action, internal_only, NotFound, require_user_admin, path_param,
|
||||
InvalidToken, require_scope, format_date, hide_if, show_if, license_error)
|
||||
InvalidToken, require_scope, format_date, hide_if, show_if, license_error,
|
||||
define_json_response)
|
||||
from endpoints.api.subscribe import subscribe
|
||||
from endpoints.common import common_login
|
||||
from data import model
|
||||
|
@ -50,13 +51,13 @@ def user_view(user):
|
|||
'verified': user.verified,
|
||||
'anonymous': False,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'gravatar': compute_hash(user.email),
|
||||
}
|
||||
|
||||
user_admin = UserAdminPermission(user.username)
|
||||
if user_admin.can():
|
||||
user_response.update({
|
||||
'email': user.email,
|
||||
'organizations': [org_view(o) for o in organizations],
|
||||
'logins': [login_view(login) for login in logins],
|
||||
'can_create_repo': True,
|
||||
|
@ -130,10 +131,51 @@ class User(ApiResource):
|
|||
},
|
||||
},
|
||||
},
|
||||
'UserView': {
|
||||
'id': 'UserView',
|
||||
'type': 'object',
|
||||
'description': 'Describes a user',
|
||||
'required': ['verified', 'anonymous', 'gravatar'],
|
||||
'properties': {
|
||||
'verified': {
|
||||
'type': 'boolean',
|
||||
'description': 'Whether the user\'s email address has been verified'
|
||||
},
|
||||
'anonymous': {
|
||||
'type': 'boolean',
|
||||
'description': 'true if this user data represents a guest user'
|
||||
},
|
||||
'email': {
|
||||
'type': 'string',
|
||||
'description': 'The user\'s email address',
|
||||
},
|
||||
'gravatar': {
|
||||
'type': 'string',
|
||||
'description': 'Gravatar hash representing the user\'s icon'
|
||||
},
|
||||
'organizations': {
|
||||
'type': 'array',
|
||||
'description': 'Information about the organizations in which the user is a member'
|
||||
},
|
||||
'logins': {
|
||||
'type': 'array',
|
||||
'description': 'The list of external login providers against which the user has authenticated'
|
||||
},
|
||||
'can_create_repo': {
|
||||
'type': 'boolean',
|
||||
'description': 'Whether the user has permission to create repositories'
|
||||
},
|
||||
'preferred_namespace': {
|
||||
'type': 'boolean',
|
||||
'description': 'If true, the user\'s namespace is the preferred namespace to display'
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@require_scope(scopes.READ_USER)
|
||||
@nickname('getLoggedInUser')
|
||||
@define_json_response('UserView')
|
||||
def get(self):
|
||||
""" Get user information for the authenticated user. """
|
||||
user = get_authenticated_user()
|
||||
|
@ -146,6 +188,7 @@ class User(ApiResource):
|
|||
@nickname('changeUserDetails')
|
||||
@internal_only
|
||||
@validate_json_request('UpdateUser')
|
||||
@define_json_response('UserView')
|
||||
def put(self):
|
||||
""" Update a users details such as password or email. """
|
||||
user = get_authenticated_user()
|
||||
|
|
Reference in a new issue