Jump to:

23373 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Check for read access permission of specified page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 409 Views
  • Vodnar
    Avatar
    Community Member
    2 Posts

    Check for read access permission of specified page Link to this post

    Hi all,

    I'm trying to do this: The access to page A is limited to website readers that are members of specified groups only. The access to page B is wider, the same readers like for page A can access it but also other too. I use shortcode in the Content of page B to create link to page A (in fact it's an excerpt from the text of page A, that's why I use shortcode).

    When somebody who doesn't have access to page A click on that link, he/she will see an error message and possibility to login with different username. I would like to hide completely that link for such readers (it means the shortcode will return empty string) but I can not figure out how to check whether currently logged user has privileges to access page A or not. If possible I don't want to create some additional permission for that purpose as it's already there - appropriate user groups are selected on "access" tab of page A.

    Please, could someone help me with that?

  • Vodnar
    Avatar
    Community Member
    2 Posts

    Re: Check for read access permission of specified page Link to this post

    Well, I have found that the solution is really simple. I added into my shortcode handler something like this:

    $page = DataObject::get_by_id( 'Page', $id );
    if ( $page && $page->canView() ) {
    ... return page excerpt ...
    } else {
    ... return nothing ...
    }

    Where $id is ID of linked page A.

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