示例#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
示例#2
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.NotFound(_('User "%s" not found') % user_id)
     project = db.project_get(context.get_admin_context(), project_id)
     if not project:
         raise exception.NotFound(_('Project "%s" not found') % project_id)
     return user, project
示例#3
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.NotFound(_('User "%s" not found') % user_id)
     project = db.project_get(context.get_admin_context(), project_id)
     if not project:
         raise exception.NotFound(_('Project "%s" not found') % project_id)
     return user, project
示例#4
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.NotFound(
                _("Project can't be created because "
                  "manager %s doesn't exist") % 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 != None:
            for member_uid in member_uids:
                member = db.user_get(context.get_admin_context(), member_uid)
                if not member:
                    raise exception.NotFound(
                        _("Project can't be created "
                          "because user %s doesn't exist") % 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.Duplicate(
                _("Project can't be created because "
                  "project %s already exists") % 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)
示例#5
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.NotFound(_("Project can't be created because "
                                       "manager %s doesn't exist")
                                     % 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 != None:
            for member_uid in member_uids:
                member = db.user_get(context.get_admin_context(), member_uid)
                if not member:
                    raise exception.NotFound(_("Project can't be created "
                                               "because user %s doesn't exist")
                                             % 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.Duplicate(_("Project can't be created because "
                                        "project %s already exists") % 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)
示例#6
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)
示例#7
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)
示例#8
0
 def _validate_user_and_project(self, user_id, project_id):
     user = db.user_get(context.get_admin_context(), user_id)
     project = db.project_get(context.get_admin_context(), project_id)
     return user, project