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
45 changes: 41 additions & 4 deletions resources/js/app/components/system-info/system-info.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
<template>
<div>
<p v-for="item,key of infos">
<span class="key">{{ key }}</span>:
<span class="version">{{ item }}</span>
<div class="system-info">
<p
v-for="item,key of infos"
:key="key"
>
<template v-if="jsonKeys.includes(key)">
<details>
<summary>{{ key }}</summary>
<div
:id="`container-${hash}-${key}`"
class="jsoneditor-container"
/>
<json-editor
:name="`${hash}-${key}`"
:options="jsonEditorOptions"
:target="`container-${hash}-${key}`"
:text="JSON.stringify(item, null, 2)"
/>
</details>
</template>
<template v-else>
<span class="key">{{ key }}</span>:
<span class="version">{{ item }}</span>
</template>
</p>
</div>
</template>
Expand All @@ -11,6 +31,9 @@ import Vue from 'vue';

export default {
name: 'SystemInfo',
components: {
JsonEditor: () => import(/* webpackChunkName: "json-editor" */'app/components/json-editor/json-editor'),
},
props: {
data: {
type: String,
Expand All @@ -20,7 +43,20 @@ export default {

data() {
return {
hash: '',
infos: {},
jsonEditorOptions: {
mainMenuBar: true,
mode: 'text',
navigationBar: false,
statusBar: false,
readOnly: true,
},
jsonKeys: [
'Extensions',
'Extensions info',
'GET /home',
],
}
},

Expand All @@ -30,6 +66,7 @@ export default {
if (this.infos['Vuejs'] !== undefined) {
this.infos['Vuejs'] = Vue.version;
}
this.hash = Math.random().toString(36).substring(2, 15);
});
},
}
Expand Down
7 changes: 7 additions & 0 deletions src/Controller/Admin/SystemInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace App\Controller\Admin;

use App\Utility\SchemaTrait;
use BEdita\SDK\BEditaClientException;
use Cake\Core\Configure;
use Cake\Http\Response;
Expand All @@ -23,6 +24,8 @@
*/
class SystemInfoController extends AdministrationBaseController
{
use SchemaTrait;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -73,6 +76,10 @@ public function getApiInfo(): array
$this->apiClient->get('/admin/sysinfo'),
'meta.info'
);
/** @var \Authentication\Identity $user */
$user = $this->Authentication->getIdentity();
$meta = $this->getMeta($user);
$info = array_merge($info, ['GET /home' => $meta]);
} catch (BEditaClientException $e) {
$this->log($e->getMessage(), 'error');
}
Expand Down
22 changes: 16 additions & 6 deletions src/Controller/Component/ModulesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,22 @@ public function getProject(): array
{
/** @var \Authentication\Identity $user */
$user = $this->Authentication->getIdentity();
$meta = $this->getMeta($user);
$project = (array)Configure::read('Project');
$name = (string)Hash::get($project, 'name', Hash::get($meta, 'project.name'));
$version = Hash::get($meta, 'version', '');

return compact('name', 'version');
$api = $this->getMeta($user);
$apiName = (string)Hash::get($api, 'project.name');
$apiName = str_replace('API', '', $apiName);
$api['project']['name'] = $apiName;

return [
'api' => (array)Hash::get($api, 'project'),
'beditaApi' => [
'name' => (string)Hash::get(
(array)Configure::read('Project'),
'name',
(string)Hash::get($api, 'project.name')
),
'version' => (string)Hash::get($api, 'version'),
],
];
}

