Skip to content

Commit

Permalink
list users groups (#610)
Browse files Browse the repository at this point in the history
* list users groups

* changelog

* add tests

* yii2 dev-master
  • Loading branch information
nadar authored Jan 12, 2021
1 parent a9d1232 commit 8c2d117
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE

## 4.0.0

+ [#610](https://github.com/luyadev/luya-module-admin/pull/610) Added API endpoint to display all groups where the current loggedin user belongs to `admin/api-user-group/me`.
+ [#605](https://github.com/luyadev/luya-module-admin/pull/605) Add new LUYA Test Suite for wider PHP Testing Support. Added Tests for PHP 8.

## 3.9.0 (24. November 2020)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"issues":"https://github.com/luyadev/luya-module-admin/issues"
},
"require":{
"yiisoft/yii2" : "dev-master",
"luyadev/luya-core":"^1.7",
"yiisoft/yii2-imagine":"^2.1",
"yiisoft/yii2-queue":"^2.0",
Expand Down
29 changes: 29 additions & 0 deletions src/apis/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace luya\admin\apis;

use luya\admin\components\Auth;
use luya\admin\models\Group;
use luya\admin\ngrest\base\Api;
use Yii;
use yii\data\ActiveDataProvider;

/**
* API to manage, create, udpate and delete all System Groups.
Expand All @@ -16,4 +20,29 @@ class GroupController extends Api
* @var string The path to the group model.
*/
public $modelClass = 'luya\admin\models\Group';

/**
* {@inheritDoc}
*/
public function actionPermissions()
{
return [
'me' => Auth::CAN_VIEW,
];
}

/**
* Loggedin User Groups
*
* Returns all groups where the current loggedin (me) belongs to.
*
* @return Group[]
* @since 4.0
*/
public function actionMe()
{
return new ActiveDataProvider([
'query' => Yii::$app->adminuser->identity->getGroups(),
]);
}
}
23 changes: 23 additions & 0 deletions tests/admin/apis/GroupControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace luya\admin\tests\admin\apis;

use admintests\AdminModelTestCase;
use luya\admin\apis\GroupController;
use luya\testsuite\scopes\PermissionScope;

class GroupControllerTest extends AdminModelTestCase
{
public function testMeGroups()
{
PermissionScope::run($this->app, function (PermissionScope $scope) {
$scope->createAndAllowApi('api-admin-group');

$ctrl = new GroupController('api-admin-group', $this->app->getModule('admin'));

$response = $scope->runControllerAction($ctrl, 'me');

$this->assertEmpty($response);
});
}
}

0 comments on commit 8c2d117

Please sign in to comment.