How hide Activity tab panel in issue , when user is member of specified group - JIRA 6

Hello,

I'm searchin for solution, how can I hide Activity tab panel in issue view.

In details I don't want to show Activity tab panel for user that aren't members of

specified group (e.g. 'my-users')

I've tested solution with file activitystream.vm, but it only works from project view.

code from "jira\atlassian-jira\WEB-INF\classes\templates\plugins\jira\projectpanels\fragments\summary\activitystream.vm"

#disable_html_escaping()
#if($jiraUserUtils.getGroupNamesForUser($authcontext.getLoggedInUser().getName()).contains("my-users"))
#if($!gadgetHtml)
<div class="mod-header">
<h3>$i18n.getText('common.concepts.activity.stream')</h3>
</div>
<div class="mod-content">
<div class="activitystream-container">
$gadgetHtml
</div>
</div>
#end
#end

When I go to issue view, then Activity is still shown.

Regards

Robert M.

14 answers

1 accepted

1 vote
Accepted answer

it should work now, try with this

&lt;script type="text/javascript"&gt;  
JIRA.ViewIssueTabs.onTabReady(function() {
hideTab();    
})
function hideTab(){
        var user=getCurrentUserName();
		var groupName='my-users';
		if(!isUserInGroup(user,groupName)){
			//to hide the Activity Tab
			AJS.$('#activity-stream-issue-tab').hide();
		}else{
			AJS.$('#activity-stream-issue-tab').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+"&amp;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 &lt; groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}
    
 

&lt;/script&gt;

i have tested this and it is working fine on my machine!!

Hi, 

I am having  requirement of hiding the History Tab under Activity Panel for specific project and users/groups. I am using JIRA 7.3.9. Any one please suggest.

ActivityPanel.PNG

Regards,

Dileep.

you can hide the tab panels using javascript, try with the following code
	
&lt;script type="text/javascript"&gt;
jQuery(document).ready(function() {

var user=getCurrentUserName();
var groupName='my-users';
if(!isUserInGroup(user,groupName)){
//to hide the Activity Tab
    AJS.$('#activity-stream-issue-tab').hide(); 
}else{
	AJS.$('#activity-stream-issue-tab').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+"&amp;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 &lt; groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}
	
});
&lt;/script&gt;

add the above script in footer.jsp

i copied and modified script from http://www.j-tricks.com/1/post/2012/02/some-ajs-tricks.html

Note: pls check the REST API URL's as per the Jira 6

i think you have to use the following code to get current user in jira 6

AJS.$.get("/jira/rest/auth/1/session", function (data) {   
        var userName = data.name;      
    });

Thank you it works indeed !!!

AJS.$.ajax({

url: "/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.username;
}
});
This also works
but unfortunatelly Activity tab is only hidden when I reload/open issue page (when footer is reloaded)
But when I click on tabs All/comments /Work Log it appears again.
It seems the "on-click event" reloades whole Activity table.
Do You know how can I fix it?
Where should I additionally link this javascript?
Robert
Bind your jQuery to JIRA Event, cause after partial-reload (p.e. AJAX) all bindings are gone.
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
        //Your Code here!
});


I'm beggining with JIRA. Can You describe it in more details:

Where should I code this line?

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason)

In this function jQuery(document).ready(function(), like in example above?

Or in other file?

Robert

try with this

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		callHideFunction();
	});
	callHideFunction();
	
function callHideFunction(){
		var user=getCurrentUserName();
var groupName='my-users';
if(!isUserInGroup(user,groupName)){
//to hide the Activity Tab
    AJS.$('#activity-stream-issue-tab').hide();
}else{
    AJS.$('#activity-stream-issue-tab').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+"&amp;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 &lt; groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}
	}

});
&lt;/script&gt;

Un fortunatelly it still works the same way.

On refreshing issue tha Activity tab is hidden,

but after click on one of All/Comment/Work log tabs it appeares again.

Robert

