Commit 0cf19177 authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3280870 by kristiaanvandeneynde: Rely on the Flexible permissions module

parent 256a21a2
Loading
Loading
Loading
Loading
+1 −1
Changes for composer.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -19,6 +19,6 @@
  "require": {
    "drupal/core": "^8.9 || ^9",
    "drupal/entity": "^1.2",
    "drupal/variationcache": "^1.0"
    "drupal/flexible_permissions": "^1.0"
  }
}
+2 −2
Changes for group.info.yml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@ name: 'Group'
description: 'Allows you to group users, content and other entities'
package: 'Group'
type: 'module'
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
configure: 'group.settings'
dependencies:
  - 'drupal:options'
  - 'entity:entity'
  - 'variationcache:variationcache'
  - 'flexible_permissions:flexible_permissions'
+14 −59
Changes for group.services.yml: 14 added lines, 59 removed lines.
Original line number Diff line number Diff line
@@ -41,13 +41,6 @@ services:
    tags:
      - { name: 'access_check', applies_to: '_group_latest_revision' }

  cache.group_permission:
    class: 'Drupal\Core\Cache\CacheBackendInterface'
    factory: 'cache_factory:get'
    arguments: ['group_permission']
    tags:
      - { name: 'cache.bin' }

  cache_context.route.group:
    class: 'Drupal\group\Cache\Context\RouteGroupCacheContext'
    arguments: ['@current_route_match', '@entity_type.manager']
@@ -55,7 +48,7 @@ services:
      - { name: 'cache.context'}
  cache_context.user.group_permissions:
    class: 'Drupal\group\Cache\Context\GroupPermissionsCacheContext'
    arguments: ['@current_user', '@group.permissions_hash_generator']
    arguments: ['@current_user', '@group_permission.hash_generator']
    tags:
      - { name: 'cache.context'}
  cache_context.user.is_group_member:
@@ -91,33 +84,33 @@ services:
  group.membership_loader:
    class: 'Drupal\group\GroupMembershipLoader'
    arguments: ['@entity_type.manager', '@current_user']
  # @todo Rename to group_permission.builder in 8.2.0.
  group.permissions:
    class: 'Drupal\group\Access\GroupPermissionHandler'
    arguments: ['@module_handler', '@string_translation', '@controller_resolver', '@group_relation_type.manager']
  # @todo Rename to group_permission.hash_generator in 8.2.0.
  group.permissions_hash_generator:

  group_permission.hash_generator:
    class: 'Drupal\group\Access\GroupPermissionsHashGenerator'
    arguments: ['@private_key', '@cache.static', '@group_permission.chain_calculator']
  group_permission.chain_calculator:
    class: 'Drupal\group\Access\ChainGroupPermissionCalculator'
    arguments: ['@variation_cache.group_default', '@variation_cache.corefix_static_no_serialize', '@cache.corefix_static_no_serialize', '@account_switcher']
    tags:
      - { name: service_collector, call: addCalculator, tag: group_permission_calculator }
    arguments: ['@private_key', '@cache.static', '@group_permission.calculator']

  # Wrappers for Flexible permissions services.
  group_permission.calculator:
    class: 'Drupal\group\Access\GroupPermissionCalculator'
    arguments: ['@flexible_permissions.chain_calculator']
  group_permission.checker:
    class: 'Drupal\group\Access\GroupPermissionChecker'
    arguments: ['@group_permission.chain_calculator', '@group.membership_loader']
    arguments: ['@group_permission.calculator', '@group.membership_loader']

  # Flexible permissions calculators.
  group_permission.individual_calculator:
    class: 'Drupal\group\Access\IndividualGroupPermissionCalculator'
    arguments: ['@entity_type.manager', '@group.membership_loader']
    tags:
      - { name: group_permission_calculator, priority: -100 }

      - { name: flexible_permission_calculator, priority: -100 }
  group_permission.synchronized_calculator:
    class: 'Drupal\group\Access\SynchronizedGroupPermissionCalculator'
    arguments: ['@entity_type.manager']
    tags:
      - { name: group_permission_calculator, priority: -50 }
      - { name: flexible_permission_calculator, priority: -50 }

  group.uninstall_validator.group_content:
    class: 'Drupal\group\UninstallValidator\GroupContentUninstallValidator'
