Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto Close Subtasks reqires 'assign issue' permission

Peter Müller October 25, 2016

Hi,

i'm using ScriptRunner 4.3.12 and JIRA 7.1.9.

I'm trying to close all subtasks of an issue by using a custom "Post Function" Script in the parent's workflow transition.

There are two Workflow, one for the "Parent" an one for the "Subtasks".

The script looks as follows:

import com.atlassian.jira.component.ComponentAccessor
def transitionId = 81 // abnehmen
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
issue.subTaskObjects.each {
    def issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.with {
    	setResolutionId("10000") // resolution of "Fertig"
		setComment("*Abnahme* durch erfolgreiche Abnahme des Oberauftrags.")
		setSkipScreenCheck(true)
	}
    
    def validationResult = issueService.validateTransition(user, it.id, transitionId, issueInputParameters)
	if (validationResult.isValid()) {
    	def issueResult = issueService.transition(user, validationResult)
        if (! issueResult.isValid()) {
        	log.warn("Failed to transition subtask ${it.key}, errors: ${issueResult.errorCollection}")
        }
    } else {
		log.warn("Could not transition subtask ${it.key}, errors: ${validationResult.errorCollection}")
    }
}

The transition in the subtask workflow is "abnehmen" with id 81. And the "Post Function" are

 

  1. Lösung des Vorgangs wird auf Fertig gesetzt.
    (Set the Resolution to "Fertig")
  2. Setzt den Vorgangsstatus auf den verknüpften Status des Zielarbeitsablaufschritts.
    (Set the Status of the issue to the Status of the transitions target)
  3. Fügt dem Vorgang einen Kommentar hinzu, wenn beim Übergang ein Kommentar eingegeben wird.
    (Add a comment if available)
  4. Aktualisiert die Änderungshistorie eines Vorgangs und speichert den Vorgang in der Datenbank.
    (Update the issues history and save the issue in the database)
  5. Indiziert einen Vorgang neu, um die Indizes mit der Datenbank zu synchronisieren.
    (index the issue to synchronize the indices with the database)
  6. Startet ein Ereignis Allgemeines Ereignis, das von Listenern bearbeitet werden kann.
    (Start a general event that can be processed by listerners)

(Since our JIRA is set to German, I've added some loosely translations)

When the script get's triggered by the parent workflow's transition, the script itself run's without an error.
But the conditon to validate the "validationResult" fails, because of the following error:

2016-10-25 12:23:48,585 WARN [workflow.ScriptWorkflowFunction]: Could not transition subtask AES-174, errors: Errors: {}
Error Messages: [Sie sind nicht berechtigt, Vorgänge zuzuweisen.]

(engl. "You're not allowed to assign issues")

And well, that's right. The user has no permission to assign an issue. But I don't understand why this should be required?

I don't want to give him this permission.

All i try to do is "programatically" invoke the "abnehmen" transition of each subtask - which works perfectly fine if the user clicks manually on this button.

 

Whats wrong there?

 

Best regards

Peter

 

7 answers

0 votes
Peter Müller November 1, 2016

I think there are three security context to investigate:

  1. User who invokes the script by clicking the transition "Abnahme erteilen" at the Issue level
  2. User who is used inside the script (In my case: ComponentAccessor.jiraAuthenticationContext.loggedInUser)
  3. And the User who triggers the transition of the subtask manually.

In my test screnario all three users should be the same: I log in as "AE-Führungskraft-1", click on the "Abnahme erteilen" Action, the scripts loads the current logged in user and performs the transition with this user. -> Should be the same.

As it's not working per script, i later try to perform the transition at the subtask manually with the same logged in user. -> Should also be the same.
0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2016

As you can do it manually, but not via script, it implies that the script is running with different permissions than you have in the UI.  Is it the same user?

0 votes
Peter Müller October 31, 2016

I've added the "setRetainExistingValuesWhenParameterNotProvided(true)" and another log output message (log.warn("Try to transition $it.key ($it.id)")) just to verify the Issue key and ID.

The error message is still the same :-/

2016-10-31 17:12:24,080 WARN [workflow.ScriptWorkflowFunction]: Try to transition AES-227 (13632)
2016-10-31 17:12:24,127 WARN [workflow.ScriptWorkflowFunction]: Could not transition subtask AES-227, errors: Errors: {}
Error Messages: [Sie sind nicht berechtigt, Vorgänge zuzuweisen.]
2016-10-31 17:12:24,127 WARN [workflow.ScriptWorkflowFunction]: Try to transition AES-228 (13633)
2016-10-31 17:12:24,158 WARN [workflow.ScriptWorkflowFunction]: Could not transition subtask AES-228, errors: Errors: {}
Error Messages: [Sie sind nicht berechtigt, Vorgänge zuzuweisen.]

Translation: "Sie sind nicht berechtigt, Vorgänge zuzuweisen."
>> "You're not allowed to assign issues"

Also, i've tried to invoke the transition on the AES-227 Issue (first Subtask) manually, which works perfectly.

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2016

Could you replace the issueInputParameters with:

issueInputParameters.with {
        setResolutionId("10000") // resolution of "Fertig"
        setComment("*Abnahme* durch erfolgreiche Abnahme des Oberauftrags.")
        setSkipScreenCheck(true)
		setRetainExistingValuesWhenParameterNotProvided(true)
    }
0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2016

I'd want to check the validators and conditions on the transitions as well.  Do they block assignment?

Peter Müller October 25, 2016

There are the following conditions (OR'd)

  • Nur Benutzer welche zu folgenden Rollen gehören können diesen übergang ausführen: Führungskraft AE
    (Only user with the following Role can perform this transition: "Führungskraft AE")

  • Aktueller Benutzer muss im Feld Abnahme sein.
    (Current User must be in custom Field "Abnahme") 

and one validator:

  • Simple Script Validator

    issue.parentObject.status.name == 'Abgenommen'

the following post function (as mentioned above)

  1. Lösung des Vorgangs wird auf Fertig gesetzt.
    (Set the Resolution to "Fertig")
  2. Setzt den Vorgangsstatus auf den verknüpften Status des Zielarbeitsablaufschritts.
    (Set the Status of the issue to the Status of the transitions target)
  3. Fügt dem Vorgang einen Kommentar hinzu, wenn beim Übergang ein Kommentar eingegeben wird.
    (Add a comment if available)
  4. Aktualisiert die Änderungshistorie eines Vorgangs und speichert den Vorgang in der Datenbank.
    (Update the issues history and save the issue in the database)
  5. Indiziert einen Vorgang neu, um die Indizes mit der Datenbank zu synchronisieren.
    (index the issue to synchronize the indices with the database)
  6. Startet ein Ereignis Allgemeines Ereignis, das von Listenern bearbeitet werden kann.
    (Start a general event that can be processed by listerners)

no trigger.

 

The user who triggers the transition has the role "Führungskraft AE".

 

Is there maybe a problem caused by the different workflows for the Task and Subtask?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2016

Is that the validators and conditions for the sub-task workflow?

 

Peter Müller October 25, 2016

Yes, its for the transition 81 named "abnehmen" of the sub-task workflow.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2016

Ok, that's good information.  The next question is can the user executing the post-function assign the sub-tasks when they look at them in the UI?  And can they perform the transition manually?

Peter Müller October 26, 2016

Sure, manually it's working without any problems.

0 votes
Peter Müller October 25, 2016

Double checked the post functions. There is nothing that changes the assingee, just the six steps already mentioned above.

In case there were such a "post function", the manual way should also not work, should it?

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2016

Try to investigate transition wuth id = 81 for any postfunction which change assignee.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events