Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2019-04-22 19:01:39 -05:00
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the user.
*
2021-03-24 15:13:43 +01:00
* @param User $user
* @param User $target
2019-04-22 19:01:39 -05:00
*/
public function view(User $user, User $target): ?bool
2020-05-23 19:05:18 +02:00
{
return $target->is($user) ?: null; // allow users to view themselves
2020-05-23 19:05:18 +02:00
}
2019-04-22 19:01:39 -05:00
/**
* Determine whether the user can create users.
*
2021-03-24 15:13:43 +01:00
* @param User $user
2019-04-22 19:01:39 -05:00
*/
public function create(User $user): ?bool
2019-04-22 19:01:39 -05:00
{
// if not mysql, forbid, otherwise defer to bouncer
if (\LibreNMS\Config::get('auth_mechanism') != 'mysql') {
return false;
}
return null;
2019-04-22 19:01:39 -05:00
}
/**
* Determine whether the user can update the user.
*
2021-03-24 15:13:43 +01:00
* @param User $user
* @param User $target
2019-04-22 19:01:39 -05:00
*/
public function update(User $user, User $target = null): ?bool
2019-04-22 19:01:39 -05:00
{
if ($target == null) {
return null;
}
return $target->is($user) ?: null; // allow user to update self or defer to bouncer
2019-04-22 19:01:39 -05:00
}
/**
* Determine whether the user can delete the user.
*
2021-03-24 15:13:43 +01:00
* @param User $user
* @param User $target
2019-04-22 19:01:39 -05:00
*/
public function delete(User $user, User $target): ?bool
2019-04-22 19:01:39 -05:00
{
return $target->is($user) ? false : null; // do not allow users to delete themselves or defer to bouncer
2019-04-22 19:01:39 -05:00
}
}