Jump to content

Publish/Unpublish a page setting required to edit published pages


adrian
 Share

Recommended Posts

I wonder if this is completely logical. I can imagine a scenario where I have a user that I don't want to have permission to publish a page, but I am happy for them to edit a page once it has been published. Not really a trust issue, but rather want to ensure they can't accidentally publish a draft until it is ready to be public.

This is currently a theoretical scenario for me so I haven't gone looking for solutions, but just want to raise the issue and see what the consensus is.

Link to comment
Share on other sites

If i understand correctly you want to change the standard publish workflow ? If right is a missing (?) feature of PW, in fact it will be useful to change the standard workflow especially when you have a lot of editor with different roles.

A real-life scenario is in a editorial staff, when all journalists submit their article to editor and only the editor have the power to publish the article.

Link to comment
Share on other sites

At this point I haven't really thought about the workflow, but I think there might be some room for improvement there.

Initially, I am just wondering if it makes sense that a user who has editing rights should be blocked from editing a page, just because it is already published - maybe it is more of a terminology issue for me at the moment.

  • Like 1
Link to comment
Share on other sites

That is actually the permission I am referring to above as "Publish/Unpublish" - that is the title it is set to. I didn't realize that removing the permission would do what pogidude describes.

There still doesn't seem to be a way to set someone to be able to author and edit published posts, but not actually do the publishing - am I missing an option somewhere?

Link to comment
Share on other sites

The functionality doesn't seem like it would be hard to write yourself as a (really) short module, but I'm not sure if a module would be necessary (i.e. it might already be in core somehow).

Link to comment
Share on other sites

Hey Soma - that is the permission we are talking about. Once it is set up, but unchecked, it overrides the ability of a user with page-edit to edit a page that is already published. Hence there doesn't seem to be a way to prevent a user from publishing a post, while still giving them the ability to edit a published post, which seems like a valuable scenario to me.

Link to comment
Share on other sites

Yeah, I know. I guess the title of post isn't really accurate as at the time I didn't realize that removing it completely provides different behavior to having it unchecked.

I guess I think the page-edit should not be affected by page-publish. Maybe there needs to be a page-edit-published as well to provide the scenario I am talking about. So you could check page-edit, page-edit-published and uncheck page-publish. Might be a better way to achieve this, but you get the idea.

  • Like 1
Link to comment
Share on other sites

  • 5 years later...

Hi. I'm going to bump this one alive again.

What Adrian was mentioning is exactly what I need. I need to give some users (agents) the possibility to create pages with a specific template (property) but I don't want them to have access to publish it before someone checks if everything is correct. I've used the special permission page-publish and that takes care of that part. But I also need to give them permission to edit the page as soon as they are published so they can make alterations.

I'm kind lost on how to handle this. I guess I'll have creat a module to handle this, but how can I override the page-publish behavior so it can give access to edit published pages? Or should I ignore this permission?

Thanks in advance.

Link to comment
Share on other sites

This is how I solved this question:

I've assigned page-publish permission to the agent role so they can publish pages based on the property template.

I've created a module that with a hook on ProcessPageEdit::buildForm like this

$this->addHookAfter('ProcessPageEdit::buildForm', $this, 'removePublishButton');

The function that handles this just looks at the page being edited and if it has a status of Unpublished, it removes the Publish button:

foreach($form->children() as $f){
        if($f->name == "submit_publish" && $page->isUnpublished())
          $form->children()->remove($f);  // Removes the Publish Button from Properties not yet published.
}

This allows the users with agent role to edit already published pages (if they belong to them, something that the module also checks) but keeps them from publish new pages directly.

  • Like 2
Link to comment
Share on other sites

6 hours ago, zyON said:

The function that handles this just looks at the page being edited and if it has a status of Unpublished, it removes the Publish button

You still have the "Unpublished" checkbox on the Settings tab and the "Pub" action button in Page List to deal with. Plus to be extra sure you can hook Pages::publishReady to prevent publishing by any means.

Some hooks...

// Remove publish button and unpublished checkbox in Page Edit
$wire->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) {
	/* @var InputfieldForm $form */
	$form = $event->return;
	/* @var ProcessPageEdit $ppe */
	$ppe = $event->object;
	$page = $ppe->getPage();
	// Return early if user is not an agent or it's not a restricted page
	if(!$event->user->hasRole('agent') || $page->template != 'property') return;
	// Return early if page is published
	if(!$page->isUnpublished()) return;
	// Get status field
	/* @var InputfieldCheckboxes $status_field */
	$status_field = $form->getChildByName('status');
	// Remove unpublished checkbox
	$status_field->removeOption(2048);
	// Get publish button
	$publish_button = $form->getChildByName('submit_publish');
	// Remove button
	$form->remove($publish_button);
});

// Remove publish button from Page List
$wire->addHookAfter('ProcessPageListActions::getExtraActions', function(HookEvent $event) {
	$page = $event->arguments(0);
	$extras = $event->return;
	// Return early if user is not an agent or it's not a restricted page
	if(!$event->user->hasRole('agent') || $page->template != 'property') return;
	// Return early if page is published
	if(!$page->isUnpublished()) return;
	// Remove publish action
	unset($extras['pub']);
	$event->return = $extras;
});

// Prevent publishing by any means
$pages->addHookAfter('publishReady', function(HookEvent $event) {
	$page = $event->arguments(0);
	// Return early if user is not an agent or it's not a restricted page
	if(!$event->user->hasRole('agent') || $page->template != 'property') return;
	// Return early if page is published
	if(!$page->isUnpublished()) return;
	// Throw exception
	throw new WireException('You do not have permission to publish this page');
});

 

  • Like 3
Link to comment
Share on other sites

11 hours ago, Robin S said:

You still have the "Unpublished" checkbox on the Settings tab and the "Pub" action button in Page List to deal with. Plus to be extra sure you can hook Pages::publishReady to prevent publishing by any means. 

Robin, I don't have the "Unpublished" checkbox because I'm using the RestrictTabView module to hide the Settings and Delete tabs for this role.
Thank you for the hooks code, this will come in handy very soon.

  • Like 1
Link to comment
Share on other sites

It seems like this hook doesn't work with other Lists, only on the Page Tree list (I'm using ListerPro). Any ideas how can I remove publish and hide buttons from lists?

EDIT: Ok, forget it. The hook still works on a Lister. I had a debug message being fired on the hook handle function that was not appearing, but the unset of the buttons still work.

ProcessPageListActions::getExtraActions
Link to comment
Share on other sites

  • 4 years later...

Using RockMigrations you can now do this in /site/ready.php. It will remove the publish button and it will prevent publishing via API as well:

<?php
// prevent publishing of pages with id 1010 and 1012
rockmigrations()->preventPublish("id=1010|1012");

// optionally allow publishing for superusers
rockmigrations()->preventPublish("id=1010|1012", true);

@Robin S code was not working for me, because removing the checkbox from the form means that on every submit the page will be automatically published even when clicking the "save + keep unpublished". Here's what I did: https://github.com/baumrock/RockMigrations/commit/de7a39b7ad0e58ed7f174db8954672f3dcbf103e

Ah! And it will inform you about where the preventPublish() call happened 🙂 

Z8GIdvS.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...