Content items can automatically check if the user has permission to perform certain actions by examining the container node object. For this functionality to be supported, as you might expect, your content items need to be using container nodes. Consult the documentation on container nodes and supporting containers in content items for more information.
Supporting permissions in content items
All you need to do to support permissions is implement the permissions interface in your content item model class:
Changes to model methods after implementing permissions
Several methods in your content item model change behavior slightly when permissions are implemented.
- canView() will return FALSE for an item a node the member does not have permission to view.
- loadAndCheckPerms() will throw an OutOfRange exception if an object is loaded that the member does not have permission to view.
- All places where features do things will check the permission. For example, canCreate() will now return FALSE if the member does not have permission to create content items in the specified node.
- getItemsWithPermission() will only return items that the currently logged in user has permission to view (or other permission as specified by parameters).
Additional model methods available
Returns a boolean indicating whether the user has permission to perform the specified action.
$permission (string, required)
The permission key to be checked. The action should match a value from the static $permissionMap property of the container class.
$member (\IPS\Member, optional)
The member object of the member whose permissions should be checked. You can also pass an \IPS\Member\Group object to check a group's permissions instead. If no value is passed, the currently-logged in member is used.
Returns the permission index ID for this item model.