Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add canPublish check for ChangeSet #384

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn’t add this kind of logic here, as it’ll potentially block programatic publishing (e.g. a CLI task where no user is logged in)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChangeSetItem already has its own canPublish method that checks the record object's canPublish, so it must be something else going on (if something is actually going on).

Nope, ChangeSetItem canPublish method is not called.

$object->publishSingle();

Already acts on the asset

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kinglozzer -> not sure where to put the logic if it is not the correct place. (In our use case this might suffice)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for your use case I’d probably remove the image from $owns and add some logic in onAfterPublish() to check the date and publish if applicable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a workaround for Mark, but I think this is a legit bug where it is reasonable to anticipate the permissions are respected, or we openly document that ownership cascade publishing trumps individual object permissions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a legit bug where it is reasonable to anticipate the permissions are respected

I agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep sorry I meant as a workaround! Will post my thoughts in the issue #383

$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