[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - metaConfigure.py:1.1.2.21 protectClass.py:1.1.2.6 publicClass.py:1.1.2.5
Jim Fulton
jim@zope.com
Thu, 3 Jan 2002 16:45:13 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv18644/App/Security
Modified Files:
Tag: Zope-3x-branch
metaConfigure.py protectClass.py publicClass.py
Log Message:
Changed permission, role, and principal attributes in directives
to permission_id, role_id, and principal_id because they name ids,
not instances.
=== Zope3/lib/python/Zope/App/Security/metaConfigure.py 1.1.2.20 => 1.1.2.21 ===
return [('defaultPolicy', setSecurityPolicy, (policy,))]
-def definePermission(permission, title, description=''):
- action = (('definePermission', permission),
- perm_reg.definePermission, (permission, title, description))
+def definePermission(permission_id, title, description=''):
+ action = (('definePermission', permission_id),
+ perm_reg.definePermission, (permission_id, title, description))
return (action,)
-def defineRole(role, title, description=''):
- action = (('defineRole', role),
- role_reg.defineRole, (role, title, description))
+def defineRole(role_id, title, description=''):
+ action = (('defineRole', role_id),
+ role_reg.defineRole, (role_id, title, description))
return (action,)
-def principal(principal, title, login, password, description=''):
+def principal(principal_id, title, login, password, description=''):
return [(
- ('principal', principal),
+ ('principal', principal_id),
principalRegistry.definePrincipal,
- (principal, title, description, login, password)
+ (principal_id, title, description, login, password)
)]
-def defaultPrincipal(principal, title, description=''):
+def defaultPrincipal(principal_id, title, description=''):
return [(
'defaultPrincipal',
principalRegistry.defineDefaultPrincipal,
- (principal, title, description)
+ (principal_id, title, description)
)]
-def grantPermissionToRole(permission, role):
+def grantPermissionToRole(permission_id, role_id):
return [(
- ('grantPermissionToRole', permission, role),
+ ('grantPermissionToRole', permission_id, role_id),
role_perm_mgr.grantPermissionToRole,
- (permission, role)
+ (permission_id, role_id)
)]
-def grantPermissionToPrincipal(permission, principal):
+def grantPermissionToPrincipal(permission_id, principal_id):
return [(
- ('grantPermissionToPrincipal', permission, principal),
+ ('grantPermissionToPrincipal', permission_id, principal_id),
principal_perm_mgr.grantPermissionToPrincipal,
- (permission, principal)
+ (permission_id, principal_id)
)]
-def assignRoleToPrincipal(role, principal):
+def assignRoleToPrincipal(role_id, principal_id):
return [(
- ('assignRoleToPrincipal', role, principal),
+ ('assignRoleToPrincipal', role_id, principal_id),
principal_role_mgr.assignRoleToPrincipal,
- (role, principal)
+ (role_id, principal_id)
)]
=== Zope3/lib/python/Zope/App/Security/protectClass.py 1.1.2.5 => 1.1.2.6 ===
__class_implements__ = INonEmptyDirective
- def __init__(self, name, permission=None, interface=None,
+ def __init__(self, name, permission_id=None, interface=None,
method=None, methods=None):
self.__class = resolve(name)
self.__name = name
- self.__permission = permission
- self.__r = self.protect(permission, interface, method, methods)
+ self.__permission_id = permission_id
+ self.__r = self.protect(permission_id, interface, method, methods)
# So subsequent simple-declaration-style self() calls process instances
self.__empty = 1
# ._getPermission() is handy for subclassing with different permission
# policy, eg publicClass.
- def _getPermission(self, permission=None):
+ def _getPermission(self, permission_id=None):
"""Return the permission to use.
Consider optional permission argument and permission specified on
class init."""
- if permission is None:
- permission = self.__permission
- if permission is None:
+ if permission_id is None:
+ permission_id = self.__permission_id
+ if permission_id is None:
raise ProtectionDeclarationException("No permission specified")
else:
- return permission
+ return permission_id
- def protect(self, permission=None, interface=None,
+ def protect(self, permission_id=None, interface=None,
method=None, methods=None):
"Protect a specific aspect"
@@ -69,73 +69,73 @@
if not (interface or method or methods):
return []
- permission = self._getPermission(permission)
+ permission_id = self._getPermission(permission_id)
r = []
if interface:
- self.__protectByInterface(interface, permission, r)
+ self.__protectByInterface(interface, permission_id, r)
if method:
- self.__protectMethod(method, permission, r)
+ self.__protectMethod(method, permission_id, r)
if methods:
- self.__protectMethods(methods, permission, r)
+ self.__protectMethods(methods, permission_id, r)
return r
- def instances(self, permission=None):
+ def instances(self, permission_id=None):
"Protect instances of the class, as opposed to methods"
self.__empty = 0
- permission = self._getPermission(permission)
+ permission_id = self._getPermission(permission_id)
r=[]
- self.__instances(permission, r)
+ self.__instances(permission_id, r)
return r
- def __inst(self, permission):
- self.__class.__permission__ = permission
+ def __inst(self, permission_id):
+ self.__class.__permission__ = permission_id
- def __instances(self, permission, r):
+ def __instances(self, permission_id, r):
"Protect instances of the class, as opposed to methods"
- permission = self._getPermission(permission)
+ permission_id = self._getPermission(permission_id)
r.append((
('protectInstances', self.__class),
- self.__inst, (permission,)))
+ self.__inst, (permission_id,)))
- def __protectMethod(self, method, permission, r):
+ def __protectMethod(self, method, permission_id, r):
"Set a permission on a particular method."
r.append((
('protectMethod', self.__class, method),
- self.__method, (method, permission)))
+ self.__method, (method, permission_id)))
- def __method(self, method, permission):
+ def __method(self, method, permission_id):
"Set a permission on a particular method."
m = getattr(self.__class, method)
try:
- setattr(m, "__permission__", permission)
+ setattr(m, "__permission__", permission_id)
except AttributeError, TypeError:
if hasattr(m, "im_func"):
- setattr(m.im_func, "__permission__", permission)
+ setattr(m.im_func, "__permission__", permission_id)
else:
raise ProtectionDeclarationException(
"Couldn't assign permission to method %s of class %s"
% (m, self.__class.__name__))
- def __protectMethods(self, methods, permission, r):
+ def __protectMethods(self, methods, permission_id, r):
"Set a permission on a bunch of methods."
for method in methods.split(","):
- self.__protectMethod(method.strip(), permission, r)
+ self.__protectMethod(method.strip(), permission_id, r)
- def __protectByInterface(self, interface, permission, r):
+ def __protectByInterface(self, interface, permission_id, r):
"Set a permission on methods in an interface."
interface = resolve(interface)
for n, d in interface.namesAndDescriptions():
if isinstance(d, Method):
- self.__protectMethod(n, permission, r)
+ self.__protectMethod(n, permission_id, r)
def __call__(self):
"Handle empty/simple declaration."
r = self.__r
if self.__empty:
- self.__instances(self.__permission, r)
+ self.__instances(self.__permission_id, r)
return r
=== Zope3/lib/python/Zope/App/Security/publicClass.py 1.1.2.4 => 1.1.2.5 ===
class publicClass(protectClass):
- def __init__(self, name, permission=None, interface=None,
+ def __init__(self, name, permission_id=None, interface=None,
method=None, methods=None):
- self._getPermission(permission) # Prohibit explicit permission!
- protectClass.__init__(self, name, permission=PublicPermission,
+ self._getPermission(permission_id) # Prohibit explicit permission!
+ protectClass.__init__(self, name, permission_id=PublicPermission,
interface=interface, method=method,
methods=methods)
- def _getPermission(self, permission=None):
- if permission not in [None, PublicPermission]:
+ def _getPermission(self, permission_id=None):
+ if permission_id not in [None, PublicPermission]:
raise PublicDeclarationException(
"It's invalid to specify a permission in public declarations.")
- return permission
+ return permission_id
def __call__(self):