Is it possible to show "create sub task" option to only particular group

Ramesh Udari1 September 16, 2013

Hi,

We are using JIRA 5.0.2 version and We want show "create sub task" option to only particular group, is it possible?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
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.
September 16, 2013

add this javascript on footer.jsp or load it as webresource module in a plugin

<script type="text/javascript">
jQuery(document).ready(function($) {  
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { 
hideTab();    
});
hideTab();  
function hideTab(){
        var user=getCurrentUserName();
//change group as per your requirement		
		if(isUserInGroup(user,'Developers')){			
			$("#create-subtask").hide();
			//if you want to hide "Convert to Sub-Task" operation then use this
			$("#issue-to-subtask").hide();
		}else{
			$("#create-subtask").show();
			$("#issue-to-subtask").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>

Ramesh Udari1 September 16, 2013

Hi Prasad,

Thanks for your help. I have tried with above script like adding to footer.jsp, but it is not working. what i have observed that rest call to get current user that is getCurrentUserName() method returing "undefined" value.

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.
September 16, 2013

which version of jira you are using?

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.
September 16, 2013

then i don't think the problem with the getCurrentUserName() method, are you passing correct group name as parameter?

Ramesh Udari1 September 16, 2013

JIRA Version - 5.0.2

Ramesh Udari1 September 16, 2013

Yes Prasad, i am passing correct group only. i have debuged with firbug and found this error in console.

<html><head><title>Apache Tomcat/5.5.29 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /rest/gadget/1.0/currentUser</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/rest/gadget/1.0/currentUser</u></p><p><b>description</b> <u>The requested resource (/rest/gadget/1.0/currentUser) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.29</h3></body></html>
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.
September 16, 2013

can you try this on your browser

<your instance url>/rest/gadget/1.0/currentUser

Ramesh Udari1 September 16, 2013

Hi Prasad,

I have already tried with my instance context path and found that rest call is working fine, but "create-subtask" option is still enabled for that group.

What i have observed that page is already loaded before executing javascript that is why it is not hiding create-subtask option.

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.
September 16, 2013

can you try with my updated answer!!

Ramesh Udari1 September 16, 2013

I have tried and user name and group details coming properly but "create-subtask" option is not hidden.

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.
September 16, 2013

in jira 5.2.5 the id for this operation is "create-subtask" so same you can check on your jira instance with firebug!

Ramesh Udari1 September 16, 2013

Hi Prasad,

Thanks for your help, now it is working fine.

I have modified below javascript little bit and then it is working fine.

if(isUserInGroup(user,'Developer')){
                       AJS.$("#create-subtask").hide();
            //if you want to hide "Convert to Sub-Task" operation then use this
            AJS.$("#issue-to-subtask").hide();
     
        }else{
 
             AJS.$("#create-subtask").show();
         AJS.$("#issue-to-subtask").show();
     
        }

Thanks a lot for your help.

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.
September 16, 2013

Glad to hear it worked!!

0 votes
Ramesh Udari1 September 16, 2013

Hi Prasad,

Thanks for your help, now it is working fine. The problem with below code earlier

if(isUserInGroup(user,'Developers')){           
            $("#create-subtask").hide();
            //if you want to hide "Convert to Sub-Task" operation then use this
            $("#issue-to-subtask").hide();
        }else{
            $("#create-subtask").show();
            $("#issue-to-subtask").show();
        }

Now i have modified above code to added AJS reference then it is working fine.

if(isUserInGroup(user,'Nagpur-IT')){
                       AJS.$("#create-subtask").hide();
            //if you want to hide "Convert to Sub-Task" operation then use this
            AJS.$("#issue-to-subtask").hide();
	
        }else{

             AJS.$("#create-subtask").show();
	     AJS.$("#issue-to-subtask").show();
	
        }

Thanks a lot for your help.

niranjan April 2, 2019

@Ramesh Udari1  Hi Can you help me to solve this issue. I was in the same boat but was not figure it out how to do this one. Could you please explain me in details how you did. 

0 votes
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.
September 16, 2013

as of now who have create issue permission can create subtasks also, to implement create sub tasks permission improvement request has submitted, check this

https://jira.atlassian.com/browse/JRA-8521

workaround: you can do this by using javascript

Ramesh Udari1 September 16, 2013

Hi Prasad,

Thanks for your response on this. Can you please explain bit more on workaround. I mean by using javascript how can i achieve this ?

Thanks

Tom

TAGS
AUG Leaders

Atlassian Community Events