From 65ac17151e5009bab540ea0c11aeef0b04952288 Mon Sep 17 00:00:00 2001 From: Kyle Huynh Date: Tue, 23 Jul 2024 09:41:35 -0400 Subject: [PATCH 1/2] Remove Access control dependencies, to get the module works with sites which has no Group access control Make module to available for D11 --- group_solr.info.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/group_solr.info.yml b/group_solr.info.yml index dde4095..0cb42fc 100644 --- a/group_solr.info.yml +++ b/group_solr.info.yml @@ -1,9 +1,7 @@ name: 'Search API Solr Access Control With Groups' type: module description: 'This module add Solr indexed field(s) which is determined access control with Group module for an indexed item to be public or private for annonymous users' -core_version_requirement: ^8.8 || ^9 || ^10 +core_version_requirement: ^8.8 || ^9 || ^10 || ^11 package: 'Custom' dependencies: - - group - - groupmedia - search_api_solr From c848df5ff8577cca0732e9c80700d8b398cfad6b Mon Sep 17 00:00:00 2001 From: Kyle Huynh Date: Tue, 23 Jul 2024 09:41:45 -0400 Subject: [PATCH 2/2] Set content has no Group access control with 200 --- .../search_api/processor/AccessControl.php | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Plugin/search_api/processor/AccessControl.php b/src/Plugin/search_api/processor/AccessControl.php index 19d6161..ae3344c 100644 --- a/src/Plugin/search_api/processor/AccessControl.php +++ b/src/Plugin/search_api/processor/AccessControl.php @@ -53,49 +53,54 @@ public function addFieldValues(ItemInterface $item) { $entity = $item->getOriginalObject()->getValue(); $operation = "view"; - /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $plugin_manager */ - $plugin_manager = \Drupal::service('group_relation_type.manager'); + if (\Drupal::hasService('group_relation_type.manager')) { + /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $plugin_manager */ + $plugin_manager = \Drupal::service('group_relation_type.manager'); - if (!method_exists($entity, "getEntityTypeId")) - return; - - $plugin_ids = $plugin_manager->getPluginIdsByEntityTypeAccess($entity->getEntityTypeId()); - - $plugin_cache_tags = []; - foreach ($plugin_ids as $plugin_id) { - $plugin_cache_tags[] = "group_content_list:plugin:$plugin_id"; - } + if (!method_exists($entity, "getEntityTypeId")) + return; + + $plugin_ids = $plugin_manager->getPluginIdsByEntityTypeAccess($entity->getEntityTypeId()); - // Load all of the group content for this entity. - $group_contents = GroupRelationship::loadByEntity($entity); - if (!empty($group_contents) && count($group_contents) > 0) { - $access = AccessResult::neutral(); + $plugin_cache_tags = []; foreach ($plugin_ids as $plugin_id) { - /*if (!$plugin_manager->hasHandler($plugin_id, 'access')) { - continue; - }*/ - - $handler = $plugin_manager->getAccessControlHandler($plugin_id); - $access = $access->orIf($handler->entityAccess($entity, $operation, User::getAnonymousUser(), TRUE)); + $plugin_cache_tags[] = "group_content_list:plugin:$plugin_id"; } - $access - ->addCacheTags($plugin_cache_tags) - ->addCacheContexts(['user.group_permissions']); - - if ($access->isAllowed()) { + // Load all of the group content for this entity. + $group_contents = GroupRelationship::loadByEntity($entity); + if (!empty($group_contents) && count($group_contents) > 0) { + $access = AccessResult::neutral(); + foreach ($plugin_ids as $plugin_id) { + /*if (!$plugin_manager->hasHandler($plugin_id, 'access')) { + continue; + }*/ + + $handler = $plugin_manager->getAccessControlHandler($plugin_id); + $access = $access->orIf($handler->entityAccess($entity, $operation, User::getAnonymousUser(), TRUE)); + } + + $access + ->addCacheTags($plugin_cache_tags) + ->addCacheContexts(['user.group_permissions']); + + if ($access->isAllowed()) { + $value = "200"; + } + else { + $groups = Utilities::getGroupsByNode($entity->id()); + sort($groups); + $value = implode(",", $groups); + } + + + }else { $value = "200"; } - else { - $groups = Utilities::getGroupsByNode($entity->id()); - sort($groups); - $value = implode(",", $groups); - } - - - }else { + } else { $value = "200"; } + // index field $fields = $item->getFields(FALSE); $fields = $this->getFieldsHelper()