-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhide-if.vtl
117 lines (108 loc) · 4.87 KB
/
hide-if.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#** ===========================================================================
HIDE IF
This Confluence user macro allows to hide content from users, groups or
permissions.
Version: 1.1.0
Updated: 2022-01-09
Author/s: Cyrille Martin [VALIANTYS], George Lewe
Source: https://github.com/glewe/confluence-user-macros
License: GNU LGPLv3
Macro Body processing: Rendered
*#
#** ---------------------------------------------------------------------------
PARAMETER
*#
## @param match:title=Match Using|type=enum|enumValues=all,any|required=false|desc=If set to any, only one of the specified restrictions needs to match.|default=any
## @param user:title=Users|type=username|required=false|desc=The list of users to match.|multiple=true
## @param group:title=User groups|type=string|required=false|desc=The list of user groups to match.
## @param spacePermission:title=Space Permissions|type=string|required=false|desc=This property allows you to define whether the content inside this macro is hidden to a certain user based on his space permissions. This can be done by either of the following:</br>Using @self to specify current space, followed by ":", then followed by permission type e.g. @self:view<br>These are the permission types:</br><ul><li><strong>view</strong> - (default) The user can view the space.</li><li><strong>edit</strong> - The user can edit pages.</li><li><strong>admin</strong> - The user can administer the space.</li><li><strong>news</strong> - The user can post a blog entry</li></ul>
## @param display:title=Display Types|type=string|required=false|desc=This property allows the user to hide content only in a document that has been exported to PDF or Word and not on the Confluence page. </br>The (list of) display modes:</br><strong>default</strong> - content is hidden in both Confluence and the exported PDF or Word document</br><strong>printable</strong> - content is hidden only in the exported PDF document
#set( $hidecontentuser = false )
#set( $hidecontentgroup = false )
#set( $getPermission = false )
#set( $username = "$req.getRemoteUser()" )
#** ---------------------------------------------------------------------------
PROCESS INPUT
*#
#**
Check users to hide from
*#
#if( $!paramuser )
#foreach( $userlisted in $paramuser.split(",") )
#if( $userlisted == $username )
#set( $hidecontentuser = true )
#end
#end
#end
#**
Check groups to hide from
*#
#if( $!paramgroup )
#foreach( $grouplist in $userAccessor.getGroupNamesForUserName($username) )
#foreach( $grouplisted in $paramgroup.split(",") )
#if( $grouplist == $grouplisted )
#set( $hidecontentgroup = true )
#end
#end
#end
#end
#**
Check permissions to hide from
*#
#if( $!paramspacePermission )
#set ( $colonIndex = $paramspacePermission.indexOf(":") )
#if ( $colonIndex == -1 )
#set ( $pagePermission = $paramspacePermission )
#else
#set ( $spaceKey = $paramspacePermission.substring(0, $colonIndex) )
#set ( $pageActionIndex = $colonIndex + 1 )
#set ( $pagePermission = $paramspacePermission.substring($pageActionIndex) )
#end
#if( $pagePermission == "edit" )
#set( $getPermission = $permissionHelper.canEdit($userAccessor.getUserByName($username),$content) )
#elseif( $pagePermission == "view" )
#set( $getPermission = $permissionHelper.canViewPage($userAccessor.getUserByName($username),$content) )
#elseif( $pagePermission == "news" )
#set( $getPermission = $permissionHelper.canCreateBlogPost($userAccessor.getUserByName($username),$space) )
#elseif( $pagePermission == "admin" )
#set( $getPermission = $permissionHelper.canAdminister($userAccessor.getUserByName($username),$space) )
#end
#end
#** ---------------------------------------------------------------------------
OUTPUT
*#
<!-- User Macro: Hide If START -->
#if( $parammatch == "any" )
#if( $hidecontentuser || $hidecontentgroup || $getPermission )
#if( $!paramdisplay != "printable" )
#else
<div class="NoDisplay">
#set($body = $body)
$body
</div>
#end
#else
#if( $!paramdisplay != "printable" )
#set($body = $body)
$body
#else
<div class="NoDisplay">
#set($body = $body)
$body
</div>
#end
#end
#else
#if( (($!paramuser && $hidecontentuser) || !($!paramuser || $hidecontentuser)) && (( $!paramgroup && $hidecontentgroup) || !( $!paramgroup || $hidecontentgroup)) && (($!paramspacePermission && $getPermission) || !($!paramspacePermission || $getPermission)) )
#if( $!paramdisplay != "printable" )
#else
<div class="NoDisplay">
#set($body = $body)
$body
</div>
#end
#else
$body
#end
#end
<!-- User Macro: Hide If END -->