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

Also check for id in assertObjectExists #7240

Merged
merged 2 commits into from
Jun 8, 2021

Conversation

VincentLanglet
Copy link
Member

@VincentLanglet VincentLanglet commented Jun 6, 2021

Changelog

### Added
- `strict` param to `CRUDController::assertObjectExist` in order to check for the existence of the id in the request.

));
}
$adminObject = $admin->getObject($objectId);
if (null === $adminObject) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need an extra assert if you are checking here? Maybe make this method final fixes it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is already final.
But phpstan/psalm doesn't know what's happening in the method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus (next commit), the check cannot be done for list and create actions.

@VincentLanglet VincentLanglet requested review from jordisala1991, phansys and a team June 6, 2021 08:13
@VincentLanglet VincentLanglet marked this pull request as ready for review June 6, 2021 08:13
@VincentLanglet VincentLanglet requested review from a team, franmomu and dmaicher June 6, 2021 10:47
@VincentLanglet VincentLanglet added this to the 4.0 milestone Jun 7, 2021
@@ -1658,23 +1671,27 @@ protected function handleXmlHttpRequestSuccessResponse(Request $request, object
], Response::HTTP_OK);
}

final protected function assertObjectExists(Request $request): void
final protected function assertObjectExists(Request $request, bool $strict = false): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases you want to call it with false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For listAction and createAction.

There is no id in the request for the current admin.
But if it's a childAdmin, there will be id for the parent admin, grand-parent admin, and so on.

@jordisala1991 jordisala1991 merged commit 9a5b16b into sonata-project:3.x Jun 8, 2021
@jordisala1991
Copy link
Member

Thanks @VincentLanglet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants