Enable the link in JIRA based on project role

Tarun Arora April 9, 2014

I have made a new jira plugin which has some links enabled based on the following condition specified in atlassian-plugin.xml

<conditionclass="com.atlassian.jira.plugin.webfragment.conditions.JiraGlobalPermissionCondition">

<paramname="permission"><u>admin</u></param>

</condition>

But the problem here is that all the project leads need to be provided with the Admin access in JIRA.

Is there a way where i can modify the above condition and use the project role instead.

Currently following project roles are defined in projectrole table.

10000 Users A project role that represents users in a project
10001 Developers A project role that represents developers in a project
10002 Administrators A project role that represents administrators in a project
10100 leads One who has previlege to create,modify and delete
10200 RCCL Scrum Master RCCL Scrum Master
10300 Eventing Shift Leads Eventing team resource who come in shifts and support, attend incidents, etc

how can i use this information and enable the link only for role 10100 i.e leads.

regards

Tarun Arora

1 answer

1 vote
Boris Georgiev _Appfire_
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.
April 9, 2014

How about com.atlassian.jira.plugin.webfragment.conditions.HasProjectPermissionCondition ? It allows testing the current user for specific project permission

Here's a sample :

&lt;condition class="com.atlassian.jira.plugin.webfragment.conditions.HasSelectedProjectCondition" /&gt;
        &lt;conditions type="OR"&gt;
            &lt;condition class="com.atlassian.jira.plugin.webfragment.conditions.HasProjectPermissionCondition"&gt;
                &lt;param name="permission"&gt;project&lt;/param&gt;
            &lt;/condition&gt;

        &lt;/conditions&gt;

Tarun Arora April 10, 2014

This will not be feasible solution in my case.

It is something like this.

There are 4 links for my plugin. Only one of those 4 links is enabled for the developers and the other 3 should be enabled only for the leads and the administrator.

using the solution mentioned above,it will enable all the 4 links for developers,leads and administrator.

Need a solution to clearly distinguish between a developer and a lead.

Regards

Tarun

Boris Georgiev _Appfire_
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.
April 10, 2014

The solution I offered may be used if the roles can be distinguished by permissions but that's not ideal solution if the permissions change over time. So the best will be if you implement you own condition that checks the role of a user which should be pretty straightforward

Tarun Arora April 10, 2014

<condition class="class name">

<param name="role">lead</param>
</condition>
Can we have a solution something like the above where class name has a attribute role which maps to the role in the projectrole table.
Or if there is no direct class available in Jira for the same,can u give me an example(sample code) of how to write my own custom condition to find the role of the logged in user and enable /disable the link based on his role.
regards
Tarun
Boris Georgiev _Appfire_
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.
April 10, 2014

Here's a sample (not tested though):

package com.myplugin.conditions;

import java.util.Map;

import com.atlassian.jira.plugin.webfragment.conditions.AbstractWebCondition;
import com.atlassian.jira.plugin.webfragment.model.JiraHelper;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.plugin.PluginParseException;

public class HasProjectRoleCondition extends AbstractWebCondition {

	private ProjectRoleManager roleManager;
	private ProjectRole projectRole;

	public HasProjectRoleCondition(ProjectRoleManager roleManager) {
		this.roleManager = roleManager;
	}

	@Override
	public void init(Map&lt;String, String&gt; params) throws PluginParseException {
		String roleName = params.get("role");
		projectRole = roleManager.getProjectRole(roleName);
		if (projectRole == null) {
			throw new PluginParseException("Could not determine role for: " + params.get("role"));
		}
		super.init(params);
	}

	@Override
	public boolean shouldDisplay(ApplicationUser user, JiraHelper jiraHelper) {
		final Project project = jiraHelper.getProjectObject();
		return roleManager.isUserInProjectRole(user, projectRole, project);
	}

}

and then in the atlassian-plugin.xml

&lt;condition class="com.atlassian.jira.plugin.webfragment.conditions.HasSelectedProjectCondition" /&gt;
       &lt;conditions type="OR"&gt;
           &lt;condition class="com.myplugin.conditions.HasProjectRoleCondition"&gt;
               &lt;param name="role"&gt;leads&lt;/param&gt;
           &lt;/condition&gt;
 
       &lt;/conditions&gt;

Suggest an answer

Log in or Sign up to answer