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

  1. CCK version: 6.x-2.6
  2. ImageField version: 6.x-3.3
  3. permissions for files and tmp: 775
  4. download method: public
  5. 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.
  6. 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
  7. unexpected result: I receive an error from the not visible field that I have not uploaded a file
  8. 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.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Title: CCK field permissions are not properly handled » Required file fields not validated properly when Content permissions hide the field
Project: ImageField » FileField

You'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.

locomo’s picture

subscribe

mikebell_’s picture

subscribe

kunago’s picture

Status: Active » Needs review
FileSize
504 bytes

I seem to have solved the issue modifying the "filefield_node_form_validate" function. Check whether it works for you as well.

Mariano’s picture

It's not validating the submitted file even though it's a valid file.

franz’s picture

Version: 6.x-3.3 » 6.x-3.7
Status: Needs review » Reviewed & tested by the community
FileSize
553 bytes

Rerolled patch, seems to work fine.

@Mariano, didn't understand what you meant...

quicksketch’s picture

Thanks guys, I'll put this in next time I'm working on FileField.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Sweet 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.

jrockowitz’s picture

Kunago 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.

franz’s picture

Status: Fixed » Needs review

That's true, don't know how I missed this

quicksketch’s picture

Status: Needs review » Fixed

Thanks jrockowitz. Committed your fix.

Status: Fixed » Closed (fixed)

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