Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,503,102
Community Members
 
Community Events
180
Community Groups

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

1 vote
Answer 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?

Like Marc-Antoine Boisvert likes this

I would also like to know the answer to this. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events