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

Michel Barros September 16, 2014

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

1 vote
Answer accepted
Michel Barros September 17, 2014

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

Jesse Anderson January 28, 2015

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

Michel Barros January 28, 2015

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

Daniel Alonso February 28, 2018

Any idea to use this solution on Cloud?

Like Marc-Antoine Boisvert likes this
SB May 2, 2018

I would also like to know the answer to this. 

Suggest an answer

Log in or Sign up to answer