Skip to content

Commit

Permalink
Merge branch '3' into 4.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	yarn.lock
  • Loading branch information
GuySartorelli committed Dec 10, 2024
2 parents 8a893c8 + 5de30ec commit b501926
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
23 changes: 18 additions & 5 deletions src/Extensions/ShareDraftContentControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Control\Controller;
use SilverStripe\Core\Extension;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;

/**
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%-- Placeholder is re-rendered by the ShareDraftContent React component --%>
<span class="share-draft-content__placeholder"
data-url="<% if $CurrentPage.ShareDraftLinkAction %>{$CurrentPage.ShareDraftLinkAction}<% else %>{$Controller.CurrentPage.ShareDraftLinkAction}<% end_if %>"
data-helpurl="https://userhelp.silverstripe.org/en/4/optional_features/share_draft_content"
data-helpurl="https://userhelp.silverstripe.org/en/optional_features/share_draft_content"
>
</span>

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2177,9 +2177,9 @@ cosmiconfig@^9.0.0:
parse-json "^5.2.0"

cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.5.tgz#910aac880ff5243da96b728bc6521a5f6c2f2f82"
integrity sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==
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"
Expand Down

0 comments on commit b501926

Please sign in to comment.