Skip to content
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

Feature/visits threshold change #1284

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

### Changed
* [#1268](https://github.com/shlinkio/shlink/issues/1268) Updated dependencies, including symfony/console 6 and mezzio/mezzio-swoole 4.
* [#1283](https://github.com/shlinkio/shlink/issues/1283) Changed behavior of `DELETE_SHORT_URL_THRESHOLD` env var, disabling the feature if a value was not provided.

### Deprecated
* *Nothing*
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* `tag:create`: Creating orphan tags makes no sense.
* Params in camelCase format are no longer supported. They all have an equivalent kebab-case replacement. (for example, from `--startDate` to `--start-date`).
* The `short-url:create` command no longer accepts the `--no-validate-url` flag. Now URLs are never validated, unless `--validate-url` is passed.
* The CLI installer tool entry-points have changed.
* `bin/install`: replaced by `vendor/bin/shlink-installer install`
* `bin/update`: replaced by `vendor/bin/shlink-installer update`
* `bin/set-option`: replaced by `vendor/bin/shlink-installer set-option`

### Changes in config

Expand All @@ -31,6 +35,8 @@
* `SHORT_DOMAIN_SCHEMA`: Replaced by `IS_HTTPS_ENABLED`.
* `USE_HTTPS`: Replaced by `IS_HTTPS_ENABLED`.
* `VALIDATE_URLS`: There's no replacement. URLs are not validated, unless explicitly requested during creation or edition.
* The next env vars behavior has changed:
* `DELETE_SHORT_URL_THRESHOLD`: Now, if this env var is not provided, the "visits threshold" won't be checked at all when deleting short URLs. Make sure you explicitly provide a value if you want to enable this feature.

### Other changes

Expand Down
12 changes: 0 additions & 12 deletions bin/install

This file was deleted.

14 changes: 0 additions & 14 deletions bin/set-option

This file was deleted.

12 changes: 0 additions & 12 deletions bin/update

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"shlinkio/shlink-config": "^1.4",
"shlinkio/shlink-event-dispatcher": "^2.3",
"shlinkio/shlink-importer": "^2.5",
"shlinkio/shlink-installer": "^6.3",
"shlinkio/shlink-installer": "dev-develop#64f8ab2 as 7.0",
"shlinkio/shlink-ip-geolocation": "^2.2",
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
Expand Down
16 changes: 9 additions & 7 deletions config/autoload/delete_short_urls.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use function Shlinkio\Shlink\Common\env;

use const Shlinkio\Shlink\DEFAULT_DELETE_SHORT_URL_THRESHOLD;
return (static function (): array {
$threshold = env('DELETE_SHORT_URL_THRESHOLD');

return [
return [

'delete_short_urls' => [
'check_visits_threshold' => true,
'visits_threshold' => (int) env('DELETE_SHORT_URL_THRESHOLD', DEFAULT_DELETE_SHORT_URL_THRESHOLD),
],
'delete_short_urls' => [
'check_visits_threshold' => $threshold !== null,
'visits_threshold' => (int) ($threshold ?? DEFAULT_DELETE_SHORT_URL_THRESHOLD),
],

];
];
})();
3 changes: 1 addition & 2 deletions config/autoload/installer.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Option\Database\DatabaseMySqlOptionsConfigOption::class,
Option\UrlShortener\ShortDomainHostConfigOption::class,
Option\UrlShortener\ShortDomainSchemaConfigOption::class,
Option\UrlShortener\ValidateUrlConfigOption::class,
Option\Visit\VisitsWebhooksConfigOption::class,
Option\Visit\OrphanVisitsWebhooksConfigOption::class,
Option\Redirect\BaseUrlRedirectConfigOption::class,
Expand All @@ -33,7 +32,7 @@
Option\BasePathConfigOption::class,
Option\Worker\TaskWorkerNumConfigOption::class,
Option\Worker\WebWorkerNumConfigOption::class,
Option\RedisServersConfigOption::class,
Option\RedisConfigOption::class,
Option\UrlShortener\ShortCodeLengthOption::class,
Option\Mercure\EnableMercureConfigOption::class,
Option\Mercure\MercurePublicUrlConfigOption::class,
Expand Down
20 changes: 0 additions & 20 deletions module/Rest/test-api/Action/DeleteShortUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ public function notFoundErrorIsReturnWhenDeletingInvalidUrl(
self::assertEquals($domain, $payload['domain'] ?? null);
}

/** @test */
public function unprocessableEntityIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void
{
// Generate visits first
for ($i = 0; $i < 20; $i++) {
self::assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
}
$expectedDetail = 'Impossible to delete short URL with short code "abc123", since it has more than "15" '
. 'visits.';

$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
$payload = $this->getJsonResponsePayload($resp);

self::assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $resp->getStatusCode());
self::assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $payload['status']);
self::assertEquals('INVALID_SHORT_URL_DELETION', $payload['type']);
self::assertEquals($expectedDetail, $payload['detail']);
self::assertEquals('Cannot delete short URL', $payload['title']);
}

/** @test */
public function properShortUrlIsDeletedWhenDomainIsProvided(): void
{
Expand Down