Example #1
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 #2
0
 def add_to_project(self, uid, project_id):
     """Add user to project"""
     user, project = self._validate_user_and_project(uid, project_id)
     db.project_add_member(context.get_admin_context(),
                           project['id'],
                           user['id'])