Restrict assign case only to the members of a group

RAFA3L - April 9, 2009 - 02:49
Project:Case Tracker
Version:6.x-1.0-beta1
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'm playing again with CT and I notice that in the 6 version the autofill in the assign field was changed by radio boxes. This is in the create case form.

Is possible hide the users of another group? I'm using OG too and all is working fine except that. My users can see his own projects and cases, but when create a new case see the another users of anothers groups too.

Thanks in advance

#1

RAFA3L - April 9, 2009 - 03:44

Ok, good news and bad news...

First, is possible get back to the autocomplete field. Change this in casetracker.module

    $form['casetracker']['assign_to'] = array(
    '#type' => 'radios',
    '#title' => t('Assign to'),
    '#required' => TRUE,
    '#options' => $normalized,
    );

To this:

$form['casetracker']['assign_to'] = array(
    '#type' => 'textfield',
    '#title' => t('Assign to'),
    '#autocomplete_path' => 'casetracker_autocomplete',
    '#required' => TRUE,
    '#options' => $normalized,

With this we can hide all the users.

And the another thing, I found this:

function casetracker_autocomplete($string) {
  $matches = array();
  $group = module_exists('og') ? og_get_group_context() : NULL;
  if ($group) {
    $gid = $group->nid;
    $result = db_query_range("SELECT u.name FROM {users} u LEFT JOIN {og_uid} ou ON u.uid = ou.uid WHERE LOWER(name) LIKE LOWER('%s%%') AND u.status > 0 AND ou.nid = %d", $string, $gid, 0, 10);
  }
  else {
    $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10);
  }
  while ($user = db_fetch_object($result)) {
    $matches[$user->name] = check_plain($user->name);
  }
  drupal_json($matches);
}

And the problem in this code is that "og_get_group_context()" doesn't work because is not IN a node, is CREATING one

#2

RAFA3L - April 9, 2009 - 05:06

Well, I modify a bit casetracker.module and I don't know much about create a patch.

I revert the form to use radios, so this must look like the original code:

  $form['casetracker']['assign_to'] = array(
    '#type' => 'textfield',
    '#title' => t('Assign to'),
    '#autocomplete_path' => 'casetracker_autocomplete',
    '#required' => TRUE,
    '#size' => 12,
  );
  if (count($options) < 20) {
    $normalized = array();
    foreach ($options as $name) {
      $normalized[$name] = $name;
    }
    $form['casetracker']['assign_to'] = array(
    '#type' => 'radios',
    '#title' => t('Assign to'),
    '#required' => TRUE,
    '#options' => $normalized,
    );

But just in the above line of this piece of code I change this:

$options = casetracker_user_options();

to this:

$options = casetracker_user_options($default_project);

And the function casetracker_user_options must change to this:

function casetracker_user_options($default_project = NULL) {
  $group = module_exists('og') ? og_get_group_context() : NULL;
  $options = array(0 => variable_get('casetracker_default_assign_to', variable_get('anonymous', t('Anonymous'))));
  if ($default_project) {
    $results = db_query('SELECT u.uid, u.name FROM {users} u INNER JOIN {og_uid} ou ON u.uid = ou.uid WHERE u.status > 0 AND u.uid > 0 AND ou.nid = %d ORDER BY u.name ASC', $default_project);
  }
  else {
    $results = db_query('SELECT u.uid, u.name FROM {users} u WHERE u.status > 0 AND u.uid > 0 ORDER BY u.name ASC');
  }
  while ($result = db_fetch_object($results)) {
    $options[$result->uid] = check_plain($result->name);
  }
  return $options;
}

Look the use of the argument $default_project inside the function. (in the conditional and the query).

And one last thing, You must disable the option Create content/Case in the Navigation menu, because from here the default project don't pass to the form, so I don't know how to get it without any reference.

I don't know if this is the best solution but work for now

#3

yhahn - August 13, 2009 - 04:30
Status:active» fixed

As of beta3, you can provide a View that customizes/filters the potential assignees for a case. Use a view of users in the current group to get the OG integration here.

#4

System Message - August 27, 2009 - 04:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.