Versions Compared

Key

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

...

Don’t Allow Non Service Desk Users to Create Worklogs

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!"
  } }

Worklogs with an Invoice Number can't be Deleted!

Code Block
import com.atlassian.jira.component.ComponentAccessor;
import com.deniz.jira.worklog.services.attr.AttrTypeService;
 
//We need to load WorklogPRO classes differently using getOSGiComponentInstanceOfType
def attrTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(AttrTypeService.class);
 
def invoiceNumberAttrType = attrTypeService.getAttrTypeWithName("Invoice Number").get();
if (invoiceNumberAttrType == null) {
  return; //there is no "invoice number" attribute
}
 
def invoiceNumber = worklogAttributes.get(invoiceNumberAttrType.getID());
 
if (invoiceNumber != null) {
  return "Worklogs with an invoice number can't be deleted!"
}