Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ModuleAccessLevel
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
6 / 6
15
100.00% covered (success)
100.00%
1 / 1
 isPublic
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 allowsPublicRead
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 allowsPublicEdit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 allowsPublicDelete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 label
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 description
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Access\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Defines module-level base access policy tiers.
13 *
14 * @package App\Core\Access\Domain\Model
15 */
16enum ModuleAccessLevel: string
17{
18    case PUBLIC_READ = 'public_read';
19    case PUBLIC_EDIT = 'public_edit';
20    case PUBLIC_DELETE = 'public_delete';
21    case PRIVATE = 'private';
22
23    /**
24     * Checks if this level allows any public access.
25     *
26     * @return bool True if level is not strictly private.
27     */
28    public function isPublic(): bool
29    {
30        return $this !== self::PRIVATE;
31    }
32
33    /**
34     * Checks if actor can view unassigned records under this level.
35     *
36     * @return bool True if read access is granted to all authenticated actors.
37     */
38    public function allowsPublicRead(): bool
39    {
40        return $this !== self::PRIVATE;
41    }
42
43    /**
44     * Checks if actor can edit unassigned records under this level.
45     *
46     * @return bool True if public edit is granted.
47     */
48    public function allowsPublicEdit(): bool
49    {
50        return $this === self::PUBLIC_EDIT || $this === self::PUBLIC_DELETE;
51    }
52
53    /**
54     * Checks if actor can delete unassigned records under this level.
55     *
56     * @return bool True if public delete is granted.
57     */
58    public function allowsPublicDelete(): bool
59    {
60        return $this === self::PUBLIC_DELETE;
61    }
62
63    /**
64     * Returns human-readable label.
65     *
66     * @return string Label in English.
67     */
68    public function label(): string
69    {
70        return match ($this) {
71            self::PUBLIC_READ => 'Public: View',
72            self::PUBLIC_EDIT => 'Public: Edit',
73            self::PUBLIC_DELETE => 'Public: Delete',
74            self::PRIVATE => 'Private',
75        };
76    }
77
78    /**
79     * Returns detailed description of the access tier behavior.
80     *
81     * @return string Description text in English.
82     */
83    public function description(): string
84    {
85        return match ($this) {
86            self::PUBLIC_READ => 'Everyone can view unassigned records, without edit/delete permissions.',
87            self::PUBLIC_EDIT => 'Everyone can view and edit unassigned records, without delete permissions.',
88            self::PUBLIC_DELETE => 'Everyone can view, edit and delete any records in the module.',
89            self::PRIVATE => 'Access restricted to own records, structure units and defined rules.',
90        };
91    }
92}