From 287bd6498e2f51525864d9667e2014df5a9c534c Mon Sep 17 00:00:00 2001 From: Mark Anthony Adriano Date: Wed, 30 Nov 2022 20:47:02 +1300 Subject: [PATCH] Add canPublish check for ChangeSet --- src/ChangeSetItem.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ChangeSetItem.php b/src/ChangeSetItem.php index edbf1ca9..13e5848c 100644 --- a/src/ChangeSetItem.php +++ b/src/ChangeSetItem.php @@ -304,16 +304,21 @@ public function publish() case static::CHANGE_CREATED: { // Non-recursive publish $object = $this->getObjectInStage(Versioned::DRAFT); - $object->publishSingle(); - - // Point after version to the published version actually created, not the - // version copied from draft. - $this->VersionAfter = Versioned::get_versionnumber_by_stage( - $this->ObjectClass, - Versioned::LIVE, - $this->ObjectID, - false - ); + $member = Security::getCurrentUser(); + + // Check if object has canPublish set to true + if ($object->canPublish($member)) { + $object->publishSingle(); + + // Point after version to the published version actually created, not the + // version copied from draft. + $this->VersionAfter = Versioned::get_versionnumber_by_stage( + $this->ObjectClass, + Versioned::LIVE, + $this->ObjectID, + false + ); + } break; } default: @@ -524,8 +529,8 @@ public function getPreviewLinks() $live = $this->getObjectInStage(Versioned::LIVE); if ($live instanceof CMSPreviewable && $live->canView() && ($link = $live->PreviewLink())) { $links[Versioned::LIVE] = [ - 'href' => Controller::join_links($link, '?stage=' . Versioned::LIVE), - 'type' => $live->getMimeType(), + 'href' => Controller::join_links($link, '?stage=' . Versioned::LIVE), + 'type' => $live->getMimeType(), ]; } }