Skip to content

Commit 5e2da7f

Browse files
authored
Fixes #392 (#394) Visibility attribute for API product not enforced correctly
The Apigee M10n module’s hook_ENTITY_TYPE_access uses the Apigee Monetization API to determine an API Product ‘assign’ access by calling `/developers/{developer}/eligible-products`, which returns AccessResult::allowed for all API products. This API returns all API Products 1. That are able to be assigned to an App because the developer purchased a Rate plan that contains the API product 2. All API products that are not monetized. Due to #2, the Apigee Edge module hook_ENTITY_TYPE_access needs to return AccessResult::forbidden when the operation is ‘assign’ and the user does not have the correct role to assign an API product to an app.
1 parent 84e256c commit 5e2da7f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

apigee_edge.module

+8-7
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ function apigee_edge_entity_view(array &$build, EntityInterface $entity, EntityV
365365
* for the API Product (entity) if the API product's access attribute value is
366366
* either one of the selected access attribute values OR if a developer
367367
* app is in association with the selected API product.
368-
* - If operation is "assign" then second part of the previous sentence does
369-
* not apply only access attribute's value matters.
368+
* - If operation is "assign" then disallow access if the role is configured
369+
* in the "Access by visibility" settings at the route
370+
* apigee_edge.settings.developer.api_product_access.
370371
*/
371372
function apigee_edge_api_product_access(EntityInterface $entity, $operation, AccountInterface $account) {
372373
/** @var \Drupal\apigee_edge\Entity\ApiProductInterface $entity */
@@ -386,12 +387,12 @@ function apigee_edge_api_product_access(EntityInterface $entity, $operation, Acc
386387
// access setting but we should still grant view access
387388
// if they have a developer app in association with this API product.
388389
if (empty(array_intersect($visible_to_roles, $account->getRoles()))) {
389-
// We should not return allowed if the operation is "assign"
390-
// just because a user has an app with the API product.
391-
// Displaying these API products to a user should be solved on the
392-
// form level always.
390+
393391
if ($operation === 'assign') {
394-
$result = AccessResult::neutral();
392+
// If the apigee_edge.settings.developer.api_product_access settings
393+
// limits access to this API product, do not allow user to assign it
394+
// to an application.
395+
$result = AccessResult::forbidden("User {$account->getEmail()} is does not have permissions to see API Product with visibility {$product_visibility}.");
395396
}
396397
else {
397398
$result = _apigee_edge_user_has_an_app_with_product($entity->id(), $account, TRUE);

tests/src/FunctionalJavascript/ApiProductAccessTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function entityAccessTest() {
179179
];
180180
$this->saveAccessSettings($settings);
181181
// We have to clear entity access control handler's static cache because
182-
// otherwise access results comes from there instead of gets
182+
// otherwise access results comes from there instead of getting
183183
// recalculated.
184184
$this->accessControlHandler->resetCache();
185185
foreach ($this->users as $userRole => $user) {

0 commit comments

Comments
 (0)