ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilClaimingPermissionHelper Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

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

Static Public Member Functions

static getInstance (int $a_user_id, int $a_ref_id)
 

Protected Member Functions

 __construct (int $a_user_id, int $a_ref_id)
 
 setUserId (int $a_value)
 
 getUserId ()
 
 setRefId (int $a_value)
 
 getRefId ()
 
 readContextIds (int $a_context_type)
 Get all context ids for context type (from DB, is cached) More...
 
 buildPermissionMap ()
 Build map of context and actions. More...
 
 isValidContextAndAction (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check if given combination of context and action is valid. More...
 
 getValidContextIds (int $a_context_type)
 Get context ids for context type (uses cache) More...
 
 checkPermission (int $a_context_type, string $a_context_id, int $a_action_id, ?int $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 (int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
 Check permission against plugins. More...
 

Protected Attributes

int $user_id = 0
 
int $ref_id = 0
 
array $map = []
 
array $context_ids = []
 
array $plugins = null
 

Static Protected Attributes

static array $instances = []
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

35  {
36  $this->setUserId($a_user_id);
37  $this->setRefId($a_ref_id);
38  $this->map = $this->buildPermissionMap();
39  $this->reset();
40  }
buildPermissionMap()
Build map of context and actions.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildPermissionMap()

ilClaimingPermissionHelper::buildPermissionMap ( )
abstractprotected

Build map of context and actions.

Referenced by __construct(), and getRefId().

+ Here is the caller graph for this function:

◆ checkPermission()

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

Check permission (helper: rbac, plugins)

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

References checkPlugins(), and checkRBAC().

Referenced by hasPermission().

192  : bool {
193  return ($this->checkRBAC() &&
194  $this->checkPlugins($a_context_type, (string) $a_context_id, $a_action_id, $a_action_sub_id));
195  }
checkRBAC()
Check permission against RBAC.
checkPlugins(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission against plugins.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPlugins()

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

Check permission against plugins.

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

References XapiProxy\$plugin, $valid, getActivePlugins(), and ilAdvancedMDPermissionHelper\SUBACTION_UNDEFINED.

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

222  : bool {
223  $valid = true;
224 
225  if (!is_array($this->plugins)) {
226  $this->plugins = iterator_to_array($this->getActivePlugins());
227  }
228 
229  foreach ($this->plugins as $plugin) {
230  $a_action_sub_id = is_null($a_action_sub_id)
232  : $a_action_sub_id;
233  if (!$plugin->checkPermission($this->getUserId(), $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
234  $valid = false;
235  break;
236  }
237  }
238 
239  return $valid;
240  }
$valid
getActivePlugins()
Get active plugins (for current slot)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkRBAC()

ilClaimingPermissionHelper::checkRBAC ( )
protected

Check permission against RBAC.

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

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

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

200  : bool
201  {
202  global $DIC;
203  $ilAccess = $DIC->access();
204 
205  // we are currently only supporting write operations
206  return $ilAccess->checkAccessOfUser($this->getUserId(), "write", "", $this->getRefId());
207  }
global $DIC
Definition: shib_login.php:22
+ 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)

Referenced by checkPlugins(), and checkRBAC().

+ Here is the caller graph for this function:

◆ getAllowedObjectTypes()

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

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

Referenced by ilAdvancedMDPermissionHelper\readContextIds().

245  : array
246  {
247  $accepted_types = ['cat','crs','sess','grp','iass','exc','file'];
248 
249  $obj_def = new ilObjectDefinition();
250  $adv_md_types = $obj_def->getAdvancedMetaDataTypes();
251 
252  $valid_accepted_types = [];
253  foreach ($adv_md_types as $value) {
254  if (in_array($value['obj_type'], $accepted_types) || in_array($value['sub_type'], $accepted_types)) {
255  array_push($valid_accepted_types, $value['obj_type']);
256  }
257  }
258 
259  return $valid_accepted_types;
260  }
+ Here is the caller graph for this function:

◆ getInstance()

static ilClaimingPermissionHelper::getInstance ( int  $a_user_id,
int  $a_ref_id 
)
static

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

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

42  : self
43  {
44  if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
45  self::$instances[$a_user_id][$a_ref_id] = new static($a_user_id, $a_ref_id);
46  }
47  return self::$instances[$a_user_id][$a_ref_id];
48  }
+ Here is the caller graph for this function:

◆ getRefId()

ilClaimingPermissionHelper::getRefId ( )
protected

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

References $ref_id, buildPermissionMap(), and readContextIds().

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

76  : int
77  {
78  return $this->ref_id;
79  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserId()

ilClaimingPermissionHelper::getUserId ( )
protected

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

References $user_id.

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

66  : int
67  {
68  return $this->user_id;
69  }
+ Here is the caller graph for this function:

◆ getValidContextIds()

ilClaimingPermissionHelper::getValidContextIds ( int  $a_context_type)
protected

Get context ids for context type (uses cache)

See also
self::readContextIds()

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

References readContextIds().

Referenced by isValidContextAndAction().

139  : array
140  {
141  if (!array_key_exists($a_context_type, $this->context_ids)) {
142  $this->context_ids[$a_context_type] = $this->readContextIds($a_context_type);
143  }
144  return (array) $this->context_ids[$a_context_type];
145  }
readContextIds(int $a_context_type)
Get all context ids for context type (from DB, is cached)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermission()

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

Check permission.

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

References checkPermission(), and isValidContextAndAction().

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

155  : bool {
156  if ($this->isValidContextAndAction($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)) {
157  return $this->checkPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
158  }
159  // :TODO: exception?
160  return false;
161  }
checkPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission (helper: rbac, plugins)
isValidContextAndAction(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check if given combination of context and action is valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPermissions()

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

Check permissions.

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

References $res, and hasPermission().

Referenced by ilAdvancedMDFieldDefinition\addToFieldDefinitionForm().

166  : array
167  {
168  $res = [];
169 
170  foreach ($a_action_ids as $action_id) {
171  if (is_array($action_id)) {
172  $action_sub_id = $action_id[1];
173  $action_id = $action_id[0];
174 
175  $res[$action_id][$action_sub_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id, $action_sub_id);
176  } else {
177  $res[$action_id] = $this->hasPermission($a_context_type, $a_context_id, $action_id);
178  }
179  }
180 
181  return $res;
182  }
$res
Definition: ltiservices.php:66
hasPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidContextAndAction()

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

Check if given combination of context and action is valid.

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

References $valid, and getValidContextIds().

Referenced by hasPermission().

105  : bool {
106  $valid = false;
107 
108  if (array_key_exists($a_context_type, $this->map)) {
109  if (!$a_action_sub_id) {
110  if (in_array($a_action_id, $this->map[$a_context_type]["actions"])) {
111  $valid = true;
112  }
113  } else {
114  if (array_key_exists($a_action_id, $this->map[$a_context_type]["subactions"]) &&
115  in_array($a_action_sub_id, $this->map[$a_context_type]["subactions"][$a_action_id])) {
116  $valid = true;
117  }
118  }
119  }
120 
121  if ($valid &&
122  $a_context_id &&
123  !in_array($a_context_id, $this->getValidContextIds($a_context_type))) {
124  $valid = false;
125  }
126 
127  if (DEVMODE && !$valid) {
128  trigger_error("INVALID permission context - " . $a_context_type . ":" . $a_context_id . ":" . $a_action_id . ":" . $a_action_sub_id, E_USER_WARNING);
129  }
130 
131  return $valid;
132  }
getValidContextIds(int $a_context_type)
Get context ids for context type (uses cache)
$valid
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readContextIds()

ilClaimingPermissionHelper::readContextIds ( int  $a_context_type)
abstractprotected

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

Referenced by getRefId(), and getValidContextIds().

+ Here is the caller graph for this function:

◆ reset()

ilClaimingPermissionHelper::reset ( )

Reset (internal caches)

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

Referenced by __construct().

53  : void
54  {
55  $this->context_ids = [];
56  }
+ Here is the caller graph for this function:

◆ setRefId()

ilClaimingPermissionHelper::setRefId ( int  $a_value)
protected

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

Referenced by __construct().

71  : void
72  {
73  $this->ref_id = $a_value;
74  }
+ Here is the caller graph for this function:

◆ setUserId()

ilClaimingPermissionHelper::setUserId ( int  $a_value)
protected

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

Referenced by __construct().

61  : void
62  {
63  $this->user_id = $a_value;
64  }
+ Here is the caller graph for this function:

Field Documentation

◆ $context_ids

array ilClaimingPermissionHelper::$context_ids = []
protected

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

◆ $instances

array ilClaimingPermissionHelper::$instances = []
staticprotected

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

◆ $map

array ilClaimingPermissionHelper::$map = []
protected

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

◆ $plugins

array ilClaimingPermissionHelper::$plugins = null
protected

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

◆ $ref_id

int ilClaimingPermissionHelper::$ref_id = 0
protected

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

Referenced by getRefId().

◆ $user_id

int ilClaimingPermissionHelper::$user_id = 0
protected

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

Referenced by getUserId().


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