diff --git a/docs/swagger/paths/v1_short-urls.json b/docs/swagger/paths/v1_short-urls.json index a29c221e..1a58ef14 100644 --- a/docs/swagger/paths/v1_short-urls.json +++ b/docs/swagger/paths/v1_short-urls.json @@ -156,6 +156,15 @@ "schema": { "type": "string" } + }, + { + "name": "apiKeyName", + "in": "query", + "description": "Only get short URLs created with this API key.
This value is **ignored** if the request is performed with a non-admin API key that does not match this name.", + "required": false, + "schema": { + "type": "string" + } } ], "security": [ diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 755d179c..8d75322e 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -209,6 +209,7 @@ class ListShortUrlsCommandTest extends TestCase string|null $endDate = null, array $excludeTags = [], string $excludeTagsMode = TagsMode::ANY->value, + string|null $apiKeyName = null, ): void { $this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([ 'page' => $page, @@ -219,6 +220,7 @@ class ListShortUrlsCommandTest extends TestCase 'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null, 'excludeTags' => $excludeTags, 'excludeTagsMode' => $excludeTagsMode, + 'apiKeyName' => $apiKeyName, ]))->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->setInputs(['n']); @@ -275,6 +277,18 @@ class ListShortUrlsCommandTest extends TestCase ['foo', 'bar'], TagsMode::ALL->value, ]; + yield [ + ['--api-key-name' => 'foo'], + 1, + null, + [], + TagsMode::ANY->value, + null, + null, + [], + TagsMode::ANY->value, + 'foo', + ]; } #[Test, DataProvider('provideOrderBy')] diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index 34aaa802..14b52d42 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -297,6 +297,24 @@ class ListShortUrlsTest extends ApiTestCase self::SHORT_URL_DOCS, ]]; + // Filter by API key name + yield [['apiKeyName' => 'author_api_key'], [ + self::SHORT_URL_CUSTOM_SLUG, + self::SHORT_URL_META, + self::SHORT_URL_SHLINK_WITH_TITLE, + ]]; + yield [['apiKeyName' => 'invalid'], []]; + yield [['apiKeyName' => 'valid_api_key'], [ + // If the author_api_key is used, the `apiKeyName` param is ignored + self::SHORT_URL_CUSTOM_SLUG, + self::SHORT_URL_META, + self::SHORT_URL_SHLINK_WITH_TITLE, + ], 'author_api_key']; + yield [['apiKeyName' => 'valid_api_key'], [ + // If the domain_api_key is used, the `apiKeyName` param is ignored + self::SHORT_URL_CUSTOM_DOMAIN, + ], 'domain_api_key']; + // Different API keys yield [[], [ self::SHORT_URL_CUSTOM_SLUG,