mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 07:03:44 -06:00
Show only API key name in short URLs list
This commit is contained in:
parent
a094be2b9e
commit
9f6975119e
@ -118,14 +118,9 @@ class ListShortUrlsCommand extends Command
|
||||
'show-api-key',
|
||||
'k',
|
||||
InputOption::VALUE_NONE,
|
||||
'Whether to display the API key from which the URL was generated or not.',
|
||||
)
|
||||
->addOption(
|
||||
'show-api-key-name',
|
||||
'm',
|
||||
InputOption::VALUE_NONE,
|
||||
'Whether to display the API key name from which the URL was generated or not.',
|
||||
)
|
||||
->addOption('show-api-key-name', 'm', InputOption::VALUE_NONE, '[DEPRECATED] Use show-api-key')
|
||||
->addOption(
|
||||
'all',
|
||||
'a',
|
||||
@ -242,11 +237,7 @@ class ListShortUrlsCommand extends Command
|
||||
$columnsMap['Domain'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
||||
$shortUrl->getDomain()?->authority ?? Domain::DEFAULT_AUTHORITY;
|
||||
}
|
||||
if ($input->getOption('show-api-key')) {
|
||||
$columnsMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
||||
$shortUrl->authorApiKey?->key ?? '';
|
||||
}
|
||||
if ($input->getOption('show-api-key-name')) {
|
||||
if ($input->getOption('show-api-key') || $input->getOption('show-api-key-name')) {
|
||||
$columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): string|null =>
|
||||
$shortUrl->authorApiKey?->name;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
use function count;
|
||||
use function explode;
|
||||
|
||||
class ListShortUrlsCommandTest extends TestCase
|
||||
@ -105,94 +104,100 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
#[Test, DataProvider('provideOptionalFlags')]
|
||||
public function provideOptionalFlagsMakesNewColumnsToBeIncluded(
|
||||
array $input,
|
||||
array $expectedContents,
|
||||
array $notExpectedContents,
|
||||
ApiKey $apiKey,
|
||||
string $expectedOutput,
|
||||
ShortUrl $shortUrl,
|
||||
): void {
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(
|
||||
ShortUrlsParams::empty(),
|
||||
)->willReturn(new Paginator(new ArrayAdapter([
|
||||
ShortUrlWithDeps::fromShortUrl(
|
||||
ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||
'longUrl' => 'https://foo.com',
|
||||
'tags' => ['foo', 'bar', 'baz'],
|
||||
'apiKey' => $apiKey,
|
||||
])),
|
||||
),
|
||||
ShortUrlWithDeps::fromShortUrl($shortUrl),
|
||||
])));
|
||||
|
||||
$this->commandTester->setInputs(['y']);
|
||||
$this->commandTester->execute($input);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
if (count($expectedContents) === 0 && count($notExpectedContents) === 0) {
|
||||
self::fail('No expectations were run');
|
||||
}
|
||||
|
||||
foreach ($expectedContents as $column) {
|
||||
self::assertStringContainsString($column, $output);
|
||||
}
|
||||
foreach ($notExpectedContents as $column) {
|
||||
self::assertStringNotContainsString($column, $output);
|
||||
}
|
||||
self::assertStringContainsString($expectedOutput, $output);
|
||||
}
|
||||
|
||||
public static function provideOptionalFlags(): iterable
|
||||
{
|
||||
$apiKey = ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'my api key'));
|
||||
$key = $apiKey->key;
|
||||
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||
'longUrl' => 'https://foo.com',
|
||||
'tags' => ['foo', 'bar', 'baz'],
|
||||
'apiKey' => ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'my api key')),
|
||||
]));
|
||||
$shortCode = $shortUrl->getShortCode();
|
||||
$created = $shortUrl->dateCreated()->toAtomString();
|
||||
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
yield 'tags only' => [
|
||||
['--show-tags' => true],
|
||||
['| Tags ', '| foo, bar, baz'],
|
||||
['| API Key ', '| API Key Name |', $key, '| my api key', '| Domain', '| DEFAULT'],
|
||||
$apiKey,
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | Tags |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | foo, bar, baz |
|
||||
+------------+-------+-------------+-------------- Page 1 of 1 ------------------+--------------+---------------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
yield 'domain only' => [
|
||||
['--show-domain' => true],
|
||||
['| Domain', '| DEFAULT'],
|
||||
['| Tags ', '| foo, bar, baz', '| API Key ', '| API Key Name |', $key, '| my api key'],
|
||||
$apiKey,
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | Domain |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | DEFAULT |
|
||||
+------------+-------+-------------+----------- Page 1 of 1 ---------------------+--------------+---------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
yield 'api key only' => [
|
||||
['--show-api-key' => true],
|
||||
['| API Key ', $key],
|
||||
['| Tags ', '| foo, bar, baz', '| API Key Name |', '| my api key', '| Domain', '| DEFAULT'],
|
||||
$apiKey,
|
||||
];
|
||||
yield 'api key name only' => [
|
||||
['--show-api-key-name' => true],
|
||||
['| API Key Name |', '| my api key'],
|
||||
['| Tags ', '| foo, bar, baz', '| API Key ', $key],
|
||||
$apiKey,
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+--------------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | API Key Name |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+--------------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | my api key |
|
||||
+------------+-------+-------------+------------- Page 1 of 1 -------------------+--------------+--------------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
yield 'tags and api key' => [
|
||||
['--show-tags' => true, '--show-api-key' => true],
|
||||
['| API Key ', '| Tags ', '| foo, bar, baz', $key],
|
||||
['| API Key Name |', '| my api key'],
|
||||
$apiKey,
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+--------------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | Tags | API Key Name |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+--------------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | foo, bar, baz | my api key |
|
||||
+------------+-------+-------------+-----------------+--- Page 1 of 1 -----------+--------------+---------------+--------------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
yield 'tags and domain' => [
|
||||
['--show-tags' => true, '--show-domain' => true],
|
||||
['| Tags ', '| foo, bar, baz', '| Domain', '| DEFAULT'],
|
||||
['| API Key Name |', '| my api key'],
|
||||
$apiKey,
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+---------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | Tags | Domain |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+---------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | foo, bar, baz | DEFAULT |
|
||||
+------------+-------+-------------+-----------------+- Page 1 of 1 -------------+--------------+---------------+---------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
yield 'all' => [
|
||||
['--show-tags' => true, '--show-domain' => true, '--show-api-key' => true, '--show-api-key-name' => true],
|
||||
[
|
||||
'| API Key ',
|
||||
'| Tags ',
|
||||
'| API Key Name |',
|
||||
'| foo, bar, baz',
|
||||
$key,
|
||||
'| my api key',
|
||||
'| Domain',
|
||||
'| DEFAULT',
|
||||
],
|
||||
[],
|
||||
$apiKey,
|
||||
['--show-tags' => true, '--show-domain' => true, '--show-api-key' => true],
|
||||
<<<OUTPUT
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+---------+--------------+
|
||||
| Short Code | Title | Short URL | Long URL | Date created | Visits count | Tags | Domain | API Key Name |
|
||||
+------------+-------+-------------+-----------------+---------------------------+--------------+---------------+---------+--------------+
|
||||
| {$shortCode} | | http:/{$shortCode} | https://foo.com | {$created} | 0 | foo, bar, baz | DEFAULT | my api key |
|
||||
+------------+-------+-------------+-----------------+-------- Page 1 of 1 ------+--------------+---------------+---------+--------------+
|
||||
OUTPUT,
|
||||
$shortUrl,
|
||||
];
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideArgs')]
|
||||
|
@ -200,6 +200,11 @@ class ShortUrl extends AbstractEntity
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function dateCreated(): Chronos
|
||||
{
|
||||
return $this->dateCreated;
|
||||
}
|
||||
|
||||
public function reachedVisits(int $visitsAmount): bool
|
||||
{
|
||||
return count($this->visits) >= $visitsAmount;
|
||||
|
Loading…
Reference in New Issue
Block a user