You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really often have the use case to check if the creation of a portal_type is allowed for a specific context.
Just checking for Add portal content is not enough. First allowedContentTypes (taking constraintypes into account) need to be checked and also checks for custom add permissions (stored at the FTI) are needed. The FTI has a method for this.
A sample code snippet doing this looks like so (I am sure it needs some polishing):
def can_create(self, context, portal_type=None):
"""check if creation/construction is allowed.
if no type is given check for general add permission
"""
allowed_ftis_iterator = getattr(context, 'allowedContentTypes', None)
if not allowed_ftis_iterator:
# context is not a valid container
return False
if portal_type is None:
# generic if no explicit type was given
return api.user.has_permission('Add portal content', obj=context)
allowed_types = [fti.getId() for fti in allowed_ftis_iterator()]
if portal_type not in allowed_types:
return False
types_tool = api.portal.get_tool('portal_types')
type_info = types_tool.getTypeInfo(portal_type)
return bool(type_info.isConstructionAllowed(context))
I propose to add such a check either to plone.api.user or plone.api.content and enhance the function to take a user or username argument.
If there are enough thumbs up for this I will implement and test it.
The text was updated successfully, but these errors were encountered:
I really often have the use case to check if the creation of a portal_type is allowed for a specific context.
Just checking for
Add portal content
is not enough. FirstallowedContentTypes
(taking constraintypes into account) need to be checked and also checks for custom add permissions (stored at the FTI) are needed. The FTI has a method for this.A sample code snippet doing this looks like so (I am sure it needs some polishing):
I propose to add such a check either to plone.api.user or plone.api.content and enhance the function to take a user or username argument.
If there are enough thumbs up for this I will implement and test it.
The text was updated successfully, but these errors were encountered: