from AccessControl import ClassSecurityInfo class MyClass: security = ClassSecurityInfo() security.setDefaultAccess('deny') security.setPermissionDefault('my_permission', ('Manager',)) def my_method(self): pass security.declareProtected('my_permission', 'my_method')
from AccessControl import ClassSecurityInfo from Products.CMFCore.utils import getToolByName class MyFolder: security = ClassSecurityInfo() security.setDefaultAccess('allow') def my_method(self): portal_membership = getToolByName(self, 'portal_membership') if portal_membership.checkPermission('my_permission', self): # do something pass security.declareProtected('my_permission', 'my_method')In this example, we define a class MyFolder and a method 'my_method'. Inside the method, we use the 'getToolByName' function to get the portal_membership tool and check if the current user has the 'my_permission' permission. If yes, we execute the code. Otherwise, we skip it. The method is protected with the 'my_permission' permission using the 'declareProtected' method. The AccessControl module is a part of the Zope Toolkit library, which is used for building web applications and content management systems.