mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 04:06:51 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Http\Requests\Api\Client\Servers\Schedules;
 | 
						|
 | 
						|
use App\Models\Task;
 | 
						|
use App\Models\Server;
 | 
						|
use App\Models\Schedule;
 | 
						|
use App\Models\Permission;
 | 
						|
use App\Http\Requests\Api\Client\ClientApiRequest;
 | 
						|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 | 
						|
 | 
						|
class ViewScheduleRequest extends ClientApiRequest
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Determine if this resource can be viewed.
 | 
						|
     */
 | 
						|
    public function authorize(): bool
 | 
						|
    {
 | 
						|
        if (!parent::authorize()) {
 | 
						|
            return false;
 | 
						|
        }
 | 
						|
 | 
						|
        $server = $this->route()->parameter('server');
 | 
						|
        $schedule = $this->route()->parameter('schedule');
 | 
						|
 | 
						|
        // If the schedule does not belong to this server throw a 404 error. Also throw an
 | 
						|
        // error if the task being requested does not belong to the associated schedule.
 | 
						|
        if ($server instanceof Server && $schedule instanceof Schedule) {
 | 
						|
            $task = $this->route()->parameter('task');
 | 
						|
 | 
						|
            if ($schedule->server_id !== $server->id || ($task instanceof Task && $task->schedule_id !== $schedule->id)) {
 | 
						|
                throw new NotFoundHttpException('The requested resource does not exist on the system.');
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    public function permission(): string
 | 
						|
    {
 | 
						|
        return Permission::ACTION_SCHEDULE_READ;
 | 
						|
    }
 | 
						|
}
 |