atlascommunity / jira-plugins-groovy

Jira Groovy plugin
https://atlasteam.ru
BSD 2-Clause "Simplified" License
66 stars 42 forks source link

Permission issue during workflow Fast Transitions #117

Closed joojoomen closed 2 years ago

joojoomen commented 3 years ago

Hey there.

We have implemented a scheduled task to transition some task into a close state for some conditions using the fast transition example from the global object class. The transition works but we have two problems:

  1. The transition works only if the job is running as user with jira admin permission. Also if the user who should to this is permitted and can make the transition using the GUI.

  2. We want to log the affected task. But if some task was transitioned no log will be there. Find the code below

    
    import  com.atlassian.jira.issue.*
    import com.atlassian.jira.user.ApplicationUser
    import groovy.sql.GroovyRowResult
    import org.codehaus.groovy.runtime.StackTraceUtils 
    import com.atlassian.jira.component.ComponentAccessor
    Date today=new Date()
    Date lastdate

if(DateFunc.isWorkingDay(today)==false){ return true }

log.info("Start Cancle Implementation.") def sqlstr=new File("FilePath") if(sqlstr==null){ log.info("Unable to load sql filel") return false; } HashMap map

ApplicationUser pima = Base.getUser('jiraadmin') String query=sqlstr.getText('UTF-8') String countertemplquery="SELECT COUNT(id) AS counter,MAX (date_create) AS lastnotification FROM customer_issue_notifications WHERE issue='%ISSUE%' AND notification_type='close_umsetzungsauftrag'" String counterquery List result=Base.select('jiraDB',query) if(result.size()==0){ log.info("Nothing to do") return true; }

Issue issue MutableIssue parentIssue ApplicationUser assignee

String key

GroovyRowResult sendDone Long count Integer actionId = 41 // The transition ID

try{ result.each{item ->

key=item['issue'].toString() issue=Base.getIssue(key) parentIssue=issue.getParentObject() as MutableIssue counterquery=countertemplquery.replaceAll("%ISSUE%",key) sendDone=Base.SqlGetRow("serviceDB",counterquery)
lastdate = Date.parse("yyyy-MM-dd hh:mm:ss", sendDone.lastnotification.toString())
count=sendDone.counter as Long if(count==4){

   if(DateFunc.daysBetween(lastdate,today)>=7){

     try{
         Base.doTransition(parentIssue,actionId)
         Base.reIndex(parentIssue)
         Base.createComment((Issue)parentIssue,pima,'SW-Deployment wurde nach Ablauf der Frist automatisch storniert.',true)
        log.info("Cancle Task "+parentIssue.key)
     }catch(RuntimeException rex) {
        log.info(rex.toString()+"=>"+rex.stackTrace.head().lineNumber)
     }
     catch(Exception ex) {
        log.info(ex.toString()+"=>"+ex.stackTrace.head().lineNumber)
     }         
  }
}

}

}catch(Exception ex) { log.error(ex.toString()+"=>"+ex.stackTrace.head().lineNumber) return false }

log.info("Done Cancle Implementation") return true



Would be nice if we can find a solution

Regards
Hannes