From f58af10d1ccca46e16f22ef7cdf49bc01961fabe Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Thu, 4 Aug 2022 10:07:17 +1200 Subject: [PATCH 1/2] Bugfix: Check for active controller before access getRequest() --- ...reDraftContentFileShortcodeProviderExtension.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php b/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php index aef709c..270feb6 100644 --- a/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php +++ b/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php @@ -20,16 +20,27 @@ public function updateGrant(bool &$grant, ?File $record = null, ?array $args = n if ($grant) { return; } - $session = $session = Controller::curr()->getRequest()->getSession(); + + $controller = Controller::curr(); + + if (!$controller) { + return; + } + + $session = $controller->getRequest()->getSession(); + if (!$session) { return; } + if (!ShareDraftController::getIsViewingPreview()) { return; } + if (!$record && $args) { $record = FileShortcodeProvider::find_shortcode_record($args); } + if ($record) { $grant = !$record->hasRestrictedAccess(); } From 07487f849d06edda83f5beef12fc6968fdeac13c Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Mon, 8 Aug 2022 07:13:28 +1200 Subject: [PATCH 2/2] Update src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- .../ShareDraftContentFileShortcodeProviderExtension.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php b/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php index 270feb6..3651302 100644 --- a/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php +++ b/src/Extensions/ShareDraftContentFileShortcodeProviderExtension.php @@ -20,14 +20,11 @@ public function updateGrant(bool &$grant, ?File $record = null, ?array $args = n if ($grant) { return; } - - $controller = Controller::curr(); - - if (!$controller) { + if (!Controller::has_curr()) { return; } - $session = $controller->getRequest()->getSession(); + $session = Controller::curr()->getRequest()->getSession(); if (!$session) { return;