The Workbench Access module should have a function that can be used to retrieve an array of users who have been granted access to a particular editorial section.
I encountered a need for this function while building a jobs website in which we want to use Workbench to handle moderation and editorial access related to created, editing and publishing job announcements. We need a notification system which will be somewhat different from the system provided by the workbench_notification module. When a job is created in a particular editorial section, email notification needs to be sent automatically to whomever is designated as with the role of "project approver" and assigned to that editorial section.
To facilitate creation of this functionality, we created a function named workbench_access_users($access_type, $access_type_id, $rid=NULL) which retrieves an array of all users for a specified editorial section. If the optional $rid function is included, the results can be restricted to only users with the specified role.
Comments
Comment #1
sheldon rampton commentedI'm attaching a patch with the proposed function.
Comment #2
agentrickardNice. Notes:
* I would always pass an array to $rids and make its default array(). Mixing types like that leads to bugs. If you need to pass a single rid, use a wrapper function in the style of _load() calling _load_multiple() in D7.
* If possible, this should be abstracted for use with workbench_access_editor_form() and workbench_access_role_form(), which duplicate some of this logic.
Comment #3
sheldon rampton commentedI see your point about always passing an array to $rids.
I actually copied and modified some of the code in workbench_access_editor_form() to create this patch, so it would be easy to edit that function to have it use the workbench_access_users() function. I roll a new patch if you'd like. I can take a stab at doing that also with workbench_access_role_form() when I get a minute.
On another topic, you wouldn't happen to know how to go about adopting someone else's module, would you? I just submitted a D7 version of the Publication Date module to add Workbench support, and I noticed that the module's original creator hasn't committed any updates in two years. I'd be willing to take it over just so I could get it released for D7 and get the Workbench support added. However, I don't know how to go about applying.
Comment #4
agentrickardRefactoring both form functions would be ideal.
You can create a new issue in the Webmaster queue to take over a project.
See http://drupal.org/node/251466
Comment #5
sheldon rampton commentedOK, here's a revised patch. Upon reviewing workbench_access_role_form(), I concluded that the logic there is substantially different from the logic used to generate the list of users in workbench_access_editor_form(). The workbench_access_editor_form() function needs a list of users who have been assigned editorial permission to a section via individual assignment, whereas the workbench_access_role_form() function needs a list of users who have been assigned editorial permissions through their workbench_access user roles.
I've therefore created TWO helper functions: workbench_access_user_editor_assignments() and workbench_access_user_role_assignments(). I've modified the workbench_access_editor_form() and workbench_access_role_form() functions so that they rely on these helper functions to retrieve their lists of users, and everything seems to be working on my website.
I've also incorporated your suggestion about passing an array of role IDs rather than mixing types.
Comment #6
agentrickardNice. I'll try to take a look and clean it up some. For instance, since we have two functions that are siblings:
* workbench_access_user_role_assignments()
* workbench_access_users()
I would go for consistency and rename them as:
* workbench_access_get_section_users()
* workbench_access_get_section_roles()
Changing to 'sections' from 'assignments' for internal consistency.
Comment #7
sheldon rampton commentedThat all makes sense to me. I'm sure you have a better sense of the naming conventions for your module than I do. FYI, my patch is also working on top of the latest patch for the Default taxonomy form support issue:
http://drupal.org/node/1187424
Comment #8
agentrickardAwesome.
Comment #9
sheldon rampton commentedComment #11
sheldon rampton commentedHm, OK, here's a new patch.
Comment #12
agentrickardHere's a re-roll that fixes the following errors:
I think the pager needs testing, and the whole change likely needs some form of test.
Comment #13
ronny89 commentednice to see that feature grow. :-D
i would give it a try. is the list available as token?
Comment #14
agentrickardNo. That would be a follow-up patch.
Comment #15
sheldon rampton commentedIf you've removed the $page argument from the editor form call, maybe we can dispense with the pager entirely. The only reason I put it in there at all was to support the fact that it was being being in the editor form.
Other than that, all of your changes make sense to me. Sorry about the workbench_access_users() error.
Comment #16
agentrickardI can see a pager being useful if you have > 50 entries. We just have to support it in the theme code.
Comment #17
agentrickardWe need this to be sensitive to the fact that role id 2 DRUPAL_AUTHENTICATED_RID is not stored in the dang database.
Comment #18
gabriel.achille commentedWhat if we add the ability to extract the users assigned to that editorial section AND ITS PARENTS ? Does it make sense in the initial requirement of this issue ? I'm working on a patch for that...
Comment #19
gabriel.achille commentedthe patch.
Comment #20
agentrickardLet's set to "needs review" for automated testing.
Comment #22
gabriel.achille commentedmy second patch (the first one was built on the top of the 7.x-1.0 version. This one is for dev version.) My local tests are ok but because I had to integrate some others modification made in between (especially Adding authenticated user role fails to list users) i'm not sure it's perfect.
Comment #23
gabriel.achille commentedAnd: Let's set to "needs review" for automated testing.
Comment #24
Sborsody commentedPHP Fatal error: Call to undefined function workbench_access_users() in /workbench_access/workbench_access.admin.inc on line 496
Comment #25
agentrickardThen why did it pass the testbot?
@Sborsody - What were you doing when that happened?
Comment #26
gabriel.achille commented@Sborsody
Yes there was a motherless call to workbench_access_users() into my previous patch.
I did a little bit of clean-up inside this new patch and i repack it against latest state of dev branch.
to expose another function: workbench_access_get_section_roles: Return an array of roles who are editors for a section
Comment #27
hefox commented$page = FALSE maybe? = 0 seems a bit odd
$depth = FALSE
wat?
}
else {
Would it be better to have a function that get users one calls to get uid's that are in the user table, not restricted by role, e.g. if looking to see what user assignment exists that no longer have access, etc.