Added UserObject::$authorizeCallable to allow $user->authorize() customization

This commit is contained in:
Matias Griese
2021-07-29 23:09:25 +03:00
parent c5dfa65994
commit def389356e
2 changed files with 14 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
1. [](#new)
* Include active form and request in `onPageTask` and `onPageAction` events (defaults to `null`)
* Added `UserObject::$authorizeCallable` to allow `$user->authorize()` customization
1. [](#improved)
* Added meta support for `UploadedFile` class
* Add `setCurrent()` method to Page Collection [#3398](https://github.com/getgrav/grav/pull/3398)

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Grav\Common\Flex\Types\Users;
use Closure;
use Countable;
use Grav\Common\Config\Config;
use Grav\Common\Data\Blueprint;
@@ -75,6 +76,9 @@ class UserObject extends FlexObject implements UserInterface, Countable
use UserTrait;
use UserObjectLegacyTrait;
/** @var Closure|null */
static public $authorizeCallable;
/** @var array|null */
protected $_uploads_original;
/** @var FileInterface|null */
@@ -259,6 +263,15 @@ class UserObject extends FlexObject implements UserInterface, Countable
}
}
$authorizeCallable = static::$authorizeCallable;
if ($authorizeCallable instanceof Closure) {
$authorizeCallable->bindTo($this);
$authorized = $authorizeCallable($action, $scope);
if (is_bool($authorized)) {
return $authorized;
}
}
// Check user access.
$access = $this->getAccess();
$authorized = $access->authorize($action, $scope);