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

Issue #3487312: Site managers can't see content of groups they are not part of #4184

Merged
merged 2 commits into from
Dec 5, 2024
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
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are lucky that #4118 is not merged yet, it brings a current group service that could have been used. :)

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
if (
!$account->hasPermission('bypass group access') &&
!$account->hasPermission('bypass create group access') &&
!$this->configFactory->get('social_group.settings')->get('allow_group_create')
) {
Expand Down
Loading