Actions

API16

Difference between revisions of "JAccess/check"

From Joomla! Documentation

< API16:JAccess
(New page: ===Description=== Method to check if a user is authorised to perform an action, optionally on an asset. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Descripti...)
 
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JAccess/check|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JAccess/check}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 85: Line 85:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JAccess/check|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JAccess/check}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 100: Line 100:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:54, 12 May 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to check if a user is authorised to perform an action, optionally on an asset.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

static check($userId, $action, $asset=null)
Parameter Name Default Value Description
$userId Id of the user for which to check authorisation.
$action The name of the action to authorise.
$asset null Integer asset id or the name of the asset as a string. Defaults to the global asset node.

Returns

boolean True if authorised.

Defined in

libraries/joomla/access/access.php

Importing

jimport( 'joomla.access.access' );

Source Body

public static function check($userId, $action, $asset = null)
{
        if (self::$isRoot) {
                return true;
        }
        else
        {
                // Sanitize inputs.
                $userId = (int) $userId;
 
                $action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
                $asset  = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));
 
                // Default to the root asset node.
                if (empty($asset)) {
                        $asset = 1;
                }
 
                // Get the rules for the asset recursively to root if not already retrieved.
                if (empty(self::$assetRules[$asset])) {
                        self::$assetRules[$asset] = self::getAssetRules($asset, true);
                }
 
                // Get all groups against which the user is mapped.
                $identities = self::getGroupsByUser($userId);
                array_unshift($identities, $userId * -1);
 
                // Make sure we only check for core.admin once during the run.
                if (self::$isRoot === null)
                {
                        if (self::getAssetRules(1)->allow('core.admin', $identities)) {
                                self::$isRoot = true;
                                return true;
                        }
                        else {
                                self::$isRoot = false;
                        }
                }
 
                return self::$assetRules[$asset]->allow($action, $identities);
        }
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />