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

Fix invalid handling of possible null values #393

Merged
merged 7 commits into from
Aug 22, 2022
18 changes: 14 additions & 4 deletions src/Entity/Access/RatePlanAccessControlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
// does not belong to rate_plan category.
/** @var \Drupal\apigee_edge\Entity\DeveloperInterface $developer */
if ($rate_plan instanceof DeveloperCategoryRatePlanInterface) {
if (($category = $rate_plan->getDeveloperCategory()) && ($developer = $this->entityTypeManager->getStorage('developer')->load($account->getEmail()))) {
return AccessResult::allowedIf(($developer_category = $developer->decorated()->getAttributeValue('MINT_DEVELOPER_CATEGORY')) && ($category->id() === $developer_category))
->andIf(AccessResult::allowedIfHasPermission($account, "$operation rate_plan"));
$category = $rate_plan->getDeveloperCategory();
if ($category === NULL) {
return AccessResult::forbidden("Missing developer category reference on {$rate_plan->id()} rate plan, {$operation} is not allowed.");
}
else {
$developer = $this->entityTypeManager->getStorage('developer')->load($account->getEmail());
if ($developer) {
$developer_category = $developer->decorated()->getAttributeValue('MINT_DEVELOPER_CATEGORY') ?? '';
return AccessResult::allowedIf($category->id() === $developer_category)->andIf(AccessResult::allowedIfHasPermission($account, "$operation rate_plan"));
}
else {
// Should not happen.
return AccessResult::forbidden("Could not fetch developer information for {$account->getEmail()}.");
}
}
return AccessResult::forbidden("User {$developer->getEmail()} missing required developer category.");
}

// If rate plan is a developer rate plan, and the assigned developer is
Expand Down