Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Disabling Publish Button


Reply


7 Posts   2765 Views

Avatar
cerelac

Community Member, 34 Posts

17 July 2008 at 2:19am

Edited: 17/07/2008 2:20am

Hi everyone.

Is there anyway to add a permission that would allow the users to save new content in the CMS without having the permission to publish the content added?

My idea was to let people add new content, but it would only be published by another user with permission to publish.

Thank you.

Avatar
Pixel

Community Member, 78 Posts

17 July 2008 at 8:28pm

That sounds like a feature that could come in handy. I have almost finished a website for a local community magazine publisher (Will showcase it soonish, just need to set up Paypal and let them add some content) where they post news stories, jobs, editorial articles etc and that would be useful for the Editor to confirm what their staff write.

Avatar
simon_w

Forum Moderator, 474 Posts

17 July 2008 at 8:43pm

This can be done easily. Assuming only someone with ADMIN rights can publish, in your Page class add:

   function canPublish() {
      if(Permission::check('ADMIN')) {
         return true;
      } else {
         return parent::canPublish();
      }
   }

Though having a certain group that is allowed to publish is a bit harder.

Avatar
Pixel

Community Member, 78 Posts

17 July 2008 at 8:55pm

I may try that sometime. However the security and reports tab on my site do not work at the moment. I get:

Fatal error: Access to undeclared static property: ViewableData::$db in /var/www/vhosts/mags4dorset.co.uk/httpdocs/sapphire/core/Object.php(324) : eval()'d code on line 1

Which I think I can remember reading that is a bug in php 5.1.2 and need to upgrade to 5.2.x

Avatar
cerelac

Community Member, 34 Posts

17 July 2008 at 10:13pm

Edited: 22/07/2008 10:20pm

simon_w I've used the code you provided but an user with access to the CMSMain and LeftAndMain (without admin permissions) is able to add new content and also to publish it.

I don't know if I've done anything wrong, but I think I don't.

EDIT: I've finally got this to work.

I have a question. What is the functionallity of the "return parent::canPublish();"? It wasn't working and I removed this line and it only showed the "Save" as expected.

function canPublish() {
if(Permission::check('ADMIN')) {
return true;
// } else {
//return parent::canPublish();
// }
}

EDIT (2): Is it possible to do the same thing based on groups (a group can only add new content and only one can publish)?
Is it really hard to achieve that?

Avatar
Anatol

126 Posts

28 August 2008 at 3:24pm

Edited: 28/08/2008 3:25pm

Hi,

I am not sure if that is what you mean: If you add this method to your Page class in /mysite/code/Page.php ...

// Group names that have publishing permissions (only groups listed here can publish/unpublish)
protected $publisherGroups = array(
   "Administrators",
   "Editors"
);

function canPublish() {
   $member = Member::currentUser();
   return $member->inGroups($this->publisherGroups);
}

... then only members of the groups in the $publisherGroups array can publish/unpublish. If you have another group e.g. "Non-publishing Editors" members of this group could only save, but not publish.

I wanted to add an additional permission code to the CMS Security section, but I could not figure out how. It would be nice to have an option like "has publishing rights" to choose from the permissions dropdown.

For me the solution above is good enough for now, but there was some [url=http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/3679#post4051]rumour about a permission matrix[/url] about a year ago. Was there any further development?

Cheers!
Anatol

Avatar
olafmol

Community Member, 10 Posts

6 September 2008 at 12:21am

I get an error when i try to do this:

Parse error: syntax error, unexpected T_PROTECTED in /home/admin/domains/silverstripe.ilink2.nl/public_html/mysite/code/Page.php on line 21

This is my PHP code:

<?php

class Page extends SiteTree {
   static $db = array(
   );
   static $has_one = array(
);
}

class Page_Controller extends ContentController {
   function init() {
      parent::init();
      
      Requirements::themedCSS("layout");
      Requirements::themedCSS("typography");
      Requirements::themedCSS("form");
   }
}

// Group names that have publishing permissions (only groups listed here can publish/unpublish)
protected $publisherGroups = array(
"Administrators"
);

function canPublish() {
$member = Member::currentUser();
return $member->inGroups($this->publisherGroups);
}

?>