Skip to content

Commit

Permalink
Merge pull request #8 from digitalutsc/20240723
Browse files Browse the repository at this point in the history
Update July 23, 2023
  • Loading branch information
kylehuynh205 authored Jul 23, 2024
2 parents a9e64f9 + c848df5 commit f17d138
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
4 changes: 1 addition & 3 deletions group_solr.info.yml
Original file line number Diff line number Diff line change
@@ -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
73 changes: 39 additions & 34 deletions src/Plugin/search_api/processor/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f17d138

Please sign in to comment.