added modify project command to allow project manager and description to be updated
This commit is contained in:
@@ -33,6 +33,7 @@ SCOPE_ONELEVEL = 1 # not implemented
|
|||||||
SCOPE_SUBTREE = 2
|
SCOPE_SUBTREE = 2
|
||||||
MOD_ADD = 0
|
MOD_ADD = 0
|
||||||
MOD_DELETE = 1
|
MOD_DELETE = 1
|
||||||
|
MOD_REPLACE = 2
|
||||||
|
|
||||||
|
|
||||||
class NO_SUCH_OBJECT(Exception): # pylint: disable-msg=C0103
|
class NO_SUCH_OBJECT(Exception): # pylint: disable-msg=C0103
|
||||||
@@ -175,7 +176,7 @@ class FakeLDAP(object):
|
|||||||
Args:
|
Args:
|
||||||
dn -- a dn
|
dn -- a dn
|
||||||
attrs -- a list of tuples in the following form:
|
attrs -- a list of tuples in the following form:
|
||||||
([MOD_ADD | MOD_DELETE], attribute, value)
|
([MOD_ADD | MOD_DELETE | MOD_REPACE], attribute, value)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
redis = datastore.Redis.instance()
|
redis = datastore.Redis.instance()
|
||||||
@@ -185,6 +186,8 @@ class FakeLDAP(object):
|
|||||||
values = _from_json(redis.hget(key, k))
|
values = _from_json(redis.hget(key, k))
|
||||||
if cmd == MOD_ADD:
|
if cmd == MOD_ADD:
|
||||||
values.append(v)
|
values.append(v)
|
||||||
|
elif cmd == MOD_REPLACE:
|
||||||
|
values = [v]
|
||||||
else:
|
else:
|
||||||
values.remove(v)
|
values.remove(v)
|
||||||
values = redis.hset(key, k, _to_json(values))
|
values = redis.hset(key, k, _to_json(values))
|
||||||
|
|||||||
@@ -202,6 +202,24 @@ class LdapDriver(object):
|
|||||||
self.conn.add_s('cn=%s,%s' % (name, FLAGS.ldap_project_subtree), attr)
|
self.conn.add_s('cn=%s,%s' % (name, FLAGS.ldap_project_subtree), attr)
|
||||||
return self.__to_project(dict(attr))
|
return self.__to_project(dict(attr))
|
||||||
|
|
||||||
|
def modify_project(self, project_id, manager_uid=None, description=None):
|
||||||
|
"""Modify an existing project"""
|
||||||
|
if not manager_uid and not description:
|
||||||
|
return
|
||||||
|
attr = []
|
||||||
|
if manager_uid:
|
||||||
|
if not self.__user_exists(manager_uid):
|
||||||
|
raise exception.NotFound("Project can't be modified because "
|
||||||
|
"manager %s doesn't exist" %
|
||||||
|
manager_uid)
|
||||||
|
manager_dn = self.__uid_to_dn(manager_uid)
|
||||||
|
attr.append((self.ldap.MOD_REPLACE, 'projectManager', manager_dn))
|
||||||
|
if description:
|
||||||
|
attr.append((self.ldap.MOD_REPLACE, 'description', description))
|
||||||
|
self.conn.modify_s('cn=%s,%s' % (project_id,
|
||||||
|
FLAGS.ldap_project_subtree),
|
||||||
|
attr)
|
||||||
|
|
||||||
def add_to_project(self, uid, project_id):
|
def add_to_project(self, uid, project_id):
|
||||||
"""Add user to project"""
|
"""Add user to project"""
|
||||||
dn = 'cn=%s,%s' % (project_id, FLAGS.ldap_project_subtree)
|
dn = 'cn=%s,%s' % (project_id, FLAGS.ldap_project_subtree)
|
||||||
|
|||||||
@@ -525,6 +525,26 @@ class AuthManager(object):
|
|||||||
if project_dict:
|
if project_dict:
|
||||||
return Project(**project_dict)
|
return Project(**project_dict)
|
||||||
|
|
||||||
|
def modify_project(self, project, manager_user=None, description=None):
|
||||||
|
"""Modify a project
|
||||||
|
|
||||||
|
@type name: Project or project_id
|
||||||
|
@param project: The project to modify.
|
||||||
|
|
||||||
|
@type manager_user: User or uid
|
||||||
|
@param manager_user: This user will be the new project manager.
|
||||||
|
|
||||||
|
@type description: str
|
||||||
|
@param project: This will be the new description of the project.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if manager_user:
|
||||||
|
manager_user = User.safe_id(manager_user)
|
||||||
|
with self.driver() as drv:
|
||||||
|
drv.modify_project(Project.safe_id(project),
|
||||||
|
manager_user,
|
||||||
|
description)
|
||||||
|
|
||||||
def add_to_project(self, user, project):
|
def add_to_project(self, user, project):
|
||||||
"""Add user to project"""
|
"""Add user to project"""
|
||||||
with self.driver() as drv:
|
with self.driver() as drv:
|
||||||
|
|||||||
@@ -206,6 +206,12 @@ class AuthTestCase(test.BaseTestCase):
|
|||||||
self.assert_(len(self.manager.get_projects()) > 1)
|
self.assert_(len(self.manager.get_projects()) > 1)
|
||||||
self.assertEqual(len(self.manager.get_projects('test2')), 1)
|
self.assertEqual(len(self.manager.get_projects('test2')), 1)
|
||||||
|
|
||||||
|
def test_220_can_modify_project(self):
|
||||||
|
self.manager.modify_project('testproj', 'test2', 'new description')
|
||||||
|
project = self.manager.get_project('testproj')
|
||||||
|
self.assertEqual(project.project_manager_id, 'test2')
|
||||||
|
self.assertEqual(project.description, 'new description')
|
||||||
|
|
||||||
def test_299_can_delete_project(self):
|
def test_299_can_delete_project(self):
|
||||||
self.manager.delete_project('testproj')
|
self.manager.delete_project('testproj')
|
||||||
self.assertFalse(filter(lambda p: p.name == 'testproj', self.manager.get_projects()))
|
self.assertFalse(filter(lambda p: p.name == 'testproj', self.manager.get_projects()))
|
||||||
|
|||||||
Reference in New Issue
Block a user