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
21 * This supplements the permissions of the CMS system, allowing us
22 * to temporarily acknowledge permission grants for API keys.
24 * In normal usage, the class isn't even instantiated - it's only
25 * used when processing certain API backends.
27 class CRM_Core_Permission_Temp
{
28 public static $id = 0;
31 * Array(int $grantId => array($perm))
44 * Grant permissions temporarily.
46 * @param string|array $perms
47 * List of permissions to apply.
49 * A handle for the grant. Useful for revoking later on.
51 public function grant($perms) {
52 $perms = (array) $perms;
54 $this->grants
[$id] = $perms;
55 $this->idx
= $this->index($this->grants
);
60 * Revoke a previously granted permission.
62 * @param string|int $id
63 * The handle previously returned by grant().
65 public function revoke($id) {
66 unset($this->grants
[$id]);
67 $this->idx
= $this->index($this->grants
);
71 * Determine if a permission has been granted.
74 * The permission name (e.g. "view all contacts").
77 public function check($perm) {
78 return (isset($this->idx
['administer CiviCRM']) ||
isset($this->idx
[$perm]));
82 * Generate an optimized index of granted permissions.
84 * @param array $grants
85 * Array(string $permName).
87 * Array(string $permName => bool $granted).
89 protected function index($grants) {
91 foreach ($grants as $grant) {
92 foreach ($grant as $perm) {