diff --git a/resources/js/app/components/system-info/system-info.vue b/resources/js/app/components/system-info/system-info.vue index 3f59052b7..bb9751068 100644 --- a/resources/js/app/components/system-info/system-info.vue +++ b/resources/js/app/components/system-info/system-info.vue @@ -1,8 +1,28 @@ @@ -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, @@ -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', + ], } }, @@ -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); }); }, } diff --git a/src/Controller/Admin/SystemInfoController.php b/src/Controller/Admin/SystemInfoController.php index 74069e358..37ea48d04 100644 --- a/src/Controller/Admin/SystemInfoController.php +++ b/src/Controller/Admin/SystemInfoController.php @@ -12,6 +12,7 @@ */ namespace App\Controller\Admin; +use App\Utility\SchemaTrait; use BEdita\SDK\BEditaClientException; use Cake\Core\Configure; use Cake\Http\Response; @@ -23,6 +24,8 @@ */ class SystemInfoController extends AdministrationBaseController { + use SchemaTrait; + /** * @inheritDoc */ @@ -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'); } diff --git a/src/Controller/Component/ModulesComponent.php b/src/Controller/Component/ModulesComponent.php index d10334c32..22352b21f 100644 --- a/src/Controller/Component/ModulesComponent.php +++ b/src/Controller/Component/ModulesComponent.php @@ -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'), + ], + ]; } /** diff --git a/templates/Element/Menu/colophon.twig b/templates/Element/Menu/colophon.twig index af8e4f5eb..7927776c4 100644 --- a/templates/Element/Menu/colophon.twig +++ b/templates/Element/Menu/colophon.twig @@ -8,11 +8,18 @@ {{ Html.link('Manager', 'https://github.com/bedita/manager', {'target': '_blank'})|raw }} {{ config('Manager.version') }} - {% if project.version %} + {% if project.api.name %} + + + {{ project.api.name }} API + {% if project.api.version %}{{ project.api.version }}{% endif %} + + {% endif %} + {% if project.beditaApi.version %} {% if apiCheck == 1 %}{% endif %} {% if apiCheck != 1 %}{% 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 }} {% endif %} ©{{ 'now'|date('Y') }} {{ authors|shuffle|toList(__('&'))|raw }} diff --git a/tests/TestCase/Controller/Admin/SystemInfoControllerTest.php b/tests/TestCase/Controller/Admin/SystemInfoControllerTest.php index 60ade9908..5c3292ad1 100644 --- a/tests/TestCase/Controller/Admin/SystemInfoControllerTest.php +++ b/tests/TestCase/Controller/Admin/SystemInfoControllerTest.php @@ -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; @@ -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', @@ -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); @@ -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); } diff --git a/tests/TestCase/Controller/Component/ModulesComponentTest.php b/tests/TestCase/Controller/Component/ModulesComponentTest.php index 7706d22da..fb8b9338c 100644 --- a/tests/TestCase/Controller/Component/ModulesComponentTest.php +++ b/tests/TestCase/Controller/Component/ModulesComponentTest.php @@ -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' => [ @@ -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'), ], @@ -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', @@ -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' => [ @@ -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' => [ diff --git a/yarn.lock b/yarn.lock index 0e8169f16..4a2094d34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== chalk@4.1.2, chalk@^4.0.0: version "4.1.2"