diff --git a/protected/humhub/components/access/ControllerAccess.php b/protected/humhub/components/access/ControllerAccess.php index ed17cc4423..b0efd6faf6 100644 --- a/protected/humhub/components/access/ControllerAccess.php +++ b/protected/humhub/components/access/ControllerAccess.php @@ -424,7 +424,7 @@ class ControllerAccess extends BaseObject */ public function validatePostRequest() { - return Yii::$app->request->method == 'POST'; + return Yii::$app->request->isPost; } /** diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index a13b829e3c..a522b703b1 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -9,6 +9,8 @@ HumHub Change Log - Fix: space archive activity wrong originator assignment - Fix: suppress "unable to determine dataType" error for aborted xhr requests - Enh: added `FunctionalTester::loginBySpaceUserGroup()` and `FunctionalTest::assertSpaceAccessStatus()` for ACL testing +- Fix #2721 delete space button not visible for system admin +- Enh: added `humhub\modules\space\behaviors\SpaceModelMembership::canDelete()` 1.3.0-beta.2 (July 18, 2018) ----------------------------- diff --git a/protected/humhub/modules/space/behaviors/SpaceModelMembership.php b/protected/humhub/modules/space/behaviors/SpaceModelMembership.php index 3f61f5644f..1d548c3206 100644 --- a/protected/humhub/modules/space/behaviors/SpaceModelMembership.php +++ b/protected/humhub/modules/space/behaviors/SpaceModelMembership.php @@ -157,6 +157,15 @@ class SpaceModelMembership extends Behavior return $this->_spaceOwner; } + /** + * @return bool checks if the current user is allowed to delete this space + * @since 1.3 + */ + public function canDelete() + { + return Yii::$app->user->isAdmin() || $this->isSpaceOwner(); + } + /** * Is given User owner of this Space * @param User|int|null $userId diff --git a/protected/humhub/modules/space/modules/manage/controllers/DefaultController.php b/protected/humhub/modules/space/modules/manage/controllers/DefaultController.php index 737dd4a637..1bb29b4908 100644 --- a/protected/humhub/modules/space/modules/manage/controllers/DefaultController.php +++ b/protected/humhub/modules/space/modules/manage/controllers/DefaultController.php @@ -8,6 +8,7 @@ namespace humhub\modules\space\modules\manage\controllers; +use humhub\modules\content\components\ContentContainerControllerAccess; use humhub\modules\space\components\UrlRule; use Yii; use humhub\modules\space\models\Space; @@ -34,10 +35,8 @@ class DefaultController extends Controller public function getAccessRules() { $result = parent::getAccessRules(); - $result[] = [ - 'userGroup' => [Space::USERGROUP_OWNER], 'actions' => ['archive', 'unarchive', 'delete'] - ]; - + $result[] = [ContentContainerControllerAccess::RULE_USER_GROUP_ONLY => [Space::USERGROUP_OWNER], 'actions' => ['archive', 'unarchive', 'delete']]; + $result[] = [ContentContainerControllerAccess::RULE_POST => ['archive', 'unarchive']]; return $result; } @@ -90,15 +89,10 @@ class DefaultController extends Controller // Create Activity when the space in archieved SpaceArchieved::instance()->from(Yii::$app->user->getIdentity())->about($space->owner)->save(); - if (Yii::$app->request->isAjax) { - Yii::$app->response->format = 'json'; - return [ - 'success' => true, - 'space' => Chooser::getSpaceResult($space, true, ['isMember' => true]) - ]; - } - - return $this->redirect($space->createUrl('/space/manage')); + return $this->asJson( [ + 'success' => true, + 'space' => Chooser::getSpaceResult($space, true, ['isMember' => true]) + ]); } /** @@ -136,5 +130,4 @@ class DefaultController extends Controller return $this->render('delete', ['model' => $model, 'space' => $this->getSpace()]); } - } diff --git a/protected/humhub/modules/space/modules/manage/controllers/MemberController.php b/protected/humhub/modules/space/modules/manage/controllers/MemberController.php index 2207eec525..ccefc99302 100644 --- a/protected/humhub/modules/space/modules/manage/controllers/MemberController.php +++ b/protected/humhub/modules/space/modules/manage/controllers/MemberController.php @@ -31,9 +31,7 @@ class MemberController extends Controller public function getAccessRules() { $result = parent::getAccessRules(); - $result[] = [ - 'userGroup' => [Space::USERGROUP_OWNER], 'actions' => ['change-owner'] - ]; + $result[] = ['userGroup' => [Space::USERGROUP_OWNER], 'actions' => ['change-owner']]; return $result; } @@ -186,7 +184,6 @@ class MemberController extends Controller if ($model->load(Yii::$app->request->post()) && $model->validate()) { $space->setSpaceOwner($model->ownerId); - return $this->redirect($space->getUrl()); } diff --git a/protected/humhub/modules/space/modules/manage/models/ChangeOwnerForm.php b/protected/humhub/modules/space/modules/manage/models/ChangeOwnerForm.php index 949d99a87a..32c457e4ed 100644 --- a/protected/humhub/modules/space/modules/manage/models/ChangeOwnerForm.php +++ b/protected/humhub/modules/space/modules/manage/models/ChangeOwnerForm.php @@ -8,6 +8,7 @@ namespace humhub\modules\space\modules\manage\models; +use humhub\modules\space\models\Space; use Yii; use yii\base\Model; use humhub\modules\space\models\Membership; @@ -60,7 +61,7 @@ class ChangeOwnerForm extends Model { $possibleOwners = []; - $query = Membership::find()->joinWith(['user', 'user.profile'])->andWhere(['space_membership.group_id' => 'admin', 'space_membership.space_id' => $this->space->id]); + $query = Membership::find()->joinWith(['user', 'user.profile'])->andWhere(['space_membership.group_id' => Space::USERGROUP_ADMIN, 'space_membership.space_id' => $this->space->id]); foreach ($query->all() as $membership) { $possibleOwners[$membership->user->id] = $membership->user->displayName; } diff --git a/protected/humhub/modules/space/modules/manage/views/default/delete.php b/protected/humhub/modules/space/modules/manage/views/default/delete.php index f40a948213..9bbd0e45b1 100644 --- a/protected/humhub/modules/space/modules/manage/views/default/delete.php +++ b/protected/humhub/modules/space/modules/manage/views/default/delete.php @@ -1,8 +1,9 @@
= Yii::t('SpaceModule.views_admin_delete', 'Please provide your password to continue!'); ?>
= Yii::t('SpaceModule.manage', 'As owner of this space you can transfer this role to another administrator in space.'); ?>
- = $form->field($model, 'ownerId')->dropDownList($model->getNewOwnerArray()) ?> -