Hi all!!
I am developing a macro to know all view permissions for a specific user in every spaces in Confluence. For that, first I loop for all the spaces looking for his view individual permissions, and then I loop again to loop through the groups with permissions in the space to know if the user is there.
The problem is that we have many users and spaces, and after thinking for a while it shows the error that I attach.
Here is my macro:
## Macro title: User permissions ## Macro has a body: Y or N (N) ## Body processing: Selected body processing option ## Output: Selected output option ## ## Developed by: Arantxa Lacasa Madero ## Date created: 01/08/2012 ## Installed by: Arantxa Lacasa Madero ## Macro que lista todos los espacios en los que un usuario tiene acceso ## @param nombreusuario:title=Nombre de usuario|type=string|desc=El nombre de inicio de sesion del usuario|required=true #set($allSpaces = $spaceManager.getAllSpaces()) <h1>Permisos del usuario</h1> <h3>Permisos individuales</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> </tr> #foreach($space in $allSpaces) #foreach ($permission in $space.getPermissions()) #if ($permission.isUserPermission() && $permission.getType() == "VIEWSPACE" && $permission.getUserName() == ($paramnombreusuario)) <tr> <td class="confluenceTd">$space.getName()</td> </tr> #end #end #end </table> <h3>Permisos en grupos</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> <th class="confluenceTh">Grupo</th> </tr> #foreach($space in $allSpaces) #foreach ($permission in $space.getPermissions()) #if ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE") #set ( $groupString = $permission.getGroup() ) #set ( $groupObject = $userAccessor.getGroup($groupString) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) #foreach ($member in $memberList) #if ($member == "$paramnombreusuario") <tr> <td class="confluenceTd">$space.getName()</td> <td class="confluenceTd">$groupString</td> </tr> #end #end #end #end #end </table>
Any ideas of how could I optimizate it?
Or is it something wrong in it?
Thanks!!
How about this one... I think you don't need to go through loop to know if a user is a member of a group because there's a function for that. But I'm not sure if this is the same as the above code...
## Macro title: User permissions ## Macro has a body: Y or N (N) ## Body processing: Selected body processing option ## Output: Selected output option ## ## Developed by: Arantxa Lacasa Madero ## Date created: 01/08/2012 ## Installed by: Arantxa Lacasa Madero ## Macro que lista todos los espacios en los que un usuario tiene acceso ## @param nombreusuario:title=Nombre de usuario|type=string|desc=El nombre de inicio de sesion del usuario|required=true #set($allSpaces = $spaceManager.getAllSpaces()) #set($result1 = "") #set($result2 = "") #foreach($space in $allSpaces) #foreach ($permission in $space.getPermissions()) #if ($permission.isUserPermission() && $permission.getType() == "VIEWSPACE" && $permission.getUserName() == ($paramnombreusuario)) #set($result1 = "${result1}<tr> <td class='confluenceTd'>$space.getName()</td> </tr>") #elseif ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE") #set ( $groupString = $permission.getGroup() ) #if ($userAccessor.hasMembership("$groupString", "$paramnombreusuario")) #set($result2 = "${result2}<tr> <td class='confluenceTd'>$space.getName()</td> <td class='confluenceTd'>$groupString</td> </tr>") #end #end #end #end <h1>Permisos del usuario</h1> <h3>Permisos individuales</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> </tr> $result1 </table> <h3>Permisos en grupos</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> <th class="confluenceTh">Grupo</th> </tr> $result2 </table>
This is really cool. Now I just need to figure out how to add JS so that people can make a query without having to edit the page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How about this one? I put only a single loop for both tables :)
## Macro title: User permissions ## Macro has a body: Y or N (N) ## Body processing: Selected body processing option ## Output: Selected output option ## ## Developed by: Arantxa Lacasa Madero ## Date created: 01/08/2012 ## Installed by: Arantxa Lacasa Madero ## Macro que lista todos los espacios en los que un usuario tiene acceso ## @param nombreusuario:title=Nombre de usuario|type=string|desc=El nombre de inicio de sesion del usuario|required=true #set($allSpaces = $spaceManager.getAllSpaces()) #set($result1 = "") #set($result2 = "") #foreach($space in $allSpaces) #foreach ($permission in $space.getPermissions()) #if ($permission.isUserPermission() && $permission.getType() == "VIEWSPACE" && $permission.getUserName() == ($paramnombreusuario)) #set($result1 = "${result1}<tr> <td class='confluenceTd'>$space.getName()</td> </tr>") #elseif ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE") #set ( $groupString = $permission.getGroup() ) #set ( $groupObject = $userAccessor.getGroup($groupString) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) #foreach ($member in $memberList) #if ($member == "$paramnombreusuario") #set($result2 = "${result2}<tr> <td class='confluenceTd'>$space.getName()</td> <td class='confluenceTd'>$groupString</td> </tr>") #end #end #end #end #end <h1>Permisos del usuario</h1> <h3>Permisos individuales</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> </tr> $result1 </table> <h3>Permisos en grupos</h3> <table class="confluenceTable"> <tr> <th class="confluenceTh">Espacio</th> <th class="confluenceTh">Grupo</th> </tr> $result2 </table>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Amalia, that's a good idea!
Did you test if it worked for you? It does not work for me, and I would like to discard any code mistake.
Thanks so much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I have tested it and it's working for me. What does it show?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which version of Confluence are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm using version 3.5.7.
I'm afraid that I'm getting a java heap space while searching for group permissions. Only with individual permissions it works all right...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.