mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Applied API role specs to single short URL edition
This commit is contained in:
@@ -11,6 +11,7 @@ use Shlinkio\Shlink\Core\Model\ShortUrlEdit;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
|
||||
|
||||
class EditShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
@@ -28,8 +29,9 @@ class EditShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
$shortUrlEdit = ShortUrlEdit::fromRawData((array) $request->getParsedBody());
|
||||
$identifier = ShortUrlIdentifier::fromApiRequest($request);
|
||||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
||||
|
||||
$this->shortUrlService->updateMetadataByShortCode($identifier, $shortUrlEdit);
|
||||
$this->shortUrlService->updateMetadataByShortCode($identifier, $shortUrlEdit, $apiKey);
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
class EditShortUrlActionTest extends TestCase
|
||||
{
|
||||
@@ -43,6 +44,7 @@ class EditShortUrlActionTest extends TestCase
|
||||
public function correctShortCodeReturnsSuccess(): void
|
||||
{
|
||||
$request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
|
||||
->withAttribute(ApiKey::class, new ApiKey())
|
||||
->withParsedBody([
|
||||
'maxVisits' => 5,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user