From e3f02cef94661fa56a52da20d7e5e2f33c7161e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:22:50 +1300 Subject: [PATCH 1/3] Bump cross-spawn from 7.0.3 to 7.0.6 (#269) Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6. - [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md) - [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v7.0.3...v7.0.6) --- updated-dependencies: - dependency-name: cross-spawn dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 08c5aff..0312af4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2289,9 +2289,9 @@ cosmiconfig@^9.0.0: parse-json "^5.2.0" cross-spawn@^7.0.2, cross-spawn@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" From 5de30ec6736bb318e4da503c37b34da8a517c5de Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:29:46 +1300 Subject: [PATCH 2/3] ENH Update code to avoid calling deprecated code (#271) --- .../ShareDraftContentControllerExtension.php | 23 +++++++++++++++---- .../Includes/LeftAndMain_ViewModeSelector.ss | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Extensions/ShareDraftContentControllerExtension.php b/src/Extensions/ShareDraftContentControllerExtension.php index c205f37..9468e18 100644 --- a/src/Extensions/ShareDraftContentControllerExtension.php +++ b/src/Extensions/ShareDraftContentControllerExtension.php @@ -4,6 +4,7 @@ use SilverStripe\Control\Controller; use SilverStripe\Core\Extension; +use SilverStripe\Security\Member; use SilverStripe\Security\Security; /** @@ -24,17 +25,29 @@ class ShareDraftContentControllerExtension extends Extension public function MakeShareDraftLink() { if ($member = Security::getCurrentUser()) { - if ($this->owner->hasMethod('CurrentPage') && $this->owner->CurrentPage()->canView($member)) { - return $this->owner->CurrentPage()->ShareTokenLink(); - } - if ($this->owner->hasMethod('canView') && $this->owner->canView($member)) { - return $this->owner->ShareTokenLink(); + if ($this->owner->hasMethod('currentRecord')) { + $link = $this->getShareTokenLink($this->owner->currentRecord(), $member); + } elseif ($this->owner->hasMethod('CurrentPage')) { + // Could be a non-LeftAndMain controller, since the extension is applied directly to Controller + $link = $this->getShareTokenLink($this->owner->CurrentPage(), $member); } + $link ??= $this->getShareTokenLink($this->owner, $member); + } + if ($link) { + return $link; } return Security::permissionFailure(); } + private function getShareTokenLink(object $record, Member $member): ?string + { + if ($record->hasMethod('canView') && $record->canView($member)) { + return $record->ShareTokenLink(); + } + return null; + } + /** * @return string */ diff --git a/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss b/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss index 625da5a..6a47657 100644 --- a/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss +++ b/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss @@ -2,7 +2,7 @@ <%-- Placeholder is re-rendered by the ShareDraftContent React component --%> From 6cccd255a7a39130655e30102d497f4dcd946b10 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:29:54 +1300 Subject: [PATCH 3/3] FIX Don't rely on session for current record ID (#272) --- .../ShareDraftContentControllerExtension.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Extensions/ShareDraftContentControllerExtension.php b/src/Extensions/ShareDraftContentControllerExtension.php index 9468e18..f7f1b03 100644 --- a/src/Extensions/ShareDraftContentControllerExtension.php +++ b/src/Extensions/ShareDraftContentControllerExtension.php @@ -53,9 +53,27 @@ private function getShareTokenLink(object $record, Member $member): ?string */ public function getShareDraftLinkAction() { - if ($this->owner->config()->get('url_segment')) { - return $this->owner->Link('MakeShareDraftLink'); + $owner = $this->getOwner(); + if (!$owner->config()->get('url_segment')) { + return ''; } - return ''; + $id = $this->getRecordID(); + if (!$id) { + return ''; + } + return $owner->Link(Controller::join_links('MakeShareDraftLink', $id)); + } + + private function getRecordID(): ?int + { + $owner = $this->getOwner(); + if ($owner->hasMethod('currentRecordID')) { + return $owner->currentRecordID(); + } + // Could be a non-LeftAndMain controller, since the extension is applied directly to Controller + if ($owner->hasMethod('CurrentPage')) { + return $owner->CurrentPage()?->ID; + } + return null; } }