-
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
[Fix] Update delete path name to avoid route conflicts #740
Conversation
'delete' => '', | ||
default => '/' . $shortName, | ||
}; | ||
$path = $operation instanceof ApiOperationInterface && 'delete' === $shortName ? '' : '/' . $shortName; |
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
'delete' => '', | ||
default => '/' . $shortName, | ||
}; | ||
$path = $operation instanceof ApiOperationInterface && 'delete' === $shortName ? '' : '/' . $shortName; |
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.
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 delete
only for non ApiOperationInterface
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.
With my proposal, we have these behaviors.
Non API
#[Delete]
#[Delete(name: 'remove')]
app_book_delete DELETE /admin/books/delete
app_book_remove DELETE /admin/books/remove
API
#[Delete]
#[Delete(name: 'remove')]
app_book_delete DELETE /admin/books
app_book_remove DELETE /admin/books/remove
IMHO, this is ok like this.
Don't think about hidden field, cause we'll need to support POST method with non api routes.
With the next PR, it will be
Non API
#[Delete]
#[Delete(name: 'remove')]
app_book_delete POST, DELETE /admin/books/delete
app_book_remove POST, DELETE /admin/books/remove
API
#[Delete]
#[Delete(name: 'remove')]
app_book_delete DELETE /admin/books
app_book_remove DELETE /admin/books/remove
Thank you, @loic425! |
1/ Delete path name can have some conflicts depending on operation sorting.
On previous routing system, these routing sorting system was hard-coded.
If we place the Bulk delete operation after the delete operation, the bulk delete is broken due to path conflicts.
2/ On current version of Symfony, http method overrides is not enabled by default and then these paths have another issue with same path for delete and edit operation (with POST method).
symfony/recipes#892
Before
After