Access
Class that handles all access authorisation routines.
since |
1.7.0 |
---|---|
package |
Joomla CMS |
Methods
check
Method to check if a user is authorised to perform an action, optionally on an asset.
check( userId, action, int|string assetKey = null, preload = true) : bool|null
since |
1.7.0 |
---|
Arguments
- userId
int
Id of the user for which to check authorisation.- action
string
The name of the action to authorise.- assetKey
int|string
The asset key (asset id or asset name). null fallback to root asset.- preload
bool
Indicates whether preloading should be used.
Response
bool|null
True if allowed, false for an explicit deny, null for an implicit deny.
checkGroup
Method to check if a group is authorised to perform an action, optionally on an asset.
checkGroup( groupId, action, int|string assetKey = null, preload = true) :
since |
1.7.0 |
---|
Arguments
- groupId
int
The path to the group for which to check authorisation.- action
string
The name of the action to authorise.- assetKey
int|string
The asset key (asset id or asset name). null fallback to root asset.- preload
bool
Indicates whether preloading should be used.
Response
bool
True if authorised.
cleanAssetKey
Method to clean the asset key to make sure we always have something.
cleanAssetKey(int|string assetKey = null) : int|string
since |
3.7.0 |
---|
Arguments
- assetKey
int|string
The asset key (asset id or asset name). null fallback to root asset.
Response
int|string
Asset id or asset name.
clearStatics
Method for clearing static caches.
clearStatics() :
since |
1.7.3 |
---|
Response
void
getActionsFromData
Method to return a list of actions from a string or from an xml for which permissions can be set.
getActionsFromData(string|\SimpleXMLElement data, xpath = "/access/section[@name='component']/") : bool|array
since |
3.0.0 |
---|
Arguments
- data
string|SimpleXMLElement
The XML string or an XML element.- xpath
string
An optional xpath to search for the fields.
Response
bool|array<string|int, mixed>
False if case of error or the list of actions available.
getActionsFromFile
Method to return a list of actions from a file for which permissions can be set.
getActionsFromFile( file, xpath = "/access/section[@name='component']/") : bool|array
since |
3.0.0 |
---|
Arguments
- file
string
The path to the XML file.- xpath
string
An optional xpath to search for the fields.
Response
bool|array<string|int, mixed>
False if case of error or the list of actions available.
getAssetAncestors
Method to recursively retrieve the list of parent Asset IDs for a particular Asset.
getAssetAncestors( assetType, assetId) : mixed||string|int
since |
1.6 |
---|
Arguments
- assetType
string
The asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').- assetId
int
The numeric asset id.
Response
array<string|int, mixed>
List of ancestor ids (includes original $assetId).
getAssetId
Method to get the asset id from the asset key.
getAssetId(int|string assetKey) :
since |
3.7.0 |
---|
Arguments
- assetKey
int|string
The asset key (asset id or asset name).
Response
int
The asset id.
getAssetName
Method to get the asset name from the asset key.
getAssetName(int|string assetKey) :
since |
3.7.0 |
---|
Arguments
- assetKey
int|string
The asset key (asset id or asset name).
Response
string
The asset name (ex: com_content.article.8).
getAssetRules
Method to return the Rules object for an asset. The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules.
getAssetRules(int|string assetKey, recursive = false, recursiveParentAsset = true, preload = true) : \Joomla\CMS\Access\Rules
since |
1.7.0 |
---|---|
note |
The non preloading code will be removed in 4.0. All asset rules should use asset preloading. |
Arguments
- assetKey
int|string
The asset key (asset id or asset name). null fallback to root asset.- recursive
bool
True to return the rules object with inherited rules.- recursiveParentAsset
bool
True to calculate the rule also based on inherited component/extension rules.- preload
bool
Indicates whether preloading should be used.
Response
Rules
Rules object for the asset.
getAssetType
Method to get the asset type from the asset name.
getAssetType(int|string assetKey) :
For top level components this returns "components": 'com_content' returns 'components'
For other types: 'com_content.article.1' returns 'com_content.article' 'com_content.category.1' returns 'com_content.category'
since |
1.6 |
---|
Arguments
- assetKey
int|string
The asset key (asset id or asset name).
Response
string
The asset type (ex: com_content.article).
getAuthorisedViewLevels
Method to return a list of view levels for which the user is authorised.
getAuthorisedViewLevels( userId) : mixed||string|int
since |
1.7.0 |
---|
Arguments
- userId
int
Id of the user for which to get the list of authorised view levels.
Response
array<string|int, mixed>
List of view levels for which the user is authorised.
getExtensionNameFromAsset
Method to get the extension name from the asset name.
getExtensionNameFromAsset(int|string assetKey) :
since |
1.6 |
---|
Arguments
- assetKey
int|string
The asset key (asset id or asset name).
Response
string
The extension name (ex: com_content).
getGroupPath
Gets the parent groups that a leaf group belongs to in its branch back to the root of the tree (including the leaf group id).
getGroupPath( groupId) :
since |
1.7.0 |
---|
Arguments
- groupId
mixed
An integer or array of integers representing the identities to check.
Response
mixed
True if allowed, false for an explicit deny, null for an implicit deny.
getGroupsByUser
Method to return a list of user groups mapped to a user. The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited by the user.
getGroupsByUser( userId, recursive = true) : mixed||string|int
since |
1.7.0 |
---|
Arguments
- userId
int
Id of the user for which to get the list of groups.- recursive
bool
True to include inherited user groups.
Response
array<string|int, mixed>
List of user group ids to which the user is mapped.
getGroupTitle
Method to return the title of a user group
getGroupTitle( groupId) :
since |
3.5 |
---|
Arguments
- groupId
int
Id of the group for which to get the title of.
Response
string
The title of the group
getUsersByGroup
Method to return a list of user Ids contained in a Group
getUsersByGroup( groupId, recursive = false) : mixed||string|int
since |
1.7.0 |
---|---|
todo |
This method should move somewhere else |
Arguments
- groupId
int
The group Id- recursive
bool
Recursively include all child groups (optional)
Response
array<string|int, mixed>
preload
Method to preload the Rules object for the given asset type.
preload(int|string|array assetTypes = 'components', reload = false) :
since |
1.6 |
---|---|
note |
This method will return void in 4.0. |
Arguments
- assetTypes
int|string|array<string|int, mixed>
The type or name of the asset (e.g. 'com_content.article', 'com_menus.menu.2'). Also accepts the asset id. An array of asset type or a special 'components' string to load all component assets.- reload
bool
Set to true to reload from database.
Response
bool
True on success.
preloadComponents
Method to preload the Rules objects for all components.
preloadComponents() : mixed||string|int
Note: This will only get the base permissions for the component. e.g. it will get 'com_content', but not 'com_content.article.1' or any more specific asset type rules.
since |
1.6 |
---|
Response
array<string|int, mixed>
Array of component names that were preloaded.
preloadPermissions
Method to retrieve the Asset Rule strings for this particular Asset Type and stores them for later usage in getAssetRules().
preloadPermissions( assetType, reload = false) :
Stores 2 arrays: one where the list has the Asset ID as the key and a second one where the Asset Name is the key.
since |
1.6 |
---|
Arguments
- assetType
string
The asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').- reload
bool
Reload the preloaded assets.
Response
void
Properties
viewLevels
Array of view levels
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
assetRules
Array of rules for the asset
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
assetRulesIdentities
Array of identities for asset rules
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
assetPermissionsParentIdMapping
Array of the permission parent ID mappings
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
preloadedAssetTypes
Array of asset types that have been preloaded
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
identities
Array of loaded user identities
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
userGroups
Array of user groups.
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
userGroupPaths
Array of user group paths.
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
groupsByUser
Array of cached groups by user.
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
preloadedAssets
Array of preloaded asset names and ids (key is the asset id).
since |
3.7.0 |
---|
Type(s)
array<string|int, mixed>
rootAssetId
The root asset id.
since |
3.7.0 |
---|
Type(s)
int