-
Notifications
You must be signed in to change notification settings - Fork 16
/
CheckoutPolicy.php
74 lines (64 loc) · 1.82 KB
/
CheckoutPolicy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace App\Policies;
use App\Models\Checkout;
use App\Models\Role;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class CheckoutPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the checkout.
*/
public function view(User $user, Checkout $checkout): bool
{
return $user->isCollegist();
}
/**
* Determine whether the user can create a transaction in the given checkout.
*/
public function createTransaction(User $user, Checkout $checkout): bool
{
if ($checkout->name === Checkout::STUDENTS_COUNCIL) {
//everyone can create transactions that is not in checkout
//the checkout administrator can handle these later
return $user->isCollegist();
}
if ($checkout->name === Checkout::ADMIN) {
return $user->isAdmin();
}
return false;
}
/**
* Determine whether the user can make kkt/netreg transactions.
*/
public function addKKTNetreg(User $user): bool
{
return $user->hasRole([
Role::SYS_ADMIN,
Role::KKT_HANDLER,
Role::STUDENT_COUNCIL => [
Role::ECONOMIC_VICE_PRESIDENT,
],
]);
}
/**
* Determine whether the user can calculate the workshop balance.
*/
public function calculateWorkshopBalance(User $user): bool
{
return $user->hasRole([
Role::SYS_ADMIN,
Role::STUDENT_COUNCIL => [
Role::ECONOMIC_VICE_PRESIDENT,
]
]);
}
/**
* Determine whether the user can administrate the given checkout.
*/
public function administrate(User $user, Checkout $checkout): bool
{
return $checkout->handler?->id == $user->id;
}
}