Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure generic search instance #657

Merged
merged 4 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.0

+ [#657](https://github.com/luyadev/luya-module-admin/pull/657) Fix problem with global admin UI search when model does not exists, this could be due to old controller structure or custom code.
+ [#656](https://github.com/luyadev/luya-module-admin/pull/656) Ensure queue items are removed when schedule item is deleted, improved filter of upcoming queue events, fix issue with scheduler log for multiple attributes on the same model.
+ [#654](https://github.com/luyadev/luya-module-admin/pull/654) Fix issue with ngrest detail view when json is not an array.
+ [#496](https://github.com/luyadev/luya-module-admin/issues/496) Added default color for link elements in NgRest CRUD table.
Expand Down
27 changes: 16 additions & 11 deletions src/apis/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,31 @@ public function actionIndex($query)
];
}

unset($data);
unset($model, $data);
}
}

foreach (Yii::$app->adminmenu->getItems() as $api) {
if ($api['permissionIsApi']) {
$ctrl = $module->createController($api['permissionApiEndpoint']);
$controller = $ctrl[0];
$data = $this->transformGenericSearchToData($controller->model->genericSearch($query));
if (count($data) > 0) {
$search[] = [
'hideFields' => $controller->model->genericSearchHiddenFields(),
'type' => 'api',
'menuItem' => $api,
'data' => $data,
'stateProvider' => $controller->model->genericSearchStateProvider(),
];

if ($controller && $controller->model && $controller->model instanceof GenericSearchInterface) {
$data = $this->transformGenericSearchToData($controller->model->genericSearch($query));
if (count($data) > 0) {
$search[] = [
'hideFields' => $controller->model->genericSearchHiddenFields(),
'type' => 'api',
'menuItem' => $api,
'data' => $data,
'stateProvider' => $controller->model->genericSearchStateProvider(),
];
}

unset($data);
}

unset($data);
unset($controller, $ctrl);
}
}

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

namespace luya\admin\tests\admin\apis;

use admintests\AdminModelTestCase;
use luya\admin\apis\SearchController;
use luya\admin\models\SearchData;
use luya\testsuite\fixtures\NgRestModelFixture;
use luya\testsuite\scopes\PermissionScope;

class SearchControllerTest extends AdminModelTestCase
{
public function testIndexAction()
{
PermissionScope::run($this->app, function (PermissionScope $scope) {
new NgRestModelFixture([
'modelClass' => SearchData::class,
]);

$this->createAdminTagFixture([
1 => [
'id' => 1,
'name' => 'none',
'translation' => 'none',
]
]);

$ctrl = new SearchController('search', $scope->getApp()->getModule('admin'));
$scope->loginUser();
$response = $scope->runControllerAction($ctrl, 'index', ['query' => 'test']);

$this->assertEmpty($response);
}, function (PermissionScope $config) {
$config->userFixtureData = ['is_api_user' => 0];
});
}
}