...
Code Block | ||
---|---|---|
| ||
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.util.UserManager
//the project role
final String PROJECT_OWNER = "Project Owner";
//the project
final String PROJECT_NAME = "TnT Jira Support Services";
//setting flags
final boolean NOTES_VISIBLE = true;
final boolean NOTES_NOT_VISIBLE = false;
//custom field name
final String NOTES = "Notes";
//to get the current logged in user
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
//get projectManager class
def projectManagerClass = ComponentAccessor.projectManager;
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager);
//get project role object
ProjectRole newRole = projectRoleManager.getProjectRole(PROJECT_OWNER);
//get project object
def project = projectManagerClass.getProjectObjByName(PROJECT_NAME);
//get the custom field
def notesField = getFieldByName(NOTES);
//check if the logged in user belongs to a role in a project, returns boolean
def projectRoles = projectRoleManager.isUserInProjectRole(loggedInUser, newRole, project);
//conditions to hide and show custom field based on project role
if(projectRoles.equals(NOTES_VISIBLE)) {
notesField.setHidden(NOTES_NOT_VISIBLE);
} else {
notesField.setHidden(NOTES_VISIBLE);
}
|
...