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
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
Thanks @Benjamin
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 bannervar 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 groupvar 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 availablevar 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 groupvar 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>
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:
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()if (ComponentAccessor.groupManager.isUserInGroup(currentUser, "administrators") || ComponentAccessor.groupManager.isUserInGroup(currentUser, "system-administrators")) return trueelse return false
It looks like you're new here. Sign in or register to get started.