'take webform' is a bad name, but there's currently nothing stopping anonymous users from submitting their own webform results. A new permission should exist ('submit own webform submissions?', heh) that checks against this. This may be unwieldly though - it should ideally be a per-webform setting (a per-webform "roles that can submit results?').

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Morbus Iff’s picture

Assigned: Unassigned » Morbus Iff
Status: Active » Needs review
FileSize
2.89 KB

Nothing too surprising here: there's a new permission to access webform nodes (ie., which allows me to stop anonymous users from taking the form, or any other role), and then an update that gives this new permission to any user who had any sort of other webform permission (which is safe, but not infallible, logic: if the admin had not used set any webform permission, then he'd have a webform that any one could submit again and again, without being able to modify or view their results.) A drupal_set_message() is also displayed to warn users to manually check their access control.

quicksketch’s picture

Because webforms are nodes, they follow the same access permissions used by all other node types. If you need to limit access to webforms, you should be using taxonomy_access, simple_access, or something similar. There aren't any permissions for "access story" or "access page" for the same reason. View access control can get a little more complicated than edit. Webform provides access control for submissions though, because it's the only module that knows what a webform submission is.

Morbus Iff’s picture

How would one stop a webform submission? As far as I can tell, it's impossible to, say, "don't allow anonymous people to submit a webform" - that's the real need behind this patch.

quicksketch’s picture

Adding a "view" access permission in webform_access is the same thing as installing taxonomy_access (or any other ACL module) which can prevent view access to nodes. Because webforms are nodes, if a user doesn't have access to view the node they won't be able to make a submission. I don't want to add an "access webforms" permission because there's nothing special about a webform node that would prevent existing solutions from working with it just the same as stories or pages.

A different request I've had before though is allowing access to the page but disabling the form: http://drupal.org/node/143448

Morbus Iff’s picture

Title: No permission for 'take webform' » No permission for 'create webform submission'
Status: Needs review » Needs work

Yeah, I understand what you're saying (and did in #2), but you implicated that one could already stop submissions via the default module ("Webform provides access control for submissions though, because it's the only module that knows what a webform submission is."). I agree that the patch, as is, is horrifically wrong, and should not be considered.

Really, the only thing I want to do is /stop/ a particular role from /submitting/ (or even seeing the actual rendered form of) the webform. I'm perfectly fine if they see the webform's node body (wherein the admin could explain how to gain access to the submission process). I just want the form not to show based on a permission. I don't want it time-delimited, I don't want it autoexpired, I don't want it unpublished (per the issue you linked) - I just can't have anonymous users submitting the form and, currently, there doesn't seem to be anyway of handling that /within the module itself/ (contrary to your sentence I pasted above).

So, regardless, I'll be repatching the module with a new "create webform submission" which, if unset, will continue to show the body of the webform node, but will just stop the drupal_get_form from being assigned to $output. Is this something that you'd accept?

quicksketch’s picture

Okay cool, we're on the same page here. The patch threw me off a bit.

I think what's likely to happen here is many users are going to want the ability to prevent submissions on a per-webform basis, just like users are apt to want access control on a per-node basis (hence the variety of ACL modules). However, since webform certainly isn't going to implement ACLs for webform submissions, I think it'd be helpful to make a basic per-node, per-role submission access. So instead of this being another permission on admin/user/access, this permission would be part of the node form for webforms. Then it would work for both your purposes in this issue and the request in http://drupal.org/node/143448.

I also like the idea of disabling the form rather than not displaying it at all, but perhaps we could make that an option at a later time.

Morbus Iff’s picture

Status: Needs work » Needs review
FileSize
7.47 KB

Here's another attempt at this. The pattern used is from blocks.module, which uses "blocks_roles" (thus, "webform_roles" here). The update path gives every role access to submit every webform (which replicates current behavior). The default behavior is to hide the form and display a message if the current role cannot submit the webform ("You do not have permission to submit this webform."). I don't much need the "show the form but keep it disabled" feature, but it'd be pretty easy to add.

Morbus Iff’s picture

From quicksketch: "block's default behavior is if no roles are checked, assume access is allowed to all of them". Repatch.

quicksketch’s picture

FileSize
10.03 KB

Okay, some change-up here:

- I kept the behavior of needing to check roles to allow submit access. This is because I want users to be able to uncheck all roles and prevent further submission.
- Changed the update function to only add roles for anonymous and authenticated, since users of all other roles count as authenticated anyway.
- Update help text to describe the new access settings.
- Moved the access queries to hook_load().
- Create new theme_webform_view() function that returns the output that needs to be displayed.
- Added messages for "Submissions for this form are closed", "You must login or register to submit this form", and "You do not have permission to submit this form".
- By default if access is not allowed, the form is still displayed in a disabled mode.

I think this sets us up well for the patch to warn users of the submit limit. Where we can just pass in another argument to the theme function and print out a different message for that case.

cmckay’s picture

I am having the same problem. I am fairly new to drupal and wanted to know how is it that i apply the patch?

quicksketch’s picture

http://drupal.org/patch/apply

This patch is up for review and after it's been okayed, I'll put it into the actual version. Please report any problem you have with the patch.

Morbus Iff’s picture

I'm slightly ambivalent about this patch. Some things are great - the anon/auth only for the update path and moving the role loading into hook_load, but others just bug me. Your help text again repeats things we already know - the fieldset says "These permissions affect which roles can submit webforms." which is pretty much the exact name of the checkbox label. I'd chop that sentence out entirely and just change the remaining one to "If you'd like to prevent access to the webform node itself...".

