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)
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?
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.
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.
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:
This gives me a FormatException which comes from this line in UserPermissions.SaveNewPermissions (from reflector)
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:
Which doesn't seem quite as elegant.
Any ideas? Should I log this as a bug?
Cheers,
Rob
Sorry there's an error in the code, this line
should be
Anyone?
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?
In fact this seems to affect the entire UserPermissions class. Why is this not using CMSNode.Path?
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.
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.
Added to Codeplex here: http://umbraco.codeplex.com/workitem/27609
is working on a reply...