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

Robert Marczak July 17, 2013

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.

15 answers

1 accepted

1 vote
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.
July 18, 2013

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!!

1 vote
DILEEP KUMAR June 6, 2018

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.

0 votes
Nishant Paraskar November 24, 2021

Is there specific page where i can apply Css or java scrip to hide the "Activity"  tab as i already hide the 1. All 2. Work log 3. HistoryTest issue.png

0 votes
Hardik Parekh September 9, 2015

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

0 votes
Robert Marczak July 18, 2013

Thanks for Your support.

It works!!

Robert

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.
July 18, 2013

glad to hear it worked!!

Cheers!!

Michel Barros September 17, 2014

@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

Ranjith Rajan August 5, 2015

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

Michel Barros August 5, 2015

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

Ranjith August 5, 2015

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>

Michel Barros August 6, 2015

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

0 votes
Robert Marczak July 18, 2013

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

0 votes
Robert Marczak July 18, 2013

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

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.
July 18, 2013

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

0 votes
Robert Marczak July 18, 2013

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

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.
July 18, 2013

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

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.
July 18, 2013

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;

Klaas Van Ammel May 7, 2015

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.

0 votes
Robert Marczak July 18, 2013

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

Nishant Paraskar November 24, 2021

Is there specific page where i can apply Css or java scrip to hide the "Activity"  tab as i already hide the 1. All 2. Work log 3. History

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.
July 18, 2013

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;

0 votes
Robert Marczak July 18, 2013

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

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.
July 17, 2013
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!
});


0 votes
Robert Marczak July 17, 2013

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
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.
July 17, 2013
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

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.
July 17, 2013

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;      
    });

Suggest an answer

Log in or Sign up to answer