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-182: Patch Moderated Content Bulk using composer #185

Merged
merged 2 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
},
"drupal/core": {
"Fix Ajax/Preserve Facets on exposed forms Drupal 9.3.x": "patches/3032353-25-archipelago-05162022.patch"
},
"drupal/moderated_content_bulk_publish": {
"Fix access check on every action": "patches/3280584-archipelago-05162022.patch"
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions patches/3280584-archipelago-05162022.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From cf94ccef9488e6ee4dd712e37407dbcd2aed51bc Mon Sep 17 00:00:00 2001
From: DiegoPino <diegopino@3564864.no-reply.drupal.org>
Date: Mon, 16 May 2022 00:03:29 +0000
Subject: [PATCH] Fix ::access

---
.../Action/UnpublishCurrentRevisionAction.php | 28 +++++++++++++------
1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/Plugin/Action/UnpublishCurrentRevisionAction.php b/src/Plugin/Action/UnpublishCurrentRevisionAction.php
index 129ce70..65db735 100644
--- a/src/Plugin/Action/UnpublishCurrentRevisionAction.php
+++ b/src/Plugin/Action/UnpublishCurrentRevisionAction.php
@@ -9,6 +9,7 @@ use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\moderated_content_bulk_publish\AdminModeration;
+use Drupal\Core\Access\AccessResult;

/**
* An example action covering most of the possible options.
@@ -133,19 +134,28 @@ class UnpublishCurrentRevisionAction extends ActionBase/*extends ViewsBulkOperat
}
*/

- /**
+ /**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
- if ($object->getEntityType() === 'node') {
- $access = $object->access('update', $account, TRUE)
- ->andIf($object->status->access('edit', $account, TRUE));
- return $return_as_object ? $access : $access->isAllowed();
+ if ($object->getEntityTypeId() === 'node') {
+ $moderation_info = \Drupal::service('content_moderation.moderation_information');
+ // Moderated Entities will return AccessResult::forbidden for attemps
+ // to edit $object->status.
+ // @see content_moderation_entity_field_access
+ if ($moderation_info->isModeratedEntity($object)) {
+ $access = $object->access('update', $account, TRUE)
+ ->andIf($object->moderation_state->access('edit', $account, TRUE));
+ }
+ else {
+ $access = $object->access('update', $account, TRUE)
+ ->andIf($object->status->access('edit', $account, TRUE));
+ }
}
-
- // Other entity types may have different
- // access methods and properties.
- return TRUE;
+ else {
+ $access = AccessResult::forbidden()->setReason('The chosen Action only acts on entities of type node')->setCacheMaxAge(0);
+ }
+ return $return_as_object ? $access : $access->isAllowed();
}

}
--
GitLab