2020-05-06 09:12:33 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Facades\Permissions;
|
|
|
|
use App\Models\Port;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
|
|
|
class PortPolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view any ports.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function viewAny(User $user): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view the port.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Port $port
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function view(User $user, Port $port): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $this->viewAny($user) || Permissions::canAccessDevice($port->device_id, $user) || Permissions::canAccessPort($port, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can create ports.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function create(User $user): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can update the port.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Port $port
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function update(User $user, Port $port): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can delete the port.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Port $port
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function delete(User $user, Port $port): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can restore the port.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Port $port
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function restore(User $user, Port $port): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can permanently delete the port.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Port $port
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function forceDelete(User $user, Port $port): bool
|
2020-05-06 09:12:33 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
}
|