I am writing a xwork plugin module where I need to check if the current user has a admin permissions for a specific project. How can I do this?
Community moderators have prevented the ability to post new answers.
David's answer on this page describes how to find the "Administrators" role (read more about Project Roles). Project roles are configurable, and not all Projects will have a role named "Administrators".
You are probably referring to the "Administer Projects" permission (read more about Project Permissions). This permission controls who can administer a given project, and may be configured to consider the "Administrators" project role, but also may be assigned to other groups or users or roles.
You can check this permission using the PermissionManager.
User user = ...;
Project project = ...;
PermissionManager permissionManager = ComponentAccessor.getComponent(PermissionManager.class);
permissionManager.hasPermission(Permissions.PROJECT_ADMIN, project, user);
Thanks Matt! Exactly what I needed. Saved me an afternoon. Cheers, nick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In code you can do this using:
JiraAuthenticationContext jiraAuthenticationContext = ComponentManager.getComponentInstanceOfType(JiraAuthenticationContext.class);
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class);
User user = jiraAuthenticationContext.getUser();
ProjectRole administratorProjectRole = projectRoleManager.getProjectRole("Administrators");
projectRoleManager.isUserInProjectRole(user, administratorProjectRole, project);
The APIs are available here:
http://docs.atlassian.com/jira/4.3.3/index.html (see ProjectRoleManager)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.