Skip to content

Commit

Permalink
Add canPublish check for ChangeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-a-j-adriano authored and airnzadrim2 committed Nov 30, 2022
1 parent 4baa7b4 commit 287bd64
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/ChangeSetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(),
];
}
}
Expand Down

0 comments on commit 287bd64

Please sign in to comment.