I am experiencing an issue with field permissions set through CCK. Even though I don't see a field, I am given an error upon submission that the field has not been filled in. I previously thought the issue had something to do with CCK permissions handling but that might not be the case because the module for setting permissions seems to be very straightforward.
The original issue is posted as #792814: Possibility of setting a field permission on creating a node.
Scenario
I have a picture node which contains a date field and an ImageField. However, there are several user roles that I would like to restrict while creating picture nodes. For my use, I would like to have an unlimited size, for other users to set limits lets say to 800x600.
I created 2 ImageField fields. One (unrestricted dimensions) is visible to me, the other one (restricted) is visible to others. In both cases, they are set as "required".
All seems to go fine till the point when I want to submit the node. Then, even though I don't see the other field (the restricted one), I am warned that I have not uploaded a picture (through the field I don't see). It does not seem logical to me that I can set a restriction on editing fields but not on creating them.
Even though I am using the ImageField module in this case, it is very likely to appear in the FileField module as well as it is the base module for ImageField.
Am I doing something wrong here?
Details
- CCK version: 6.x-2.6
- ImageField version: 6.x-3.3
- permissions for files and tmp: 775
- download method: public
- imagefield config: As for this issue, both fields are set as required with only 1 acceptable file each. One has set filesize and dimensions limits, the other one does not. I am also using the FileField Paths module.
- expected result: I expect to upload an image through the visible field only while the other (not visible one) field does not bother me about not having uploaded anything
- unexpected result: I receive an error from the not visible field that I have not uploaded a file
- steps to reproduce: Set a new content type with 2 imagefields in it. Have both set as required. Not install the CCK field permissions module and have one field visible for one user role, the other visible for another role. Now as one field is invisible for one of the role, upload an image into the visible field and try to submit the node. You should receive an error that the field (the hidden one) is required to have an image uploaded.
Comment | File | Size | Author |
---|---|---|---|
#9 | filefield_required_fix_01.patch | 562 bytes | jrockowitz |
#6 | filefield_required_fix.patch | 553 bytes | franz |
#4 | filefield_widget.inc_.patch | 504 bytes | kunago |
Comments
Comment #1
quicksketchYou're not doing anything wrong, sounds like a valid bug (or more like a conflict) between FileField and Content Permissions modules. Drupal core itself doesn't handle required fields properly for file uploads, so FileField implements its own validation to correct this. However it sounds like it does not properly handle the situation where Content Permissions is hiding a required file field.
I'm moving this over to FileField, since it's actually responsible for the validation that you're experiencing.
Comment #2
locomo CreditAttribution: locomo commentedsubscribe
Comment #3
mikebell_ CreditAttribution: mikebell_ commentedsubscribe
Comment #4
kunago CreditAttribution: kunago commentedI seem to have solved the issue modifying the "filefield_node_form_validate" function. Check whether it works for you as well.
Comment #5
Mariano CreditAttribution: Mariano commentedIt's not validating the submitted file even though it's a valid file.
Comment #6
franzRerolled patch, seems to work fine.
@Mariano, didn't understand what you meant...
Comment #7
quicksketchThanks guys, I'll put this in next time I'm working on FileField.
Comment #8
quicksketchSweet thanks franz, tested and it worked great for me. Still validates when it's supposed to and skips validation if you don't have access to the field.
Comment #9
jrockowitz CreditAttribution: jrockowitz commentedKunago and Franz, when I tested your patch the $type_name variable was not defined.
So I change $type_name to $field['type_name'] and your patch works.
Changed
if (!$valid && $field['required'] && filefield_edit_access($type_name, $field_name))
- to-
if (!$valid && $field['required'] && filefield_edit_access($field['type_name'], $field_name))
Attached is an updated copy of your patch.
Comment #10
franzThat's true, don't know how I missed this
Comment #11
quicksketchThanks jrockowitz. Committed your fix.