-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasProjectRoleCondition.java
38 lines (30 loc) · 1.23 KB
/
HasProjectRoleCondition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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<String, String> 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);
}
}