import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.deniz.jira.worklog.services.attr.AttrTypeService;
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class);
//We need to load WorklogPRO classes differently using getOSGiComponentInstanceOfType
def attrTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(AttrTypeService.class);
def billableAttrType = attrTypeService.getAttrTypeWithName("Billable").get();
if (billableAttrType == null) {
return; //there is no billable attribute
}
def isBillable = worklogAttributes.get(billableAttrType.getID());
def loggedInUser = authenticationContext.getLoggedInUser();
def serviceDeskTeamRole = projectRoleManager.getProjectRole("Service Desk Team");
def project = worklog.getIssue().getProjectObject();
println(worklogAttributes);
if (isBillable == "yes") { //boolean attributes are has either "no" or "yes" value.
if (!projectRoleManager.isUserInProjectRole(loggedInUser, serviceDeskTeamRole, project)) {
return "Only Service Desk Team can register billable worklogs!"
}
} |