finally try with this

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
        callHideFunction();
    });
    callHideFunction();
     
function callHideFunction(){
	hideTab();
	('#all-tabpanel, #comment-tabpanel, #worklog-tabpanel, #changehistory-tabpanel').click(function(){
	hideTab();	
	});
}
function hideTab(){
        var user=getCurrentUserName();
		var groupName='my-users';
		if(!isUserInGroup(user,groupName)){
			//to hide the Activity Tab
			AJS.$('#activity-stream-issue-tab').hide();
		}else{
			AJS.$('#activity-stream-issue-tab').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+"&amp;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 &lt; groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}
    
 
});
&lt;/script&gt;

Hello Rambanam. I'm looking how to disable certain tabs and panels for JIRA issues. You're using #all-tabpanel, #comment-tabpanel, #worklog-tabpanel and #changehistory-tabpanel in you're script, but where can these be found? Is there a list published somewhere? I'm not using Javascript currently, but only CSS. However, the tags in your script match to the CSS containers.

It works the same way.

Maybe this function should be bind with a different event?

I only remind that this script is referenced in footer.jsp as You wished.

Any more help/idea will be appriatieted!

Robert

as of now where you added this script and testing? and check the id's as per your instance

i've created script test.jsp and saved it under "includes\decorators\aui-layout" directory (thesame with footer.jsp)

In footer.jsp I have added this java script:

<%@ page import="com.atlassian.jira.plugin.navigation.HeaderFooterRendering" %>
<%@ page import="static com.atlassian.jira.component.ComponentAccessor.*" %>
<%
//
// IDEA gives you a warning below because it cant resolve JspWriter. I don't know why but its harmless
//
getComponent(HeaderFooterRendering.class).includeFooters(out, request);
%>
<jsp:include page="/includes/decorators/global-translations.jsp" />
<jsp:include page="/includes/decorators/aui-layout/test.jsp" />

functionality works for members and non-members of specified group.

Olny problem is that this Activity tab is still shown when I click one of shown tabs (All\Comment\Work log)

Robert

can you share source of the view screen of your issue?

You mean source code of page displayed with issue and activity tab?

I think I can't upload zip files.

In attachment 2 screen shots:

1 - after load of issue page

2 - after click on Comment tab

Robert

Thanks for Your support.

It works!!

Robert

glad to hear it worked!!

Cheers!!

@Rambanam Prasad could you please share / inform how guys solve the issue mentioned above? I'm having the same problem. It means, after click in a tab, my desired previous hided tab show up again :-/ I coded exactly what you mentioned in your last posted code (above), but with no success regarding to tab click. In my particular case, I'd like to hide tabs: *worklog and history*. Could you help me please? Thanks in advance. Michel

Hi Michel @Michel Barros , I am facing a similar problem, Can you please let me know if you were able to resolve it ? Thanks, Ranjith

Hi @Ranjith Rajan, Unfortunately, not. We still facing the same problem. If you have any ideas, please share with me. Thanks! Michel Barros

Hi Michel, @Michel Barros Yes i figured out. Place the below code in the any of the plugin.xml available. In my case i pasted under atlassian-plugins-websource-plugin-mock.xml. Assuming that you already have a javascript to hide the tabs. Place the javascript in the location mention in the web-resource below. Let me know if you need any help with the javascript. Regards, Ranjith web-resource key="test-js" name="javascript"> <dependency>jira.webresources:global-static</dependency> <description>JavaScript</description> <resource name="hidefields.js" location="includes/js/hidefields.js" type="download"/> <context>atl.general</context> <context>atl.admin</context> </web-resource>

Hi @ranjith.rajan, Thanks for sharing it. I will try it, as soon as I reconfigure my own environment around here. Best Regards! Michel Barros

Hi All,

So as per above comments, Only problem is that this Activity tab is still shown when I click one of shown tabs (All\Comment\Work log) so any idea how to hide remaining tan on click event as well ?

Thanks,

Hardik

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,417 views 15 19
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