fix: integration doctest/ MemberRegistrationManager groups param
This commit is contained in:
parent
3a6b61f71c
commit
c74af2b960
2 changed files with 32 additions and 9 deletions
|
@ -231,7 +231,7 @@ Extracting Document Properties from MS Office Files
|
|||
>>> path = os.path.join(dataDir, 'office')
|
||||
>>> fn = os.path.join(path, 'example.docx')
|
||||
>>> os.path.getsize(fn)
|
||||
20337L
|
||||
20337...
|
||||
|
||||
>>> officeFile = addAndConfigureObject(resources, Resource, 'test.docx',
|
||||
... title=u'Example Word File', resourceType=tOfficeFile,
|
||||
|
|
|
@ -65,20 +65,36 @@ class MemberRegistrationManager(object):
|
|||
self.context = context
|
||||
|
||||
def register(self, userId, password, lastName, firstName=u'',
|
||||
groups=[], useExisting=False, **kw):
|
||||
groups=[], useExisting=False, pfName=None, **kw):
|
||||
concepts = self.context.getConceptManager()
|
||||
personType = adapted(concepts[self.person_typeName])
|
||||
options = IOptions(personType)
|
||||
pfName = options(self.principalfolder_key,
|
||||
(self.default_principalfolder,))[0]
|
||||
# step 1: create an internal principal in the loops principal folder:
|
||||
if pfName is None:
|
||||
pfName = options(self.principalfolder_key,
|
||||
(self.default_principalfolder,))[0]
|
||||
self.createPrincipal(pfName, userId, password, lastName, firstName)
|
||||
if len(groups)==0:
|
||||
groups = options(self.groups_key, ())
|
||||
self.setGroupsForPrincipal(pfName, userId, groups=groups)
|
||||
self.createPersonForPrincipal(pfName, userId, lastName, firstName,
|
||||
useExisting, **kw)
|
||||
|
||||
def createPrincipal(self, pfName, userId, password, lastName,
|
||||
firstName=u'', groups=[], useExisting=False,
|
||||
overwrite=False, **kw):
|
||||
pFolder = getPrincipalFolder(self.context, pfName)
|
||||
if IPersonBasedAuthenticator.providedBy(pFolder):
|
||||
pFolder.setPassword(userId, password)
|
||||
else:
|
||||
title = firstName and ' '.join((firstName, lastName)) or lastName
|
||||
principal = InternalPrincipal(userId, password, title)
|
||||
if useExisting:
|
||||
if overwrite:
|
||||
if userId in pFolder:
|
||||
principal = pFolder[userId]
|
||||
principal.password = password
|
||||
else:
|
||||
pFolder[userId] = principal
|
||||
elif useExisting:
|
||||
if userId not in pFolder:
|
||||
pFolder[userId] = principal
|
||||
else:
|
||||
|
@ -86,8 +102,9 @@ class MemberRegistrationManager(object):
|
|||
return dict(fieldName='loginName', error='duplicate_loginname')
|
||||
else:
|
||||
pFolder[userId] = principal
|
||||
# step 2 (optional): assign to group(s)
|
||||
groups = options(self.groups_key, ())
|
||||
|
||||
def setGroupsForPrincipal(self, pfName, userId, groups=[]):
|
||||
pFolder = getPrincipalFolder(self.context, pfName)
|
||||
for groupInfo in groups:
|
||||
names = groupInfo.split(':')
|
||||
if len(names) == 1:
|
||||
|
@ -101,7 +118,13 @@ class MemberRegistrationManager(object):
|
|||
members = list(group.principals)
|
||||
members.append(pFolder.prefix + userId)
|
||||
group.principals = members
|
||||
# step 3: create a corresponding person concept:
|
||||
|
||||
def createPersonForPrincipal(self, pfName, userId, lastName, firstName=u'',
|
||||
useExisting=False, **kw):
|
||||
concepts = self.context.getConceptManager()
|
||||
personType = adapted(concepts[self.person_typeName])
|
||||
pFolder = getPrincipalFolder(self.context, pfName)
|
||||
title = firstName and ' '.join((firstName, lastName)) or lastName
|
||||
name = baseId = 'person.' + userId
|
||||
if useExisting and name in concepts:
|
||||
person = concepts[name]
|
||||
|
|
Loading…
Add table
Reference in a new issue