Added support for configurable actions in Flex

This commit is contained in:
Matias Griese
2019-04-24 17:14:44 +03:00
parent a4f679adcf
commit 4c5c26033a

View File

@@ -13,6 +13,7 @@ namespace Grav\Framework\Flex\Traits;
use Grav\Common\Grav;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Framework\Flex\FlexDirectory;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
/**
@@ -44,7 +45,11 @@ trait FlexAuthorizeTrait
$action = $this->exists() ? 'update' : 'create';
}
return $user->authorize(sprintf($this->_authorize, $scope, $action));
$directory = $this instanceof FlexDirectory ? $this : $this->getFlexDirectory();
$config = $directory->getConfig();
$allowed = $config->get("{$scope}.actions.{$action}") ?? $config->get("actions.{$action}") ?? true;
return $allowed && $user->authorize(sprintf($this->_authorize, $scope, $action));
}
protected function setAuthorizeRule(string $authorize) : void