| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Http\Policies; |
| 4 |
|
| 5 |
use FluentBooking\App\Services\PermissionManager; |
| 6 |
use FluentBooking\Framework\Http\Request\Request; |
| 7 |
use FluentBooking\Framework\Foundation\Policy; |
| 8 |
|
| 9 |
class MeetingPolicy extends Policy |
| 10 |
{ |
| 11 |
/** |
| 12 |
* Check user permission for any method |
| 13 |
* @param \FluentBooking\Framework\Http\Request\Request $request |
| 14 |
* @return Boolean |
| 15 |
*/ |
| 16 |
public function verifyRequest(Request $request) |
| 17 |
{ |
| 18 |
if (current_user_can('manage_options')) { |
| 19 |
return true; |
| 20 |
} |
| 21 |
|
| 22 |
if ($request->method() == 'GET') { |
| 23 |
if (PermissionManager::userCan(['manage_own_calendar','read_all_bookings', 'manage_all_bookings'])) { |
| 24 |
return true; |
| 25 |
} |
| 26 |
if ($request->id) { |
| 27 |
$booking = \FluentBooking\App\Models\Booking::find($request->id); |
| 28 |
if (!$booking) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
return in_array(get_current_user_id(), $booking->getHostIds()); |
| 33 |
} |
| 34 |
|
| 35 |
return PermissionManager::userCan('manage_own_calendar'); |
| 36 |
} |
| 37 |
|
| 38 |
if (PermissionManager::userCan(['manage_own_calendar', 'manage_all_bookings'])) { |
| 39 |
return true; |
| 40 |
} |
| 41 |
|
| 42 |
if ($request->id) { |
| 43 |
$booking = \FluentBooking\App\Models\Booking::find($request->id); |
| 44 |
if (!$booking) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return in_array(get_current_user_id(), $booking->getHostIds()); |
| 49 |
} |
| 50 |
|
| 51 |
return PermissionManager::userCan('manage_own_calendar'); |
| 52 |
} |
| 53 |
|
| 54 |
public function getGroupAttendees(Request $request) |
| 55 |
{ |
| 56 |
if (current_user_can('manage_options')) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
if (PermissionManager::userCan(['read_all_bookings', 'manage_all_bookings'])) { |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
$booking = \FluentBooking\App\Models\Booking::where('group_id', $request->group_id)->first(); |
| 65 |
|
| 66 |
if (!$booking) { |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
return in_array(get_current_user_id(), $booking->getHostIds()); |
| 71 |
|
| 72 |
} |
| 73 |
} |
| 74 |
|