Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
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!"
  }
}

Don't Allow Worklog Without Comment Except for Defined Projects

Code Block
import com.deniz.jira.worklog.*;
def worklogComment = worklog.comment;
def issue = worklog.getIssue();
def workloggedProject = issue.getProject().key.toString();
def exemptProjects= ["ATP", "SP"];

if(!exemptProjects.contains(workloggedProject) && !worklogComment){
    return "Comment is required.";
}