Copied to clipboard

Flag this post as spam?

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


  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 09, 2010 @ 14:01
    Rob Stevenson-Leggett
    0

    Error when saving Permissions on "New" node

    Hi,

    I've got a requirement to allow editors to create a very low permissions user that can only see and edit a single page. I've noticed that be default any user can see a node unless they are specifically assigned the ActionNull permission ('-').

    So what I tried to do was use the UserPermissions.SaveNewPermissions method and hook into the CMSNode.AfterNew event like so:

     

            void CMSNode_AfterNew(object sender, NewEventArgs e)
            {
                var current = sender as CMSNode;

                if (current.Parent.Parent.Id == Helper.ProtectedRoot)
                {
                    foreach (User otherUser in GetSupplierUsers())
                    {
                       //This doesn't work on new nodes
                       UserPermissions p = new UserPermissions(otherUser);
                        p.SaveNewPermissions(new[] { node.Id }, new List<IAction>(), true);
                   
                     }
                }
            }

    This gives me a FormatException which comes from this line in UserPermissions.SaveNewPermissions (from reflector)

    List<IAction> list3 = Action.FromString(UmbracoEnsuredPage.CurrentUser.GetPermissions(this.GetNodePath(num)));

    Which leads to this line in User.GetPermissions

    if (this._cruds.ContainsKey(int.Parse(str2))) 

    It seems like the path is screwed up somehow for the new node.

    I have coded around this using the following lines instead:

    Permission.MakeNew(otherUser,node, ActionNull.Instance.Letter);
     HttpRuntime.Cache.Remove(string.Format("UmbracoUser{0}", otherUser.Id));

    Which doesn't seem quite as elegant.

    Any ideas? Should I log this as a bug?

    Cheers,

    Rob

     

  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 09, 2010 @ 14:02
    Rob Stevenson-Leggett
    0

    Sorry there's an error in the code, this line

     p.SaveNewPermissions(new[] { node.Id }, new List<IAction>(), true);

    should be

    p.SaveNewPermissions(new[] { current.Id }, new List<IAction>(), true);
  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 14, 2010 @ 13:34
    Rob Stevenson-Leggett
    0

    Anyone?

  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 14, 2010 @ 14:16
    Rob Stevenson-Leggett
    0

    To follow this up I've dug a bit deeper in and it seems the UserPermissions class can only work on published nodes because the GetNodePath method uses GetXmlNodeById. Is there an alternative way of saving permissions when a node is unpublished?

    private string GetNodePath(int iNodeID)
    {
        string attribute = "";
        XPathNodeIterator xmlNodeByXPath = library.GetXmlNodeByXPath("//node[@id=" + iNodeID.ToString() + "]");
        if (xmlNodeByXPath.MoveNext())
        {
            attribute = xmlNodeByXPath.Current.GetAttribute("path", "");
        }
        return attribute;
    }
    
  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 14, 2010 @ 14:32
    Rob Stevenson-Leggett
    0

    In fact this seems to affect the entire UserPermissions class. Why is this not using CMSNode.Path?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 14, 2010 @ 14:49
    Lee Kelleher
    0

    Hi Rob,

    Not sure how to resolve the problem, but can hopefully suggest a few things that might lead you in the right direction?

    I'm curious why the GetNodePath method uses GetXmlNodeByXPath ... as that only queries published content - not sure if that is the intended functionality ... you might need to raise a CodePlex ticket on that one?

    Events-wise, do you have to use CMSNode.AfterSave? Could you hook into umbraco.content.FireAfterUpdateDocumentCache? This only applied to Documents, but it might resolve the Format exception - as the content node would have been published (to the XML umbraco.config cache) by then.

    Good luck, Lee.

  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 15, 2010 @ 18:37
    Rob Stevenson-Leggett
    0

    Cheers for the reply.

    I've got around it by rewriting code from the UserPermissions class for removing permissions.

    I'll raise a codeplex item on the GetNodePath.

    I think it has to be on Document.AfterNew because otherwise other users seem to be able to browse to this node until it saved. What I'm trying to do is make it so the low permissions users can only see their own page.

     

  • Rob Stevenson-Leggett 38 posts 110 karma points
    Jun 16, 2010 @ 13:48
    Rob Stevenson-Leggett
    0
Please Sign in or register to post replies

Write your reply to:

Draft