Fix update user with not existing group (#6105)

* Fix update user with not existing group

* Restrict group selector only with existing groups

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2023-02-16 12:55:48 +04:00 committed by GitHub
parent ecf7e616e8
commit 433a78a1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -5,6 +5,7 @@ HumHub Changelog
-------------------------
- Fix #5965: Suppress log warning 'Invalid session auth key attempted for user'
- Fix #6084: Automatic LDAP user registration broken when not all req. attributes provided
- Fix #6104: Fix update user with not existing group
- Fix #6103: Fix null passing to parse_str()
1.13.1 (January 25, 2023)

View File

@ -148,7 +148,8 @@ class UserController extends Controller
'items' => UserEditForm::getGroupItems(),
'options' => [
'data-placeholder' => Yii::t('AdminModule.user', 'Select Groups'),
'data-placeholder-more' => Yii::t('AdminModule.user', 'Add Groups...')
'data-placeholder-more' => Yii::t('AdminModule.user', 'Add Groups...'),
'data-tags' => 'false'
],
'maxSelection' => 250,
'isVisible' => Yii::$app->user->can(new ManageGroups())

View File

@ -2,12 +2,11 @@
namespace humhub\modules\admin\models\forms;
use humhub\libs\Html;
use humhub\modules\user\models\GroupUser;
use Yii;
use humhub\modules\user\models\User;
use humhub\modules\user\models\Group;
use humhub\modules\admin\permissions\ManageGroups;
use humhub\modules\user\models\Group;
use humhub\modules\user\models\GroupUser;
use humhub\modules\user\models\User;
use Yii;
/**
* Description of UserEditForm
@ -18,14 +17,13 @@ class UserEditForm extends User
{
/**
* GroupId selection array of the form.
* @var type
* @var array
*/
public $groupSelection;
/**
* Current member groups (models) of the given $user
* @var type
*
* @var Group[]
*/
public $currentGroups;
@ -103,19 +101,19 @@ class UserEditForm extends User
if (!$this->isCurrentlyMemberOf($groupId)) {
/* @var $group Group */
$group = Group::findOne(['id' => $groupId]);
if(!$group->is_admin_group || Yii::$app->user->isAdmin()) {
if ($group && (!$group->is_admin_group || Yii::$app->user->isAdmin())) {
$group->addUser($this);
}
}
}
}
return parent::afterSave($insert, $changedAttributes);
parent::afterSave($insert, $changedAttributes);
}
/**
* Checks if the given group (id or model object) is contained in the form selection
* @param integer $groupId groupId or Group model object
* @param int|Group $groupId groupId or Group model object
* @return boolean true if contained in selection else false
*/
private function isInGroupSelection($groupId)