3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This supplements the permissions of the CMS system, allowing us
20 * to temporarily acknowledge permission grants for API keys.
22 * In normal usage, the class isn't even instantiated - it's only
23 * used when processing certain API backends.
25 class CRM_Core_Permission_Temp
{
26 public static $id = 0;
29 * Array(int $grantId => array($perm))
42 * Grant permissions temporarily.
44 * @param string|array $perms
45 * List of permissions to apply.
47 * A handle for the grant. Useful for revoking later on.
49 public function grant($perms) {
50 $perms = (array) $perms;
52 $this->grants
[$id] = $perms;
53 $this->idx
= $this->index($this->grants
);
58 * Revoke a previously granted permission.
60 * @param string|int $id
61 * The handle previously returned by grant().
63 public function revoke($id) {
64 unset($this->grants
[$id]);
65 $this->idx
= $this->index($this->grants
);
69 * Determine if a permission has been granted.
72 * The permission name (e.g. "view all contacts").
75 public function check($perm) {
76 return (isset($this->idx
['administer CiviCRM']) ||
isset($this->idx
[$perm]));
80 * Generate an optimized index of granted permissions.
82 * @param array $grants
83 * Array(string $permName).
85 * Array(string $permName => bool $granted).
87 protected function index($grants) {
89 foreach ($grants as $grant) {
90 foreach ($grant as $perm) {