The biggest complaint, though, is that webform /continues/ to tease the user with things /they cannot do/ (the core complaint with the max throttle issue, mentioned). Drupal core doesn't show the user the admin pages, but with disabled forms. If a user doesn't have access to create a node, we don't show them the form but taunt "nuh-uh!!" Even the core contact.module, which has limit throttling just like webform, doesn't show the form when the throttle has been hit. The /only/ time a form element should be disabled is when the user's actions have caused that choice - and that's just a single element, not the /entire/ form. I've never seen a site that consistently disables an entire form for the user, taunting them so with forbidden typing.

I'd much rather hiding the form be the default. It makes more far more sense from a usability perspective.

quicksketch’s picture

FileSize
104.82 KB
10.37 KB

My primary concern is that the message displayed to the user implies that there's a form that they don't have access to, but it's not clear which form it means. In the screenshot attached for example, there are already 2 forms on the page.

So instead of the verbiage "submit this form", I simply changed it to "view this form". Implying that there's a form on this page that they currently cannot see. It helps with my particular reservation. The form is now hidden by default in this version.

As for the help text, cutting it down made things significantly less helpful for me. Webform has a target audience that's probably a little below the average Drupal user. Explaining the entire option from start to finish will hopefully keep me from having to answer support requests about access control.

SeanA’s picture

FileSize
10.02 KB

Good work guys, this is a nice feature.

The patch in #13 works as advertised, but the messages aren't cleared away in some situations. For example, "You must login or register to view this form" appears at the top of the (now revealed and submittable) form after logging in via the sidebar login block.

So I reworked the patch to avoid using drupal_set_message(). I ended up removing the theme_webform_view() function and put that conditional logic in webform_view(), where $output is set to either the form, or one of the three messages.

Morbus Iff’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
11.12 KB

@quicksketch: patch in #13 worked for me. Retweaked the .install to match numbering format of head. Attached. I was unable to reproduce SeanA's bug report. @SeanA I'd much rather we find out why the dsm() happened to you again, as opposed to ripping it out entirely; the use of dsm() is correct - your faking of the dsm() display is not.

SeanA’s picture

I've tested this patch on the site I'm working on, on a fresh install of Drupal 5.7 with no other modules, with PHP4 and PHP5, and on two different hosts... every time the message shows up again after logging in. Weird, huh? This unanswered forum post describes the same thing: http://drupal.org/node/214389.

I noticed another small issue with the patch, the links in "You must login or register to view this form" don't always point to the right places. Line 925:

--- drupal_set_message(t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array('!login' => 'user/login', '!register' => 'user/register')), 'error');
+++ drupal_set_message(t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array('!login' => url('user/login'), '!register' => url('user/register'))), 'error');
belio’s picture

Status: Reviewed & tested by the community » Needs work

When I apply this patch
- hidden fields show up to users (mentioning '(hidden)')
- things like %get[] %username don't return a value

mdowsett’s picture

i tried both the patches in #14 & #15 and got this error:

user warning: Table 'drupal5.webform_roles' doesn't exist query: SELECT rid FROM webform_roles WHERE nid = 2385 in /var/www/vhosts/goflyxc.com/httpdocs/includes/database.mysql.inc on line 172.

And there were no new permissions added too access control and it flagged my webforms as 'closed' for all users...

Morbus Iff’s picture

mdowsett: did you run update.php after applying the patch?

mdowsett’s picture

no....I didn't know I had to with patches (I'm rather new to patches).

I did run it now, it mentioned an update to be done. I ran it, no errors....but no change.....still no new permissions to access control....and anon users can still submit.

SeanA’s picture

mdowsett: These permissions are not under Admin->Access Control, but are configured for each webform you create. Look on the webform|edit page for the settings.

(Running update.php in this case is needed because this patch adds a new database table.)

mdowsett’s picture

Ah! That'd be a better place for it!

However, there's no mention of any sort of restriction in the webform|edit|configuration page....what am I looking for?

There's nothing in the 'Form components' tab either but I would expect there to be.

SeanA’s picture

@#22: On edit/configuration there should be a fieldset called "Webform access control" and the permissions are set there under "Roles that can submit this webform". I hope you are using the patch in #15 so we can see if anyone else encounters the same problem I have with the message persisting after logging in.

@#17: Hidden fields showing up can be fixed by applying the patch in http://drupal.org/node/247490.

mdowsett’s picture

Bingo! Got it.

I reinstalled a fresh copy of webform and then ran the #15 patch and all is good.

I think I ran #15 and didn't figure out where to look for the changes so I ran #14.

It would be nice to have the option to show anon users the form, but not allow them to fill it in or submit it so they know what they are missing! I am sure there are some forms that need to be kept private so it'd be best to make this an admin option - 'show the uneditable form to these roles'

quicksketch’s picture

Status: Needs work » Fixed

I rerolled #13 for updates, broke out the messages into a second theme function and committed the patch. I also found a solution to the "Register or login" message showing up after logging in. This problem occurred when you visited a webform node to which you didn't have access to make a submission, then login using the Login block on the same page. The node's hook_view() was being fired once as an anonymous user (during the login) then again after successfully logging in. This resulted in the message being displayed to the user once as anonymous then again as a the registered user. While I'm tempted to blame this on a core bug somewhere, we can work around it in Webform.

The final code looks something like this:

  // When logging in using a form on the same page as a webform node, surpress
  // output messages so that they don't show up after the user has logged in.
  if (isset($_POST['op']) && isset($_POST['name']) && isset($_POST['pass'])) {
    $logging_in = TRUE;
  }

  if (!$preview && !$logging_in) {
    theme('webform_view_messages', $node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles);
  }

Anyway, let's test out the latest code now that it's in CVS and reopen this issue for any bugs introduced. It seemed stable enough to go ahead and get it in there.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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