Skip to content
Snippets Groups Projects
Commit bce51275 authored by Steven Ayers's avatar Steven Ayers
Browse files

Issue #3507558: Remove Group 8.x-1.x support

parent 69f8e763
Branches
Tags
1 merge request!46Issue #3507558 by bluegeek9: Remove Group 8.x-1.x support
Pipeline #427979 passed with warnings
......@@ -64,7 +64,7 @@ group_integration:
_PHPUNIT_TESTGROUPS: group_integration
parallel:
matrix:
- GROUP_VERSION: [ '^1', '^2' ]
- GROUP_VERSION: [ '^2', '^3']
###################################################################################
#
......
......@@ -23,6 +23,6 @@
},
"require-dev": {
"drupal/paragraphs": "1.x-dev",
"drupal/group": "^1 || ^2 || ^3"
"drupal/group": "^2 || ^3"
}
}
......@@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupRelationship;
use Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface;
......@@ -116,30 +115,18 @@ function _quick_node_clone_has_clone_permission(ContentEntityInterface $node) {
$bundle = $node->bundle();
if ($current_user->hasPermission("clone $bundle content")) {
if (\Drupal::moduleHandler()->moduleExists('gnode')) {
// Check that user has permission to create a relationship.
// Support for group module version 1.x.
if (class_exists(GroupContent::class)) {
$group_relationships = GroupContent::loadByEntity($node);
foreach ($group_relationships as $group_relationship) {
$access = $group_relationship->getContentPlugin()->createEntityAccess($group_relationship->getGroup(), $current_user);
if ($access->isAllowed()) {
return TRUE;
}
}
}
// Support for group module version 2.x and 3.x.
else {
$group_relationships = GroupRelationship::loadByEntity($node);
$relation_type_manager = \Drupal::service('group_relation_type.manager');
assert($relation_type_manager instanceof GroupRelationTypeManagerInterface);
foreach ($group_relationships as $group_relationship) {
$access_handler = $relation_type_manager->getAccessControlHandler($group_relationship->getPluginId());
$access = $access_handler->entityCreateAccess($group_relationship->getGroup(), $current_user);
if ($access) {
return TRUE;
}
$group_relationships = GroupRelationship::loadByEntity($node);
$relation_type_manager = \Drupal::service('group_relation_type.manager');
assert($relation_type_manager instanceof GroupRelationTypeManagerInterface);
foreach ($group_relationships as $group_relationship) {
$access_handler = $relation_type_manager->getAccessControlHandler($group_relationship->getPluginId());
$access = $access_handler->entityCreateAccess($group_relationship->getGroup(), $current_user);
if ($access) {
return TRUE;
}
}
}
// Only check global access if we there is no group module enabled, or
......
......@@ -5,11 +5,9 @@ namespace Drupal\Tests\quick_node_clone\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\group\Entity\Group;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupRelationship;
use Drupal\group\Entity\GroupRole;
use Drupal\group\Entity\GroupType;
use Drupal\group\Entity\Storage\GroupContentTypeStorageInterface;
use Drupal\group\Entity\Storage\GroupRelationshipTypeStorageInterface;
use Drupal\group\PermissionScopeInterface;
......@@ -59,73 +57,6 @@ class QuickNodeCloneGroupIntegrationTest extends BrowserTestBase {
* Test node cloning.
*/
public function testNodeClone() {
if (class_exists(GroupContent::class)) {
$this->checkGroupContent();
}
else {
$this->checkGroupRelations();
}
}
/**
* Test groups v1.
*/
public function checkGroupContent() {
// Prepare a group type.
$group_type = GroupType::create([
'id' => $this->randomMachineName(),
'label' => $this->randomString(),
'creator_wizard' => FALSE,
]);
$group_type->save();
$node_type = 'page';
$gnode_plugin_id = 'group_node:' . $node_type;
$content_type_storage = $this->entityTypeManager->getStorage('group_content_type');
/* @phpstan-ignore-next-line */
assert($content_type_storage instanceof GroupContentTypeStorageInterface);
$content_type_storage->save($content_type_storage->createFromPlugin($group_type, $gnode_plugin_id));
// Create a node and add it to a group.
$node = $this->createNode([
'type' => $node_type,
'title' => $this->randomString(200),
]);
$group = Group::create([
'type' => $group_type->id(),
'label' => $this->randomString(),
]);
$group->save();
$group->addContent($node, $gnode_plugin_id);
// Create a user with the required permissions.
$group_role = GroupRole::create([
'group_type' => $group_type->id(),
'id' => $this->randomMachineName(),
'label' => $this->randomString(),
'permissions' => ['administer group'],
]);
$group_role->save();
$user = $this->drupalCreateUser(["clone $node_type content"]);
$group->addMember($user, ['group_roles' => [$group_role->id()]]);
// Clone the node and check that it is added to the group.
$this->drupalLogin($user);
$this->drupalGet("clone/{$node->id()}/quick_clone");
$cloned_node_title = $this->randomMachineName(200);
$edit = [
'title[0][value]' => $cloned_node_title,
];
$this->submitForm($edit, 'Save');
$cloned_node = $this->getNodeByTitle($cloned_node_title);
/* @phpstan-ignore-next-line */
$cloned_relation = GroupContent::loadByEntity($cloned_node);
$this->assertCount(1, $cloned_relation);
}
/**
* Test groups v2 and higher.
*/
protected function checkGroupRelations() {
// Prepare a group type.
$group_type = GroupType::create([
'id' => $this->randomMachineName(),
......@@ -136,8 +67,8 @@ class QuickNodeCloneGroupIntegrationTest extends BrowserTestBase {
// Determine the relation type entity ID
// for the installed version of the group module (v2 or v3).
$relation_type_id = $this->entityTypeManager->getDefinition('group_content_type', FALSE)
? 'group_content_type'
: 'group_relationship_type';
? 'group_content_type'
: 'group_relationship_type';
$relation_type_storage = $this->entityTypeManager->getStorage($relation_type_id);
assert($relation_type_storage instanceof GroupRelationshipTypeStorageInterface);
$node_type = 'page';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment