Jira Transition Permissions
MediumState Machine · Atlassian
You are implementing the permission check behind a Jira-style workflow.
Issues. Each entry of issues is [issue_id, status, assignee, reporter], giving the issue's starting status and the user names of its assignee and reporter.
Rules. Each entry of rules is [from_status, to_status, required_role] and allows an issue to move from from_status to to_status for any user who satisfies required_role:
"any": every user satisfies it."assignee": only the user whose name equals the issue's assignee."reporter": only the user whose name equals the issue's reporter.- Any other string (for example
"admin"): a user satisfies it if that string appears in the request'suser_roleslist.
Requests. Process requests in order. Each is [issue_id, user, to_status, user_roles]: user user, who holds the roles in user_roles, asks to move the issue to to_status. The request succeeds if and only if:
- the issue exists, and
- at least one rule has
from_statusequal to the issue's current status,to_statusequal to the requested status, and arequired_rolethe user satisfies.
A successful request changes the issue's status immediately, so it affects later requests. A failed request changes nothing.
Return a list with one boolean per request, True if it succeeded and False otherwise.
Notes:
- All comparisons are exact and case-sensitive.
- Several rules may cover the same
from_status/to_statuspair; satisfying any one of them is enough. - There is no implicit "stay in the same status" transition: moving to the current status needs a rule whose
from_statusandto_statusare equal.
Example 1
- Input:
- issues = [["PROJ-1", "To Do", "alice", "bob"]], rules = [["To Do", "In Progress", "assignee"], ["In Progress", "Done", "reporter"], ["In Progress", "Done", "admin"]], requests = [["PROJ-1", "carol", "In Progress", []], ["PROJ-1", "alice", "In Progress", []], ["PROJ-1", "alice", "Done", []], ["PROJ-1", "dave", "Done", ["admin"]]]
- Output:
- [False, True, False, True]
- Explanation
- Carol is not the assignee, so the first request fails. Alice is, so the issue moves to In Progress. Alice is neither the reporter nor an admin, so her Done request fails, but Dave holds the
adminrole, which satisfies the second Done rule.
Example 2
- Input:
- issues = [["A-7", "Open", "sam", "kim"]], rules = [["Open", "Closed", "any"]], requests = [["A-7", "lee", "Closed", []], ["A-7", "lee", "Closed", []], ["B-1", "lee", "Closed", []]]
- Output:
- [True, False, False]
- Explanation
- The first request succeeds because anyone may close an open issue. The second fails because the issue is now Closed and no rule starts from Closed.
B-1does not exist, so that request fails too.
Constraints
0 <= issues.length, rules.length, requests.length <= 10^5- Issue ids in
issuesare unique; a request may name an issue id that does not exist. 0 <= user_roles.length <= 10for each request- Statuses, user names and roles are non-empty strings.