| 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 AvailabilityPolicy 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 (PermissionManager::userCan(['manage_all_data', 'manage_other_availabilities'])) { |
| 19 |
return true; |
| 20 |
} |
| 21 |
|
| 22 |
if ($request->getMethod() == 'GET' && PermissionManager::userCan('read_and_use_other_availabilities')) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
// Resolve the schedule from the URL route only — request-body values |
| 27 |
// must not be permitted to redirect the authorization target. |
| 28 |
$urlParams = (array) $request->get_url_params(); |
| 29 |
$scheduleId = isset($urlParams['schedule_id']) ? (int) $urlParams['schedule_id'] : 0; |
| 30 |
|
| 31 |
if ($scheduleId) { |
| 32 |
$availability = \FluentBooking\App\Models\Availability::find($scheduleId); |
| 33 |
|
| 34 |
if (!$availability) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
return (int)$availability->object_id === get_current_user_id(); |
| 39 |
} |
| 40 |
|
| 41 |
return PermissionManager::userCan('manage_own_calendar'); |
| 42 |
} |
| 43 |
} |
| 44 |
|