Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

ProjectPolicy::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Policies;
13
14
use Illuminate\Auth\Access\HandlesAuthorization;
15
use Tinyissue\Extensions\Policies\ProjectAccess;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\User;
18
19
class ProjectPolicy
20
{
21
    use HandlesAuthorization, ProjectAccess;
22
23
    /**
24
     * @param User $user
25
     *
26
     * @return bool
27
     */
28
    public function before(User $user)
29
    {
30
        if ($user instanceof User && ($user->isAdmin() || $user->isManager())) {
31
            return true;
32
        }
33
    }
34
35
    /**
36
     * Determine whether the user can view the project.
37
     *
38
     * @param User    $user
39
     * @param Project $project
40
     *
41
     * @return bool
42
     */
43
    public function view(User $user, Project $project)
44
    {
45
        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
46
            return true;
47
        }
48
49
        return false;
50
    }
51
52
    /**
53
     * Determine whether the user can create projects.
54
     *
55
     * @param User $user
56
     *
57
     * @return bool
58
     */
59
    public function create(User $user)
60
    {
61
        return $user->isAdmin();
62
    }
63
64
    /**
65
     * Determine whether the user can update the project.
66
     *
67
     * @param User $user
68
     *
69
     * @return bool
70
     */
71
    public function update(User $user)
72
    {
73
        return $this->create($user);
74
    }
75
76
    /**
77
     * Determine whether the user can delete the project.
78
     *
79
     * @param User $user
80
     *
81
     * @return bool
82
     */
83
    public function delete(User $user)
84
    {
85
        return $this->create($user);
86
    }
87
88
    /**
89
     * Can user export issues in project.
90
     *
91
     * @param User $user
92
     *
93
     * @return bool
94
     */
95
    public function export(User $user)
96
    {
97
        return $user->isAdmin() || $user->isManager();
98
    }
99
}
100