Passed
Push — master ( 453af3...b6447c )
by Darko
09:30
created

ThreadPolicy::view()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Policies;
4
5
use TeamTeaTime\Forum\Models\Thread;
6
7
class ThreadPolicy extends \TeamTeaTime\Forum\Policies\ThreadPolicy
8
{
9
    public function view($user, Thread $thread): bool
10
    {
11
        // Everyone (including Admin) can view by default
12
        return parent::view($user, $thread);
13
    }
14
15
    public function rename($user, Thread $thread): bool
16
    {
17
        // Admins can rename any thread; users can rename their own
18
        return $user->hasRole('Admin') || ($user->getKey() === $thread->author_id);
0 ignored issues
show
Bug introduced by
The property author_id does not seem to exist on TeamTeaTime\Forum\Models\Thread. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
19
    }
20
21
    public function reply($user, Thread $thread): bool
22
    {
23
        // Admins can reply even if locked; otherwise respect lock state
24
        return $user->hasRole('Admin') || (! $thread->locked);
25
    }
26
27
    public function delete($user, Thread $thread): bool
28
    {
29
        // Admins can delete any thread; users can delete their own
30
        return $user->hasRole('Admin') || ($user->getKey() === $thread->author_id);
0 ignored issues
show
Bug introduced by
The property author_id does not seem to exist on TeamTeaTime\Forum\Models\Thread. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
31
    }
32
33
    public function restore($user, Thread $thread): bool
34
    {
35
        // Admins can restore any thread; users can restore their own
36
        return $user->hasRole('Admin') || ($user->getKey() === $thread->author_id);
0 ignored issues
show
Bug introduced by
The property author_id does not seem to exist on TeamTeaTime\Forum\Models\Thread. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
37
    }
38
39
    public function deletePosts($user, Thread $thread): bool
40
    {
41
        // Admins can delete posts in any thread; otherwise fall back to default (true)
42
        return $user->hasRole('Admin') || parent::deletePosts($user, $thread);
43
    }
44
45
    public function restorePosts($user, Thread $thread): bool
46
    {
47
        // Admins can restore posts in any thread; otherwise fall back to default (true)
48
        return $user->hasRole('Admin') || parent::restorePosts($user, $thread);
49
    }
50
}
51