The patch is attached, done against 6.x-1.3.
The normal behavior of workflow is not changed. As long as you dont have any modules implementing this, workflow does the same.
One minor downside is, that you have to give at least a role the right to do a specific transition,as otherwise the transition_table wont get an entry for this transition. You can later anyway e.g. revoke that right with your hook anyway.
Documentation
hook_workflow_transition_allowed($tid)
You have to return a string, which will be the callback method to execute. You can use the $tid to decide, whether you want to define an callback for this transition or not.
Example:
/*
* Implementation of hook_workflow_transition_allowed
*/
function workflow_workflow_transition_allowed($tid) {
return '_workflow_transition_allowed_access';
}
Callback for transistion access
Every callback defined by the hook_workflow_transition_allowed hooks are exectuted, there results are merged using AND.
Every callback has to return a boolean.
Example
function _workflow_transition_allowed_access($tid, $role, $user, $node) {
$allowed = db_result(db_query("SELECT roles FROM {workflow_transitions} WHERE tid = %d", $tid));
$allowed = explode(',', $allowed);
if ($role) {
if (!is_array($role)) {
$role = array($role);
}
return array_intersect($role, $allowed) == TRUE;
}
// else as no roles, use cant have access
return FALSE;
}
------
Usecases
Well in my case, i use this extendable api to check for a userrefrence field in the node. According to that selected user, i grant or not grant the right to make the current transition. This way e.g. you can let the right to be able to change a state make relative to a user selected in the workflow before ( in a user reference field e.g. or where yuo like..its PHP :) )
Comment | File | Size | Author |
---|---|---|---|
#5 | workflow.api_.php_.txt | 404 bytes | dawehner |
#3 | workflow_rights_api.patch | 3.04 KB | EugenMayer |
workflow_rights_api.patch | 3.09 KB | EugenMayer | |
Comments
Comment #1
EugenMayer CreditAttribution: EugenMayer commentedCorrecting title
Comment #2
dawehnerCodestyle: if ( , foreach ( , two many spaces in $result
codestyle: FALSE
node parameter is required, but some before not. This makes no sense.
The rest looks fine.
Comment #3
EugenMayer CreditAttribution: EugenMayer commentedOptimzing code (thanks to dereine and stbochert), documentation changes:
Documentation
hook_workflow_transition_allowed($tid)
You have to return a boolean, whether to allow or not allow this transition. The results of all hooks are AND`ed together
Example:
/*<br> * Implementation of hook_workflow_transition_allowed<br> */<br>function workflow_workflow_transition_allowed($tid) {<br> return '_workflow_transition_allowed_access';<br>}
Callback for transistion access
Comment #4
dawehneradd a space after each parameter
codestyle is still there
and here too
nitpicking: don't use two * * in a row
Powered by Dreditor.
Comment #5
dawehnerThis is a initial workflow.api.php
Comment #6
EugenMayer CreditAttribution: EugenMayer commentedDereine you used the old API, please have a look at the documentation. This is the current documentatin (wrong example in #3)
Documentation
hook_workflow_transition_allowed($tid)
You have to return a boolean, whether to allow or not allow this transition. The results of all hooks are AND`ed together
Example:
Comment #7
EugenMayer CreditAttribution: EugenMayer commentedComment #8
jvandyk CreditAttribution: jvandyk commentedPlease help me understand how this is different from the current case, where a module responds to the 'transition pre' op of the workflow hook with FALSE if it wants to veto the transition (see workflow_execute_transition()).
Comment #9
iris_passcal CreditAttribution: iris_passcal commentedIf I'm reading this correctly, I had written something similar for our institution's website that I was thinking of submitting as a patch, too.
The difference between this and the "transition pre" is that workflow_execute_transition allows a module to veto a particular transition change that is about to happen, but this proposed patch allows a module specify additional users who are allowed to perform a particular transition. The way Workflow is currently written, a module cannot change who can do a transition, only stop or allow a transition that is being requested by a user already allowed to do a transition.
For example:
I have Roles defined for Authors and Editors. Authors can create content and then pass it onto an Editor once that is done, the Author loses permission to the page while the Editor can choose to bounce it back to the Author or publish it. Currently, anyone who is defined as part of the Editors Role can work on the page.
We wanted each page to have additional authors and editors specifically assigned, so only those users had those permissions. So, we created CCK userref fields for Additional Authors and Editors. With a patch similar to the one being proposed here, we can say that the users specified in those selected CCK userref fields are allowed to transition to/from various states, too.
This is a method to additionally expand the circumstances where transitions are allowed (like allowing more users beyond simple Roles).
I hope I'm explaining this well enough, and that I haven't completely misunderstood "transition pre" and "transition post" because I could not find a way to do this without adding an additional API to Workflow.
Comment #10
dawehnerupdating status
Comment #11
Bastlynn CreditAttribution: Bastlynn commentedI'll dig into this one a little more once I have the queue down to reasonable.
Comment #12
johnvFYI, this is fixed in D7, using
$result = module_invoke_all('workflow', 'transition permission', ...);
See[#1997242]
The D6-version probably won't be updated anymore.
Comment #13
johnvI wish there was a nicer way to clear the issue queue from 'D6-issues that are fixed in D7' then a "won't fix for D6."