Skip to content
Snippets Groups Projects
Commit c45d7dfc authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

Merge remote-tracking branch 'origin/develop' into EPIC-9024

parents afbc9fc8 91605b0f
No related branches found
No related tags found
1 merge request!209Release 2.2.0
......@@ -13,41 +13,46 @@ Feature: Creating content and commenting on archived collection
And collection content:
| title | abstract | description | logo | topic |
| The Willing Consort | The Willing Consort | The Willing Consort | logo.png | Statistics and Analysis |
Given solution content:
| title | collection |
| The Loyal Companion | The Willing Consort |
And the following collection user memberships:
| collection | user | roles |
| The Willing Consort | Karl Fields | owner, facilitator |
Scenario: 'Comment form' should not be accessible on an archived collection content.
Given discussion content:
| title | collection |
| The Weeping's Stars | The Willing Consort |
Scenario Outline: 'Comment form' should not be accessible on an archived collection content.
Given <content_type> content:
| title | collection | solution |
| Commented entity | <collection> | <solution> |
When I am logged in as "Lee Reeves"
And I go to the "The Weeping's Stars" discussion
Then the following fields should be present "Create comment"
And I should see the button "Post comment"
And I go to the content page of the type <content_type> with the title "Commented entity"
And I should see a ".comment-form" element
# Archive the collection.
When I am logged in as "Karl Fields"
And I go to the "The Willing Consort" collection
And I click "Edit"
And I go to the "edit-form" content page of the type "collection" with the title "The Willing Consort"
And I press "Request archival"
And I am logged in as a moderator
And I go to the "The Willing Consort" collection
And I click "Edit"
And I go to the "edit-form" content page of the type "collection" with the title "The Willing Consort"
When I fill in "Motivation" with "As you wish."
And I press "Archive"
And I go to the "The Weeping's Stars" discussion
Then the following fields should not be present "Create comment"
And I should not see the button "Post comment"
And I go to the content page of the type <content_type> with the title "Commented entity"
And I should not see a ".comment-form" element
When I am logged in as "Lee Reeves"
And I go to the "The Weeping's Stars" discussion
Then the following fields should not be present "Create comment"
And I should not see the button "Post comment"
And I go to the content page of the type <content_type> with the title "Commented entity"
And I should not see a ".comment-form" element
When I am not logged in
And I go to the "The Weeping's Stars" discussion
Then the following fields should not be present "Your name, Email, Create comment"
And I should not see the button "Post comment"
And I go to the content page of the type <content_type> with the title "Commented entity"
And I should not see a ".comment-form" element
Examples:
| content_type | collection | solution |
| discussion | The Willing Consort | |
| news | The Willing Consort | |
| discussion | | The Loyal Companion |
| news | | The Loyal Companion |
Scenario: 'Add community content' menu items should not be visible in the archived connection.
When I am logged in as "Karl Fields"
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\collection\Entity\CollectionContentInterface;
use Drupal\comment\CommentAccessControlHandler;
use Drupal\joinup_community_content\Entity\CommunityContentInterface;
use Drupal\joinup_workflow\ArchivableEntityInterface;
......@@ -124,15 +125,27 @@ protected function isAllowedIfHasPermission(string $permission, CommunityContent
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
$commented_entity = $context['commented_entity'] ?? NULL;
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL): AccessResultInterface {
$access_result = parent::checkCreateAccess($account, $context, $entity_bundle);
\assert($access_result instanceof AccessResultInterface);
if ($commented_entity instanceof ArchivableEntityInterface && $commented_entity->isArchived()) {
return AccessResult::forbidden('Commented entity is archived')
// Restrict access if the commented entity is archived.
$commented_entity = $context['commented_entity'] ?? NULL;
if ($commented_entity instanceof ArchivableEntityInterface) {
$access_result = $access_result
->orIf(AccessResult::forbiddenIf($commented_entity->isArchived()))
->addCacheableDependency($commented_entity);
}
return parent::checkCreateAccess($account, $context, $entity_bundle);
// Restrict access if the commented entity is in an archived collection.
if ($commented_entity instanceof CollectionContentInterface) {
$collection = $commented_entity->getCollection();
$access_result = $access_result
->orIf(AccessResult::forbiddenIf($collection->isArchived()))
->addCacheableDependency($collection);
}
return $access_result;
}
}
......@@ -7,13 +7,10 @@
declare(strict_types=1);
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\changed_fields\EntitySubject;
use Drupal\joinup_discussion\DiscussionObserver;
......@@ -150,27 +147,6 @@ function joinup_discussion_entity_bundle_info_alter(array &$bundles): void {
}
}
/**
* Implements hook_ENTITY_TYPE_create_access() for comment entity type.
*
* Prevents comments from being posted to archived discussions.
*/
function joinup_discussion_comment_create_access(AccountInterface $account, array $context, string $entity_bundle): AccessResultInterface {
if (isset($context['commented_entity'])) {
$discussion = $context['commented_entity'];
if ($discussion instanceof DiscussionInterface) {
$collection = $discussion->getCollection();
return AccessResult::forbiddenIf(
// Either the top collection or the discussion are archived.
$collection->isArchived() || $discussion->isArchived()
)
->addCacheableDependency($collection)
->addCacheableDependency($discussion);
}
}
return AccessResult::neutral();
}
/**
* Implements hook_preprocess_HOOK().
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment