Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email events for deputies #68

Open
bradfordcondon opened this issue Nov 1, 2018 · 6 comments
Open

email events for deputies #68

bradfordcondon opened this issue Nov 1, 2018 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@bradfordcondon
Copy link
Contributor

bradfordcondon commented Nov 1, 2018

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 bradfordcondon added the enhancement New feature or request label Nov 1, 2018
@bradfordcondon bradfordcondon self-assigned this Nov 1, 2018
@bradfordcondon
Copy link
Contributor Author

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
Copy link
Contributor Author


  $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
Copy link
Contributor Author

/remind me in 24 hours

@reminders reminders bot added the reminder label Nov 19, 2018
@reminders
Copy link

reminders bot commented Nov 19, 2018

@bradfordcondon set a reminder for Nov 20th 2018

@bradfordcondon
Copy link
Contributor Author

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 reminders bot removed the reminder label Nov 20, 2018
@reminders
Copy link

reminders bot commented Nov 20, 2018

👋 @bradfordcondon,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant