-
Notifications
You must be signed in to change notification settings - Fork 4
/
user-permissions.vtl
92 lines (84 loc) · 3.7 KB
/
user-permissions.vtl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#** ===========================================================================
USER PERMISSIONS
This Confluence user macro lists all spaces for which a given user has at least
view permission.
Version: 1.0.0
Updated: 2022-01-09
Author/s: George Lewe
Source: https://github.com/glewe/confluence-user-macros
License: GNU LGPLv3
Macro Body Processing: No macro body
*#
#** ---------------------------------------------------------------------------
PARAMETER
*#
## @param Username:title=Username|type=string|desc=Enter the username for which you want to list all spaces with permissions|default=
#** ---------------------------------------------------------------------------
OUTPUT
*#
<!-- User Macro: User Permissions START -->
<h1>Space permissions for user: $paramUsername</h1>
<table class="confluenceTable">
<tbody>
<tr>
<th class="confluenceTh">Space</th>
<th class="confluenceTh">View</th>
<th class="confluenceTh">Edit</th>
<th class="confluenceTh">Admin</th>
<th class="confluenceTh">Permission</th>
</tr>
#**
Loop through all spaces
*#
#foreach ($space in $spaceManager.getAllSpaces())
#set ($userCanView = false)
#set ($userCanEdit = false)
#set ($userCanAdmin = false)
#**
Loop through all permissions of this space and remember if the user
holds one of the three permissions in question.
*#
#foreach ($permission in $space.getPermissions())
#if ($permission.isUserPermission() && $permission.getType() == "VIEWSPACE" && $permission.getUserName() == $paramUsername)
#set($userCanView = true)
#end
#if ($permission.isUserPermission() && $permission.getType() == "EDITSPACE" && $permission.getUserName() == $paramUsername)
#set($userCanEdit = true)
#end
#if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS" && $permission.getUserName() == $paramUsername)
#set($userCanAdmin = true)
#end
#end
#**
If the user holds one of the three permissions in question, show the row with the tick marks.
*#
#if ($userCanView || $userCanEdit || $userCanAdmin)
<tr>
<td class="confluenceTd"><a href="$req.contextPath$space.getUrlPath()">$space.getName() ($space.getKey())</a></td>
<td class="confluenceTd" style="text-align: center;">
#if ($userCanView)
<ac:emoticon ac:name="tick"/>
#end
</td>
<td class="confluenceTd" style="text-align: center;">
#if ($userCanEdit)
<ac:emoticon ac:name="tick"/>
#end
</td>
<td class="confluenceTd" style="text-align: center;">
#if ($userCanAdmin)
<ac:emoticon ac:name="tick"/>
#end
</td>
<td class="confluenceTd">
<a class="aui-button aui-button-primary aui-button-compact conf-macro output-block"
style="color:#ffffff;"
href="/spaces/spacepermissions.action?key=$space.getKey()"
target="_blank">Space permissions...</a>
</td>
</tr>
#end
#end
</tbody>
</table>
<!-- User Macro: User Permissions END -->