Coverage for girder/models/user : 94%

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. ###############################################################################
""" This model represents the users of the system. """
'login': 1, 'firstName': 1, 'lastName': 1 }, language='none')
return None
'created']
""" Validate the user every time it is stored in the database. """
if not doc.get('salt', ''): # pragma: no cover # Internal error, this should not happen raise Exception('Tried to save user document with no salt.')
raise ValidationException('First name must not be empty.', 'firstName')
raise ValidationException('Last name must not be empty.', 'lastName')
# Hard-code this constraint so we can always easily distinguish # an email address from a login
cur_config['users']['login_description'], 'login')
# Ensure unique logins raise ValidationException('That login is already registered.', 'login')
# Ensure unique emails raise ValidationException('That email is already registered.', 'email')
# If this is the first user being created, make it an admin
""" Delete a user, and all references to it in the database.
:param user: The user document to delete. :type user: dict """ # Remove creator references for this user. 'creatorId': user['_id'] } '$set': {'creatorId': None} }
# Remove references to this user from access-controlled resources. 'access.users.id': user['_id'] } '$pull': { 'access.users': {'id': user['_id']} } }
# Delete all authentication tokens owned by this user
# Delete all of the folders under this user 'parentId': user['_id'], 'parentCollection': 'user' }, limit=0)
# Finally, delete the user document itself
""" List all users. Since users are access-controlled, this will filter them by access policy.
:param text: Pass this to perform a full-text search for users. :param user: The user running the query. Only returns users that this user can see. :param limit: Result limit. :param offset: Result offset. :param sort: The sort structure to pass to pymongo. :returns: List of users. """ # TODO support full-text search
# Perform the find; we'll do access-based filtering of the result set # afterward.
level=AccessType.READ, limit=limit, offset=offset):
""" Change a user's password.
:param user: The user whose password to change. :param password: The new password. """
admin=False, public=True): """ Create a new user with the given information. The user will be created with the default "Public" and "Private" folders.
:param admin: Whether user is global administrator. :type admin: bool :param public: Whether user is publicly visible. :type public: bool :returns: The user document that was created. """ 'login': login, 'email': email, 'firstName': firstName, 'lastName': lastName, 'created': datetime.datetime.now(), 'emailVerified': False, 'admin': admin, 'size': 0, 'groupInvites': [] }
# Must have already saved the user prior to calling this since we are # granting the user access on himself.
# Create some default folders for the user and give the user admin # access to them user, 'Public', parentType='user', public=True, creator=user) user, 'Private', parentType='user', public=False, creator=user) publicFolder, user, AccessType.ADMIN, save=True) privateFolder, user, AccessType.ADMIN, save=True)
|