[xwiki-users] access rights puzzles
I'm having some strange issues with access rights on http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/ Issue 1 ====== I configured the space to permit view for unauthorized users. Yet when loggen out I get: Error number 4001 in 4: Error while parsing velocity page Cases.WebHome Wrapped Exception: Failed to evaluate content with id <http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/>Web Home<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/> the root exception seems to be: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'formatDate' in class com.xpn.xwiki.api.XWiki threw exception java.lang.NullPointerException @ Cases.WebHome74,17? When logged in, the page displays fine: Existing Case Studies Name[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Owner[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Created[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Modified[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> By[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Summary[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Status[image: ↓]<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/#> Woodforthetrees<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/Woodforthetrees> Steven Warburton<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/stevenwarburton> 15 May 2008 16 May 2008 Yishay Mor <http://localhost/xwiki/bin/view/XWiki/yish> seed Virtual World Communications<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/VirtualWorldCommunications> Jim Hensman<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/JimHensman> 15 May 2008 15 May 2008 Jim Hensman<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/JimHensman> seed Team Communications<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/TeamCommunications> john gray<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/JohnGray> 14 May 2008 14 May 2008 john gray<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/JohnGray> What goes in here? seed test <http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/test> Yishay Mor (local)<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/YishayMor> 16 May 2008 16 May 2008 Yishay Mor (local)<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/XWiki/YishayMor> The troublesome code is probably this: <td> $xwiki.formatDate($caseDoc.getCreationDate(),"dd MMM yyyy") </td> <td> $xwiki.formatDate($caseDoc.getDate(),"dd MMM yyyy") </td> issue 2 ===== I use this code to create new pages in the space: #if ($xwiki.hasAccessLevel("edit")) </p><form action="" id="newdoc" method="post"> <div> <input name="parent" value="XWiki.CaseClass" type="hidden"> <input name="template" value="Cases.CaseClassTemplate" type="hidden"> <input name="sheet" value="1" type="hidden"> <input name="webname" value="Cases" size="8" type="hidden"> Name: <input name="name" value="Name of your case study" type="text" size="20"> <input value="Create" onclick='if (updateName(this.form.name)) {this.form.action="../../inline/" + this.form.webname.value + "/" + this.form.name.value; this.form.submit(); }' type="button"> </div> </form><p> #else sorry, you have to log in to enter a case study. #end It works fine, users can create new pages, but then they can't edit them! In my desperation, I added this to the class sheet: ## set rights to allow creator and contributors to edit ## THIS DOESN'T WORK: CHICKEN & EGG PROBLEM => TURNED OFF SAVE #macro(allowEdit $user) #set ($rights = $doc.getObject("XWiki.XWikiRights", true)) #set ($result = $rights.set("levels", "edit")) #set ($result = $rights.set("users", $user)) #set ($result = $rights.set("allow", 1)) ## $doc.save() #end #allowEdit($doc.getCreator()) #foreach($contributor in $doc.getObject("Cases.CaseClass").contributors) #allowEdit($contributor) #end but as you can see in the comment, it fails because if a user doesn't have edit rights to begin with, save fails. -- ___________________________ Yishay Mor, Researcher, London Knowledge Lab http://www.lkl.ac.uk/people/mor.html http://yishaym.wordpress.com https://www.linkedin.com/in/yishaymor http://www.google.com/calendar/embed?src=yishaym%40gmail.com +44-20-78378888 x5737
Yishay Mor wrote:
I'm having some strange issues with access rights on http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/
Issue 1 ====== I configured the space to permit view for unauthorized users. Yet when loggen out I get: Error number 4001 in 4: Error while parsing velocity page Cases.WebHome Wrapped Exception: Failed to evaluate content with id <http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/>Web Home<http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Cases/> the root exception seems to be: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'formatDate' in class com.xpn.xwiki.api.XWiki threw exception java.lang.NullPointerException @ Cases.WebHome74,17? When logged in, the page displays fine: [snip] The troublesome code is probably this: <td> $xwiki.formatDate($caseDoc.getCreationDate(),"dd MMM yyyy") </td> <td> $xwiki.formatDate($caseDoc.getDate(),"dd MMM yyyy") </td>
Although you allowed view rights on the space, some of those documents have stricter access rights ("Woodforthetrees" and "test"). It is normal that document access rights are stronger than space access rights, so those documents won't be returned by the call to $xwiki.getDocument. You should put an #if($xwiki.hasAccessLevel("view", $context.user, $case)) inside the foreach.
issue 2 ===== I use this code to create new pages in the space: #if ($xwiki.hasAccessLevel("edit")) </p><form action="" id="newdoc" method="post"> <div> <input name="parent" value="XWiki.CaseClass" type="hidden"> <input name="template" value="Cases.CaseClassTemplate" type="hidden"> <input name="sheet" value="1" type="hidden"> <input name="webname" value="Cases" size="8" type="hidden"> Name: <input name="name" value="Name of your case study" type="text" size="20"> <input value="Create" onclick='if (updateName(this.form.name)) {this.form.action="../../inline/" + this.form.webname.value + "/" + this.form.name.value; this.form.submit(); }' type="button"> </div> </form><p> #else sorry, you have to log in to enter a case study. #end
It works fine, users can create new pages, but then they can't edit them! In my desperation, I added this to the class sheet: ## set rights to allow creator and contributors to edit ## THIS DOESN'T WORK: CHICKEN & EGG PROBLEM => TURNED OFF SAVE #macro(allowEdit $user) #set ($rights = $doc.getObject("XWiki.XWikiRights", true)) #set ($result = $rights.set("levels", "edit")) #set ($result = $rights.set("users", $user)) #set ($result = $rights.set("allow", 1)) ## $doc.save() #end #allowEdit($doc.getCreator()) #foreach($contributor in $doc.getObject("Cases.CaseClass").contributors) #allowEdit($contributor) #end but as you can see in the comment, it fails because if a user doesn't have edit rights to begin with, save fails.
I see that you granted edit rights only to some groups. Can users in those groups edit the documents they create? Only users not in one of those groups cannot edit? -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (2)
-
Sergiu Dumitriu -
Yishay Mor