Skip to content

Commit

Permalink
Replace 'bypass group access' permission validation to group-permissi…
Browse files Browse the repository at this point in the history
…on validation.
  • Loading branch information
vcsvinicius committed Nov 21, 2024
1 parent 28ebded commit b93338a
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Drupal\activity_viewer\Plugin\views\filter;

use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\group\Entity\GroupInterface;
use Drupal\social_group\SocialGroupHelperService;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\Views;
Expand All @@ -24,6 +26,13 @@ class ActivityPostVisibilityAccess extends FilterPluginBase {
*/
protected $groupHelper;

/**
* The route match interface.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;

/**
* Constructs a Handler object.
*
Expand All @@ -35,11 +44,20 @@ class ActivityPostVisibilityAccess extends FilterPluginBase {
* The plugin implementation definition.
* @param \Drupal\social_group\SocialGroupHelperService $group_helper
* The group helper.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The currently active route match object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, SocialGroupHelperService $group_helper) {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
SocialGroupHelperService $group_helper,
RouteMatchInterface $route_match
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);

$this->groupHelper = $group_helper;
$this->routeMatch = $route_match;
}

/**
Expand All @@ -48,7 +66,8 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration, $plugin_id, $plugin_definition,
$container->get('social_group.helper_service')
$container->get('social_group.helper_service'),
$container->get('current_route_match')
);
}

Expand Down Expand Up @@ -205,7 +224,11 @@ public function query():void {
$post_access = new Condition('AND');
$post_access->condition('activity__field_activity_entity.field_activity_entity_target_type', 'post');

if (!$account->hasPermission('bypass group access')) {
// Get group from url-parameter.
$group = $this->routeMatch->getParameter('group');
// If the group parameter isn't group entity, visibility rules.
// And check group permission when group parameter is group entity.
if (!$group instanceof GroupInterface || !$group->hasPermission('access content overview', $account)) {
$post_access->condition('post__field_visibility.field_visibility_value', '3', '!=');

if (!$account->hasPermission('view public posts')) {
Expand Down

0 comments on commit b93338a

Please sign in to comment.