Coverage for girder/api/v1/user : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*-
############################################################################### # Copyright 2013 Kitware Inc. # # Licensed under the Apache License, Version 2.0 ( the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ###############################################################################
"""API Endpoint for users in the system."""
SettingKey.COOKIE_LIFETIME, default=180))
""" Helper method to send the authentication cookie """
'userId': str(user['_id']), 'token': str(token['_id']) })
""" Helper method to kill the authentication cookie """
""" Get a list of users. You can pass a "text" parameter to filter the users by a full text search string.
:param [text]: Full text search. :param limit: The result set size limit, default=50. :param offset: Offset into the results, default=0. :param sort: The field to sort by, default=name. :param sortdir: 1 for ascending, -1 for descending, default=1. """
for user in self.model('user').search( text=params.get('text'), user=currentUser, offset=offset, limit=limit, sort=sort)] Description('List or search for users.') .responseClass('User') .param('text', "Pass this to perform a full text search for items.", required=False) .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the user list by (default=lastName)", required=False) .param('sortdir', "1 for ascending, -1 for descending (default=1)", required=False, dataType='int'))
def getUser(self, userToGet, params): Description('Get a user by ID.') .responseClass('User') .param('id', 'The ID of the user.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('You do not have permission to see this user.', 403))
Description('Retrieve the currently logged-in user information.') .responseClass('User'))
""" Login endpoint. Sends an auth cookie in the response on success. The caller is expected to use HTTP Basic Authentication when calling this endpoint. """
# Only create and send new cookie if user isn't already sending # a valid one.
except: raise RestException('Invalid HTTP Authorization header')
'user': self.model('user').filter(user, user), 'authToken': { 'token': token['_id'], 'expires': token['expires'], 'userId': user['_id'] }, 'message': 'Login succeeded.' } Description('Log in to the system.') .notes('Pass your username and password using HTTP Basic Auth. Sends' ' a cookie that should be passed back in future requests.') .errorResponse('Missing Authorization header.', 401) .errorResponse('Invalid login or password.', 403))
Description('Log out of the system.') .responseClass('Token') .notes('Attempts to delete your authentication cookie.'))
('firstName', 'lastName', 'login', 'password', 'email'), params)
login=params['login'], password=params['password'], email=params['email'], firstName=params['firstName'], lastName=params['lastName'])
Description('Create a new user.') .responseClass('User') .param('login', "The user's requested login.") .param('email', "The user's email address.") .param('firstName', "The user's first name.") .param('lastName', "The user's last name.") .param('password', "The user's requested password") .errorResponse('A parameter was invalid, or the specified login or' ' email already exists in the system.'))
def deleteUser(self, userToDelete, params): Description('Delete a user by ID.') .param('id', 'The ID of the user.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('You do not have permission to delete this user.', 403))
def updateUser(self, user, params):
# Only admins can change admin state else: if newAdminState != user['admin']: raise AccessException('Only admins may change admin state.')
Description("Update a user's information.") .param('id', 'The ID of the user.', paramType='path') .param('firstName', 'First name of the user.') .param('lastName', 'Last name of the user.') .param('email', 'The email of the user.') .param('admin', 'Is the user a site admin (admin access required)', required=False, dataType='boolean') .errorResponse() .errorResponse('You do not have write access for this user.', 403) .errorResponse('Must be an admin to create an admin.', 403))
Description('Change your password.') .param('old', 'Your current password.') .param('new', 'Your new password.') .errorResponse('You are not logged in.', 401) .errorResponse('Your old password is incorrect.', 403) .errorResponse('Your new password is invalid.'))
'password': randomPass }) text=html) Description('Reset a forgotten password via email.') .param('email', 'Your email address.') .errorResponse('That email does not exist in the system.')) |