Skip to content
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
5 changes: 5 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@
['pass' => ['id', 'relation', 'format', 'query'], '_name' => 'export:related:filtered']
);

$routes->get(
'/history/get',
['controller' => 'History', 'action' => 'get'],
'history:get',
);
$routes->get(
'/history/objects',
['controller' => 'History', 'action' => 'objects'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default {
const filterDate = this.filterDate ? new Date(this.filterDate).toISOString() : '';
const query = filterDate ? `page_size=${pageSize}&page=${page}&filter[created][gt]=${filterDate}&sort=-created` : `page_size=${pageSize}&page=${page}&sort=-created`;

return fetch(`/api/history?${query}`).then((r) => r.json());
return fetch(`/history/get?${query}`).then((r) => r.json());
},
async getObjects(ids) {
return fetch(`/history/objects?filter[id]=${ids.join(',')}`).then((r) => r.json());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default {
try {
this.loading = true;
this.error = '';
const response = await fetch(`${API_URL}api/history?filter[user_id]=${userId}&page=${page}&page_size=${pageSize}&sort=-created`, API_OPTIONS);
const response = await fetch(`${API_URL}history/get?filter[user_id]=${userId}&page=${page}&page_size=${pageSize}&sort=-created`, API_OPTIONS);
const json = await response.json();
this.pagination = json.meta.pagination;
this.currentPage = json.meta.pagination.page;
Expand Down
18 changes: 18 additions & 0 deletions src/Controller/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ public function initialize(): void
$this->loadComponent('Schema');
}

/**
* Get history using query parameters.
* This is a proxy for /api/history endpoint.
*
* @return void
*/
public function get(): void
{
$this->viewBuilder()->setClassName('Json');
$this->getRequest()->allowMethod('get');
$query = $this->getRequest()->getQueryParams();
$response = ApiTools::cleanResponse((array)$this->apiClient->get('/history', $query));
$data = $response['data'];
$meta = $response['meta'];
$this->set(compact('data', 'meta'));
$this->setSerialize(['data', 'meta']);
}

/**
* Get objects list: id, title, uname only / no relationships, no links.
*
Expand Down
39 changes: 39 additions & 0 deletions tests/TestCase/Controller/HistoryControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,45 @@ public function testSetHistory(array $data, string $expected): void
static::assertEquals($actual, $expected);
}

/**
* Test `get` method
*
* @return void
* @covers ::get()
*/
public function testGet(): void
{
$this->HistoryController->get();
$vars = ['data', 'meta'];
foreach ($vars as $var) {
static::assertNotEmpty($this->HistoryController->viewBuilder()->getVar($var));
}
$actual = $this->HistoryController->viewBuilder()->getVar('data')[0];
$vars = [
'id',
'type',
'meta',
];
foreach ($vars as $var) {
static::assertArrayHasKey($var, $actual);
}
static::assertArrayNotHasKey('links', $actual);
static::assertArrayNotHasKey('relationships', $actual);
$meta = $actual['meta'];
$vars = [
'resource_id',
'resource_type',
'created',
'user_id',
'application_id',
'user_action',
'changed',
];
foreach ($vars as $var) {
static::assertArrayHasKey($var, $meta);
}
}

/**
* Test `objects` method
*
Expand Down
Loading