Show / Hide SLA div from issue view screen based on user role

Hi folks,

I need to hide SLA div from issue view screen based on user role. Cause I don't want to expose internal SLA information to customers (cause we opened our JIRA URL for our customers). So, when the user belongs to the Customer role, I need to hide SLA div.

In order to achieve such result I tried to use Behavior ADD-ON. But, since JIRA Service Desk fields are not hideable, it was not possible to use such option.

After that, inspecting elements from issue view screen I identified the id of SLA div, which is: 

<div id="sla-web-panel" class="module toggle-wrap">

...So I thought to use some JS as a possible solution.

The main problem is I'm not a good programmer... sad

So, could you please send me some JS codes to address this particular need? Thanks in advance. Best,

Michel

1 answer

1 accepted

In fact I discovered my own need was to hide SLA div panel based on a specific group (not a role).

Due to that, I wrote the code below, put it into Summary description in the respective field configuration scheme and it worked properly.

<script type="text/javascript">
	jQuery(document).ready(function() {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
        hideSLAPanel();
    });
        hideSLAPanel();
function hideSLAPanel()
{
        var user=getCurrentUserName()
        if(isUserInGroup(user,'<define your own group here>')) {
	    AJS.$('#sla-web-panel').hide();
        } else {
	    AJS.$('#sla-web-panel').show();
        }
 }
function getCurrentUserName()
{
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     return user;
 }
function getGroups(user)
{
var groups;
     AJS.$.ajax({
        url: "/rest/api/2/user?username="+user+"&expand=groups",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            groups = data.groups.items;
        }
     });
     return groups;
 }
function isUserInGroup(user, group){
    var groups = getGroups(user);
    for (i = 0; i < groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
 }
});
</script>

Rest APIs are GREAT, specially if combined to JS. smile

Is it possible to do the same thing based on project role instead of group?

Jesse, I think so, but you will need to check APIs library in order to localize Project Role availability. If not available, you will need to write a JS code using project role objects and collections to interact using an specific user. Please let me know whether such information will help you. Best regards, Michel Barros

Any idea to use this solution on Cloud?

I would also like to know the answer to this. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

707 views 6 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you