Please note that this requires the patch at http://drupal.org/node/226853 because _upload_form() hard-codes the "upload files" permission check. However, I've run it past Neil and he said that it qualifies as a bug and will be back-ported. So I figured I'd post this here anyway, although maybe it's best to set postponed.

I had a request from a client to make the permissions more granular on this module, so a user could /only/ upload files to comments, but not necessarily to nodes. Seemed a reasonable request, and also something that might be useful to other people.

Patch forthcoming.

Comments

webchick’s picture

Here we go.

The one kind of wonky thing I've not been able to figure out is why it's not printing errors when you attempt to upload, for example, a .module file when .module files aren't allowed. Otherwise this seems to be working.

Note that because menu permissions are changed, you'll need to clear your cache to test.

Note also that this permission can now be used to *restrict* comment uploading as well, so it gives additional options there.

Upgrade path written but untested.

webchick’s picture

Status: Active » Needs review

Oops.

webchick’s picture

Status: Needs review » Needs work
StatusFileSize
new3.48 KB

Hm.

I had forgotten my hook_form_alter code here, so I've added that back in. However, this still needs work. The form appears, but the upload never quite "takes."

webchick’s picture

Status: Needs work » Needs review
StatusFileSize
new5.66 KB

This appears to be working now, although the fix was not quite as elegant as I would like. I was forced to copy/paste _upload_prepare() to _comment_upload_prepare() just to change the permission check. :( $node is the only thing in scope there, not $form, so I've no way to check $form['#access'] there.

webchick’s picture

Heine pointed out that the copy/pasted _comment_upload_prepare actually takes $comment as an argument, not $node. Updated patch to reflect this.

webchick’s picture

StatusFileSize
new2.52 KB

Also, just so I put it somewhere, here's the simpletest I was using to help me debug this. Feel free to use it if this patch ends up being committed (and if not, it should probably still work if you give the user 'upload files' permissions as well). It's not exhaustive by any means, but it covers this feature.

Needs to be renamed to comment_upload.test and placed in a "tests" subdirectory in the comment_upload module directory.

scottrigby’s picture

Hi,
I wonder if this patch worked (may be my lack of knowledge about patching)
Here's the message I received:

patching file comment_upload.module
Hunk #1 succeeded at 2 with fuzz 1.
Hunk #6 succeeded at 179 (offset 6 lines).
Hunk #7 succeeded at 192 (offset 6 lines).
Hunk #8 succeeded at 378 with fuzz 2 (offset 16 lines).

Is this what's supposed to happen?
thanks for any feedback – it would be good to know if I'm doing something horribly wrong (it'll help me to give you better feedback about the patch)
Thanks!
:) Scott

scottrigby’s picture

Well, I just got my first error in mailhandler module admin area, after installing this module. Not sure if it's the patch, or module itself, or a coincidence, but... well... if it's helpful at all here's the error

user warning: Duplicate entry '6-51' for key 1 query: INSERT INTO term_node (nid, tid) VALUES (51, 6) in /home/basekamp/public_html/dev/includes/database.mysql.inc on line 172.

netaustin’s picture

Status: Needs review » Closed (fixed)

This made it into the D6 version, which is the only version currently maintained.

jeno-1’s picture

excuse me. I think I've missed something.
I loaded this module into my Drupal 6, checked all the setting but I can't see its functionality. It suppose let me upload file into comment right? Does it work with FCKeditor?