[PATCH] Allow for arbitrary predicates in transitions' :available_to
Reported by Diego E. "Flameeyes" Pettenò | April 29th, 2010 @ 12:16 PM | in Hobo 1.1
Currently the :available_to predicate is checked against classes, arrays or direct confrontation, but there is no support for arbitrary predicates that return true/false results.
The patch at http://github.com/Flameeyes/hobo makes it possible to write an arbitrary predicate such as
:available_to => "acting_user.karma > 40"
to allow transitions.
HTH,
Diego
Comments and changes to this ticket
-
Bryan Larsen April 29th, 2010 @ 03:27 PM
- Milestone set to Hobo 1.1
- Tag set to enhancement, lifecycles
I like it. Matt or Tom, do you have comments?
It will trip a few people up since at some point somebody will try to return something that is true rather than
true
itself, but I think we should address that via careful documentation. -
Diego E. "Flameeyes" Pettenò April 29th, 2010 @ 03:31 PM
Well, as it is it checks for just true/false so for instance “:assigned_to => acting_user.karma” will not trigger it (one should write an explicit “:assigned_to => acting_user.karma != 0” to have that effect), so it shouldn't be that much of a problem, or am I misunderstanding what you said?
-
Bryan Larsen April 29th, 2010 @ 03:40 PM
Yes, that's the "problem" with your patch. Somebody's going to try and write “:available_to => acting_user.karma”. There are two options to fix this:
-
carefully write the documentation pointing out the problem and saying "don't do that"
-
add an ":available_if" option rather than overloading ":available_to".
I'm starting to lean towards the latter.
-
-
Bryan Larsen April 29th, 2010 @ 04:32 PM
I was assuming that :if and :unless would not affect "publishable_transitions_for" (aka the transition-buttons tag). But looking through the code, it appears that it does.
I seem to remember a case where I had to use some sort of wierd "condition ? User : nil" clause in an :available_to, but I can't remember why or where. Diego?
-
Matt Jones April 29th, 2010 @ 04:44 PM
The more I stare at it, the more I'm not sure what the checking in publishable_transitions_for (in lifecycle.rb, line 163ish) is for - doesn't the can_run? filter in available_transitions_for include that condition?
To answer Tom's original question: I can't see a use case for this vs. a standard :if option.
-
Diego E. "Flameeyes" Pettenò April 29th, 2010 @ 09:22 PM
The reason why I rejected using :if at first was that it didn't create the taglibs in that case, it seems like the syntax I should use then is “:available_to => all, :if => "conditions"” rather than just :if…
-
Tom Locke April 30th, 2010 @ 11:27 AM
- State changed from new to wontfix
Diego, that's correct. A transition or create without and :available_to is considered an internal transition that you can invoke from your own code, but is not published via a controller. Thanks for you input anyway.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »