ElementPolicy   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 15
dl 0
loc 74
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 0 4 2
A view() 0 8 4
A delete() 0 5 2
A update() 0 5 2
A create() 0 5 2
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\Access\User\User;
6
use App\Models\Element;
7
use App\Models\Elementset;
8
use Illuminate\Auth\Access\HandlesAuthorization;
9
10
class ElementPolicy
11
{
12
    use HandlesAuthorization;
13
14
    public function before(User $user)
15
    {
16
        if ($user->is_administrator) {
17
            return true;
18
        }
19
    }
20
21
    /**
22
     * Determine whether the user can view the element.
23
     *
24
     * @param  \App\Models\Access\User\User $user
25
     * @param  \App\Models\Element $element
26
     *
27
     * @return mixed
28
     */
29
    public function view(User $user, Element $element)
30
    {
31
        $project = $element->elementSet->project;
0 ignored issues
show
Bug introduced by
The property elementSet does not exist on App\Models\Element. Did you mean elementset?
Loading history...
32
        if ($project->is_private && $user->isMemberOfProject($project)) {
33
            return true;
34
        }
35
        if (! $project->is_private) {
36
            return true;
37
        }
38
    }
39
40
    /**
41
     * Determine whether the user can create elements.
42
     *
43
     * @param  \App\Models\Access\User\User $user
44
     *
45
     * @return mixed
46
     */
47
    public function create(User $user, Elementset $elementset)
48
    {
49
        //User must be one of: admin, projectadmin, elementSetadmin
50
        if ($user->isMaintainerForElementSet($elementset)) {
51
            return true;
52
        }
53
    }
54
55
    /**
56
     * Determine whether the user can update the element.
57
     *
58
     * @param  \App\Models\Access\User\User $user
59
     * @param  \App\Models\Element $element
60
     *
61
     * @return mixed
62
     */
63
    public function update(User $user, Element $element)
64
    {
65
        //User must be one of: admin, projectadmin, elementSetadmin
66
        if ($user->isMaintainerForElementSet($element->elementSet)) {
0 ignored issues
show
Bug introduced by
The property elementSet does not exist on App\Models\Element. Did you mean elementset?
Loading history...
67
            return true;
68
        }
69
    }
70
71
    /**
72
     * Determine whether the user can delete the element.
73
     *
74
     * @param  \App\Models\Access\User\User $user
75
     * @param  \App\Models\Element $element
76
     *
77
     * @return mixed
78
     */
79
    public function delete(User $user, Element $element)
80
    {
81
        //User must be one of: admin, projectadmin, elementSetadmin
82
        if ($user->isMaintainerForElementSet($element->elementSet)) {
0 ignored issues
show
Bug introduced by
The property elementSet does not exist on App\Models\Element. Did you mean elementset?
Loading history...
83
            return true;
84
        }
85
    }
86
}
87