[gen] Bugfixs.

This commit is contained in:
Gaetan Delannay 2013-09-22 22:08:48 +02:00
parent 1f901e5545
commit bd80d63eda
4 changed files with 16 additions and 20 deletions

View file

@ -181,9 +181,11 @@ class Group(ModelClass):
multiplicity=(1,1), **m) multiplicity=(1,1), **m)
roles = gen.String(validator=gen.Selection('getGrantableRoles'), roles = gen.String(validator=gen.Selection('getGrantableRoles'),
multiplicity=(0,None), **m) multiplicity=(0,None), **m)
def getSelectableUsers(self): pass
users = gen.Ref(User, multiplicity=(0,None), add=False, link=True, users = gen.Ref(User, multiplicity=(0,None), add=False, link=True,
back=gen.Ref(attribute='groups', show=User.showRoles, back=gen.Ref(attribute='groups', show=User.showRoles,
multiplicity=(0,None)), multiplicity=(0,None)),
select=getSelectableUsers, height=15,
showHeaders=True, shownInfo=('title', 'login')) showHeaders=True, shownInfo=('title', 'login'))
# The Translation class -------------------------------------------------------- # The Translation class --------------------------------------------------------

View file

@ -44,7 +44,8 @@ def createObject(folder, id, className, appName, wf=True, noSecurity=False):
from DateTime import DateTime from DateTime import DateTime
obj.created = DateTime() obj.created = DateTime()
obj.modified = obj.created 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() if wf: obj.notifyWorkflowCreated()
return obj return obj

View file

@ -26,24 +26,18 @@ class GroupWrapper(AbstractWrapper):
res.append( (role, self.translate('role_%s' % role)) ) res.append( (role, self.translate('role_%s' % role)) )
return res 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): def validate(self, new, errors):
'''Inter-field validation.''' '''Inter-field validation.'''
return self._callCustom('validate', new, errors) 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): def onEdit(self, created):
# If the group was created by anon, anon can't stay its Owner. # If the group was created by anon|system, anon|system can't stay Owner.
if 'anon' in self.o.__ac_local_roles__: for login in ('anon', 'system'):
del self.o.__ac_local_roles__['anon'] if login in self.o.__ac_local_roles__:
if 'system' in self.o.__ac_local_roles__: del self.o.__ac_local_roles__[login]
del self.o.__ac_local_roles__['system']
return self._callCustom('onEdit', created) return self._callCustom('onEdit', created)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -204,11 +204,10 @@ class UserWrapper(AbstractWrapper):
# "self" must be owned by its Zope user. # "self" must be owned by its Zope user.
if 'Owner' not in self.o.get_local_roles_for_userid(login): if 'Owner' not in self.o.get_local_roles_for_userid(login):
self.o.manage_addLocalRoles(login, ('Owner',)) self.o.manage_addLocalRoles(login, ('Owner',))
# If the user was created by anon or system, remove this local role. # If the user was created by anon|system, anon|system can't stay Owner.
if 'anon' in self.o.__ac_local_roles__: for login in ('anon', 'system'):
del self.o.__ac_local_roles__['anon'] if login in self.o.__ac_local_roles__:
if 'system' in self.o.__ac_local_roles__: del self.o.__ac_local_roles__[login]
del self.o.__ac_local_roles__['system']
return self._callCustom('onEdit', created) return self._callCustom('onEdit', created)
def mayEdit(self): def mayEdit(self):