Hiding confluence page elements for multiple users

Todd Winton August 22, 2018

I'm using the following script to hide elements of the confluence page for a specific user.  However, I would like to use this for the specified user and anonymous access.  How can I change this script to do this?  IS it possible to have scripts that provide different views?  Example, the one below for the specified user ID and another for another ID?

<script>
AJS.toInit(function(){
if (AJS.params.remoteUser == 'ctsidocs'){
AJS.$("#space-tools-menu-trigger").hide();
AJS.$('#header').hide();
AJS.$('#action-menu-link').hide();
AJS.$('#children-section').hide();
AJS.$('#shareContentLink').hide();
AJS.$('#likes-section').hide();
AJS.$('#labels-section').hide();
AJS.$('#watch-content-button').hide();
}
});
</script>

 

 

2 answers

1 accepted

0 votes
Answer accepted
Mirek
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 22, 2018

An empty remoteUser object denotes to anonymous users

(AJS.params.remoteUser == '')

So you need to use an alternative in the if statement to have your user and anonymous access

if (AJS.params.remoteUser == 'ctsidocs' || AJS.params.remoteUser == '')

 If you want to have different view for different users you need to have if.. else if.. else statement

https://www.w3schools.com/js/js_if_else.asp

You can try syntax here

https://www.w3schools.com/js/tryit.asp?filename=tryjs_elseif

Todd Winton August 22, 2018

Thanks @Mirek.  That did it.

0 votes
nija_kanthan August 22, 2018

You can detect logged user before rendering the view (.vm). In that you can render views (vm) according to your user level.

ApplicationUser loggedUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

ApplicationUser object contains Atlassian user details.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events