From fe6ff75c8d9666de9f4fb2571939a8ac6b576ef3 Mon Sep 17 00:00:00 2001
From: Brian Canini <canini.16@osu.edu>
Date: Mon, 6 Jul 2020 15:35:12 -0400
Subject: [PATCH] Updating drupal/view_unpublished (1.0.0-rc1 => 1.0.0-rc2)

---
 composer.json                                  |  2 +-
 composer.lock                                  | 18 +++++++++---------
 vendor/composer/installed.json                 | 18 +++++++++---------
 .../src/Plugin/views/filter/NodeStatus.php     | 13 +++++++++++--
 .../Functional/ViewUnpublishedViewsTest.php    |  2 +-
 .../view_unpublished/view_unpublished.info.yml |  7 ++++---
 .../view_unpublished/view_unpublished.install  |  2 +-
 .../view_unpublished/view_unpublished.module   |  9 ++++++++-
 .../view_unpublished.views_execution.inc       |  3 +++
 9 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/composer.json b/composer.json
index b49efeed06..17ddc02d50 100644
--- a/composer.json
+++ b/composer.json
@@ -173,7 +173,7 @@
         "drupal/twitter_block": "3.0-alpha0",
         "drupal/userprotect": "1.1",
         "drupal/video_embed_field": "2.4",
-        "drupal/view_unpublished": "1.0-rc1",
+        "drupal/view_unpublished": "1.0-rc2",
         "drupal/views_accordion": "1.1",
         "drupal/views_ajax_history": "1.5",
         "drupal/views_autocomplete_filters": "1.3",
diff --git a/composer.lock b/composer.lock
index 564c3cb598..d6670ccd50 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "c2365ed43ba16f074102a0f462effe00",
+    "content-hash": "8f3515004e0cf833c3fe5d3ee771f2bb",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -7934,26 +7934,26 @@
         },
         {
             "name": "drupal/view_unpublished",
-            "version": "1.0.0-rc1",
+            "version": "1.0.0-rc2",
             "source": {
                 "type": "git",
                 "url": "https://git.drupalcode.org/project/view_unpublished.git",
-                "reference": "8.x-1.0-rc1"
+                "reference": "8.x-1.0-rc2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://ftp.drupal.org/files/projects/view_unpublished-8.x-1.0-rc1.zip",
-                "reference": "8.x-1.0-rc1",
-                "shasum": "de254b6e7863a5badf365fb953bd676b2b2d23a5"
+                "url": "https://ftp.drupal.org/files/projects/view_unpublished-8.x-1.0-rc2.zip",
+                "reference": "8.x-1.0-rc2",
+                "shasum": "673b2a76176b68b5f27affd4c2a718c2eaa45764"
             },
             "require": {
-                "drupal/core": "^8"
+                "drupal/core": "^8 || ^9"
             },
             "type": "drupal-module",
             "extra": {
                 "drupal": {
-                    "version": "8.x-1.0-rc1",
-                    "datestamp": "1592594405",
+                    "version": "8.x-1.0-rc2",
+                    "datestamp": "1593633641",
                     "security-coverage": {
                         "status": "not-covered",
                         "message": "RC releases are not covered by Drupal security advisories."
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index a54bfe8f5b..6496457e56 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -8180,27 +8180,27 @@
     },
     {
         "name": "drupal/view_unpublished",
-        "version": "1.0.0-rc1",
-        "version_normalized": "1.0.0.0-RC1",
+        "version": "1.0.0-rc2",
+        "version_normalized": "1.0.0.0-RC2",
         "source": {
             "type": "git",
             "url": "https://git.drupalcode.org/project/view_unpublished.git",
-            "reference": "8.x-1.0-rc1"
+            "reference": "8.x-1.0-rc2"
         },
         "dist": {
             "type": "zip",
-            "url": "https://ftp.drupal.org/files/projects/view_unpublished-8.x-1.0-rc1.zip",
-            "reference": "8.x-1.0-rc1",
-            "shasum": "de254b6e7863a5badf365fb953bd676b2b2d23a5"
+            "url": "https://ftp.drupal.org/files/projects/view_unpublished-8.x-1.0-rc2.zip",
+            "reference": "8.x-1.0-rc2",
+            "shasum": "673b2a76176b68b5f27affd4c2a718c2eaa45764"
         },
         "require": {
-            "drupal/core": "^8"
+            "drupal/core": "^8 || ^9"
         },
         "type": "drupal-module",
         "extra": {
             "drupal": {
-                "version": "8.x-1.0-rc1",
-                "datestamp": "1592594405",
+                "version": "8.x-1.0-rc2",
+                "datestamp": "1593633641",
                 "security-coverage": {
                     "status": "not-covered",
                     "message": "RC releases are not covered by Drupal security advisories."
diff --git a/web/modules/view_unpublished/src/Plugin/views/filter/NodeStatus.php b/web/modules/view_unpublished/src/Plugin/views/filter/NodeStatus.php
index d274b36557..8fe9c814ee 100644
--- a/web/modules/view_unpublished/src/Plugin/views/filter/NodeStatus.php
+++ b/web/modules/view_unpublished/src/Plugin/views/filter/NodeStatus.php
@@ -22,13 +22,22 @@ class NodeStatus extends Status {
    */
   public function query() {
     $table = $this->ensureMyTable();
+    $snippet = "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***VIEWUNPUBLISHED_ANY*** = 1 OR ***BYPASS_NODE_ACCESS*** = 1";
+    if ($this->moduleHandler->moduleExists('content_moderation')) {
+      $snippet .= ' OR ***VIEW_ANY_UNPUBLISHED_NODES*** = 1';
+    }
+
     $where_per_type = [];
     foreach (NodeType::loadMultiple() as $type) {
       $type_id = $type->id();
       $where_per_type[] = "($table.type = '$type_id' AND ***VIEWUNPUBLISHED_TYPE_$type_id*** = 1)";
     }
-    $where_per_type = implode(' OR ', $where_per_type);
-    $this->query->addWhereExpression($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***VIEWUNPUBLISHED_ANY*** = 1 OR ***BYPASS_NODE_ACCESS*** = 1 OR $where_per_type");
+    if (!empty($where_per_type)) {
+      $where_per_type = implode(' OR ', $where_per_type);
+      $snippet .= " OR $where_per_type";
+    }
+
+    $this->query->addWhereExpression($this->options['group'], $snippet);
   }
 
 }
diff --git a/web/modules/view_unpublished/tests/src/Functional/ViewUnpublishedViewsTest.php b/web/modules/view_unpublished/tests/src/Functional/ViewUnpublishedViewsTest.php
index eca018600a..6f553f9dca 100644
--- a/web/modules/view_unpublished/tests/src/Functional/ViewUnpublishedViewsTest.php
+++ b/web/modules/view_unpublished/tests/src/Functional/ViewUnpublishedViewsTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\view_unpublished\Functional;
 
 use Drupal\Tests\BrowserTestBase;
-use Drupal\simpletest\ContentTypeCreationTrait;
+use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
 
 /**
  * Tests the View Unpublished module with views.
diff --git a/web/modules/view_unpublished/view_unpublished.info.yml b/web/modules/view_unpublished/view_unpublished.info.yml
index 6b74ccef9f..1030f2667b 100644
--- a/web/modules/view_unpublished/view_unpublished.info.yml
+++ b/web/modules/view_unpublished/view_unpublished.info.yml
@@ -2,11 +2,12 @@ name: 'View Unpublished'
 description: 'Select which roles should be able to see unpublished nodes.'
 package: Permissions
 core: 8.x
+core_version_requirement: ^8 || ^9
 type: module
 dependencies:
   - drupal:node
 
-# Information added by Drupal.org packaging script on 2020-06-19
-version: '8.x-1.0-rc1'
+# Information added by Drupal.org packaging script on 2020-07-01
+version: '8.x-1.0-rc2'
 project: 'view_unpublished'
-datestamp: 1592594407
+datestamp: 1593633642
diff --git a/web/modules/view_unpublished/view_unpublished.install b/web/modules/view_unpublished/view_unpublished.install
index 9ea76351a5..d8cc7b703f 100644
--- a/web/modules/view_unpublished/view_unpublished.install
+++ b/web/modules/view_unpublished/view_unpublished.install
@@ -26,7 +26,7 @@ function view_unpublished_uninstall() {
  */
 function _view_unpublished_flag_rebuild_if_needed() {
   $query = \Drupal::entityTypeManager()->getStorage('node')->getQuery();
-  $count_unpublished = $query->condition('status', FALSE)->count()->execute();
+  $count_unpublished = (int) $query->condition('status', FALSE)->count()->execute();
   if ($count_unpublished > 0) {
     node_access_needs_rebuild(TRUE);
   }
diff --git a/web/modules/view_unpublished/view_unpublished.module b/web/modules/view_unpublished/view_unpublished.module
index 96ac07f88f..9f745005dc 100644
--- a/web/modules/view_unpublished/view_unpublished.module
+++ b/web/modules/view_unpublished/view_unpublished.module
@@ -71,6 +71,11 @@ function view_unpublished_node_access_records(NodeInterface $node) {
  * Implements hook_node_grants().
  */
 function view_unpublished_node_grants(AccountInterface $account, $op) {
+  $grants_cache = &drupal_static(__FUNCTION__, []);
+  if (isset($grants_cache[$account->id()][$op])) {
+    return $grants_cache[$account->id()][$op];
+  }
+
   $grants = [];
   if ($op == 'view') {
     if ($account->hasPermission('view own unpublished content')) {
@@ -90,7 +95,9 @@ function view_unpublished_node_grants(AccountInterface $account, $op) {
       }
     }
   }
-  return $grants;
+
+  $grants_cache[$account->id()][$op] = $grants;
+  return $grants_cache[$account->id()][$op];
 }
 
 /**
diff --git a/web/modules/view_unpublished/view_unpublished.views_execution.inc b/web/modules/view_unpublished/view_unpublished.views_execution.inc
index 0ee308ce32..9df92816b8 100644
--- a/web/modules/view_unpublished/view_unpublished.views_execution.inc
+++ b/web/modules/view_unpublished/view_unpublished.views_execution.inc
@@ -12,6 +12,9 @@
  * Implements hook_views_query_substitutions().
  */
 function view_unpublished_views_query_substitutions(ViewExecutable $view) {
+  if ($view->id() != 'content' && !empty($view->filter['status']->value) && $view->filter['status']->value == 1) {
+    return;
+  }
   $account = \Drupal::currentUser();
   $substitutions = [];
   foreach (NodeType::loadMultiple() as $type) {
-- 
GitLab