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

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


Reply


7 Posts   1909 Views

Avatar
nomen

Community Member, 52 Posts

13 June 2008 at 9:33pm

Edited: 13/06/2008 9:41pm

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.

Avatar
dio5

Community Member, 501 Posts

14 June 2008 at 11:06am

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

Avatar
nomen

Community Member, 52 Posts

16 June 2008 at 10:02pm

Edited: 16/06/2008 10:03pm

Hi dio5:

Thank you for your answer.
I have read the doc in [url]http://doc.silverstripe.com/doku.php?id=security#security_in_the_cms[/url] 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.

Avatar
nomen

Community Member, 52 Posts

17 June 2008 at 8:50pm

Edited: 17/06/2008 8:53pm

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

Avatar
dio5

Community Member, 501 Posts

19 June 2008 at 1:34am

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

Avatar
cerelac

Community Member, 34 Posts

19 June 2008 at 2:36am

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

Avatar
dio5

Community Member, 501 Posts

19 June 2008 at 2:41am

Edited: 19/06/2008 2:43am

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!