@@ -179,41 +172,3 @@ services:
    class: 'Drupal\group\Plugin\Group\RelationHandler\GroupMembershipPostInstall'
    arguments: ['@group.relation_handler.post_install', '@entity_type.manager', '@string_translation']
    shared: false

  # Recently, core introduced a new static cache that does not serialize its
  # data, unlike the cache.static service. This entity.memory_cache service has
  # two major drawbacks: First of all, it is named confusingly as it can work
  # for almost anything, not just entities. Secondly, it is not declared the
  # way cache backend services should be declared, meaning it cannot make
  # proper use of cache tags. In order to fix this, we declare the cache and
  # its factory the right way, albeit prefixed with corefix_ so that we do not
  # collide with core if it ever fixes this.
  # @todo Follow up in: https://www.drupal.org/project/drupal/issues/2973286
  # @todo Follow up in: https://www.drupal.org/project/drupal/issues/3016690
  # @todo Create core bug: entity.memory_cache is not a registered bin?
  cache.backend.corefix_memory_no_serialize:
    class: Drupal\group\CoreFix\Cache\MemoryCacheFactory
  cache.corefix_static_no_serialize:
    class: Drupal\Core\Cache\CacheBackendInterface
    tags:
      - { name: cache.bin, default_backend: cache.backend.corefix_memory_no_serialize }
    factory: cache_factory:get
    arguments: [corefix_static_no_serialize]

  # Core also has a tendency to not allow people to vary their caches by cache
  # contexts unless they abuse the render cache's built-in tools. We've fixed
  # this in core, but it's taking a while to get reviewed and we simply can no
  # allow it to block further Group releases. So we created the VariationCache
  # module on drupal.org for now and will swap it out with the real deal once
  # the core issue lands.
  # See https://www.drupal.org/project/variationcache
  # See https://www.drupal.org/project/drupal/issues/2551419
  # @todo Rename to variation_cache.group_permission in 8.2.0.
  variation_cache.group_default:
    class: Drupal\variationcache\Cache\VariationCacheInterface
    factory: variation_cache_factory:get
    arguments: [group_permission]
  variation_cache.corefix_static_no_serialize:
    class: Drupal\variationcache\Cache\VariationCacheInterface
    factory: variation_cache_factory:get
    arguments: [corefix_static_no_serialize]
+10 −1
Changes for modules/gnode/tests/src/Kernel/GroupNodeConfigTest.php: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,16 @@ class GroupNodeConfigTest extends EntityKernelTestBase {
   *
   * @var array
   */
  public static $modules = ['group', 'options', 'entity', 'variationcache', 'node', 'gnode', 'views'];
  public static $modules = [
    'entity',
    'flexible_permissions',
    'gnode',
    'group',
    'node',
    'options',
    'variationcache',
    'views',
  ];

  /**
   * Tests that the module's config installs properly.
+0 −36
Changes for src/Access/CalculatedGroupPermissions.php: 0 added lines, 36 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\group\Access;

use Drupal\Core\Cache\CacheableDependencyTrait;

/**
 * Represents a calculated set of group permissions with cacheable metadata.
 *
 * @see \Drupal\group\Access\ChainGroupPermissionCalculator
 */
class CalculatedGroupPermissions implements CalculatedGroupPermissionsInterface {

  use CacheableDependencyTrait;
  use CalculatedGroupPermissionsTrait;

  /**
   * Constructs a new CalculatedGroupPermissions.
   *
   * @param \Drupal\group\Access\CalculatedGroupPermissionsInterface $source
   *   The calculated group permission to create a value object from.
   */
  public function __construct(CalculatedGroupPermissionsInterface $source) {
    foreach ($source->getItems() as $item) {
      $this->items[$item->getScope()][$item->getIdentifier()] = $item;
    }
    $this->setCacheability($source);

    // The (persistent) cache contexts attached to the permissions are only
    // used internally to store the permissions in the VariationCache. We strip
    // these cache contexts when the calculated permissions get converted into a
    // value object here so that they will never bubble up by accident.
    $this->cacheContexts = [];
  }

}
Loading