Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 12, 2014 @ 13:06
    Gavin Bewley-Jones
    0

    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

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 12, 2014 @ 15:45
    Richard Soeteman
    0

    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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 17, 2014 @ 10:27
    Gavin Bewley-Jones
    0

    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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 17, 2014 @ 10:33
    Gavin Bewley-Jones
    0

    Oh, and the folder structure for the media is:

    Media/documents/client-name/file.pdf

    Thanks

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 17, 2014 @ 10:40
    Richard Soeteman
    0

    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:

    <xsl:if test="MediaProtect.Library:HasAccess('Int32 nodeId', 'String 
    path')">
    <!-- The user has access-->
    </xsl:if>
    

    Hope this helps,

    Richard

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 17, 2014 @ 10:57
    Gavin Bewley-Jones
    0

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

    :-(

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 17, 2014 @ 11:05
    Richard Soeteman
    0

    Try filename, otherwise it would be very strange that it blocks direct access

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 17, 2014 @ 11:33
    Gavin Bewley-Jones
    0

    You mean access the file again and check if the user can view it?

    Dont and get redirected to the unauthorised page

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 17, 2014 @ 11:45
    Richard Soeteman
    0

    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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 18, 2014 @ 10:04
    Gavin Bewley-Jones
    0

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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 19, 2014 @ 10:28
    Gavin Bewley-Jones
    0

    Do you think its worth uninstalling and installing again?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 19, 2014 @ 16:19
    Richard Soeteman
    0

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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 23, 2014 @ 12:36
    Gavin Bewley-Jones
    0

    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:

     protected void Page_Load(object sender, EventArgs e)
            {
                var clientUser = Membership.GetUser();
    
                var x = MediaProtect.Library.Library.GetProtectedNodesForUser(clientUser.UserName);
    
                Response.Write("<br />User name from CTRL = " + clientUser.UserName);
    
                Response.Write("<br />Count = " + x.Count.ToString());
    
                Response.Write("<br />Has Access = " + MediaProtect.Library.Library.HasAccess(1291, "/media/6835/Mediaprotect Manual 1.pdf"));
                //Response.Write("<br />Has Access 2 = " + MediaProtect.Library.Library.HasAccess("Media-protect-Manual-1.pdf"));
    
                //while (x.MoveNext())
                //{
                //    Response.Write("<br />x = " + x.Current.Name);
                //    Response.Write("<br />x = " + x.);
                //}
    
                foreach (XPathNavigator n in x)
                {
                    Response.Write("<br />n = " + n.Name);
                    Response.Write("<br />n = " + n.LocalName);
                    Response.Write("<br />n = " + n.Value);
                }
    
            }
  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 23, 2014 @ 13:00
    Richard Soeteman
    0

    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

  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 23, 2014 @ 13:09
    Gavin Bewley-Jones
    0

    I cant seam to get any values out within the loop, id be delighted to find the Node Id and then use that ...

     

    :-)

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 23, 2014 @ 13:21
    Richard Soeteman
    0

    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;
            }
    
  • Gavin Bewley-Jones 25 posts 71 karma points
    Sep 23, 2014 @ 13:40
    Gavin Bewley-Jones
    0

    Returns no results ... 

    My XSLT / XPATH etc 100% non existant so im clueless here LOL

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 23, 2014 @ 13:43
    Richard Soeteman
    0

    Send me your mediaprotect.xml file please to [email protected]

Please Sign in or register to post replies

Write your reply to:

Draft