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
|
<?php
namespace JsonApi\Routes\Consultations;
use JsonApi\Schemas\ConsultationBooking;
final class Authority
{
public static function canShowRange(\User $user, \Range $range): bool
{
return $range->isAccessibleToUser($user->id);
}
public static function canEditRange(\User $user, \Range $range): bool
{
return $range->isEditableByUser($user->id);
}
public static function canShowBlock(\User $user, \ConsultationBlock $block): bool
{
return self::canShowRange($user, $block->range);
}
public static function canEditBlock(\User $user, \ConsultationBlock $block): bool
{
return self::canEditRange($user, $block->range);
}
public static function canShowSlot(\User $user, \ConsultationSlot $slot): bool
{
return self::canShowBlock($user, $slot->block);
}
public static function canEditSlot(\User $user, \ConsultationSlot $slot): bool
{
return self::canEditBlock($user, $slot->block);
}
public static function canBookSlot(\User $user, \ConsultationSlot $slot): bool
{
return \ConsultationBooking::userMayCreateBookingForRange(
$slot->block->range,
$user
);
}
public static function canBookSlotForUser(\User $user, \ConsultationSlot $slot, \User $booking_user): bool
{
if ($user->id !== $booking_user->id && !self::canEditSlot($user, $slot)) {
return false;
}
return self::canBookSlot($booking_user, $slot);
}
public static function canShowBooking(\User $user, \ConsultationBooking $booking): bool
{
return self::canShowSlot($user, $booking->slot)
|| $booking->user_id === $user->id;
}
public static function canEditBooking(\User $user, \ConsultationBooking $booking): bool
{
return self::canEditSlot($user, $booking->slot)
|| $booking->user_id === $user->id;
}
}
|