diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb68ce1b..c849f41a6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/apis/SearchController.php b/src/apis/SearchController.php index e5bb18469..cee5a7d6c 100644 --- a/src/apis/SearchController.php +++ b/src/apis/SearchController.php @@ -67,7 +67,7 @@ public function actionIndex($query) ]; } - unset($data); + unset($model, $data); } } @@ -75,18 +75,23 @@ public function actionIndex($query) 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); } } diff --git a/tests/admin/apis/SearchControllerTest.php b/tests/admin/apis/SearchControllerTest.php new file mode 100644 index 000000000..46d4b7e3d --- /dev/null +++ b/tests/admin/apis/SearchControllerTest.php @@ -0,0 +1,37 @@ +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]; + }); + } +}