2020-04-29 07:25:13 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Facades\Permissions;
|
|
|
|
use App\Models\Device;
|
2020-09-21 14:54:51 +02:00
|
|
|
use App\Models\User;
|
2020-04-29 07:25:13 -05:00
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
|
|
|
class DevicePolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view any devices.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function viewAny(User $user): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view the device.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function view(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
2020-05-06 09:12:33 -05:00
|
|
|
return $this->viewAny($user) || Permissions::canAccessDevice($device, $user);
|
2020-04-29 07:25:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can create devices.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function create(User $user): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can update the device.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function update(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->isAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can delete the device.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function delete(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->isAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can restore the device.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function restore(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->hasGlobalAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can permanently delete the device.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function forceDelete(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->isAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view the stored configuration of the device
|
|
|
|
* from Oxidized or Rancid
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-04-29 07:25:13 -05:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function showConfig(User $user, Device $device): bool
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
return $user->isAdmin();
|
|
|
|
}
|
2020-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can update device notes.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Device $device
|
2020-07-22 16:18:56 +02:00
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function updateNotes(User $user, Device $device): bool
|
2020-07-22 16:18:56 +02:00
|
|
|
{
|
|
|
|
return $user->isAdmin();
|
|
|
|
}
|
2020-04-29 07:25:13 -05:00
|
|
|
}
|