Forums

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

How to hide menus in top bar?

Jira User June 28, 2022

Hello, I want to hide the "Insight" menu in the top bar for non-admin users.

Can I solve it using Scriptrunner?

 

Thanks for answers

3 answers

0 votes
David Yu
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.
February 22, 2024

If you have ScriptRunner, use the Script Fragment's "Hide system or plugin UI element."

Under "Hide what," choose:

com.riadalabs.jira.plugins.insight:rlabs_insight_topmenu

You might also want to hide the assets icon on Kanban boards:

com.riadalabs.jira.plugins.insight:rlabs-project-jira-section

Then under condition, you can specify that only certain people can see the banner:

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (ComponentAccessor.groupManager.isUserInGroup(currentUser, "administrators") || ComponentAccessor.groupManager.isUserInGroup(currentUser, "system-administrators"))

return true

else

return false
0 votes
nick gleed December 29, 2023

This code worked for me - I used it to block access to the menu item "assets" and creating a jsm project to only those in a specific group (jsm-access) - might work for others so including it here. I left debugging in, but commented out. But shows you can grab via rest in JS and use it conditionally to set display=none as required.

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
fetch('/rest/api/2/myself?expand=groups', {
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
/*
// Debug: List user groups in the banner
var groupNames = data.groups.items.map(group => group.name).join(', ');
var banner = document.getElementById('announcement-banner');
if (banner) {
banner.innerHTML += '<p>User Groups: ' + groupNames + '</p>';
}
*/

// Check if the user is not in 'jsm-user'
if (!data.groups.items.some(group => group.name === 'jsm-user')) {
// Debug message for not being in the target group
var banner = document.getElementById('announcement-banner');
if (banner) {
banner.innerHTML += '<p>User is not in the target group. Hiding elements.</p>';
}

// Use MutationObserver to hide the elements when they become available
var observer = new MutationObserver(function(mutations, obs) {
var elementsToHideIds = ['project-template-group-service_desk', 'rlabs_insight_topmenu_link','project_type_service_desk','service_desk-project-type'];
elementsToHideIds.forEach(function(id) {
var elementToHide = document.getElementById(id);
if (elementToHide) {
elementToHide.style.display = 'none';
}
});

// Optional: Stop observing if both elements are found and hidden
// if (elementsToHideIds.every(id => !document.getElementById(id))) {
// obs.disconnect();
// }
});

observer.observe(document.body, {
childList: true,
subtree: true
});

} else {
// Debug message for being in the target group
var banner = document.getElementById('announcement-banner');
if (banner) {
banner.innerHTML += '<p>User is in the target group.</p>';
}
}
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
});
</script>

0 votes
Benjamin
Community Champion
June 28, 2022

HI @Jira User ,

 

There isn't a straight forward way. It's either through coding or possibly add-ons.

 

Here's some posting of similar ask:

 

https://community.atlassian.com/t5/Jira-questions/JIRA-Hide-Top-Bar-Navigation-Menu-buttons-based-on-Groups/qaq-p/1147528

https://community.developer.atlassian.com/t/hiding-native-menus-and-menu-items-via-code/13918

 

Thanks,

 

Ben

Jira User June 30, 2022

Thanks @Benjamin 

Suggest an answer

Log in or Sign up to answer