Skip to content
Open
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
40 changes: 15 additions & 25 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -112,41 +112,31 @@ function og_entity_field_access($operation, FieldDefinitionInterface $field_defi
*/
function og_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
// We only care about content entities that are groups or group content.
if (!$entity instanceof ContentEntityInterface) {
return AccessResult::neutral();
}

if ($operation == 'view') {
if (!$entity instanceof ContentEntityInterface || $operation == 'view') {
return AccessResult::neutral();
}

$entity_type_id = $entity->getEntityTypeId();
$bundle_id = $entity->bundle();

if (!Og::isGroup($entity_type_id, $bundle_id) && !Og::isGroupContent($entity_type_id, $bundle_id)) {
return AccessResult::neutral();
}

// If the user has permission to administer all groups, allow access.
if ($account->hasPermission('administer group')) {
return AccessResult::allowed();
}

/** @var \Drupal\Core\Access\AccessResult $access */
$access = \Drupal::service('og.access')->userAccessEntity($operation, $entity, $account);
if (Og::isGroup($entity_type_id, $bundle_id) || Og::isGroupContent($entity_type_id, $bundle_id)) {
// If the user has permission to administer all groups, allow access.
if ($account->hasPermission('administer group')) {
return AccessResult::allowed();
}

if ($access->isAllowed()) {
return $access;
}
/** @var \Drupal\Core\Access\AccessResult $access */
$access = \Drupal::service('og.access')->userAccessEntity($operation, $entity, $account);

if ($entity_type_id == 'node') {
$node_access_strict = \Drupal::config('og.settings')->get('node_access_strict');
if ($access->isAllowed()) {
return $access;
}

// Otherwise, ignore or deny based on whether strict node access is set.
return AccessResult::forbiddenIf($node_access_strict);
// Otherwise, forbid if strict node access is set.
if ($entity_type_id == 'node' && \Drupal::config('og.settings')->get('node_access_strict')) {
return AccessResult::forbidden();
}
}

return AccessResult::forbidden();
}

/**
Expand Down