Boy132 03745eb4be
Allow to assign nodes to roles (node ownership) (#1231)
* 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>
2025-05-05 12:58:55 +02:00

28 lines
484 B
PHP

<?php
namespace App\Policies;
use App\Models\Node;
use App\Models\User;
class NodePolicy
{
use DefaultPolicies;
protected string $modelName = 'node';
public function before(User $user, string $ability, string|Node $node): ?bool
{
// For "viewAny" the $node param is the class name
if (is_string($node)) {
return null;
}
if (!$user->canTarget($node)) {
return false;
}
return null;
}
}