
* allow to assign nodes to roles * fix typo * fix node policy * small ui improvements * add missing translation * make phpstan happy * fix migration on mysql * also restrict mounts & database hosts to allowed nodes * fix migration on mysql v2 * changes from review * fix hasManyThrough * change `accessibleNodes` to builder Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> --------- Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com>
30 lines
612 B
PHP
30 lines
612 B
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\DatabaseHost;
|
|
use App\Models\User;
|
|
|
|
class DatabaseHostPolicy
|
|
{
|
|
use DefaultPolicies;
|
|
|
|
protected string $modelName = 'databasehost';
|
|
|
|
public function before(User $user, string $ability, string|DatabaseHost $databaseHost): ?bool
|
|
{
|
|
// For "viewAny" the $databaseHost param is the class name
|
|
if (is_string($databaseHost)) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($databaseHost->nodes as $node) {
|
|
if (!$user->canTarget($node)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|