mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added authorize-*@: support for Flex blueprints
This commit is contained in:
parent
5d2dc6c329
commit
6882037b85
|
|
@ -1,3 +1,9 @@
|
|||
# v1.7.36
|
||||
## mm/dd/2022
|
||||
|
||||
1. [](#new)
|
||||
* Added `authorize-*@:` support for Flex blueprints, e.g. `authorize-disabled@: not delete` disables the field if user does not have access to delete objec
|
||||
|
||||
# v1.7.35
|
||||
## 08/04/2022
|
||||
|
||||
|
|
|
|||
|
|
@ -836,6 +836,9 @@ class FlexDirectory implements FlexDirectoryInterface
|
|||
$blueprint->addDynamicHandler('flex', function (array &$field, $property, array &$call) {
|
||||
$this->dynamicFlexField($field, $property, $call);
|
||||
});
|
||||
$blueprint->addDynamicHandler('authorize', function (array &$field, $property, array &$call) {
|
||||
$this->dynamicAuthorizeField($field, $property, $call);
|
||||
});
|
||||
|
||||
if ($context) {
|
||||
$blueprint->setContext($context);
|
||||
|
|
@ -921,6 +924,34 @@ class FlexDirectory implements FlexDirectoryInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $field
|
||||
* @param string $property
|
||||
* @param array $call
|
||||
* @return void
|
||||
*/
|
||||
protected function dynamicAuthorizeField(array &$field, $property, array $call): void
|
||||
{
|
||||
$params = (array)$call['params'];
|
||||
$object = $call['object'] ?? null;
|
||||
$permission = array_shift($params);
|
||||
$not = false;
|
||||
if (str_starts_with($permission, '!')) {
|
||||
$permission = substr($permission, 1);
|
||||
$not = true;
|
||||
} elseif (str_starts_with($permission, 'not ')) {
|
||||
$permission = substr($permission, 4);
|
||||
$not = true;
|
||||
}
|
||||
$permission = trim($permission);
|
||||
|
||||
if ($object) {
|
||||
$value = $object->isAuthorized($permission) ?? false;
|
||||
|
||||
$field[$property] = $not ? !$value : $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user