ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilClaimingPermissionHelper Class Reference

Claiming permission helper base class. More...

+ Inheritance diagram for ilClaimingPermissionHelper:
+ Collaboration diagram for ilClaimingPermissionHelper:

Public Member Functions

 reset ()
 Reset (internal caches) More...
 
 hasPermission ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check permission. More...
 
 hasPermissions ($a_context_type, $a_context_id, array $a_action_ids)
 Check permissions. More...
 
 getAllowedObjectTypes ()
 

Static Public Member Functions

static getInstance ($a_user_id=null, $a_ref_id=null)
 Factory. More...
 

Protected Member Functions

 __construct ($a_user_id, $a_ref_id)
 Constructor. More...
 
 setUserId ($a_value)
 Set user id. More...
 
 getUserId ()
 Get user id. More...
 
 setRefId ($a_value)
 Set ref id. More...
 
 getRefId ()
 Get ref id. More...
 
 readContextIds ($a_context_type)
 Get all context ids for context type (from DB, is cached) More...
 
 buildPermissionMap ()
 Build map of context and actions. More...
 
 isValidContextAndAction ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check if given combination of context and action is valid. More...
 
 getValidContextIds ($a_context_type)
 Get context ids for context type (uses cache) More...
 
 checkPermission ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check permission (helper: rbac, plugins) More...
 
 checkRBAC ()
 Check permission against RBAC. More...
 
 getActivePlugins ()
 Get active plugins (for current slot) More...
 
 checkPlugins ($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
 Check permission against plugins. More...
 

Protected Attributes

 $user_id
 
 $ref_id
 
 $map
 
 $context_ids
 
 $plugins
 

Static Protected Attributes

static $instances
 

Detailed Description

Claiming permission helper base class.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilClaimingPermissionHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ilClaimingPermissionHelper::__construct (   $a_user_id,
  $a_ref_id 
)
protected

Constructor.

Parameters
int$a_user_id
int$a_ref_id
Returns
self

Definition at line 32 of file class.ilClaimingPermissionHelper.php.

33 {
34 $this->setUserId($a_user_id);
35 $this->setRefId($a_ref_id);
36 $this->map = $this->buildPermissionMap();
37 $this->reset();
38 }
buildPermissionMap()
Build map of context and actions.

References buildPermissionMap(), reset(), setRefId(), and setUserId().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildPermissionMap()

ilClaimingPermissionHelper::buildPermissionMap ( )
abstractprotected

Build map of context and actions.

Returns
array

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ checkPermission()

ilClaimingPermissionHelper::checkPermission (   $a_context_type,
  $a_context_id,
  $a_action_id,
  $a_action_sub_id = null 
)
protected

Check permission (helper: rbac, plugins)

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
bool

Reimplemented in ilAdvancedMDPermissionHelper.

Definition at line 243 of file class.ilClaimingPermissionHelper.php.

244 {
245 return ($this->checkRBAC() &&
246 $this->checkPlugins($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id));
247 }
checkPlugins($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission against plugins.
checkRBAC()
Check permission against RBAC.
$a_context_id
Definition: workflow.php:97
$a_context_type
Definition: workflow.php:96

References $a_context_id, $a_context_type, checkPlugins(), and checkRBAC().

Referenced by hasPermission().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPlugins()

ilClaimingPermissionHelper::checkPlugins (   $a_context_type,
  $a_context_id,
  $a_action_id,
  $a_action_sub_id = null 
)
protected

Check permission against plugins.

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
boolean

Definition at line 279 of file class.ilClaimingPermissionHelper.php.

280 {
281 $valid = true;
282
283 if (!is_array($this->plugins)) {
284 $this->plugins = (array) $this->getActivePlugins();
285 }
286
287 foreach ($this->plugins as $plugin) {
288 if (!$plugin->checkPermission($this->getUserId(), $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
289 $valid = false;
290 break;
291 }
292 }
293
294 return $valid;
295 }
getActivePlugins()
Get active plugins (for current slot)
$valid

References $a_context_id, $a_context_type, XapiProxy\$plugin, $valid, and getActivePlugins().

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkPermission().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkRBAC()

ilClaimingPermissionHelper::checkRBAC ( )
protected

Check permission against RBAC.

Returns
bool

Definition at line 254 of file class.ilClaimingPermissionHelper.php.

255 {
256 global $DIC;
257 $ilAccess = $DIC->access();
258
259 // we are currently only supporting write operations
260 return $ilAccess->checkAccessOfUser($this->getUserId(), "write", "", $this->getRefId());
261 }
$DIC
Definition: xapitoken.php:46

References $DIC, getRefId(), and getUserId().

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkPermission().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActivePlugins()

ilClaimingPermissionHelper::getActivePlugins ( )
abstractprotected

Get active plugins (for current slot)

Returns
array ilPlugin

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

Referenced by checkPlugins().

+ Here is the caller graph for this function:

◆ getAllowedObjectTypes()

ilClaimingPermissionHelper::getAllowedObjectTypes ( )
Returns
array of object type strings

Definition at line 300 of file class.ilClaimingPermissionHelper.php.

300 : array
301 {
302 $accepted_types = ['cat','crs','sess','grp','iass', 'exc'];
303
304 $obj_def = new ilObjectDefinition();
305 $adv_md_types = $obj_def->getAdvancedMetaDataTypes();
306
307 $valid_accepted_types = array();
308 foreach ($adv_md_types as $idx => $value) {
309 if (in_array($value['obj_type'], $accepted_types) || in_array($value['sub_type'], $accepted_types)) {
310 array_push($valid_accepted_types, $value['obj_type']);
311 }
312 }
313
314 return $valid_accepted_types;
315 }
parses the objects.xml it handles the xml-description of all ilias objects

Referenced by ilAdvancedMDPermissionHelper\readContextIds().

+ Here is the caller graph for this function:

◆ getInstance()

static ilClaimingPermissionHelper::getInstance (   $a_user_id = null,
  $a_ref_id = null 
)
static

Factory.

Parameters
int$a_user_id
int$a_ref_id
Returns
self

Definition at line 47 of file class.ilClaimingPermissionHelper.php.

48 {
49 global $DIC;
50 $ilUser = $DIC->user();
51
52 if (!$a_user_id) {
53 $a_user_id = $ilUser->getId();
54 }
55 if (!$a_ref_id) {
56 $a_ref_id = (int) $_REQUEST["ref_id"];
57 }
58 if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
59 self::$instances[$a_user_id][$a_ref_id] = new static($a_user_id, $a_ref_id);
60 }
61 return self::$instances[$a_user_id][$a_ref_id];
62 }
$ilUser
Definition: imgupload.php:18

References $DIC, and $ilUser.

Referenced by ilAdvancedMDSettingsGUI\__construct(), and ilCustomUserFieldsGUI\__construct().

+ Here is the caller graph for this function:

◆ getRefId()

ilClaimingPermissionHelper::getRefId ( )
protected

Get ref id.

Returns
int

Definition at line 110 of file class.ilClaimingPermissionHelper.php.

References $ref_id.

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkRBAC().

+ Here is the caller graph for this function:

◆ getUserId()

ilClaimingPermissionHelper::getUserId ( )
protected

Get user id.

Returns
int

Definition at line 90 of file class.ilClaimingPermissionHelper.php.

References $user_id.

Referenced by ilAdvancedMDPermissionHelper\checkPermission(), and checkRBAC().

+ Here is the caller graph for this function:

◆ getValidContextIds()

ilClaimingPermissionHelper::getValidContextIds (   $a_context_type)
protected

Get context ids for context type (uses cache)

See also
self::readContextIds()
Parameters
int$a_context_type
Returns
array

Definition at line 183 of file class.ilClaimingPermissionHelper.php.

184 {
185 if (!array_key_exists($a_context_type, $this->context_ids)) {
186 $this->context_ids[$a_context_type] = $this->readContextIds($a_context_type);
187 }
188 return (array) $this->context_ids[$a_context_type];
189 }
readContextIds($a_context_type)
Get all context ids for context type (from DB, is cached)

References $a_context_type, and readContextIds().

Referenced by isValidContextAndAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermission()

ilClaimingPermissionHelper::hasPermission (   $a_context_type,
  $a_context_id,
  $a_action_id,
  $a_action_sub_id = null 
)

Check permission.

Parameters
int$a_context_type
int$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
bool

Definition at line 200 of file class.ilClaimingPermissionHelper.php.

201 {
202 if ($this->isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
203 return $this->checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
204 }
205 // :TODO: exception?
206 }
checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission (helper: rbac, plugins)
isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check if given combination of context and action is valid.

References $a_context_id, $a_context_type, checkPermission(), and isValidContextAndAction().

Referenced by hasPermissions(), and ilAdvancedMDFieldDefinition\importDefinitionFormPostValues().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermissions()

ilClaimingPermissionHelper::hasPermissions (   $a_context_type,
  $a_context_id,
array  $a_action_ids 
)

Check permissions.

Parameters
int$a_context_type
int$a_context_id
array$a_action_ids
Returns
bool

Definition at line 216 of file class.ilClaimingPermissionHelper.php.

217 {
218 $res = array();
219
220 foreach ($a_action_ids as $action_id) {
221 if (is_array($action_id)) {
222 $action_sub_id = $action_id[1];
223 $action_id = $action_id[0];
224
225 $res[$action_id][$action_sub_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id, $action_sub_id);
226 } else {
227 $res[$action_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id);
228 }
229 }
230
231 return $res;
232 }
hasPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission.
foreach($_POST as $key=> $value) $res

References $a_context_id, $a_context_type, $res, and hasPermission().

Referenced by ilAdvancedMDFieldDefinition\addToFieldDefinitionForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidContextAndAction()

ilClaimingPermissionHelper::isValidContextAndAction (   $a_context_type,
  $a_context_id,
  $a_action_id,
  $a_action_sub_id = null 
)
protected

Check if given combination of context and action is valid.

Parameters
int$a_context_type
mixed$a_context_id
int$a_action_id
int$a_action_sub_id
Returns
boolean

Definition at line 146 of file class.ilClaimingPermissionHelper.php.

147 {
148 $valid = false;
149
150 if (array_key_exists($a_context_type, $this->map)) {
151 if (!$a_action_sub_id) {
152 if (in_array($a_action_id, $this->map[$a_context_type]["actions"])) {
153 $valid = true;
154 }
155 } else {
156 if (array_key_exists($a_action_id, $this->map[$a_context_type]["subactions"]) &&
157 in_array($a_action_sub_id, $this->map[$a_context_type]["subactions"][$a_action_id])) {
158 $valid = true;
159 }
160 }
161 }
162
163 if ($valid &&
166 $valid = false;
167 }
168
169 if (DEVMODE && !$valid) {
170 trigger_error("INVALID permission context - " . $a_context_type . ":" . $a_context_id . ":" . $a_action_id . ":" . $a_action_sub_id, E_USER_WARNING);
171 }
172
173 return $valid;
174 }
getValidContextIds($a_context_type)
Get context ids for context type (uses cache)

References $a_context_id, $a_context_type, $valid, and getValidContextIds().

Referenced by hasPermission().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readContextIds()

ilClaimingPermissionHelper::readContextIds (   $a_context_type)
abstractprotected

Get all context ids for context type (from DB, is cached)

See also
self::getValidContextIds()
Parameters
int$a_context_type
Returns
array

Reimplemented in ilAdvancedMDPermissionHelper, and ilUDFPermissionHelper.

Referenced by getValidContextIds().

+ Here is the caller graph for this function:

◆ reset()

ilClaimingPermissionHelper::reset ( )

Reset (internal caches)

Definition at line 67 of file class.ilClaimingPermissionHelper.php.

68 {
69 $this->context_ids = array();
70 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRefId()

ilClaimingPermissionHelper::setRefId (   $a_value)
protected

Set ref id.

Parameters
int$a_value

Definition at line 100 of file class.ilClaimingPermissionHelper.php.

101 {
102 $this->ref_id = (int) $a_value;
103 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUserId()

ilClaimingPermissionHelper::setUserId (   $a_value)
protected

Set user id.

Parameters
int$a_value

Definition at line 80 of file class.ilClaimingPermissionHelper.php.

81 {
82 $this->user_id = (int) $a_value;
83 }

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $context_ids

ilClaimingPermissionHelper::$context_ids
protected

Definition at line 17 of file class.ilClaimingPermissionHelper.php.

◆ $instances

ilClaimingPermissionHelper::$instances
staticprotected

Definition at line 20 of file class.ilClaimingPermissionHelper.php.

◆ $map

ilClaimingPermissionHelper::$map
protected

Definition at line 16 of file class.ilClaimingPermissionHelper.php.

◆ $plugins

ilClaimingPermissionHelper::$plugins
protected

Definition at line 18 of file class.ilClaimingPermissionHelper.php.

◆ $ref_id

ilClaimingPermissionHelper::$ref_id
protected

Definition at line 15 of file class.ilClaimingPermissionHelper.php.

Referenced by getRefId().

◆ $user_id

ilClaimingPermissionHelper::$user_id
protected

Definition at line 14 of file class.ilClaimingPermissionHelper.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: