Hi!

I have a site with about 300 editors (more will register soon, so we can't assign the editors to sections by hand). Putting content in about 50 sections. Each editor belongs to exact one section and should only be able to create content in his or her section. If the editor registers he has also to chosse which section he belongs to. (After that there is a manual approvel proccess, which sets the editor active)

Is there a way to add the user automatically to the section (admin/config/workbench/access/editors/taxonomy/123) term with the same term (123) that has been attached to the user during registration?

I was thinking about doing it with rules and therefore working on #1285110: Add support for Rules, Actions, and Triggers to get this working again for having a start to add a rules action that will do this.

But maybe there is another way in workbench access I don't know and I am thinking to complicated. If so - please give me a hint how this could be done.

regards
marcus

Comments

agentrickard’s picture

Run workbench_access_user_section_save() during hook_user_insert() and hook_user_update().

We don't currently support doing this directly.

Pseudo-code:

function example_user_save(&$edit, $account, $category) {
  $active = workbench_access_get_active();
  // Figure out yourself how to get the $terms array from $edit.
  foreach ($terms as $tid) {
   if (isset($active['active'][$tid])) {
      workbench_access_user_section_save($account->uid, $tid, $active['access_scheme']);  
  }
}
marcusx’s picture

Ahh thanks! So my rules action does it the right way...

I will rework the rules action I am using now and add the $active stuff...

function workbench_access_assign_user_section_rules_action($user, $access_sections) {

  //Data comes as object or array of objects, convert to array.
  $sections = array();

  if (is_object($access_sections)) {
    $sections[] = $access_sections->tid;
  } else {
    foreach ($access_sections as $term) {
       $sections[] = $term->tid;
    }
  }

  if (!empty($sections)){
    workbench_access_rebuild_user($user->uid, $sections);
  }

  return array('user' => $user);
}
freddura’s picture

Hello, I am wondering what progress you have made with this.

marcusx’s picture

@freddura: Good question, I can't remember. The above code is working, so I left the $active check for now. But I can think again if you can specify in more detail what progress you would expect.

agentrickard’s picture

To be clear, this is custom module code that won't be integrated into the main module, since most sites don't tag user accounts.

agentrickard’s picture

Status: Active » Closed (works as designed)
delacosta456’s picture

hi
i would like to suggest readers to be following this related issue https://www.drupal.org/node/1285110#comment-12338530that may help solve those , Automatic , contextual assignment etc. desired cases that may be achieved with Rules modules when it will be correctly integrated

Thanks