mirror of
https://github.com/humhub/humhub.git
synced 2025-02-24 11:14:00 +01:00
Refactoring for GroupController
This commit is contained in:
parent
61877f09f3
commit
754e90c896
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\admin\controllers;
|
namespace humhub\modules\admin\controllers;
|
||||||
|
|
||||||
|
use humhub\components\Response;
|
||||||
use humhub\modules\admin\components\Controller;
|
use humhub\modules\admin\components\Controller;
|
||||||
use humhub\modules\admin\models\forms\AddGroupMemberForm;
|
use humhub\modules\admin\models\forms\AddGroupMemberForm;
|
||||||
use humhub\modules\admin\models\GroupSearch;
|
use humhub\modules\admin\models\GroupSearch;
|
||||||
@ -50,7 +51,7 @@ class GroupController extends Controller
|
|||||||
public function getAccessRules()
|
public function getAccessRules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['permissions' => ManageGroups::className()],
|
['permissions' => ManageGroups::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ class GroupController extends Controller
|
|||||||
$this->forcePostRequest();
|
$this->forcePostRequest();
|
||||||
$group = Group::findOne(['id' => Yii::$app->request->get('id')]);
|
$group = Group::findOne(['id' => Yii::$app->request->get('id')]);
|
||||||
|
|
||||||
if ($group == null) {
|
if ($group === null) {
|
||||||
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
|
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,29 +185,36 @@ class GroupController extends Controller
|
|||||||
|
|
||||||
public function actionEditManagerRole()
|
public function actionEditManagerRole()
|
||||||
{
|
{
|
||||||
Yii::$app->response->format = 'json';
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||||
$this->forcePostRequest();
|
$this->forcePostRequest();
|
||||||
$group = Group::findOne(Yii::$app->request->post('id'));
|
|
||||||
$value = Yii::$app->request->post('value');
|
|
||||||
|
|
||||||
if ($group == null) {
|
$group = Group::findOne(Yii::$app->request->post('id'));
|
||||||
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
|
if ($group === null) {
|
||||||
} else {
|
throw new HttpException(
|
||||||
if ($value == null) {
|
404,
|
||||||
throw new HttpException(400, Yii::t('AdminModule.controllers_GroupController', 'No value found!'));
|
Yii::t('AdminModule.controllers_GroupController', 'Group not found!')
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = Yii::$app->request->post('value');
|
||||||
|
if ($value === null) {
|
||||||
|
throw new HttpException(
|
||||||
|
400,
|
||||||
|
Yii::t('AdminModule.controllers_GroupController', 'No value found!')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$groupUser = $group->getGroupUser(User::findOne(Yii::$app->request->post('userId')));
|
$groupUser = $group->getGroupUser(User::findOne(Yii::$app->request->post('userId')));
|
||||||
|
if ($groupUser === null) {
|
||||||
if ($groupUser == null) {
|
throw new HttpException(
|
||||||
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group user not found!'));
|
404,
|
||||||
|
Yii::t('AdminModule.controllers_GroupController', 'Group user not found!')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$groupUser->is_group_manager = ($value) ? true : false;
|
$groupUser->is_group_manager = (bool)$value;
|
||||||
$groupUser->save();
|
|
||||||
|
|
||||||
return ['success' => true];
|
return ['success' => $groupUser->save()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionAddMembers()
|
public function actionAddMembers()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user