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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Check for read access permission of specified page


Go to End


2 Posts   810 Views

Avatar
Vodnar

Community Member, 2 Posts

12 September 2011 at 11:56pm

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?

Avatar
Vodnar

Community Member, 2 Posts

13 September 2011 at 4:53am

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.