mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 06:08:21 +01:00
Enh/default group permissions change (#7160)
* Groups - Default permissions/Space creation * Autocommit PHP CS Fixer * Groups - Default permissions/Space creation * Autocommit PHP CS Fixer * Groups - Default permissions/Space creation * Autocommit PHP CS Fixer --------- Co-authored-by: gevorgmansuryan <gevorgmansuryan@users.noreply.github.com>
This commit is contained in:
parent
c004785fda
commit
e303113792
@ -17,6 +17,7 @@ HumHub Changelog
|
|||||||
- Fix #7149: Fixed dropdown issue on mobile
|
- Fix #7149: Fixed dropdown issue on mobile
|
||||||
- Fix #7151: Disable new post's required validation for `message` when post has attached files
|
- Fix #7151: Disable new post's required validation for `message` when post has attached files
|
||||||
- Enh #7106: Enable option for non-member users of a space to create posts
|
- Enh #7106: Enable option for non-member users of a space to create posts
|
||||||
|
- Enh #7160: Default state set to Deny for `Create Private Spaces` and `Create Public Spaces` Groups permissions
|
||||||
|
|
||||||
1.16.2 (Unreleased)
|
1.16.2 (Unreleased)
|
||||||
---------------------
|
---------------------
|
||||||
|
@ -896,7 +896,7 @@ class StdClass extends \stdClass implements ArrayAccess, Stringable, SeekableIte
|
|||||||
protected static function validatedObject(): \stdClass
|
protected static function validatedObject(): \stdClass
|
||||||
{
|
{
|
||||||
if (self::$validatedObject === null) {
|
if (self::$validatedObject === null) {
|
||||||
self::$validatedObject = new class () extends \stdClass {
|
self::$validatedObject = new class extends \stdClass {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use humhub\libs\BasePermission;
|
||||||
|
use humhub\modules\space\permissions\CreatePrivateSpace;
|
||||||
|
use humhub\modules\space\permissions\CreatePublicSpace;
|
||||||
|
use humhub\modules\user\models\Group;
|
||||||
|
use humhub\modules\user\models\GroupPermission;
|
||||||
|
use yii\db\Migration;
|
||||||
|
use yii\db\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class m240807_230603_add_permissions_to_existing_user_groups
|
||||||
|
*/
|
||||||
|
class m240807_230603_add_permissions_to_existing_user_groups extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
if (Yii::$app->isInstalled()) {
|
||||||
|
foreach ((new Query())->from(Group::tableName())->batch() as $groups) {
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
foreach ([Yii::createObject(CreatePublicSpace::class), Yii::createObject(CreatePrivateSpace::class)] as $permission) {
|
||||||
|
/** @var BasePermission $permission */
|
||||||
|
|
||||||
|
$exist = (new Query())->from(GroupPermission::tableName())
|
||||||
|
->where([
|
||||||
|
'group_id' => $group['id'],
|
||||||
|
'module_id' => $permission->getModuleId(),
|
||||||
|
'class' => $permission::class,
|
||||||
|
])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (!$exist) {
|
||||||
|
Yii::$app->db->createCommand()->insert(
|
||||||
|
GroupPermission::tableName(),
|
||||||
|
[
|
||||||
|
'permission_id' => $permission->getId(),
|
||||||
|
'group_id' => $group['id'],
|
||||||
|
'module_id' => $permission->getModuleId(),
|
||||||
|
'class' => $permission::class,
|
||||||
|
'state' => $permission::STATE_ALLOW,
|
||||||
|
],
|
||||||
|
)->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
echo "m240807_230603_add_permissions_to_existing_user_groups cannot be reverted.\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -36,11 +36,6 @@ class CreatePrivateSpace extends BasePermission
|
|||||||
*/
|
*/
|
||||||
protected $moduleId = 'space';
|
protected $moduleId = 'space';
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
protected $defaultState = self::STATE_ALLOW;
|
|
||||||
|
|
||||||
public function __construct($config = [])
|
public function __construct($config = [])
|
||||||
{
|
{
|
||||||
parent::__construct($config);
|
parent::__construct($config);
|
||||||
|
@ -36,11 +36,6 @@ class CreatePublicSpace extends BasePermission
|
|||||||
*/
|
*/
|
||||||
protected $moduleId = 'space';
|
protected $moduleId = 'space';
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
protected $defaultState = self::STATE_ALLOW;
|
|
||||||
|
|
||||||
public function __construct($config = [])
|
public function __construct($config = [])
|
||||||
{
|
{
|
||||||
parent::__construct($config);
|
parent::__construct($config);
|
||||||
|
@ -28,7 +28,7 @@ use yii\web\HttpException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of PermissionManager
|
* Description of PermissionManager
|
||||||
*
|
* @property-read array $permissions
|
||||||
* @author luke
|
* @author luke
|
||||||
*/
|
*/
|
||||||
class PermissionManager extends Component
|
class PermissionManager extends Component
|
||||||
@ -490,6 +490,7 @@ class PermissionManager extends Component
|
|||||||
'contentContainer' => $permission->contentContainer,
|
'contentContainer' => $permission->contentContainer,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class DataTypeHelperTest extends Unit
|
|||||||
|
|
||||||
public function testClassTypeHelperCase3()
|
public function testClassTypeHelperCase3()
|
||||||
{
|
{
|
||||||
$value = new class () implements Stringable {
|
$value = new class implements Stringable {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
@ -117,7 +117,7 @@ class DataTypeHelperTest extends Unit
|
|||||||
DataTypeHelperMock::matchTypeHelper(Stringable::class, $value, 'object'),
|
DataTypeHelperMock::matchTypeHelper(Stringable::class, $value, 'object'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$value = new class () {
|
$value = new class {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
@ -247,13 +247,13 @@ class DataTypeHelperTest extends Unit
|
|||||||
static::assertEquals('string', DataTypeHelper::matchType('', ['string', 'NULL']));
|
static::assertEquals('string', DataTypeHelper::matchType('', ['string', 'NULL']));
|
||||||
|
|
||||||
$values = [
|
$values = [
|
||||||
new class () implements Stringable {
|
new class implements Stringable {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new class () {
|
new class {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
@ -400,7 +400,7 @@ class DataTypeHelperTest extends Unit
|
|||||||
static::assertEquals('1.1', DataTypeHelper::filterString('1.1'));
|
static::assertEquals('1.1', DataTypeHelper::filterString('1.1'));
|
||||||
static::assertEquals('1.1', DataTypeHelper::filterString(1.1));
|
static::assertEquals('1.1', DataTypeHelper::filterString(1.1));
|
||||||
|
|
||||||
$value = new class () implements Stringable {
|
$value = new class implements Stringable {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return 'foo';
|
return 'foo';
|
||||||
@ -408,7 +408,7 @@ class DataTypeHelperTest extends Unit
|
|||||||
};
|
};
|
||||||
static::assertEquals('foo', DataTypeHelper::filterString($value));
|
static::assertEquals('foo', DataTypeHelper::filterString($value));
|
||||||
|
|
||||||
$value = new class () {
|
$value = new class {
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return 'bar';
|
return 'bar';
|
||||||
|
@ -46,7 +46,7 @@ class UUIDTest extends HumHubDbTestCase
|
|||||||
{
|
{
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
static::$toString = new class () {
|
static::$toString = new class {
|
||||||
public string $uuid = '';
|
public string $uuid = '';
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
@ -57,7 +57,7 @@ class UUIDTest extends HumHubDbTestCase
|
|||||||
|
|
||||||
class_alias(get_class(static::$toString), __NAMESPACE__ . '\ToString');
|
class_alias(get_class(static::$toString), __NAMESPACE__ . '\ToString');
|
||||||
|
|
||||||
static::$stringable = new class () extends ToString implements Stringable {
|
static::$stringable = new class extends ToString implements Stringable {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ class UUIDTest extends HumHubDbTestCase
|
|||||||
|
|
||||||
$validator = new UUIDValidator();
|
$validator = new UUIDValidator();
|
||||||
|
|
||||||
$model = new class () extends Model {
|
$model = new class extends Model {
|
||||||
/**
|
/**
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user