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

With m10n module enabled, non monetized API products do not follow RBAC #394

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions apigee_edge.module
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ function apigee_edge_entity_view(array &$build, EntityInterface $entity, EntityV
* for the API Product (entity) if the API product's access attribute value is
* either one of the selected access attribute values OR if a developer
* app is in association with the selected API product.
* - If operation is "assign" then second part of the previous sentence does
* not apply only access attribute's value matters.
* - If operation is "assign" then disallow access if the role is configured
* in the "Access by visibility" settings at the route
* apigee_edge.settings.developer.api_product_access.
*/
function apigee_edge_api_product_access(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\apigee_edge\Entity\ApiProductInterface $entity */
Expand All @@ -386,12 +387,12 @@ function apigee_edge_api_product_access(EntityInterface $entity, $operation, Acc
// access setting but we should still grant view access
// if they have a developer app in association with this API product.
if (empty(array_intersect($visible_to_roles, $account->getRoles()))) {
// We should not return allowed if the operation is "assign"
// just because a user has an app with the API product.
// Displaying these API products to a user should be solved on the
// form level always.

if ($operation === 'assign') {
$result = AccessResult::neutral();
// If the apigee_edge.settings.developer.api_product_access settings
// limits access to this API product, do not allow user to assign it
// to an application.
$result = AccessResult::forbidden("User {$account->getEmail()} is does not have permissions to see API Product with visibility {$product_visibility}.");
}
else {
$result = _apigee_edge_user_has_an_app_with_product($entity->id(), $account, TRUE);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/FunctionalJavascript/ApiProductAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function entityAccessTest() {
];
$this->saveAccessSettings($settings);
// We have to clear entity access control handler's static cache because
// otherwise access results comes from there instead of gets
// otherwise access results comes from there instead of getting
// recalculated.
$this->accessControlHandler->resetCache();
foreach ($this->users as $userRole => $user) {
Expand Down