API: List Available Statuses By Issue and User
In Redmine, let's say you have two users, Al and Beau, and they're working on issue #42. Issue #42 is in status "Pending". Al has a role of Peon, so when he goes into Redmine, all he can do is change the status from "Pending" to "Grovel". Beau, having the role of Overlord can change from "Pending" to "Approve" or "Deny". Charles, being the ubermensch, has Beau's rights, but he can also change the status to "Flay" Peons.
Al -> Grovel
Beau -> Approve Deny
Charles -> Approve Deny Flay
I looked into this a year ago and couldn't find an API that would allow me to request statuses like this. (To the point where I've used custom project fields to store workflow, which my program parses.) I still don't see it, but maybe I'm just missing it. I could use:
Just to get the workflow. Or ideally:
I could even work with just:
Returning all the workflows. But I'm not seeing any way to extract this info.
Thanks for any thoughts on the topic.
I find your question confusing so I won't be able to answer it fully. Are you just looking to use the API to discover what status an issue is currently in and what status a user can move to?
Issue.find(#).status_id will show you the current status
If this is on the right path for what you need, please explain more where you get stuck using the api.
Are you just looking to use the API to discover what status an issue is currently in
No, that's not a problem.
and what status a user can move to?
Yes. "Given a user and an issue, what status can the user change that issue to?" This maps directly Redmine's Status drop-down for any given issue:
Looks like there is an instance method for the issue that allows this:
So, if you are using a hook you will get the issue in the context hash so do this:
i = context[:issue]
If extending the issue object, replace i with self.
I just tested this in the debugger and it works:
=> [#<IssueStatus id: 1, name: "New", is_closed: false, position: 1, default_done_ratio: nil>, #<IssueStatus id: 2, name: "In Progress", is_closed: false, position: 2, default_done_ratio: nil>, #<IssueStatus id: 3, name: "Resolved", is_closed: false, position: 3, default_done_ratio: nil>, #<IssueStatus id: 4, name: "Feedback", is_closed: false, position: 4, default_done_ratio: nil>, #<IssueStatus id: 5, name: "Closed", is_closed: true, position: 5, default_done_ratio: nil>, #<IssueStatus id: 6, name: "Rejected", is_closed: true, position: 6, default_done_ratio: nil>]
Yeah, but it's not exposed in the API, AFAIK. Maybe I'll ad it as [issue-id]/new_statuses_allowed_to/[user-id]. Just means I gotta patch the code whenever I upgrade.
What do you mean it isn't exposed in the API? That is the API call I was using.
Are you saying you want to make the web front end be able to change what status are available based on the user? If this is what you want, it is doable (assuming you are using the latest redmine).
Create 3 roles for the levels of permissions you want and add the users to the correct role. Then in
use those roles to define the status transition workflow for each role.
If this still isn't what you are looking for, I need a better description before I can help any further.
Oh, I'm sorry, I don't think of the code as "the API". I meant "the REST API".
That's why I've been using this web-notation, like "42.json?workflow". I'm coming at this from outside.
I apologize for the confusion. I know the code feature exists; it's just not exposed via the REST service.
I have the same problem. It does not seem to be possible to write a sensible rest-based gui without this feature