I want to create a document / macro which allows the user to select a different document
and then get a list of all XWiki users with listed rights to this selected document.
My code is listed above. It seems to works.
But my problem is:
$doc.hasAccessLevel('edit','USERID")
gives wrong results. I get “false” instead of “true”.
It looks like the same results of $doc.hasAccessLevel("admin","USERID")
May be I miss something.
I am using XWIki version 9.11.2-
{{template name="locationPicker_macros.vm"/}}
{{velocity}}
#if(!$request.name)
{{html}}
#set ($documentReference = $services.model.resolveDocument($doc.getFullName()))
#set ($selectedDocument = $xwiki.getDocument($documentReference))
<form class="xform" action="">
#locationPicker({
'id': 'target',
'title': {
'label' : 'Titel des Dokuments',
'hint' : 'Suche mittels Titeleingabe für den aktuellen Bereich',
'name': 'title',
'value': $selectedDocument.plainTitle,
'placeholder': 'core.create.name.placeholder'
},
'preview': {
'label': 'Ablage',
'hint' : ''
},
'parent': {
'label' : 'Ablagepfad',
'hint' : '',
'name': 'spaceReference',
'reference': $documentReference.parent.parent,
'placeholder': 'core.create.spaceReference.placeholder'
},
'name': {
'label' : 'Titel',
'hint': '',
'name': 'name',
'value': $documentReference.name,
'placeholder': 'core.create.name.placeholder'
}
})
<input type="submit" value="Get Rights | Berechtigungen Abfragen" />
</form>
{{/html}}
#end
{{/velocity}}
{{velocity}}
#if($request.name)
Rechte an: **${request.title}**
unter: $request.spaceReference
#set ($spaceref="$request.spaceReference")
#set ($title="$request.title")
#set ($docName="${spaceref}.$title")
#set($docRef = $services.model.createDocumentReference('', $request.spaceReference, $request.title))
#set($newDoc = $xwiki.getDocument($docRef))
##
## Eine Hash-Liste mit allen Attributen aufbauen
##
#set ($usersObj = $xwiki.rightsmanager.usersApi.getAllGlobalUsers())
#set ($allUser=[])
#set ($yesLabel="[[image:icon:accept]]")
#set ($noLabel="-")
#foreach ($xx in $usersObj)
#if($newDoc.hasAccessLevel('view',$xx.toString())) #set ($viewAccess=$yesLabel) #else #set($viewAccess=$noLabel) #end
#if($newDoc.hasAccessLevel('edit',$xx.toString())) #set ($editAccess=$yesLabel) #else #set($editAccess=$noLabel) #end
#if($newDoc.hasAccessLevel('comment',$xx.toString())) #set ($commentAccess=$yesLabel) #else #set($commentAccess=$noLabel) #end
#if($newDoc.hasAccessLevel('script',$xx.toString())) #set ($scriptingAccess=$yesLabel) #else #set($scriptingAccess=$noLabel)#end
#if($newDoc.hasAccessLevel('delete',$xx.toString())) #set ($deleteAccess=$yesLabel) #else #set($deleteAccess=$noLabel) #end
#if($newDoc.hasAccessLevel('admin',$xx.toString())) #set ($adminAccess=$yesLabel) #else #set($adminAccess=$noLabel) #end
#set ($id=$xx.toString().replaceAll("^XWiki.",""))
#set ($discard=$allUser.add({"id" : "$id" , "nachname" : "$xx.last_name", "vorname" : "$xx.first_name",
"view" : "$viewAccess", "edit" : "$editAccess", "comment" : "$commentAccess", "scripting" : "$scriptingAccess", "delete" : "$deleteAccess", "admin" : "$adminAccess" }))
#end
##
#set ($loopCount=0)
$xwiki.ssfx.use("js/xwiki/table/table.css")
$xwiki.jsfx.use("js/xwiki/table/tablefilterNsort.js", true)
#set ($discard = $xwiki.jsx.use($doc.getFullName()))
[[zurück zur Auswahl>>$doc.getFullName()]]
{{html wiki="false"}}
<input type=checkbox checked onclick="toggleColumn(1);" style="cursor:pointer">Nummer</input>
<input type=checkbox checked onclick="toggleColumn(2);" style="cursor:pointer">Account</input>
<input type=checkbox checked onclick="toggleColumn(3);" style="cursor:pointer">Name</input>
<input type=checkbox checked onclick="toggleColumn(4);" style="cursor:pointer">Lesen</input>
<input type=checkbox checked onclick="toggleColumn(5);" style="cursor:pointer">Schreiben</input> <br>
<input type=checkbox checked onclick="toggleColumn(6);" style="cursor:pointer">Kommentieren</input>
<input type=checkbox checked onclick="toggleColumn(7);" style="cursor:pointer">Scripte ausführen</input>
<input type=checkbox checked onclick="toggleColumn(8);" style="cursor:pointer">Löschen</input>
<input type=checkbox checked onclick="toggleColumn(9);" style="cursor:pointer">Administrieren</input>
{{/html}}
(% class="grid sortable filterable doOddEven" id="tableid" %)
(% class="sortHeader" %)|= Nr. |=Account |= Name |= Lesen |= Schreiben |= Kommentar |= Scripte\\ausführen |= Löschen |= Administrieren
#foreach ($u in $sorttool.sort($allUser,["nachname:asc"]))
#set ($loopCount=$loopCount+1)
|(% align=right %) $loopCount. | (% align=left%) $u.id | (% align=left%) $u.vorname $u.nachname |(% align=center%)$u.view |(% align=middle%)$u.edit |(% align=middle%)$u.comment |(% align=middle%)(% align=middle%)$u.scripting |(% align=middle%)$u.delete |(% align=middle%) $u.admin
#end
#end
## ------------------------------------------------------------------------------------------------
## The following object (type: XWiki.JavaScriptExtension) is needed to toggle visibility of columns
##
## function toggleColumn(c) {
## what1="td:nth-child("+c+")"; require(["jquery"],function($) {$(what1).toggleClass("hidden");});
## what2="th:nth-child("+c+")"; require(["jquery"],function($) {$(what2).toggleClass("hidden");});
## };
{{/velocity}}