Task-Based Permissions

concrete 5.4 introduces the concept of task-based permissions. These permissions are highly specific to a certain task, as opposed to general content-based permissions (which are based around specific instances and types of content.) These task permissions can be accessed from the dashboard. Developers can also install their own task permissions, and install them through a package.

Example of Task-Based Permissions

  • Specifying who can edit page defaults
  • Specifying who can sign in as a user account.
  • Specifying who can uninstall packages

Checking a Task-Based Permission against the Logged-In User

	$tp = TaskPermission::getByHandle('page_defaults');
	if ($tp->can()) {
		print 'yes';
	}

Using the Magic Method

Grab the handle of the task-based permission, camelcase it, and add it to "canAccess"

	$tp = new TaskPermission();
	if ($tp->canAcessPageDefaults()) {
		print 'yes';
	}

Checking a task-based permission against another user or group

Simply pass the Group or UserInfo object to the can() method

	$ui = UserInfo::getByUserName('johndoe');
	$tp = TaskPermission::getByHandle('page_defaults');
	if ($tp->can($ui)) {
		print 'johndoe can access';
	}

Methods

$tp = TaskPermission::getByID($tpID)

Returns a TaskPermission object based on $tpID.

$tp = TaskPermission::getByHandle($tpHandle)

Returns a TaskPermission object based on its handle.

$tp->getTaskPermissionID()

Gets the ID of the current task permission object.

$tp->getTaskPermissionID()

Gets the ID of the current task permission object.

$tp->getTaskPermissionName()

Gets the name of the current task permission object.

$tp->getTaskPermissionHandle()

Gets the handle of the current task permission object.

$tp->getTaskPermissionDescription()

Gets the description of the current task permission object.

$tp->getPackageID()

Returns the package ID for the current task permission object.

$tp->getPackageHandle()

Returns the package handle for the current task permission object.

$tp->delete()

Delete the current task permission.

$tp->clearPermissions()

Clear all permissions associated with the task. $tp->addAccess($obj) Pass either a UserInfo or Group object. Adds access for the passed object.

$tp->removeAccess($obj)

Pass either a UserInfo or Group object. Removes access for the passed object.

$tp->can($obj = false)

Checks whether the current task can be accessed. If $obj is false, the currently logged-in user is checked.


Recent Discussions on this Topic

Permission

I'm sure this has been asked before but I couldn't find it ie working with Permissions. Lets say I have a client/owner, I don't want him messing up the site. Is there a way to hide certain tab in the dashboard. I dont' want him to be able to change my the…

Administrators Cannot Add a Page

Hey, was wondering if anyone was having the same problem as me, Fresh install of 5.4+ make a new user account and add it to the Admin group sign in as them, you can't add a page, i checked the permissions, i even turned on advanced permissions an…

Permissions

Hi everyone, I do not want a user I created to be able to set permissions for any pages. It seems like the user can change if the admin has permission to edit a page and I can't find where to change that. Thanks!!

Edit option not showing for a user with edit rights on a block

A steep learning curve, but a fantastic product! I have almost finished building a new site and now want to give someone (user gw1)partial edit capability. I have created a special user group "editorgw", which is intended to have edit capability on one…