3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
37 * This supplements the permissions of the CMS system, allowing us
38 * to temporarily acknowledge permission grants for API keys.
40 * In normal usage, the class isn't even instantiated - it's only
41 * used when processing certain API backends.
43 class CRM_Core_Permission_Temp
{
44 public static $id = 0;
47 * Array(int $grantId => array($perm))
60 * Grant permissions temporarily.
62 * @param string|array $perms
63 * List of permissions to apply.
65 * A handle for the grant. Useful for revoking later on.
67 public function grant($perms) {
68 $perms = (array) $perms;
70 $this->grants
[$id] = $perms;
71 $this->idx
= $this->index($this->grants
);
76 * Revoke a previously granted permission.
78 * @param string|int $id
79 * The handle previously returned by grant().
81 public function revoke($id) {
82 unset($this->grants
[$id]);
83 $this->idx
= $this->index($this->grants
);
87 * Determine if a permission has been granted.
90 * The permission name (e.g. "view all contacts").
93 public function check($perm) {
94 return (isset($this->idx
['administer CiviCRM']) ||
isset($this->idx
[$perm]));
98 * Generate an optimized index of granted permissions.
100 * @param array $grants
101 * Array(string $permName).
103 * Array(string $permName => bool $granted).
105 protected function index($grants) {
107 foreach ($grants as $grant) {
108 foreach ($grant as $perm) {