-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend API documentation, #PG-5031 #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9b982cd
Started on basic page
lachiebol 69ae322
Clean up css and fix search bar
lachiebol 0ce4c2e
css theming fixes, adding in designs
lachiebol 1b6fbf0
prefetched specs and added smooth transitions
lachiebol d4251e5
build and cleanup
lachiebol 9ec2daf
Clean up code and css
lachiebol af93984
theming css fixes and dark mode support
lachiebol 03620be
removed deep linking for now
lachiebol 2f90532
fix styling
lachiebol 9c50541
PO suggestions and fixed bug with search deleting elements breaking s…
lachiebol b5f4470
codex suggestion to use computed vs method
lachiebol 1d2769a
remove unused translations and added controller test
lachiebol df0a832
Fix vue build
lachiebol f5130b2
7.2 support for tests
lachiebol af5b4dc
Fix api test
lachiebol abd559c
use npm for swagger-ui, add npm script to move swagger files to vue/lib/
lachiebol 95ccd18
Change swagger to swagger api
lachiebol d7c2cd4
remove swagger page title
lachiebol cb792d2
fix string
lachiebol 2293b70
Add auth button in and fix styling
lachiebol 20758fc
Updated API calls to new endpoint
lachiebol 46c3cb2
Fix codex review comments
lachiebol 60735ae
Fix tests
lachiebol fbb4e1c
Now loading assets via twig, fixed timeout issues with task, fixed ad…
lachiebol 2f7fc12
Now using current instance URL for SwaggerUI, to be compatible with c…
lachiebol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Piwik\Plugins\OpenApiDocs; | ||
|
|
||
| use Piwik\Piwik; | ||
| use Piwik\View; | ||
|
|
||
| class Controller extends \Piwik\Plugin\ControllerAdmin | ||
| { | ||
| public function swagger(): string | ||
| { | ||
| Piwik::checkUserHasSomeViewAccess(); | ||
|
|
||
| $view = new View('@OpenApiDocs/swagger'); | ||
| $this->setBasicVariablesView($view); | ||
|
|
||
| return $view->render(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| namespace Piwik\Plugins\OpenApiDocs; | ||
|
|
||
| use Piwik\Menu\MenuAdmin; | ||
| use Piwik\Piwik; | ||
|
|
||
| class Menu extends \Piwik\Plugin\Menu | ||
| { | ||
| public function configureAdminMenu(MenuAdmin $menu): void | ||
| { | ||
| if (!Piwik::isUserHasSomeViewAccess()) { | ||
| return; | ||
| } | ||
|
|
||
| $menu->addPlatformItem( | ||
| 'OpenApiDocs_SwaggerApi', | ||
| $this->urlForAction('swagger'), | ||
| 30 | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "OpenApiDocs": { | ||
| "ReportingApiMoreInformation": "More info about the Matomo APIs available in %1$sIntroduction to Matomo API%2$s and the %3$sMatomo API Reference%4$s.", | ||
| "ReportingApiReference": "Reporting API Reference", | ||
| "ReportingApiSummary": "All the data in Matomo is available through simple APIs.", | ||
| "SwaggerApi": "Swagger API", | ||
| "SwaggerPagePluginEmpty": "No plugins are configured in the OpenApiDocs whitelist.", | ||
| "SwaggerPageRequestFailed": "The plugin whitelist could not be loaded.", | ||
| "SwaggerPageSpecLoadFailed": "The OpenAPI spec could not be loaded for this plugin.", | ||
| "SwaggerPageSearchNoResults": "No plugins match your search.", | ||
| "SwaggerPageSearchPlaceholder": "Search by plugin name", | ||
| "UserAuthentication": "User authentication", | ||
| "UserAuthenticationManageTokens": "You can manage your authentication tokens on your security page.", | ||
| "UserAuthenticationUsingTokenAuth": "If you want to request data within a script, a crontab, etc. you need to add the '%3$s' URL parameter to the API calls for URLs that require authentication." | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| {% extends 'admin.twig' %} | ||
|
|
||
| {% block head %} | ||
| {{ parent() }} | ||
| <link rel="stylesheet" href="plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui.css" /> | ||
| <link rel="stylesheet" href="plugins/OpenApiDocs/vue/src/SwaggerPage/swagger-ui-overrides.css" /> | ||
| <script src="plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui-bundle.js"></script> | ||
| {% endblock %} | ||
|
|
||
| {% set title %}{{ 'OpenApiDocs_SwaggerApi'|translate }}{% endset %} | ||
|
|
||
| {% block content %} | ||
| <div | ||
| vue-entry="OpenApiDocs.SwaggerPage" | ||
| piwik-url="{{ piwikUrl|default(null)|json_encode }}" | ||
| ></div> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Piwik\Plugins\OpenApiDocs\tests\Integration; | ||
|
|
||
| use Piwik\Access; | ||
| use Piwik\Container\StaticContainer; | ||
| use Piwik\Plugin\Manager; | ||
| use Piwik\Plugins\OpenApiDocs\Controller; | ||
| use Piwik\Tests\Framework\Fixture; | ||
| use Piwik\Tests\Framework\Mock\FakeAccess; | ||
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | ||
|
|
||
| /** | ||
| * @group OpenApiDocs | ||
| * @group ControllerTest | ||
| * @group Plugins | ||
| */ | ||
| class ControllerTest extends IntegrationTestCase | ||
| { | ||
| /** | ||
| * @var Controller | ||
| */ | ||
| private $controller; | ||
|
|
||
| /** | ||
| * @var array<string, mixed> | ||
| */ | ||
| private $backupGet; | ||
|
|
||
| /** | ||
| * @var array<string, mixed> | ||
| */ | ||
| private $backupRequest; | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->backupGet = $_GET; | ||
| $this->backupRequest = $_REQUEST; | ||
|
|
||
| Fixture::createSuperUser(); | ||
| if (!Fixture::siteCreated(1)) { | ||
| Fixture::createWebsite('2012-01-01 00:00:00'); | ||
| } | ||
|
|
||
| Fixture::resetTranslations(); | ||
| Fixture::loadAllTranslations(); | ||
|
|
||
| Manager::getInstance()->loadPlugin('OpenApiDocs'); | ||
|
|
||
| $_GET = [ | ||
| 'idSite' => 1, | ||
| 'period' => 'day', | ||
| 'date' => 'today', | ||
| ]; | ||
| $_REQUEST = $_GET; | ||
|
|
||
| $this->controller = new Controller(); | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| $_GET = $this->backupGet; | ||
| $_REQUEST = $this->backupRequest; | ||
|
|
||
| Fixture::resetTranslations(); | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
|
|
||
| public function testSwaggerRendersAdminPageForViewAccess(): void | ||
| { | ||
| FakeAccess::clearAccess( | ||
| $superUser = false, | ||
| $idSitesAdmin = [0], | ||
| $idSitesView = [1], | ||
| $identity = 'viewAccessUser' | ||
| ); | ||
|
|
||
| $html = $this->controller->swagger(); | ||
|
|
||
| $this->assertNotSame('', $html); | ||
| $this->assertStringContainsString('vue-entry="OpenApiDocs.SwaggerPage"', $html); | ||
| $this->assertStringContainsString('piwik-url=', $html); | ||
| $this->assertStringContainsString('plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui.css', $html); | ||
| $this->assertStringContainsString('plugins/OpenApiDocs/vue/src/SwaggerPage/swagger-ui-overrides.css', $html); | ||
| $this->assertStringContainsString('plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui-bundle.js', $html); | ||
| $this->assertStringContainsString('Swagger', $html); | ||
| } | ||
|
|
||
| public function testSwaggerThrowsWhenUserHasNoAccess(): void | ||
| { | ||
| $originalAccess = StaticContainer::getContainer()->get(Access::class); | ||
| StaticContainer::getContainer()->set(Access::class, new FakeAccess(false, [], [], 'noAccess')); | ||
|
|
||
| try { | ||
| $this->expectException(\Exception::class); | ||
| $this->expectExceptionMessage('checkUserHasSomeViewAccess'); | ||
|
|
||
| $this->controller->swagger(); | ||
| } finally { | ||
| StaticContainer::getContainer()->set(Access::class, $originalAccess); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Piwik\Plugins\OpenApiDocs\tests\Integration; | ||
|
|
||
| use Piwik\Cache; | ||
| use Piwik\Menu\MenuAdmin; | ||
| use Piwik\Plugin\Manager; | ||
| use Piwik\Tests\Framework\Fixture; | ||
| use Piwik\Tests\Framework\Mock\FakeAccess; | ||
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | ||
|
|
||
| /** | ||
| * @group OpenApiDocs | ||
| * @group MenuTest | ||
| * @group Plugins | ||
| */ | ||
| class MenuTest extends IntegrationTestCase | ||
| { | ||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| Fixture::createSuperUser(); | ||
| if (!Fixture::siteCreated(1)) { | ||
| Fixture::createWebsite('2012-01-01 00:00:00'); | ||
| } | ||
|
|
||
| Manager::getInstance()->loadPlugin('OpenApiDocs'); | ||
| } | ||
|
|
||
| public function provideContainerConfig(): array | ||
| { | ||
| return ['Piwik\Access' => new FakeAccess()]; | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| Cache::getTransientCache()->flushAll(); | ||
| MenuAdmin::unsetInstance(); | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
|
|
||
| public function testConfigureAdminMenuAddsSwaggerItemForViewAccess(): void | ||
| { | ||
| FakeAccess::clearAccess( | ||
| $superUser = false, | ||
| $idSitesAdmin = [0], | ||
| $idSitesView = [1], | ||
| $identity = 'viewAccessUser' | ||
| ); | ||
|
|
||
| $items = $this->buildConfiguredMenu()->getMenu(); | ||
|
|
||
| $this->assertArrayHasKey('CorePluginsAdmin_MenuPlatform', $items); | ||
| $this->assertArrayHasKey('OpenApiDocs_SwaggerApi', $items['CorePluginsAdmin_MenuPlatform']); | ||
| } | ||
|
|
||
| public function testConfigureAdminMenuSkipsSwaggerItemWithoutViewAccess(): void | ||
| { | ||
| FakeAccess::clearAccess( | ||
| $superUser = false, | ||
| $idSitesAdmin = [], | ||
| $idSitesView = [], | ||
| $identity = 'noAccessUser' | ||
| ); | ||
|
|
||
| $items = $this->buildConfiguredMenu()->getMenu(); | ||
|
|
||
| if (!isset($items['CorePluginsAdmin_MenuPlatform'])) { | ||
| $this->assertArrayNotHasKey('CorePluginsAdmin_MenuPlatform', $items); | ||
| return; | ||
| } | ||
|
|
||
| $this->assertArrayNotHasKey('OpenApiDocs_SwaggerApi', $items['CorePluginsAdmin_MenuPlatform']); | ||
| } | ||
|
|
||
| private function buildConfiguredMenu(): MenuAdmin | ||
| { | ||
| MenuAdmin::unsetInstance(); | ||
| return MenuAdmin::getInstance(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lachiebol We should also create an FAQ, explaining how you can build the missing spec or it will be auto generated if flag is set, so that user's don't reach out to support after activating the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a part of the checklist? Adding relevant documentation?