Currently when the Confidential submissions option is turn on, logged in user will be prompt to logged out and then submit the form (This form is confidential. You must Log out to submit it). This will not work in the case where you don't want to keep track of the IP but want both anonymous user and authenticated user to able to submit the form.

The proposed implementation would add a hook that allows module to alter allowed roles for confidential submission.

/**
 * Alter allowed roles confidential submission.
 *
 * @param object $node
 *   The loaded node object containing a webform.
 * @param array $allowed_roles
 *   List of allowed roles
 * @param boolean $user_is_allowed
 *   Reference to boolean to be set to whether the current user is allowed.
 */
/**
 * Alter allowed roles confidential submission.
 *
 * @param object $node
 *   The loaded node object containing a webform.
 * @param array $allowed_roles
 *   List of allowed roles
 * @param boolean $user_is_allowed
 *   Reference to boolean to be set to whether the current user is allowed.
 */
function hook_webform_confidential_allowed_roles_alter(&$allowed_roles, $node, &$user_is_allowed) {
  global $user;

  $node_allowed_roles = $node->webform['roles'];
  
  // Base allowed roles for submission on the webform_submission_access_control.
  foreach($node_allowed_roles as $rid) {
    $context['allowed_roles'][$rid] = TRUE;
  }
  if (array_intersect( array_keys($user->roles), $node_allowed_roles)) {
    $context['user_is_allowed'] = TRUE;
  }
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xlin1003 created an issue. See original summary.

xlin1003’s picture

Issue summary: View changes
xlin1003’s picture

This patch:

  • adds a hook_webform_confidential_allowed_roles_alter function allows module to change allowed roles for confidential submission.
  • Show the message "This form is confidential. You must Log out to submit it" base on the result from allowed roles return from above.
xlin1003’s picture

Issue summary: View changes
xlin1003’s picture

Status: Active » Needs review
FileSize
1.68 KB

Update patch so that alter hook only takes two arguments.

xlin’s picture

xlin1003’s picture

Update patch to remove alteration of message from theme_webform_view_messages()

Chris Matthews’s picture

The 3 year old patch in #7 to webform.module applied cleanly to the latest 7.x-4.x-dev, looks good to me.

dalemoore’s picture

This feature would be really helpful for internal intranets. We obviously require our users to be signed in to the Intranet, and we would like to also receive feedback on features of the Intranet itself, or perhaps other sensitive organizational questions, but don't want to track who submits the submissions for confidentiality. Right now this doesn't seem possible with the Webform module as-is in Drupal 7 or 8+?

I haven't looked at the patch, but the simplest thing to me would be a checkbox that says "Anonymize submissions for logged in users" that, when a logged in user submits something, just changes the submission to be assigned to anonymous.