Skip to content

Commit

Permalink
ENH Update code to avoid calling deprecated code (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Dec 10, 2024
1 parent e3f02ce commit 5de30ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 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

0 comments on commit 5de30ec

Please sign in to comment.