Skip to content

Commit

Permalink
add new option to include api user data into module dashboard (#485)
Browse files Browse the repository at this point in the history
* add new option to include api user data into module dashboard

* tests

* add menu data for tests

* lower name keys

* tests without scope
  • Loading branch information
nadar authored Apr 29, 2020
1 parent 9eaf146 commit c038398
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE
+ [#476](https://github.com/luyadev/luya-module-admin/pull/476) Ensure importers skip objects which are not of the certain type. This is importend when a folder is used for other data.
+ [#459](https://github.com/luyadev/luya-module-admin/issues/459) New dropdown option to truncate the whole model data, if enabled.
+ [#284](https://github.com/luyadev/luya-module-admin/issues/284) Added initvalue option for zaaRadio directive.
+ [#349](https://github.com/luyadev/luya-module-admin/issues/349) Option to include ApiUsers log entries into the admin dashboard.

## 3.1.0 (24. March 2020)

Expand Down
7 changes: 7 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ final class Module extends \luya\admin\base\Module implements CoreModuleInterfac
*/
public $apiUserAllowActionsWithoutPermissions = false;

/**
* @var boolean Whether the api user log entries should be display in the module dashboard or not. This is disabled by default as ApiUsers might
* create and update a lot of data.
* @since 3.2.0
*/
public $dashboardLogDisplayApiUserData = false;

/**
* @var array A configuration array with all tags shipped by default with the admin module.
*/
Expand Down
13 changes: 8 additions & 5 deletions src/apis/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,23 @@ public function actionDashboard($nodeId)

$log = [];

$data = (new Query())
$query = (new Query())
->select(['timestamp_create', 'api', 'user_id', 'admin_ngrest_log.id', 'is_update', 'is_delete', 'is_insert', 'admin_user.firstname', 'admin_user.lastname'])
->from('{{%admin_ngrest_log}}')
->leftJoin('{{%admin_user}}', '{{%admin_ngrest_log}}.user_id = {{%admin_user}}.id')
->orderBy(['timestamp_create' => SORT_DESC])
->limit(100)
->where([
'and',
['in', 'api', array_Keys($accessList)],
['in', 'api', array_keys($accessList)],
['!=', 'user_id', 0],
['=', 'is_api_user', 0],
])->all();
]);

foreach ($data as $row) {
if (!$this->module->dashboardLogDisplayApiUserData) {
$query->andWhere(['=', 'is_api_user', 0]);
}

foreach ($query->all() as $row) {
$api = $accessList[$row['api']];
$date = mktime(0, 0, 0, date('n', $row['timestamp_create']), date('j', $row['timestamp_create']), date('Y', $row['timestamp_create']));
if ($row['is_update']) {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/dist/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/resources/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@

$scope.loadDashboard = function() {
$scope.currentItem = null;
$scope.getDashboard($scope.moduleId);
return $state.go('default', { 'moduleId' : $scope.moduleId});
}

Expand Down
51 changes: 51 additions & 0 deletions tests/admin/apis/MenuControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace luya\admin\tests\admin\apis;

use admintests\AdminModelTestCase;
use luya\admin\apis\MenuController;
use luya\testsuite\traits\AdminDatabaseTableTrait;

class MenuControllerTest extends AdminModelTestCase
{
use AdminDatabaseTableTrait;

/**
* @runInSeparateProcess
*/
public function testLoadDataWithoutApiUser()
{
$this->createAdminLangFixture();
$this->createAdminNgRestLogFixture();
$this->createAdminUserFixture();
$this->createAdminUserGroupTable();
$this->createAdminAuthTable();
$this->createAdminGroupAuthTable();
$this->createAdminUserOnlineFixture();
$this->app->getModule('admin')->moduleMenus = ['admin' => $this->app->getModule('admin')->getMenu()];
$ctrl = new MenuController('id', $this->app->getModule('admin'));
$this->assertSame([], $ctrl->actionDashboard(1));
$this->assertSame([], $ctrl->actionIndex());
$this->assertSame([], $ctrl->actionItems(1));
}

/**
* @runInSeparateProcess
*/
public function testLoadDataWithApiUser()
{
$this->createAdminLangFixture();
$this->createAdminNgRestLogFixture();
$this->createAdminUserFixture();
$this->createAdminUserGroupTable();
$this->createAdminAuthTable();
$this->createAdminGroupAuthTable();
$this->createAdminUserOnlineFixture();
$this->app->getModule('admin')->moduleMenus = ['admin' => $this->app->getModule('admin')->getMenu()];
$this->app->getModule('admin')->dashboardLogDisplayApiUserData = 1;
$ctrl = new MenuController('id', $this->app->getModule('admin'));
$this->assertSame([], $ctrl->actionDashboard(1));
$this->assertSame([], $ctrl->actionIndex());
$this->assertSame([], $ctrl->actionItems(1));
}
}

0 comments on commit c038398

Please sign in to comment.