Commit 1edeeae2 authored by Derek Wright's avatar Derek Wright
Browse files

[#397458] by dww: Added 'delete' links when managing issue notifications.

Since it's now reasonable to set a project to 'None' and we keep those
rows in the table, we need a way to remove rows entirely. Since this
is such an easy thing to recover from, we're not bothering with a
confirm form, just using drupal_valid_token() to prevent CSRF.
parent 7b80a5b4
Loading
Loading
Loading
Loading
+46 −20
Changes for includes/notification.inc: 46 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -43,10 +43,12 @@ function project_issue_notification_user_form(&$form_state, $account) {
    '#collapsible' => TRUE,
  );

  $token = drupal_get_token('project-issue-manage-notifications');

  // Per-project notification levels.
  $form['project_issue_notification']['projects'] = array(
    '#theme' => 'project_issue_notification_projects_table',
    '#header' => array(t('Project'), t('Notification level')),
    '#header' => array(t('Project'), t('Notification level'), t('Operations')),
  );
  $result = db_query(db_rewrite_sql("SELECT pisp.nid, n.title, pisp.level
    FROM {project_issue_notification_project} pisp
@@ -54,47 +56,52 @@ function project_issue_notification_user_form(&$form_state, $account) {
    WHERE n.status = 1 AND pisp.uid = %d ORDER BY n.title
    ", 'n'), $account->uid);
  while ($project = db_fetch_object($result)) {
    $form['project_issue_notification']['projects'][$project->nid]['title'] = array(
    $form['project_issue_notification']['projects'][$project->nid] = array(
      'title' => array(
        '#value' => l($project->title, "node/$project->nid"),
    );
    $form['project_issue_notification']['projects'][$project->nid]['level'] = array(
      ),
      'level' => array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => $project->level,
      // Adjust #parents to get a simple $project->nid => $level mapping in the
      // submit handler. Without adjustment, the value would be
        // Adjust #parents to get a simple $project->nid => $level mapping in
        // the submit handler. Without adjustment, the value would be
        // array('level' => $level).
        '#parents' => array('project_issue_notification', 'projects', $project->nid),
      ),
      'operations' => array(
        '#value' => l(t('delete'), "user/$account->uid/project-issue/delete/$project->nid", array('query' => array('token' => $token))),
      ),
    );
  }

  $form['project_issue_notification']['projects']['new']['title'] = array(
  $form['project_issue_notification']['projects']['new'] = array(
    'title' => array(
      '#type' => 'textfield',
      '#size' => 30,
      '#autocomplete_path' => 'project/autocomplete/project',
  );
  $form['project_issue_notification']['projects']['new']['level'] = array(
    ),
    'level' => array(
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $account->project_issue_notification['level'],
    ),
    // We don't need any operations for this one.
    'operations' => array(),
  );

  $form['project_issue_notification']['projects']['default']['title'] = array(
    '#value' => t('Default for all other projects'),
  );
  $form['project_issue_notification']['projects']['default']['level'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $account->project_issue_notification['level'],
  );
  $form['project_issue_notification']['projects']['default']['title'] = array(
  $form['project_issue_notification']['projects']['default'] = array(
    'title' => array(
      '#value' => t('Default for all other projects'),
  );
  $form['project_issue_notification']['projects']['default']['level'] = array(
    ),
    'level' => array(
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $account->project_issue_notification['level'],
      '#parents' => array('project_issue_notification', 'projects', 'default'),
    ),
    // We don't need any operations for this one.
    'operations' => array(),
  );

  $form['actions']['submit'] = array(
@@ -168,6 +175,7 @@ function theme_project_issue_notification_projects_table($element) {
    $row = array();
    $row[] = drupal_render($element[$nid]['title']);
    $row[] = drupal_render($element[$nid]['level']);
    $row[] = drupal_render($element[$nid]['operations']);
    $rows[] = $row;
  }
  if (!empty($rows)) {
@@ -243,3 +251,21 @@ function project_issue_notification_project_form_submit($form, &$form_state) {

  drupal_set_message(t('Your notification settings have been updated.'));
}

function project_issue_notification_user_delete($account, $project_nid) {
  $token = $_GET['token'];
  if (drupal_valid_token($token, 'project-issue-manage-notifications')) {
    $project = node_load($project_nid);
    if (empty($project) || $project->type != 'project_project') {
      drupal_set_message(t('Invalid project, not deleting anything.'), 'error');
    }
    else {
      project_issue_notification_project_setting_delete($account->uid, $project_nid);
      drupal_set_message(t('Deleted notification settings for %title.', array('%title' => $project->title)));
    }
  }
  else {
    drupal_set_message(t('Invalid token, not deleting anything.'), 'error');
  }
  return drupal_goto("user/$account->uid/project-issue");
}
+8 −0
Changes for project_issue.module: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,6 +96,14 @@ function project_issue_menu() {
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/notification.inc',
  );
  $items['user/%user/project-issue/delete/%'] = array(
    'page callback' => 'project_issue_notification_user_delete',
    'page arguments' => array(1, 4),
    'access callback' => 'user_edit_access',
    'access arguments' => array(1),
    'type' => MENU_CALLBACK,
    'file' => 'includes/notification.inc',
  );

  // Search.
  if (module_exists('search')) {