Skip to content

Commit

Permalink
fix: if an attribute is not required, allow it to not be set
Browse files Browse the repository at this point in the history
When using the API would get "Undefinedarray key" errors on missing
custom attributes, even though those attributes were not required.

Now allow the custom attribute to be missing if not a required custom
attribute.
  • Loading branch information
JohnVillalovos committed May 31, 2024
1 parent a27ce5b commit 657ddb7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/Application/Attributes/AttributeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,22 @@ public function Validate($category, $attributeValues, $entityIds = [], $ignoreEm

$attributes = $this->attributeRepository->GetByCategory($category);
foreach ($attributes as $attribute) {
if (!empty($entityIds) &&
if (
!empty($entityIds) &&
(($attribute->UniquePerEntity() && count(array_intersect($entityIds, $attribute->EntityIds())) == 0) ||
($attribute->HasSecondaryEntities() && count(array_intersect($entityIds, $attribute->SecondaryEntityIds())) == 0))) {
($attribute->HasSecondaryEntities() && count(array_intersect($entityIds, $attribute->SecondaryEntityIds())) == 0))
) {
continue;
}

if ($attribute->AdminOnly() && !$isAdmin) {
continue;
}

if (!$attribute->Required() && !array_key_exists($attribute->Id(), $values)) {
continue;
}

$value = trim($values[$attribute->Id()]);
$label = $attribute->Label();

Expand Down Expand Up @@ -225,13 +231,14 @@ public function GetReservationAttributes(UserSession $userSession, ReservationVi
$customAttributes = $this->GetByCategory(CustomAttributeCategory::RESERVATION);
foreach ($customAttributes as $attribute) {
$secondaryCategory = $attribute->SecondaryCategory();
if (empty($secondaryCategory) ||
(
$secondaryCategory == CustomAttributeCategory::USER &&
$this->AvailableForUser($userSession, $requestedUserId, $secondaryCategory, $attribute) ||
if (
empty($secondaryCategory) ||
(
$secondaryCategory == CustomAttributeCategory::USER &&
$this->AvailableForUser($userSession, $requestedUserId, $secondaryCategory, $attribute) ||
(($secondaryCategory == CustomAttributeCategory::RESOURCE || $secondaryCategory == CustomAttributeCategory::RESOURCE_TYPE)
&& $this->AvailableForResource($userSession, $secondaryCategory, $attribute, $requestedResourceIds))
)
&& $this->AvailableForResource($userSession, $secondaryCategory, $attribute, $requestedResourceIds))
)
) {
$viewableForPrivate = (!$attribute->IsPrivate() || ($attribute->IsPrivate() && $this->CanReserveFor($userSession, $requestedUserId)));
$viewableForAdmin = (!$attribute->AdminOnly() || ($attribute->AdminOnly() && $this->GetAuthorizationService()->IsAdminFor($userSession, $requestedUserId)));
Expand Down

0 comments on commit 657ddb7

Please sign in to comment.