mirror of
https://github.com/getgrav/grav.git
synced 2026-07-04 10:57:30 +02:00
Deprecated Grav\Common\User\Group in favor of $grav['user_groups'], which contains Flex UserGroup collection
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* Added new `-r <job-id>` option for Scheduler CLI command to force-run a job [#2720](https://github.com/getgrav/grav/issues/2720)
|
||||
* Added `Utils::isAssoc()` and `Utils::isNegative()` helper methods
|
||||
* Changed `UserInterface::authorize()` to return `null` having the same meaning as `false` if access is denied because of no matching rule
|
||||
* Moved all Flex type classes under `Grav\Common\Flex`
|
||||
* Deprecated `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection
|
||||
1. [](#improved)
|
||||
* Improved twig `|array` filter to work with iterators and objects with `toArray()` method
|
||||
* Updated Flex `SimpleStorage` code to feature match the other storages
|
||||
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Grav\Common\Flex\UserGroups;
|
||||
|
||||
use Grav\Common\User\Access;
|
||||
use Grav\Common\User\Interfaces\UserGroupInterface;
|
||||
use Grav\Framework\Flex\FlexObject;
|
||||
use Grav\Framework\Flex\Traits\FlexAuthorizeTrait;
|
||||
|
||||
@@ -23,7 +24,7 @@ use Grav\Framework\Flex\Traits\FlexAuthorizeTrait;
|
||||
* @property string $groupname
|
||||
* @property Access $access
|
||||
*/
|
||||
class UserGroup extends FlexObject
|
||||
class UserGroup extends FlexObject implements UserGroupInterface
|
||||
{
|
||||
use FlexAuthorizeTrait;
|
||||
|
||||
|
||||
@@ -16,15 +16,21 @@ use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
|
||||
/**
|
||||
* @deprecated 1.7 Use $grav['user_groups'] instead of this class. In type hints, please use UserGroupInterface.
|
||||
*/
|
||||
class Group extends Data
|
||||
{
|
||||
/**
|
||||
* Get the groups list
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
|
||||
*/
|
||||
private static function groups()
|
||||
{
|
||||
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
|
||||
|
||||
return Grav::instance()['config']->get('groups', []);
|
||||
}
|
||||
|
||||
@@ -32,9 +38,12 @@ class Group extends Data
|
||||
* Get the groups list
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
|
||||
*/
|
||||
public static function groupNames()
|
||||
{
|
||||
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
|
||||
|
||||
$groups = [];
|
||||
|
||||
foreach (static::groups() as $groupname => $group) {
|
||||
@@ -48,11 +57,13 @@ class Group extends Data
|
||||
* Checks if a group exists
|
||||
*
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
|
||||
*/
|
||||
public static function groupExists($groupname)
|
||||
{
|
||||
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
|
||||
|
||||
return isset(self::groups()[$groupname]);
|
||||
}
|
||||
|
||||
@@ -60,11 +71,13 @@ class Group extends Data
|
||||
* Get a group by name
|
||||
*
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return object
|
||||
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
|
||||
*/
|
||||
public static function load($groupname)
|
||||
{
|
||||
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
|
||||
|
||||
$groups = self::groups();
|
||||
|
||||
$content = $groups[$groupname] ?? [];
|
||||
@@ -125,11 +138,13 @@ class Group extends Data
|
||||
* Remove a group
|
||||
*
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return bool True if the action was performed
|
||||
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
|
||||
*/
|
||||
public static function remove($groupname)
|
||||
{
|
||||
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
|
||||
|
||||
$grav = Grav::instance();
|
||||
|
||||
/** @var Config $config */
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Common\User
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common\User\Interfaces;
|
||||
|
||||
/**
|
||||
* Interface AuthorizeInterface
|
||||
* @package Grav\Common\User\Interfaces
|
||||
*/
|
||||
interface AuthorizeInterface
|
||||
{
|
||||
/**
|
||||
* Checks user authorization to the action.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string|null $scope
|
||||
* @return bool|null
|
||||
*/
|
||||
public function authorize(string $action, string $scope = null): ?bool;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Common\User
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common\User\Interfaces;
|
||||
|
||||
/**
|
||||
* Interface UserGroupInterface
|
||||
* @package Grav\Common\User\Interfaces
|
||||
*/
|
||||
interface UserGroupInterface extends AuthorizeInterface
|
||||
{
|
||||
}
|
||||
@@ -30,7 +30,7 @@ use RocketTheme\Toolbox\ArrayTraits\ExportInterface;
|
||||
* @property bool $authenticated
|
||||
* @property bool $authorized
|
||||
*/
|
||||
interface UserInterface extends DataInterface, MediaInterface, \ArrayAccess, \JsonSerializable, ExportInterface
|
||||
interface UserInterface extends AuthorizeInterface, DataInterface, MediaInterface, \ArrayAccess, \JsonSerializable, ExportInterface
|
||||
{
|
||||
/**
|
||||
* @param array $items
|
||||
@@ -172,15 +172,6 @@ interface UserInterface extends DataInterface, MediaInterface, \ArrayAccess, \Js
|
||||
*/
|
||||
public function authenticate(string $password): bool;
|
||||
|
||||
/**
|
||||
* Checks user authorization to the action.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string|null $scope
|
||||
* @return bool|null
|
||||
*/
|
||||
public function authorize(string $action, string $scope = null): ?bool;
|
||||
|
||||
/**
|
||||
* Return media object for the User's avatar.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,7 @@ if (defined('GRAV_USER_INSTANCE') && GRAV_USER_INSTANCE === 'FLEX') {
|
||||
/**
|
||||
* @deprecated 1.6 Use $grav['accounts'] instead of static calls. In type hints, please use UserInterface.
|
||||
*/
|
||||
class User extends Flex\User
|
||||
class User extends Flex\Users\User
|
||||
{
|
||||
/**
|
||||
* Load user account.
|
||||
|
||||
Reference in New Issue
Block a user