Class craft\services\UserPermissions
- Inheritance
- craft\services\UserPermissions » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/services/UserPermissions.php
User Permissions service.
An instance of the User Permissions service is globally accessible in Craft via Craft::$app->userPermissions
.
Method | Description | Defined By |
---|---|---|
__call() |
Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() |
This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() |
Constructor. | yii\base\BaseObject |
__get() |
Returns the value of an object property. | yii\base\BaseObject |
__isset() |
Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() |
Sets value of an object property. | yii\base\BaseObject |
__unset() |
Sets an object property to null. | yii\base\BaseObject |
attachBehavior() |
Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() |
Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() |
Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() |
Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() |
Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() |
Returns the fully qualified name of this class. | yii\base\BaseObject |
detachBehavior() |
Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() |
Detaches all behaviors from the component. | yii\base\Component |
doesGroupHavePermission() |
Returns whether a given user group has a given permission. | craft\services\UserPermissions |
doesUserHavePermission() |
Returns whether a given user has a given permission. | craft\services\UserPermissions |
ensureBehaviors() |
Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getAllPermissions() |
Returns all of the known permissions, sorted by category. | craft\services\UserPermissions |
getAssignablePermissions() |
Returns the permissions that the current user is allowed to assign to another user. | craft\services\UserPermissions |
getBehavior() |
Returns the named behavior object. | yii\base\Component |
getBehaviors() |
Returns all behaviors attached to this component. | yii\base\Component |
getGroupPermissionsByUserId() |
Returns all of the group permissions a given user has. | craft\services\UserPermissions |
getPermissionsByGroupId() |
Returns all of a given user group's permissions. | craft\services\UserPermissions |
getPermissionsByUserId() |
Returns all of a given user's permissions. | craft\services\UserPermissions |
hasEventHandlers() |
Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() |
Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() |
Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() |
Initializes the object. | yii\base\BaseObject |
off() |
Detaches an existing event handler from this component. | yii\base\Component |
on() |
Attaches an event handler to an event. | yii\base\Component |
saveGroupPermissions() |
Saves new permissions for a user group. | craft\services\UserPermissions |
saveUserPermissions() |
Saves new permissions for a user. | craft\services\UserPermissions |
trigger() |
Triggers an event. | yii\base\Component |
Event | Type | Description | Defined By |
---|---|---|---|
EVENT_REGISTER_PERMISSIONS |
craft\events\RegisterUserPermissionsEvent | The event that is triggered when registering user permissions. | craft\services\UserPermissions |
Method Details
doesGroupHavePermission()
public method
#
Returns whether a given user group has a given permission.
public boolean doesGroupHavePermission ( \craft\services\int $groupId, \craft\services\string $checkPermission )
$groupId |
integer | |
$checkPermission |
string |
doesUserHavePermission()
public method
#
Returns whether a given user has a given permission.
public boolean doesUserHavePermission ( \craft\services\int $userId, \craft\services\string $checkPermission )
$userId |
integer | |
$checkPermission |
string |
getAllPermissions()
public method
#
Returns all of the known permissions, sorted by category.
public array getAllPermissions ( )
getAssignablePermissions()
public method
#
Returns the permissions that the current user is allowed to assign to another user.
public array getAssignablePermissions ( craft\elements\User $user = null )
$user |
craft\elements\User, null | The recipient of the permissions. If set, their current permissions will be included as well. |
getGroupPermissionsByUserId()
public method
#
Returns all of the group permissions a given user has.
public array getGroupPermissionsByUserId ( \craft\services\int $userId )
$userId |
integer |
getPermissionsByGroupId()
public method
#
Returns all of a given user group's permissions.
public array getPermissionsByGroupId ( \craft\services\int $groupId )
$groupId |
integer |
getPermissionsByUserId()
public method
#
Returns all of a given user's permissions.
public array getPermissionsByUserId ( \craft\services\int $userId )
$userId |
integer |
saveGroupPermissions()
public method
#
Saves new permissions for a user group.
public boolean saveGroupPermissions ( \craft\services\int $groupId, array $permissions )
$groupId |
integer | |
$permissions |
array | |
throws | craft\errors\WrongEditionException | if this is called from Craft Personal or Client editions |
---|
saveUserPermissions()
public method
#
Saves new permissions for a user.
public boolean saveUserPermissions ( \craft\services\int $userId, array $permissions )
$userId |
integer | |
$permissions |
array | |
throws | craft\errors\WrongEditionException | if this is called from Craft Personal edition |
---|
Event Details
EVENT_REGISTER_PERMISSIONS
event of type craft\events\RegisterUserPermissionsEvent
#
The event that is triggered when registering user permissions.