/**
Expand Down
11 changes: 9 additions & 2 deletions templates/Element/Menu/colophon.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
<app-icon icon="carbon:checkmark"></app-icon>
{{ Html.link('Manager', 'https://github.com/bedita/manager', {'target': '_blank'})|raw }} {{ config('Manager.version') }}
</span>
{% if project.version %}
{% if project.api.name %}
<span class="{{ apiClass }}">
<app-icon icon="carbon:checkmark"></app-icon>
{{ project.api.name }} API
{% if project.api.version %}{{ project.api.version }}{% endif %}
</span>
{% endif %}
{% if project.beditaApi.version %}
<span class="{{ apiClass }}" title="{{ warn }}">
{% if apiCheck == 1 %}<app-icon icon="carbon:checkmark"></app-icon>{% endif %}
{% if apiCheck != 1 %}<app-icon icon="carbon:error"></app-icon>{% endif %}
{{ Html.link('API', 'https://github.com/bedita/bedita', {'target': '_blank'})|raw }} {{ project.version }}
{{ Html.link('BEdita API', 'https://github.com/bedita/bedita', {'target': '_blank'})|raw }} {{ project.beditaApi.version }}
</span>
{% endif %}
<span>©{{ 'now'|date('Y') }} {{ authors|shuffle|toList(__('&'))|raw }}</span>
Expand Down
28 changes: 26 additions & 2 deletions tests/TestCase/Controller/Admin/SystemInfoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
namespace App\Test\TestCase\Controller\Admin;

use App\Controller\Admin\SystemInfoController;
use App\Test\TestCase\Controller\AppControllerTest;
use Authentication\Identity;
use BEdita\SDK\BEditaClient;
use BEdita\SDK\BEditaClientException;
use BEdita\WebTools\ApiClientProvider;
use Cake\Http\ServerRequest;
use Cake\TestSuite\TestCase;

/**
* {@see \App\Controller\Admin\SystemInfoController} Test Case
*
* @coversDefaultClass \App\Controller\Admin\SystemInfoController
*/
class SystemInfoControllerTest extends TestCase
class SystemInfoControllerTest extends AppControllerTest
{
public $SystemInfoController;

Expand Down Expand Up @@ -63,6 +64,13 @@ public function setUp(): void
*/
public function testIndex(): void
{
$user = new Identity([
'id' => 1,
'username' => 'dummy',
'roles' => ['readers'],
]);
$this->SystemInfoController->setRequest($this->SystemInfoController->getRequest()->withAttribute('authentication', $this->getAuthenticationServiceMock()));
$this->SystemInfoController->Authentication->setIdentity($user);
$this->SystemInfoController->index();
$keys = [
'system_info',
Expand Down Expand Up @@ -113,7 +121,15 @@ public function testGetApiInfo(): void
$expectedKeys = [
'Url',
'Version',
'GET /home',
];
$user = new Identity([
'id' => 1,
'username' => 'dummy',
'roles' => ['readers'],
]);
$this->SystemInfoController->setRequest($this->SystemInfoController->getRequest()->withAttribute('authentication', $this->getAuthenticationServiceMock()));
$this->SystemInfoController->Authentication->setIdentity($user);
$actual = $this->SystemInfoController->getApiInfo();
foreach ($expectedKeys as $expectedKey) {
static::assertArrayHasKey($expectedKey, $actual);
Expand Down Expand Up @@ -144,6 +160,14 @@ public function setApiClient($client): void
}
};
$controller->setApiClient($apiClient);

$user = new Identity([
'id' => 1,
'username' => 'dummy',
'roles' => ['readers'],
]);
$controller->setRequest($controller->getRequest()->withAttribute('authentication', $this->getAuthenticationServiceMock()));
$controller->Authentication->setIdentity($user);
$actual = $controller->getApiInfo();
static::assertEquals($expected, $actual);
}
Expand Down
54 changes: 42 additions & 12 deletions tests/TestCase/Controller/Component/ModulesComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ public function getProjectProvider(): array
return [
'ok' => [
[
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
'api' => [
'name' => 'BEdita',
],
'beditaApi' => [
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
],
],
[
'project' => [
Expand All @@ -161,15 +166,25 @@ public function getProjectProvider(): array
],
'empty' => [
[
'name' => '',
'version' => '',
'api' => [
'name' => '',
],
'beditaApi' => [
'name' => '',
'version' => '',
],
],
[],
],
'client exception' => [
[
'name' => '',
'version' => '',
'api' => [
'name' => '',
],
'beditaApi' => [
'name' => '',
'version' => '',
],
],
new BEditaClientException('I am a client exception'),
],
Expand All @@ -179,8 +194,13 @@ public function getProjectProvider(): array
],
'config' => [
[
'name' => 'Gustavo',
'version' => '4.1.2',
'api' => [
'name' => '',
],
'beditaApi' => [
'name' => 'Gustavo',
'version' => '4.1.2',
],
],
[
'version' => '4.1.2',
Expand Down Expand Up @@ -682,8 +702,13 @@ public function startupProvider(): array
],
null,
[
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
'api' => [
'name' => 'BEdita',
],
'beditaApi' => [
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
],
],
[
'resources' => [
Expand Down Expand Up @@ -717,8 +742,13 @@ public function startupProvider(): array
],
'supporto',
[
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
'api' => [
'name' => 'BEdita',
],
'beditaApi' => [
'name' => 'BEdita',
'version' => 'v4.0.0-gustavo',
],
],
[
'resources' => [
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2015,9 +2015,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001688:
version "1.0.30001699"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001699.tgz#a102cf330d153bf8c92bfb5be3cd44c0a89c8c12"
integrity sha512-b+uH5BakXZ9Do9iK+CkDmctUSEqZl+SP056vc5usa0PL+ev5OHw003rZXcnjNDv3L8P5j6rwT6C0BPKSikW08w==
version "1.0.30001731"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001731.tgz"
integrity sha512-lDdp2/wrOmTRWuoB5DpfNkC0rJDU8DqRa6nYL6HK6sytw70QMopt/NIc/9SM7ylItlBWfACXk0tEn37UWM/+mg==

[email protected], chalk@^4.0.0:
version "4.1.2"
Expand Down
Loading