Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| PermissionSet | |
100.00% |
24 / 24 |
|
100.00% |
9 / 9 |
13 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| isEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| setPolicyJson | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDecodedPolicyJson | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| setCreatedAt | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getCreatedAt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUpdatedAt | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getUpdatedAt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Db; |
| 10 | |
| 11 | use OCP\AppFramework\Db\Entity; |
| 12 | use OCP\DB\Types; |
| 13 | use function json_decode; |
| 14 | use function json_encode; |
| 15 | |
| 16 | /** |
| 17 | * @method void setId(int $id) |
| 18 | * @method int getId() |
| 19 | * @method void setName(string $name) |
| 20 | * @method string getName() |
| 21 | * @method void setDescription(?string $description) |
| 22 | * @method ?string getDescription() |
| 23 | * @method void setScopeType(string $scopeType) |
| 24 | * @method string getScopeType() |
| 25 | * @method void setEnabled(bool $enabled) |
| 26 | * @method void setPriority(int $priority) |
| 27 | * @method int getPriority() |
| 28 | * @method void setCreatedAt(\DateTime|string $createdAt) |
| 29 | * @method ?\DateTime getCreatedAt() |
| 30 | * @method void setUpdatedAt(\DateTime|string $updatedAt) |
| 31 | * @method ?\DateTime getUpdatedAt() |
| 32 | */ |
| 33 | class PermissionSet extends Entity { |
| 34 | protected string $name = ''; |
| 35 | protected ?string $description = null; |
| 36 | protected string $scopeType = 'organization'; |
| 37 | protected int $enabled = 1; |
| 38 | protected int $priority = 0; |
| 39 | protected string $policyJson = '{}'; |
| 40 | protected ?\DateTime $createdAt = null; |
| 41 | protected ?\DateTime $updatedAt = null; |
| 42 | |
| 43 | public function __construct() { |
| 44 | $this->addType('id', Types::INTEGER); |
| 45 | $this->addType('name', Types::STRING); |
| 46 | $this->addType('description', Types::TEXT); |
| 47 | $this->addType('scopeType', Types::STRING); |
| 48 | $this->addType('enabled', Types::SMALLINT); |
| 49 | $this->addType('priority', Types::SMALLINT); |
| 50 | $this->addType('policyJson', Types::TEXT); |
| 51 | $this->addType('createdAt', Types::DATETIME); |
| 52 | $this->addType('updatedAt', Types::DATETIME); |
| 53 | } |
| 54 | |
| 55 | public function isEnabled(): bool { |
| 56 | return $this->enabled === 1; |
| 57 | } |
| 58 | |
| 59 | public function setEnabled(bool $enabled): void { |
| 60 | $this->setter('enabled', [$enabled ? 1 : 0]); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param array<string, mixed> $policyJson |
| 65 | */ |
| 66 | public function setPolicyJson(array $policyJson): void { |
| 67 | $this->setter('policyJson', [json_encode($policyJson, JSON_THROW_ON_ERROR)]); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return array<string, mixed> |
| 72 | */ |
| 73 | public function getDecodedPolicyJson(): array { |
| 74 | $decoded = json_decode($this->policyJson, true); |
| 75 | return is_array($decoded) ? $decoded : []; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @param \DateTime|string $createdAt |
| 80 | */ |
| 81 | public function setCreatedAt($createdAt): void { |
| 82 | if (!$createdAt instanceof \DateTime) { |
| 83 | $createdAt = new \DateTime($createdAt, new \DateTimeZone('UTC')); |
| 84 | } |
| 85 | $this->createdAt = $createdAt; |
| 86 | $this->markFieldUpdated('createdAt'); |
| 87 | } |
| 88 | |
| 89 | public function getCreatedAt(): ?\DateTime { |
| 90 | return $this->createdAt; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @param \DateTime|string $updatedAt |
| 95 | */ |
| 96 | public function setUpdatedAt($updatedAt): void { |
| 97 | if (!$updatedAt instanceof \DateTime) { |
| 98 | $updatedAt = new \DateTime($updatedAt, new \DateTimeZone('UTC')); |
| 99 | } |
| 100 | $this->updatedAt = $updatedAt; |
| 101 | $this->markFieldUpdated('updatedAt'); |
| 102 | } |
| 103 | |
| 104 | public function getUpdatedAt(): ?\DateTime { |
| 105 | return $this->updatedAt; |
| 106 | } |
| 107 | } |