From bd80d63eda9af48f41aa3c1ac2471bcba2f0b23c Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sun, 22 Sep 2013 22:08:48 +0200 Subject: [PATCH] [gen] Bugfixs. --- gen/model.py | 2 ++ gen/utils.py | 3 ++- gen/wrappers/GroupWrapper.py | 22 ++++++++-------------- gen/wrappers/UserWrapper.py | 9 ++++----- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/gen/model.py b/gen/model.py index e344f35..5d0adae 100644 --- a/gen/model.py +++ b/gen/model.py @@ -181,9 +181,11 @@ class Group(ModelClass): multiplicity=(1,1), **m) roles = gen.String(validator=gen.Selection('getGrantableRoles'), multiplicity=(0,None), **m) + def getSelectableUsers(self): pass users = gen.Ref(User, multiplicity=(0,None), add=False, link=True, back=gen.Ref(attribute='groups', show=User.showRoles, multiplicity=(0,None)), + select=getSelectableUsers, height=15, showHeaders=True, shownInfo=('title', 'login')) # The Translation class -------------------------------------------------------- diff --git a/gen/utils.py b/gen/utils.py index e1671d3..4789ecf 100644 --- a/gen/utils.py +++ b/gen/utils.py @@ -44,7 +44,8 @@ def createObject(folder, id, className, appName, wf=True, noSecurity=False): from DateTime import DateTime obj.created = DateTime() obj.modified = obj.created - obj.__ac_local_roles__ = { userId: ['Owner'] } + from persistent.mapping import PersistentMapping + obj.__ac_local_roles__ = PersistentMapping({ userId: ['Owner'] }) if wf: obj.notifyWorkflowCreated() return obj diff --git a/gen/wrappers/GroupWrapper.py b/gen/wrappers/GroupWrapper.py index 88630d4..1b30303 100644 --- a/gen/wrappers/GroupWrapper.py +++ b/gen/wrappers/GroupWrapper.py @@ -26,24 +26,18 @@ class GroupWrapper(AbstractWrapper): res.append( (role, self.translate('role_%s' % role)) ) return res + def getSelectableUsers(self): + '''Returns all the users, excepted anon and system.''' + return [u for u in self.tool.users if u.login not in ('anon', 'system')] + def validate(self, new, errors): '''Inter-field validation.''' return self._callCustom('validate', new, errors) - def addUser(self, user): - '''Adds a p_user to this group.''' - # Update the Ref field. - self.link('users', user) - - def removeUser(self, user): - '''Removes a p_user from this group.''' - self.unlink('users', user) - def onEdit(self, created): - # If the group was created by anon, anon can't stay its Owner. - if 'anon' in self.o.__ac_local_roles__: - del self.o.__ac_local_roles__['anon'] - if 'system' in self.o.__ac_local_roles__: - del self.o.__ac_local_roles__['system'] + # If the group was created by anon|system, anon|system can't stay Owner. + for login in ('anon', 'system'): + if login in self.o.__ac_local_roles__: + del self.o.__ac_local_roles__[login] return self._callCustom('onEdit', created) # ------------------------------------------------------------------------------ diff --git a/gen/wrappers/UserWrapper.py b/gen/wrappers/UserWrapper.py index 1e7c22a..83e9c23 100644 --- a/gen/wrappers/UserWrapper.py +++ b/gen/wrappers/UserWrapper.py @@ -204,11 +204,10 @@ class UserWrapper(AbstractWrapper): # "self" must be owned by its Zope user. if 'Owner' not in self.o.get_local_roles_for_userid(login): self.o.manage_addLocalRoles(login, ('Owner',)) - # If the user was created by anon or system, remove this local role. - if 'anon' in self.o.__ac_local_roles__: - del self.o.__ac_local_roles__['anon'] - if 'system' in self.o.__ac_local_roles__: - del self.o.__ac_local_roles__['system'] + # If the user was created by anon|system, anon|system can't stay Owner. + for login in ('anon', 'system'): + if login in self.o.__ac_local_roles__: + del self.o.__ac_local_roles__[login] return self._callCustom('onEdit', created) def mayEdit(self):