Listing all permissions in the site
Purpose
For a future PAS plugin, i wanted to create a (multi)select field on a content type that takes the available site permissions as a vocabulary. For this purpose, i wanted a script that generates a list of all permissions.
Prerequisities
Any version of Plone will do.
Step by step
Place this script in your custom folder, or add it to your product's templates:
from Products.CMFCore.utils import getToolByName
portal_url = getToolByName(context, "portal_url")
portal = portal_url.getPortalObject()
all_permissions = []
# context has a method valid_roles
for role in portal.valid_roles():
# role is a string of 'Contributor', 'Reader', etc.
permissions = portal.permissionsOfRole(role)
# permissions is a list of dicts
for permission in permissions:
# permission is a dict with keys 'selected' and 'name'
if permission['name'] not in all_permissions:
all_permissions.append(permission['name'])
all_permissions.sort()
return all_permissions
Further information
This script explicitly checks the permissions at the portal root. By changing 'portal' to 'context' you will get the permissions definied on the object where you call the script.
