Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

IssuePolicy::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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\AdminAccess;
16
use Tinyissue\Extensions\Policies\ProjectAccess;
17
use Tinyissue\Model\Project;
18
use Tinyissue\Model\User;
19
use Tinyissue\Model\Project\Issue;
20
use Illuminate\Auth\Access\HandlesAuthorization;
21
22
/**
23
 * Class IssuePolicy.
24
 * View:   member of the project and manager role.
25
 * Create: admin role.
26
 * Update: admin role.
27
 * Delete: admin role.
28
 *
29
 * @author Mohamed Alsharaf <[email protected]>
30
 */
31
class IssuePolicy
32
{
33
    use HandlesAuthorization, ProjectAccess;
34
35
    public function before(UserInterface $user, $ability)
36
    {
37
        if ($ability !== 'viewLockedQuote' && $user instanceof UserInterface && ($user->isAdmin() || $user->isManager())) {
38
            return true;
39
        }
40
    }
41
42
    /**
43
     * Determine whether the user can view the issue.
44
     *
45
     * @param  User  $user
46
     * @param  Issue $issue
47
     *
48
     * @return mixed
49
     */
50
    public function view(User $user, Issue $issue, Project $project)
51
    {
52
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\IssuePolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        if ($this->isPublicProject($project)) {
54
            return true;
55
        }
56
57
        // not memeber
58
        if(!$project->isMember($user->id)) {
59
            return false;
60
        }
61
62
        if ($project->isPrivateInternal() && $user->isUser() && !$issue->isCreatedBy($user)) {
63
            return false;
64
        }
65
66
        return true;
67
    }
68
69
    /**
70
     * Determine whether the user can create issues.
71
     *
72
     * @param  User $user
73
     *
74
     * @return mixed
75
     */
76
    public function create(User $user, Project $project)
77
    {
78
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\IssuePolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
80
//        dd($project->isMember($user->id));
81
//        dump($project->isMember($user->id) || $project->isPublic());
82
        return $project->isMember($user->id) || $project->isPublic();
83
    }
84
85
    /**
86
     * Determine whether the user can update the issue.
87
     *
88
     * @param  User  $user
89
     * @param  Issue $issue
90
     *
91
     * @return mixed
92
     */
93
    public function update(User $user, Issue $issue, Project $project = null)
94
    {
95
//        dd('s');
96
//        $this->dd(func_get_args());
97
        dump($issue->hasReadOnlyTag($user));
98
        // Issue locked by read only tag
99
        if ($issue->hasReadOnlyTag($user)) {
100
            return false;
101
        }
102
103
        if ($issue->isCreatedBy($user)) {
104
            return true;
105
        }
106
107
        $project = is_null($project) ? $issue->project : $project;
108
109
        return $this->view($user, $issue, $project);
110
    }
111
112
    /**
113
     * Determine whether the user can delete the issue.
114
     *
115
     * @param  User  $user
116
     * @param  Issue $issue
117
     *
118
     * @return mixed
119
     */
120
    public function delete(User $user, Issue $issue)
121
    {
122
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\IssuePolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
124
        return $this->update($user, $issue);
125
    }
126
127
    public function lockQuote(User $user, Issue $issue, Project $project = null)
128
    {
129
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\IssuePolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
        return $this->update($user, $issue, $project);
131
    }
132
133
134
    /**
135
     * Check if a user is allowed to see the issue quote.
136
     *
137
     * @param UserInterface $user
138
     *
139
     * @return bool
140
     */
141
    public function viewLockedQuote(User $user, Issue $issue)
142
    {
143
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\IssuePolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
//        dd(($issue->time_quote > 0 && (!$issue->isQuoteLocked() || $user->isUser())));
145
        // Only manager, admin, & developer can view locked quote
146
        if ($issue->time_quote > 0 && (!$issue->isQuoteLocked() || $user->isUser())) {
147
            return true;
148
        }
149
150
        return false;
151
    }
152
}
153