Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Disabling Publish Button

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

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

Page: 1
Go to End
Author Topic: 2629 Views
  • cerelac
    Avatar
    Community Member
    34 Posts

    Disabling Publish Button Link to this post

    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.

  • Pixel
    Avatar
    Community Member
    78 Posts

    Re: Disabling Publish Button Link to this post

    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.

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Disabling Publish Button Link to this post

    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.

  • Pixel
    Avatar
    Community Member
    78 Posts

    Re: Disabling Publish Button Link to this post

    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

  • cerelac
    Avatar
    Community Member
    34 Posts

    Re: Disabling Publish Button Link to this post

    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?

  • Anatol
    Avatar
    126 Posts

    Re: Disabling Publish Button Link to this post

    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 rumour about a permission matrix about a year ago. Was there any further development?

    Cheers!
    Anatol

  • olafmol
    Avatar
    Community Member
    10 Posts

    Re: Disabling Publish Button Link to this post

    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);
    }

    ?>

    2629 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.