statonlab / tripal_hq

provides a user and administrative dashboard for Chado content creation
GNU General Public License v3.0
2 stars 0 forks source link

email events for deputies #68

Open bradfordcondon opened 6 years ago

bradfordcondon commented 6 years ago

HQ_Permissions adds chado-based deputies. The admin email config page, and the emails themselves, should take this into account and notify deputies. One way to address would be ot add a third checkbox for deputies to the config page. the other is to make deputies implied with the "admin" box.

bradfordcondon commented 5 years ago

kind of confusing. heres what i've done.

function tripal_hq_get_curator_emails($submission_id) {

  $mail = [];

  $query = db_select('tripal_hq_submission_permission', 'thsp');
  $query->join('tripal_hq_permissions', 'thp', 'thp.id = thsp.hq_permission_id');
  $query->condition('thsp.submission_id', $submission_id);
  $query->join('users', 'u', 'u.uid = thp.uid');
  $query->fields('u', ['mail']);
  $deputies = $query->execute()->fetchAll();

   // If specific permissions are set, only notify those in charge of it.

  if (!empty($deputies)){
    foreach ($deputies as $deputy) {
      $mail[] = $deputy->mail;
    }
    return implode(', ', $mail);
  }

  //Otherwise, get all admins with the role.

  $query = db_select('users', 'u')
    ->fields('u', ['mail']);
  $query->join('users_roles', 'ur', 'ur.uid = u.uid');
  $query->join('role_permission', 'rp', 'rp.rid = ur.rid');
  $query->condition('rp.permission', 'access tripal_hq admin');
  $query->condition('rp.module', 'tripal_hq');

  $results = $query->execute()->fetchAll();

  if (!$results) {
    return '';
  }
  foreach ($results as $result) {
    $mail[] = $result->mail;
  }
  return implode(', ', $mail);
}

first ,check if there are deputies. If so, thats who we email. Otherwise, we email everyone with the admin permission.

The obvious problem is if you dont set deputies for an organism, then requests go to everyone with the admin, which includes deputies.

What should happen instead is, if theres no deputies set, send it to admins who arent deputies. We can do that by doing a JOIN IS NULL on the tripal_hq_submission_permission table, ie, only get users wh odont have specific permissions configured.

bradfordcondon commented 5 years ago

  $query = db_select('users', 'u')
    ->fields('u', ['mail']);
  $query->join('users_roles', 'ur', 'ur.uid = u.uid');
  $query->join('role_permission', 'rp', 'rp.rid = ur.rid');
  $query->condition('rp.permission', 'access tripal_hq admin');
  $query->condition('rp.module', 'tripal_hq');
  $query->leftJoin('tripal_hq_permissions', 'thp', 'thp.uid = u.uid');
  $query->isNull('thp.id');

  $results = $query->execute()->fetchAll();

like this maybe? I should do some testing before merging.

bradfordcondon commented 5 years ago

/remind me in 24 hours

reminders[bot] commented 5 years ago

@bradfordcondon set a reminder for Nov 20th 2018

bradfordcondon commented 5 years ago
PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "tripal_hq_submission_permission" does not exist LINE 3: tripal_hq_submission_permission thsp ^: SELECT u.mail AS mail FROM {tripal_hq_submission_permission} thsp INNER JOIN {tripal_hq_permissions} thp ON thp.id = thsp.hq_permission_id INNER JOIN {users} u ON u.uid = thp.uid WHERE (thsp.submission_id = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 6 ) in tripal_hq_get_curator_emails() (line 219 of /Users/bc/tripal/sites/all/modules/custom/tripal_hq/includes/tripal_hq.api.inc).
reminders[bot] commented 5 years ago

:wave: @bradfordcondon,