Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ChangePermissionsCommand | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
5.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| withRecursion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRoot | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPrivilegesPerUser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isRecursive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoDacSimple\model\Command; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | |
| 27 | /** |
| 28 | * Holds data about permission changes to be done in a resource. |
| 29 | * |
| 30 | * By default, the command is set up to apply a given set of ACLs to a single |
| 31 | * resource designated as the command's root. However, it also provides methods |
| 32 | * to change its recursion settings after the command creation, making |
| 33 | * PermissionsService to operate recursively or to modify class instances under |
| 34 | * the root resource in case the root itself is a class. |
| 35 | */ |
| 36 | class ChangePermissionsCommand |
| 37 | { |
| 38 | private core_kernel_classes_Resource $root; |
| 39 | |
| 40 | /** |
| 41 | * An array in the form ['userId' => ['READ', 'WRITE'], ...] |
| 42 | * |
| 43 | * @var string[] |
| 44 | */ |
| 45 | private array $privilegesPerUser; |
| 46 | |
| 47 | private bool $isRecursive; |
| 48 | |
| 49 | /** |
| 50 | * @param array $privilegesPerUser An array in the form ['userId' => ['READ', 'WRITE'], ...] |
| 51 | */ |
| 52 | public function __construct(core_kernel_classes_Resource $root, array $privilegesPerUser, bool $isRecursive = false) |
| 53 | { |
| 54 | $this->root = $root; |
| 55 | $this->privilegesPerUser = $privilegesPerUser; |
| 56 | $this->isRecursive = $isRecursive; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Sets the isRecursive flag for the command. |
| 61 | * |
| 62 | * For commands having a class as the root, setting the recursion flag |
| 63 | * makes PermissionsService to update permissions for the class and all its |
| 64 | * descendants (i.e. updates all resources AND classes using the provided |
| 65 | * root class as the initial node for a tree traversal, which may be slow |
| 66 | * and resource-intensive). |
| 67 | * |
| 68 | * This is provided for backward compatibility purposes. |
| 69 | */ |
| 70 | public function withRecursion(): void |
| 71 | { |
| 72 | $this->isRecursive = true; |
| 73 | } |
| 74 | |
| 75 | public function getRoot(): core_kernel_classes_Resource |
| 76 | { |
| 77 | return $this->root; |
| 78 | } |
| 79 | |
| 80 | public function getPrivilegesPerUser(): array |
| 81 | { |
| 82 | return $this->privilegesPerUser; |
| 83 | } |
| 84 | |
| 85 | public function isRecursive(): bool |
| 86 | { |
| 87 | return $this->isRecursive; |
| 88 | } |
| 89 | } |