improvements and fixes for automatic setting of role permissions
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3628 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
87f46f0d28
commit
68c5dbbc08
5 changed files with 31 additions and 11 deletions
|
@ -416,6 +416,9 @@ class BaseView(GenericView, I18NView):
|
||||||
def typeOptions(self):
|
def typeOptions(self):
|
||||||
return IOptions(adapted(self.typeProvider))
|
return IOptions(adapted(self.typeProvider))
|
||||||
|
|
||||||
|
def getPredicateOptions(self, relation):
|
||||||
|
return IOptions(adapted(relation.predicate), None) or DummyOptions()
|
||||||
|
|
||||||
# versioning
|
# versioning
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
|
|
|
@ -82,8 +82,8 @@ class BlogPost(Compound):
|
||||||
res = addAndConfigureObject(self.resourceManager, Resource, name,
|
res = addAndConfigureObject(self.resourceManager, Resource, name,
|
||||||
title=self.title, contentType=self.defaultTextContentType,
|
title=self.title, contentType=self.defaultTextContentType,
|
||||||
resourceType=tTextDocument)
|
resourceType=tTextDocument)
|
||||||
|
#notify(ObjectCreatedEvent(res))
|
||||||
self.add(res, position=0)
|
self.add(res, position=0)
|
||||||
notify(ObjectCreatedEvent(res))
|
|
||||||
res = adapted(res)
|
res = adapted(res)
|
||||||
res.data = value
|
res.data = value
|
||||||
notify(ObjectModifiedEvent(res.context))
|
notify(ObjectModifiedEvent(res.context))
|
||||||
|
|
|
@ -33,7 +33,7 @@ from cybertools.meta.config import GlobalOptions as BaseGlobalOptions
|
||||||
from cybertools.meta.interfaces import IOptions
|
from cybertools.meta.interfaces import IOptions
|
||||||
from cybertools.meta.namespace import Executor, ExecutionError
|
from cybertools.meta.namespace import Executor, ExecutionError
|
||||||
from cybertools.typology.interfaces import IType
|
from cybertools.typology.interfaces import IType
|
||||||
from loops.interfaces import ILoops, ILoopsObject, ITypeConcept
|
from loops.interfaces import ILoops, ILoopsObject, ITypeConcept, IPredicate
|
||||||
#from loops.query import IQueryConcept
|
#from loops.query import IQueryConcept
|
||||||
from loops.expert.concept import IQueryConcept
|
from loops.expert.concept import IQueryConcept
|
||||||
from loops import util
|
from loops import util
|
||||||
|
@ -101,6 +101,11 @@ class QueryOptions(LoopsOptions):
|
||||||
adapts(IQueryConcept)
|
adapts(IQueryConcept)
|
||||||
|
|
||||||
|
|
||||||
|
class PredicateOptions(LoopsOptions):
|
||||||
|
|
||||||
|
adapts(IPredicate)
|
||||||
|
|
||||||
|
|
||||||
class DummyOptions(Options):
|
class DummyOptions(Options):
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
<allow interface="cybertools.meta.interfaces.IOptions" />
|
<allow interface="cybertools.meta.interfaces.IOptions" />
|
||||||
</zope:class>
|
</zope:class>
|
||||||
|
|
||||||
|
<zope:adapter factory="loops.config.base.PredicateOptions" trusted="True" />
|
||||||
|
<zope:class class="loops.config.base.PredicateOptions">
|
||||||
|
<allow interface="cybertools.meta.interfaces.IOptions" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
<!-- backward compatibility -->
|
<!-- backward compatibility -->
|
||||||
<zope:adapter factory="loops.config.base.QueryOptions" trusted="True"
|
<zope:adapter factory="loops.config.base.QueryOptions" trusted="True"
|
||||||
for="loops.query.IQueryConcept" />
|
for="loops.query.IQueryConcept" />
|
||||||
|
|
|
@ -70,6 +70,8 @@ class BaseSecuritySetter(object):
|
||||||
|
|
||||||
class LoopsObjectSecuritySetter(BaseSecuritySetter):
|
class LoopsObjectSecuritySetter(BaseSecuritySetter):
|
||||||
|
|
||||||
|
parents = []
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def baseObject(self):
|
def baseObject(self):
|
||||||
obj = self.context
|
obj = self.context
|
||||||
|
@ -77,13 +79,19 @@ class LoopsObjectSecuritySetter(BaseSecuritySetter):
|
||||||
obj = obj.context
|
obj = obj.context
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def rolePermissionManager(self):
|
||||||
|
return IRolePermissionManager(self.baseObject)
|
||||||
|
|
||||||
|
def setDefaultRolePermissions(self):
|
||||||
|
rpm = self.rolePermissionManager
|
||||||
|
for p, r, s in rpm.getRolesAndPermissions():
|
||||||
|
setRolePermission(rpm, p, r, Unset)
|
||||||
|
|
||||||
def acquireRolePermissions(self):
|
def acquireRolePermissions(self):
|
||||||
obj = self.baseObject
|
|
||||||
if isinstance(obj, AdapterBase):
|
|
||||||
obj = obj.context
|
|
||||||
settings = {}
|
settings = {}
|
||||||
for p in self.parents:
|
for p in self.parents:
|
||||||
if p == obj:
|
if p == self.baseObject:
|
||||||
continue
|
continue
|
||||||
secProvider = p
|
secProvider = p
|
||||||
wi = p.workspaceInformation
|
wi = p.workspaceInformation
|
||||||
|
@ -97,12 +105,9 @@ class LoopsObjectSecuritySetter(BaseSecuritySetter):
|
||||||
current = settings.get((p, r))
|
current = settings.get((p, r))
|
||||||
if current is None or overrides(s, current):
|
if current is None or overrides(s, current):
|
||||||
settings[(p, r)] = s
|
settings[(p, r)] = s
|
||||||
rpm = IRolePermissionManager(obj)
|
self.setDefaultRolePermissions()
|
||||||
for p, r, s in rpm.getRolesAndPermissions():
|
|
||||||
# clear previous settings
|
|
||||||
setRolePermission(rpm, p, r, Unset)
|
|
||||||
for (p, r), s in settings.items():
|
for (p, r), s in settings.items():
|
||||||
setRolePermission(rpm, p, r, s)
|
setRolePermission(self.rolePermissionManager, p, r, s)
|
||||||
|
|
||||||
|
|
||||||
class ConceptSecuritySetter(LoopsObjectSecuritySetter):
|
class ConceptSecuritySetter(LoopsObjectSecuritySetter):
|
||||||
|
@ -127,6 +132,8 @@ class ConceptSecuritySetter(LoopsObjectSecuritySetter):
|
||||||
updated.add(obj)
|
updated.add(obj)
|
||||||
for r in obj.getChildRelations():
|
for r in obj.getChildRelations():
|
||||||
self.setAcquiredRolePermissions(r, updated=updated)
|
self.setAcquiredRolePermissions(r, updated=updated)
|
||||||
|
for r in obj.getResourceRelations():
|
||||||
|
self.setAcquiredRolePermissions(r, updated=updated)
|
||||||
|
|
||||||
def propagatePrincipalRoles(self, updated=None):
|
def propagatePrincipalRoles(self, updated=None):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue