Forums

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

Hiding issue fields based on user role

Deleted user November 28, 2013

We have added a custom field for Developer Notes, but don't want this to be visible to anyone other than staff with the Developer role. How can we do this ?

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
November 28, 2013

Jira doesn't have field level security.

You can try to do it with a bit of javascript for yourself, but have a look at the field security plugin from quisapps or the behavours plugin.

1 vote
RambanamP
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.
November 28, 2013

if you want to do with javascript then you can try with following script

<script type="text/javascript">  
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {	
		hideFieldForGroup();    
	});
	hideFieldForGroup();
function hideFieldForGroup(){
        var user=getCurrentUserName();		
		var statusText=$('#status-val').text();	
		var status=$.trim(statusText);
		if(isUserInGroup(user,'Developers') && status=='In Progress'){			
			$("#customfield_10571").closest('div.field-group').hide();
		}else if(isUserInGroup(user,'Users') && status=='Open') {
			AJS.$("#customfield_10571").closest('div.field-group').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>

Faiza Kazmi April 19, 2019

can i put this code in field description

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events