mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 00:17:24 +02:00
Added UserObject::$authorizeCallable to allow $user->authorize() customization
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user