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

sheldon rampton’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB

I'm attaching a patch with the proposed function.

agentrickard’s picture

Status: Needs review » Needs work

Nice. 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.

sheldon rampton’s picture

I 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.

agentrickard’s picture

Refactoring 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

sheldon rampton’s picture

StatusFileSize
new6.58 KB

OK, 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.

agentrickard’s picture

Nice. 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.

sheldon rampton’s picture

That 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

agentrickard’s picture

Awesome.

sheldon rampton’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, workbench_access_user-1350764-4.patch, failed testing.

sheldon rampton’s picture

Status: Needs work » Needs review
StatusFileSize
new6.38 KB

Hm, OK, here's a new patch.

agentrickard’s picture

Status: Needs review » Needs work
StatusFileSize
new6.55 KB

Here's a re-roll that fixes the following errors:

  • Missing function workbench_access_users() causes fatal error.
  • Turns $roles argument to array() from NULL to avoid type mixing.
  • Turns $pager into an integer, to allow for variable pager lengths. Defaults to 0.
  • Removes the $page argument on the editor form call, because I don't know if that actually works. The form theme function isn't prepared to handler a pager AFAIK.
  • Docblock formatting consistency (see d.o. documentation).
  • Properly documents return functions.

I think the pager needs testing, and the whole change likely needs some form of test.

ronny89’s picture

nice to see that feature grow. :-D
i would give it a try. is the list available as token?

agentrickard’s picture

No. That would be a follow-up patch.

sheldon rampton’s picture

If 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.

agentrickard’s picture

I can see a pager being useful if you have > 50 entries. We just have to support it in the theme code.

agentrickard’s picture

We need this to be sensitive to the fact that role id 2 DRUPAL_AUTHENTICATED_RID is not stored in the dang database.

gabriel.achille’s picture

What 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...

gabriel.achille’s picture

the patch.

agentrickard’s picture

Status: Needs work » Needs review

Let's set to "needs review" for automated testing.

Status: Needs review » Needs work

The last submitted patch, workbench_access-list_of_users-1350764-19.patch, failed testing.

gabriel.achille’s picture

my 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.

gabriel.achille’s picture

Status: Needs work » Needs review

And: Let's set to "needs review" for automated testing.

Sborsody’s picture

Status: Needs review » Needs work

PHP Fatal error: Call to undefined function workbench_access_users() in /workbench_access/workbench_access.admin.inc on line 496

agentrickard’s picture

Then why did it pass the testbot?

@Sborsody - What were you doing when that happened?

gabriel.achille’s picture

Status: Needs work » Needs review
StatusFileSize
new10.43 KB

@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.

  • function workbench_access_get_section_users_by_account
    • renamed (previously named workbench_access_user_editor_assignments): following agentrickard recommendation (#6) and terminology already in use in the module.
    • optional argument roles: I kept it however it is not use (internally at least), My view is it is too specific. keen to remove it.
    • remove unused sql join with table role_permission in the query
    • update function description
    • pager: i kept it however i don't undestand if it is appropriated here...
  • function workbench_access_get_section_users_by_role
    • renamed (previously named workbench_access_user_role_assignments): following agentrickard recommendation (#6) and terminology already in use in the module.
    • update function description
    • optional argument roles: I kept it however it is not use (internally at least), My view is it is too specific. keen to remove it.
    • use db_select instead of db_query
  • I split apart the function workbench_access_get_section_users_by_role
    to expose another function: workbench_access_get_section_roles: Return an array of roles who are editors for a section
hefox’s picture

Status: Needs review » Needs work
+++ b/workbench_access.module
@@ -2151,3 +2151,145 @@ function workbench_access_update_records($find, $replace, $scheme = NULL) {
+function workbench_access_get_section_users_by_account($access_type, $access_type_id, $roles = array(), $pager = 0) {

$page = FALSE maybe? = 0 seems a bit odd

+++ b/workbench_access.module
@@ -2151,3 +2151,145 @@ function workbench_access_update_records($find, $replace, $scheme = NULL) {
+function workbench_access_get_section_roles($access_type, $access_type_id, $roles = array(), $depth=FALSE) {

$depth = FALSE

+++ b/workbench_access.module
@@ -2151,3 +2151,145 @@ function workbench_access_update_records($find, $replace, $scheme = NULL) {
+  if (!$roles || empty($roles)) {

wat?

+++ b/workbench_access.module
@@ -2151,3 +2151,145 @@ function workbench_access_update_records($find, $replace, $scheme = NULL) {
+  } else {

}
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.