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

How can i control web item condition ?

sooji na July 27, 2014

I add Additional menu ( in picture)

I want to add condition.

For Example

There are 2 Groups in jira User Management.

One is A Group, the others is B Group.

A group can see Additional menu.

And B group don't see Extra Additional menu.

How can I control condition?

This is XML code written by me.

<web-item key="effort_input" name="Effort Input" section="system.user.options/system" i18n-name-key="webfragments.user.options.item.effort.input" weight="50">

<label key="Effort Input" />

<tooltip key="tooltip.Effort Input" />

<link linkId="KPI_Dashboard">/kpi/jsp/effort/effortList.jsp</link>

<condition class="com.atlassian.jira.plugin.webfragment.conditions.UserLoggedInCondition" />

</web-item>

I add web-item.

but Can I Where to control ?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
rambabu patina
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 27, 2014

Sooji, You need to write another condition in your <web-item> module. And in that condition class you have to restrict for the group whom you dont want to show.

For example: If th group name is 'Effort Group' then

In atlassina-plugin.xml:

<condition class="packagename.classname">

<param name="group">Effort Group</param></condition>

And in java:

public class @classname@ extends AbstractJiraCondition{

private String group;

@Override

public void init(Map params) throws PluginParseException {

this.group=(String)params.get("group");

super.init(params);

}

//If the user is not in 'Effort Group', it returns false

@Override

public boolean shouldDisplay(User user, JiraHelper arg1) {

if(user!=null && this.group!=null){

return user.inGroup(this.group);

}

return false;

}

}

Hope this helps you,
Thanks.
sooji na July 29, 2014

Hi rambabu patina ·

I want to know where to add source that you told me.

I confused which source do I modify

"atlassina-plugin.xml" is "system-user-nav-bar-sections.xml" ?

What you said is this?

but I don't know where is java file

Please tell me the location of files.


Thank you

rambabu patina
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 29, 2014

Hi Sooji, The atlassian-plugin.xml file will be available in the location <your plugin source>\src\main\resources. And for the java file you can create new file in your <your plugin source>\src\main\java. While creation you need to define the package name for that class then you can use the class name with this package in atlassin-plugin.xml.

And "atlassina-plugin.xml" and "system-user-nav-bar-sections.xml" are different files.

Thanks.

sooji na July 29, 2014

Thank tou for your support.

I found xml file and I create new java file.

but I don't compile new java file.

0 votes
Alexander Franke July 7, 2016

I had a very similar problem but with confluence. Just wanted to share my solution.

Starting with the code from rambabu patina and updating to non-deprecated classes I got:

package %package name%;
import java.util.Map;
import com.atlassian.confluence.plugin.descriptor.web.WebInterfaceContext;
import com.atlassian.confluence.plugin.descriptor.web.conditions.BaseConfluenceCondition;
import com.atlassian.plugin.PluginParseException;
import com.atlassian.sal.api.user.UserManager;

public class userHasGroup extends BaseConfluenceCondition{
private String group;
private UserManager userManager;

public userHasGroup(UserManager userManager){
this.userManager = userManager;
}

@Override
public void init(Map params) throws PluginParseException {
this.group=(String)params.get("group");
super.init(params);
}
@Override
public boolean shouldDisplay(WebInterfaceContext context) {
if(userManager.getRemoteUserKey()!=null &amp;&amp; this.group!=null){
return userManager.isUserInGroup(userManager.getRemoteUserKey(), this.group);
}
return false;
}
}

My atlassian-plugin.xml looks similar to this (just adding web resources like css or js files)

&lt;web-resource key="forwarder-resources" name="forwarder-resources Resources"&gt;
      &lt;dependency&gt;com.atlassian.auiplugin:ajs&lt;/dependency&gt;
      &lt;resource type="download" name="improvedsearch.js" location="improvedsearch.js"/&gt;
      &lt;resource type="download" name="skel.js" location="/assets/js/skel.min.js"/&gt;
      &lt;resource type="download" name="util.js" location="/assets/js/util.js"/&gt;
      &lt;resource type="download" name="main.js" location="/assets/js/main.js"/&gt;
      &lt;resource type="download" name="main.css" location="/assets/css/main.css"/&gt;
  &lt;!-- add group condition --&gt;
      &lt;condition class="%package name%.userHasGroup"&gt;
       &lt;param name="group"&gt;%%%the groupname a user has to hve%%%&lt;/param&gt;
      &lt;/condition&gt;
 
      &lt;context&gt;atl.general&lt;/context&gt;
  &lt;/web-resource&gt;
0 votes
sooji na August 3, 2014

end

TAGS
AUG Leaders

Atlassian Community Events