-
Notifications
You must be signed in to change notification settings - Fork 71
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
Admin can not save an applied work definition to a page (bad request) #333
Comments
Cannot reproduce. @sachajudd we might need you to provide a bit more info on how to reproduce this - seems fine as far as I can tell =) |
Reproduced:
Error: |
@robbieaverill yeah only happens with the Save & Publish button when a Workflow Definition has never been added to a page before. Although Save draft seems to work. |
My experience:
|
Oh right, if the page doesn't have the workflow, at the start it doesn't have the workflow, which itself hides the publish button. I think I can see a fix. ;) |
What if:
|
This hack will fix the initial save. A second save however will break again. |
Should it be that an |
If an admin can't publish their page, they could manually remove the workflow and then publish, so it's not really secure anyway. If you can do that you may as well allow publish anyway. |
I'd like to make this issue clear, both for my own understanding and for anyone else who reads this thread :) The issue stems from the fact that a Save & Publish is executed as two actions in series, first a save, then a publish. If my understanding is correct, then simply allowing Admins to be able to publish a page probably isn't an ideal solution either, as it would not apply to any other user than has permission to alter the applied workflow. I'll open a Pull Request for your work around @tractorcow - that at least gets us most of the way there. |
As far as I can see, the main change between this working between SS3 and SS4 is that WorkflowDefinition now has public function canWorkflowPublish($member, $target)
{
$publish = $this->extendedCan('canWorkflowPublish', $member, $target);
if (is_null($publish)) {
return false;
}
return $publish;
} which has changed the ultimate result of the If this behaviour is undesirable and a specific project has a use-case for not allowing ADMIN publishing-at-will, then the 'canWorkflowPublish` hook can be implemented by an extension to explicitly return false regardless of user type, and handle the hack-around capture of this being a Save & Publish event for something that didn't originally have workflow. |
The subsequent publish fails because the first save removes the save button, making it an invalid action. I'm not sure the suggested fix by @nyeholt will fix it, but @NightJar please test it and let me know if it does. |
My solution is like this: public function canWorkflowPublish($member, $target)
{
$publish = $this->extendedCan('canWorkflowPublish', $member, $target);
if (isset($publish)) {
return $publish;
}
return Permission::checkMember($member, 'ADMIN');
} |
@tractorcow - what I was getting at was effectively the same as what you're doing, but without the explicit ADMIN permission checking. If you do
(and running this locally means an admin can save/publish on first application of workflow too) . |
@nyeholt actually it'll let you publish by default if you have edit permissions... that could open up publishing to a much larger group which should not have publish rights (in the event a workflow is in place). The rest of SiteTree::canPublish() // Check extension
$extended = $this->extendedCan('canPublish', $member);
if ($extended !== null) {
return $extended;
}
if (Permission::checkMember($member, "ADMIN")) {
return true;
}
// Default to relying on edit permission
return $this->canEdit($member); If there's a workflow in place, all editors can publish, even if the workflow SHOULD disable it. By a forcible check for admin in canWorkflowPublish, you limit it to admins, but only in the case a workflow exists. |
I'm mildly confused as this is my first foray into this module, but would the action of advancing a workflow not be covered by |
@tractorcow yep, didn't see how WorkflowApplicable had changed. It might be best if the return false was done at that tier though, to remain consistent with the previous model of workflow perms? |
You could do the permission check (true / false) at a few levels:
As long as you always return a boolean for canPublish if $definition is not null. |
Admin can not save an applied work definition to a page (bad request) (saved but error message)
The text was updated successfully, but these errors were encountered: