Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
🐛 (Small bugs) Fixed 3 bugs
Browse files Browse the repository at this point in the history
UserDataVisibilityItemDataProvider was crashing when trying to provide data to a non-authenticated user. PATCH /users/{id} didn't have the skip_null_values parameter set to false. On creation,
UserInfos::$birthday was not set to a round day (it was set to the current time, not the current day)
  • Loading branch information
Teddy Roncin committed Feb 3, 2023
1 parent d449038 commit b2b9718
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/DataProvider/UserDataVisibilityItemDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
return null;
}

if (!$userLogged) {
// We don't want to return null because it would return a 404
return new User();
}

/** @var UserAddress $address */
foreach ($userToShow->getAddresses()->getValues() as $address) {
if (!$this->canAccessInfo($userToShow, $address->getAddressVisibility(), $userLogged)) {
Expand Down
5 changes: 4 additions & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
security: "is_granted('ROLE_ADMIN')",
),
new Patch(
normalizationContext: ['groups' => ['user:read:one']],
normalizationContext: [
'groups' => ['user:read:one'],
'skip_null_values' => false,
],
denormalizationContext: ['groups' => ['user:write:update']],
security: "object == user or is_granted('ROLE_ADMIN')",
),
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/UserInfos.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function __construct()
{
// Default values
$this->setSex('Autre');
$this->setBirthday(new \DateTime());
$this->setBirthday((new \DateTime())->setTime(0, 0));
$this->setAvatar('/default_user_avatar.png');

$this->sexVisibility = new ArrayCollection();
Expand Down

0 comments on commit b2b9718

Please sign in to comment.