Protecting Pages and Files with Different Roles / Users
Hi,
Could you let me know if the following scenario can work and how you would suggest doing it.
We have users who need access to their client page but not all users will have access to the same media files.
I can either set this up as a Group / Role for the page and assign the user to that group, or, create a new group / role for each user and assign each user to the page.
Then, what I want to do is show all the documents assigned to that individual user and some other page / client level elements from that document type.
I want he CMS user to set the roles and groups up through the members area to keep confusion to a minimum.
I would just have one role for example customers to give access to the page and then have additional roles for each customer that needs to download the media.
After protecting you can use the library method MediaProtect.Library.GetProtectedNodesForRole to get the protected (root) nodes where the role has access to.
Thats exactly what I thought and what I had set up but cant get it working properly.
I have a page with a role called 'Customer' which is assigned to the page.
I then have two users, 'Gavin' and 'Katie', both are members of the 'Customer' role and are also membes of their own roles, 'Gavin' and 'Katie'.
The only role allowed on the test file is 'Gavin' but when I land on the page it doesnt matter whether im logged in as 'Gavin' or 'Katie' but it appears to show that both roles can view the file.
But, if I access the file directly, only the 'Gavin' role is authorised, which is correct.
The way im checking this is by a really low level piece of XSLT (as my XSLT knowdledge is pretty non existant) within the template for the protected page.
Yes, its actually protectecting the media correctly but within the page where I need to list all protected media for the logged in user its essentially telling me the user has access ta a file they dont.
Just added that check into the loop and its telling me the user has access ...
No since the file is protected. Have you already tried writing the value of "MediaProtect.Library:HasAccess('Mediaprotect Manual 1.pdf') my xslt is a little rusty too..
In the XSLT in a templkate I Was still receiving some odd results so ive gone back to what I know and c# code behind ...
:-)
Im now able to tell whether a file is protected etc and thats great but when I loop through GetProtectedNodesByUser the loop is working but I cant get any value out for the media item itself.
Im using the following quick and simple test code (neither loops spat out any information although the loop worded), any ideas:
Bit of Murphey's law sorry. This API was designed when XSLT was still hot ;-). It's returning an xpathNodeIterator. I think the code below should give you the info.
var reader = xPathNodeIterator.Current.Select("//node");
while (reader.MoveNext())
{
var mediaId = reader.Current.Value;
}
Protecting Pages and Files with Different Roles / Users
Hi,
Could you let me know if the following scenario can work and how you would suggest doing it.
We have users who need access to their client page but not all users will have access to the same media files.
I can either set this up as a Group / Role for the page and assign the user to that group, or, create a new group / role for each user and assign each user to the page.
Then, what I want to do is show all the documents assigned to that individual user and some other page / client level elements from that document type.
I want he CMS user to set the roles and groups up through the members area to keep confusion to a minimum.
I look forward to hearing from you.
Thanks
Gavin
Hi Gavin,
I would just have one role for example customers to give access to the page and then have additional roles for each customer that needs to download the media.
After protecting you can use the library method MediaProtect.Library.GetProtectedNodesForRole to get the protected (root) nodes where the role has access to.
Hope this helps for now.
Best,
Richard
Hi Richard,
Thanks for the response.
Thats exactly what I thought and what I had set up but cant get it working properly.
I have a page with a role called 'Customer' which is assigned to the page.
I then have two users, 'Gavin' and 'Katie', both are members of the 'Customer' role and are also membes of their own roles, 'Gavin' and 'Katie'.
The only role allowed on the test file is 'Gavin' but when I land on the page it doesnt matter whether im logged in as 'Gavin' or 'Katie' but it appears to show that both roles can view the file.
But, if I access the file directly, only the 'Gavin' role is authorised, which is correct.
The way im checking this is by a really low level piece of XSLT (as my XSLT knowdledge is pretty non existant) within the template for the protected page.
<xsl:for-each select="MediaProtect.Library:GetProtectedNodesForRole('Katie')">
<!--Loop through all protected ROOT nodes -->
<br />One protected file
</xsl:for-each>
Basically, both users see the same one line of 'One protected file'.
I just want to get it conceptially working before I then role out everything I need to do.
Any ideas?
Many thanks
Gavin
Oh, and the folder structure for the media is:
Media/documents/client-name/file.pdf
Thanks
So it is protecting only the displayed nodes are incorrect?
What you can do is include MediaProtect.Library:HasAccess in the loop that checks if the current user has access to the file.
From the manual:
Hope this helps,
Richard
Yes, its actually protectecting the media correctly but within the page where I need to list all protected media for the logged in user its essentially telling me the user has access ta a file they dont.
Just added that check into the loop and its telling me the user has access ...
:-(
Try filename, otherwise it would be very strange that it blocks direct access
You mean access the file again and check if the user can view it?
Dont and get redirected to the unauthorised page
No was more talking about adding the filename as parameter to the xslt if statement then you are sure you are using the same file
<xsl:for-each select="MediaProtect.Library:GetProtectedNodesForRole('Katie DPC')">
<!--Loop through all protected ROOT nodes -->
<br />Hello
<xsl:if test="MediaProtect.Library:HasAccess('Mediaprotect Manual 1.pdf')">
- Still has ACCESS!
</xsl:for-each>
Is still outputting:
Hello - Still has ACCESS!
Somethings not right somewhere ... :-(
Do you think its worth uninstalling and installing again?
No since the file is protected. Have you already tried writing the value of "MediaProtect.Library:HasAccess('Mediaprotect Manual 1.pdf') my xslt is a little rusty too..
Hi Richard,
In the XSLT in a templkate I Was still receiving some odd results so ive gone back to what I know and c# code behind ...
:-)
Im now able to tell whether a file is protected etc and thats great but when I loop through GetProtectedNodesByUser the loop is working but I cant get any value out for the media item itself.
Im using the following quick and simple test code (neither loops spat out any information although the loop worded), any ideas:
Hi,
you only get the id I think. Use the mediaservice GetById method to get all the info.
http://our.umbraco.org/documentation/Reference/Management-v6/Services/MediaService
Hope this helps,
Richard
I cant seam to get any values out within the loop, id be delighted to find the Node Id and then use that ...
:-)
Bit of Murphey's law sorry. This API was designed when XSLT was still hot ;-). It's returning an xpathNodeIterator. I think the code below should give you the info.
Returns no results ...
My XSLT / XPATH etc 100% non existant so im clueless here LOL
Send me your mediaprotect.xml file please to [email protected]
is working on a reply...