Beispiel #1
0
 def create_project(self, name, manager_uid,
                    description=None, member_uids=None):
     """Create a project"""
     if self.__project_exists(name):
         raise exception.ProjectExists(project=name)
     if not self.__user_exists(manager_uid):
         raise exception.LDAPUserNotFound(user_id=manager_uid)
     manager_dn = self.__uid_to_dn(manager_uid)
     # description is a required attribute
     if description is None:
         description = name
     members = []
     if member_uids is not None:
         for member_uid in member_uids:
             if not self.__user_exists(member_uid):
                 raise exception.LDAPUserNotFound(user_id=member_uid)
             members.append(self.__uid_to_dn(member_uid))
     # always add the manager as a member because members is required
     if not manager_dn in members:
         members.append(manager_dn)
     attr = [
         ('objectclass', [LdapDriver.project_objectclass]),
         ('cn', [name]),
         ('description', [description]),
         (LdapDriver.project_attribute, [manager_dn]),
         ('member', members)]
     dn = self.__project_to_dn(name, search=False)
     self.conn.add_s(dn, attr)
     return self.__to_project(dict(attr))
Beispiel #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.Duplicate:
            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)