def _validate_user_and_project(self, user_id, project_id): user = db.user_get(context.get_admin_context(), user_id) if not user: raise exception.UserNotFound(user_id=user_id) project = db.project_get(context.get_admin_context(), project_id) if not project: raise exception.ProjectNotFound(project_id=project_id) return user, project
def create_project(self, name, manager_uid, description=None, member_uids=None): """Create a project""" manager = db.user_get(context.get_admin_context(), manager_uid) if not manager: raise exception.UserNotFound(user_id=manager_uid) # description is a required attribute if description is None: description = name # First, we ensure that all the given users exist before we go # on to create the project. This way we won't have to destroy # the project again because a user turns out to be invalid. members = set([manager]) if member_uids is not None: for member_uid in member_uids: member = db.user_get(context.get_admin_context(), member_uid) if not member: raise exception.UserNotFound(user_id=member_uid) members.add(member) values = {'id': name, 'name': name, 'project_manager': manager['id'], 'description': description} try: project = db.project_create(context.get_admin_context(), values) except exception.DBError: raise exception.ProjectExists(project=name) for member in members: db.project_add_member(context.get_admin_context(), project['id'], member['id']) # This looks silly, but ensures that the members element has been # correctly populated project_ref = db.project_get(context.get_admin_context(), project['id']) return self._db_project_to_auth_projectuser(project_ref)
def modify_project(self, project_id, manager_uid=None, description=None): """Modify an existing project""" if not manager_uid and not description: return values = {} if manager_uid: manager = db.user_get(context.get_admin_context(), manager_uid) if not manager: raise exception.UserNotFound(user_id=manager_uid) values['project_manager'] = manager['id'] if description: values['description'] = description db.project_update(context.get_admin_context(), project_id, values) if not self.is_in_project(manager_uid, project_id): self.add_to_project(manager_uid, project_id)
def get_user(self, uid): """Retrieve user by id""" user = db.user_get(context.get_admin_context(), uid) return self._db_user_to_auth_user(user)
def delete_user(self, id): """Delete a user""" user = db.user_get(context.get_admin_context(), id) db.user_delete(context.get_admin_context(), user['id'])