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 Tinyissue\Contracts\Model\UserInterface; |
15
|
|
|
use Tinyissue\Extensions\Policies\ProjectAccess; |
16
|
|
|
use Tinyissue\Model\Project; |
17
|
|
|
use Tinyissue\Model\User; |
18
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ProjectPolicy. |
22
|
|
|
* View: member of the project and manager role. |
23
|
|
|
* Create: admin role. |
24
|
|
|
* Update: admin role. |
25
|
|
|
* Delete: admin role. |
26
|
|
|
* |
27
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class ProjectPolicy |
30
|
|
|
{ |
31
|
|
|
use HandlesAuthorization, ProjectAccess; |
32
|
|
|
|
33
|
|
View Code Duplication |
public function before(UserInterface $user) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
36
|
|
|
if ($user instanceof UserInterface && ($user->isAdmin() || $user->isManager())) { |
37
|
|
|
return true; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Determine whether the user can view the project. |
43
|
|
|
* |
44
|
|
|
* @param User $user |
45
|
|
|
* @param Project $project |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function view(User $user, Project $project) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
if ($this->isPublicProject($project) || $project->isMember($user->id)) { |
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Determine whether the user can create projects. |
60
|
|
|
* |
61
|
|
|
* @param User $user |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
public function create(User $user) |
65
|
|
|
{ |
66
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
67
|
|
|
return $user->isAdmin(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Determine whether the user can update the project. |
72
|
|
|
* |
73
|
|
|
* @param User $user |
74
|
|
|
* @return mixed |
75
|
|
|
*/ |
76
|
|
|
public function update(User $user) |
77
|
|
|
{ |
78
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
79
|
|
|
return $this->create($user); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Determine whether the user can delete the project. |
84
|
|
|
* |
85
|
|
|
* @param User $user |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
|
|
public function delete(User $user) |
89
|
|
|
{ |
90
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
91
|
|
|
return $this->create($user); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function export(User $user) |
95
|
|
|
{ |
96
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
97
|
|
|
return $user->isAdmin() || $user->isManager(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function viewInactiveUsers(User $user, Project $project = null) |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
103
|
|
|
|
104
|
|
|
return $user->isUser(); // TODO check this!!!! |
105
|
|
|
$this->dd(__METHOD__); |
|
|
|
|
106
|
|
|
if ($this->isPublicProject($project) || $project->isMember($user->id)) { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return false; |
111
|
|
|
} |
112
|
|
|
//inactiveUsers |
113
|
|
|
} |
114
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.