Example #1
0
 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
Example #2
0
    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)
Example #3
0
 def get_project(self, pid):
     """Retrieve project by id"""
     project = db.project_get(context.get_admin_context(), pid)
     return self._db_project_to_auth_projectuser(project)