-
Notifications
You must be signed in to change notification settings - Fork 155
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
[Fix] Update delete path name to avoid route conflicts #740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Resource\Metadata\Api; | ||
|
||
/** | ||
* @experimental | ||
*/ | ||
interface ApiOperationInterface | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
namespace Sylius\Component\Resource\Symfony\Routing\Factory; | ||
|
||
use Sylius\Component\Resource\Metadata\Api\ApiOperationInterface; | ||
use Sylius\Component\Resource\Metadata\DeleteOperationInterface; | ||
use Sylius\Component\Resource\Metadata\HttpOperation; | ||
|
||
|
@@ -28,10 +29,7 @@ public function createRoutePath(HttpOperation $operation, string $rootPath): str | |
$identifier = $operation->getResource()?->getIdentifier() ?? 'id'; | ||
|
||
if ($operation instanceof DeleteOperationInterface) { | ||
$path = match ($shortName) { | ||
'delete' => '', | ||
default => '/' . $shortName, | ||
}; | ||
$path = $operation instanceof ApiOperationInterface && 'delete' === $shortName ? '' : '/' . $shortName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about it. The fix is needed, but in API this delete suffix should be required only in non API context. Once we are in API context, it is okay to have exactly the same URL but with different HTTP method. This logic is required only when we have a form, that will send a POST request with hidden DELETE notation. What I would recommend is to reverse this condition so we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With my proposal, we have these behaviors. Non API #[Delete]
#[Delete(name: 'remove')]
API #[Delete]
#[Delete(name: 'remove')]
IMHO, this is ok like this. With the next PR, it will be Non API #[Delete]
#[Delete(name: 'remove')]
API #[Delete]
#[Delete(name: 'remove')]
|
||
|
||
return sprintf('%s/{%s}%s', $rootPath, $identifier, $path); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,17 +50,17 @@ public function it_allows_browsing_subscriptions(): void | |
$this->assertStringContainsString('<td>[email protected]</td>', $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s">Show</a>', $subscriptions['subscription_marty']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s/edit">Edit</a>', $subscriptions['subscription_marty']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s" method="post">', $subscriptions['subscription_marty']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s/delete" method="post">', $subscriptions['subscription_marty']->getId()), $content); | ||
|
||
$this->assertStringContainsString('<td>[email protected]</td>', $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s">Show</a>', $subscriptions['subscription_doc']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s/edit">Edit</a>', $subscriptions['subscription_doc']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s" method="post">', $subscriptions['subscription_doc']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s/delete" method="post">', $subscriptions['subscription_doc']->getId()), $content); | ||
|
||
$this->assertStringContainsString('<td>[email protected]</td>', $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s">Show</a>', $subscriptions['subscription_biff']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s/edit">Edit</a>', $subscriptions['subscription_biff']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s" method="post">', $subscriptions['subscription_biff']->getId()), $content); | ||
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s/delete" method="post">', $subscriptions['subscription_biff']->getId()), $content); | ||
} | ||
|
||
/** @test */ | ||
|
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.
What about adding the
delete
string injected in this service, allowing developers to customize the url slug can maybe be a thing.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.
Hum interesting, but if we do that for this one, we have to do that for every operations.
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.
It was just an idea, it will need a dedicated PR