Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hide page history from certain user groups using wildcard

Roel van Dijk
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 20, 2022

How do I prevent anonymous users from using page history? | Confluence | Atlassian Documentation

In the help article above, a code is presented for hiding page history from anonymous users. I want to edit the code in such a way that it will hide the page history from users with only read-rights on a page, but shows it for users with modify rights.

In our organization we use grouprights that either end with _M or with _R to specify if the group has Modify or Read. Would it be possible to use wildcards in the code so that it just picks up on the last part of a group name?

#if ($action.remoteUser != $null)

would become something like:

#if ($action.remoteUser != *_R)

 

1 answer

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 20, 2022

Just to confirm, do you mean the user must be a member of a specific group to be able to see the page history, or that his username must end with '_M'?

 

According to https://developer.atlassian.com/server/confluence/confluence-objects-accessible-from-velocity there is userAccessor which could resolve group membership.

If it's usernames, then you could try

#if ($action.authenticatedUser.getName().contains("_M"))

or

#if ($action.authenticatedUser.getName().endsWith("_M"))

 

AuthenticatedUser resolves to ConfluenceUser (https://docs.atlassian.com/ConfluenceServer/javadoc/7.20.0/com/atlassian/confluence/user/ConfluenceUser.html) and apache velocity should have both contains and endsWith methods for String objects, once you get the username.

 

If it's about group membership then the UserAccessor has this method in it - https://docs.atlassian.com/ConfluenceServer/javadoc/7.20.0/bucket/user/UserAccessor.html#hasMembership-java.lang.String-java.lang.String- which would conveniently return a boolean.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events