Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How to set permissions to a user to see and edit a concrete tree branch?

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: 1861 Views
  • nomen
    Avatar
    Community Member
    52 Posts

    How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    Hi all:

    Supose my tree is:

    =>Home
    =>Product
    =>...
    =>News
    =====>New1
    =====>New2
    =====>...
    =>About us


    I need that a concrete user only can see, edit and create new news.
    Ideally, the user should not see the rest of the tree, but if it can see it but no edit it, it will be enough for me.

    Any ideas?

    Thanks in advance.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    AFAIK there currently is no 'cms' way of doing that.

    You could however create a special member group in security, code in permissions and change the canEdit, canCreate etc methods in Page.php.

    see http://doc.silverstripe.com/doku.php?id=security#security_in_the_cms

    I'm not sure if that's the recommended way, but more or less worked for me once... although it feels weird it constantly checks it for every page again and again.. (queries... )

  • nomen
    Avatar
    Community Member
    52 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    Hi dio5:

    Thank you for your answer.
    I have read the doc in http://doc.silverstripe.com/doku.php?id=security#security_in_the_cms but i don´t understand well how to apply it.
    I try to debug my PageType but, when the user cliks on site tree in CMS, my page type controller is not called (the init function is not called).
    I have search in the doc and in the forum but i can´t find a sample. Can someone give me a sample of the usage of this?

    Thanks to all.

  • nomen
    Avatar
    Community Member
    52 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    Hi all:

    I finally edited the file sapphire/core/model/SiteTree.php. In the can function I changed the first part like this. (will supose the user mail is "usermail" and the page type is "pagetype"):

    function can($perm, $member = null) {
          if(!isset($member)) {
             $member = Member::currentUser();
          }
       
          if($member && $member->isAdmin()) {
             
             if ($member->Email != "usermail")         
                return true;
          }

        switch(strtolower($perm)) {
        case 'edit':
           
           if ($member->Email == "usermail")
           {
              
              if ($this->ClassName == "pagetype")
                 return true;
              else
                 return false;
           }
           

        if((Permission::check('CMS_ACCESS_CMSMain') &&
                      (($this->Editors == 'LoggedInUsers' && $member) ||
                    ($this->Editors == 'OnlyTheseUsers' && $member &&
                      $member->isInGroup($this->EditorsGroup)))) == false)
                   return false;
                break;
    ....

    I don´t know if this is the best way to do it but it works for me.
    bye

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    hi,

    I did it by changing the canEdit etc methods in Page.php

    something like:

    function canEdit()
    {
        if (Permission::check("NEWSAUTHORS") && !Permission::check("ADMIN"))
    {
    if($this->class == "News")
        {
             return true;
        }
          else
          {
             return false;   
          }
       }
    return true;
    }

    Of course you'll have to create a permission and a group with that permission code first...

  • cerelac
    Avatar
    Community Member
    34 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    Hi.
    I've created a new permission to restrict the access to a especific pagetype.
    Now, users that don't have the right (permission) to edit that pagetype are unable to edit it.
    What I would like to know is if it's possible to completely restrict the access to that pagetype so users without that permission wouldn't be able to even see the page.

    Thanks in advance

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to set permissions to a user to see and edit a concrete tree branch? Link to this post

    Don't think that's possible at the moment, as I assume you'll need to mess with getChildrenAsUL or stagechildren() for that deeper in the core...


    Might be wrong though.


    Please someone fix these line breaks/paragraphs!

    1861 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.