Save default value when user has no permission to edit the field

Amitaibu - November 16, 2008 - 10:39
Project:Content Construction Kit (CCK)
Version:6.x-3.x-dev
Component:content.module
Category:feature request
Priority:critical
Assigned:Unassigned
Status:closed
Description

Scenario:
1. Create text field called state with Pending, Complete, Error.
2. Set field to be required.
3. Set field's default value to pending.
4. Allow user to view field_state but not edit.
5. Create node - field_state isn't set.

This might be by design, but I think it's a bug.

#1

Amitaibu - November 16, 2008 - 10:48
Status:active» needs review

And here's the patch.

AttachmentSize
334945_set_required_field_if_not_editable.patch 501 bytes

#2

yched - November 16, 2008 - 15:54
Status:needs review» needs work

Doesn't work like that. Default values only come into play on node *creation*. The default value shouldn't override the existing value on node *edit*
Plus your patch doesn't get the actual default values correctly.

If we want this behavior (which I'm not sure we do, might need some consideration), the if (!$access) { code branch needs to be moved down the // Prepare the values to be filled in the widget part.

#3

yched - November 16, 2008 - 15:57
Title:Required field isn't set when user has no permission to edit» Save default value when user has no permission to edit the field
Category:bug report» feature request

Plus I don't think 'required' status is actually related.

#4

Amitaibu - November 18, 2008 - 09:17
Status:needs work» needs review

Moved !$access down.

My use case is that, using the rules module, I'm preforming an action upon node save according to a certain field value, that the user can view but can't edit.

AttachmentSize
334945_set_field_if_no_access_and_created_2.patch 1.28 KB

#5

aquila - November 27, 2008 - 07:25

I'm interested in this as well. Use case: user submits subscription and required payment field is set to not okay by default. Only staff can update this to default. The current situation creates an empty required field.
So I very much support fixing this, if possible.

#6

Alan D. - November 28, 2008 - 00:16

+1 It is a pain having to add another check on every query for NULL when the field should only be set to the default.

Eg: WHERE xxx_field IN (1,2,3) becomes WHERE (xxx_field IN (1,2,3) OR xxx_field IS NULL)

#7

RoboPhred - December 2, 2008 - 17:45

#8

yched - December 2, 2008 - 17:52

Right, I marked that 'old' one as duplicate.

#9

aquila - December 8, 2008 - 11:56

Is there any update on this problem? What would be a good way to patch around this?

#10

Alan D. - December 9, 2008 - 09:26

I took a two step approach to this in a project where it was vital to ensure that the defaults were set.

Firstly, define up a custom action for Rules. Since the logic was complex, I defined a new action to set the default for each content type.

Then I added a backup hook_cron to blanket set all required fields that were NULL, just in case...

#11

BenKewell - February 8, 2009 - 20:50

subscribing
it's much more reasonable to make the unprivileged field gets its default value
which's much better for many applications
looking forward the issue can be fixed in upcoming release

#12

finlaycm - March 5, 2009 - 19:06

subscribing

#13

liquidcms - April 2, 2009 - 07:03

subscribing... i posted same issue against cck_field_perms back in Dr5 days about a year ago. Seems like issue still persists with Dr6 field perms built into CCK.

Not sure the use case where user wouldn't want field defaults to take precedence over field access privileges. Every case i have come across, if i define a field to have a default - i REALLY do want that to be the default.

In case if there is a valid case where you DON'T want defaults to be your defaults based on access rights; then maybe some sort of checkbox with default to override perms?

#14

Justin W Freeman - April 16, 2009 - 22:16

I have made a little bit of a change to the patch in #4 that I find makes it work a bit better (the patch in #4 skipped access control when editing an existing node).

This patch is against the current 6.x-2.x-dev version (2009-Apr-16).

AttachmentSize
334945_set_field_if_no_access_and_created_3.patch 1.7 KB

#15

ailgm - May 7, 2009 - 13:39

subscribing

#16

moshe weitzman - June 25, 2009 - 01:33
Priority:normal» critical

I think #14 is a worthy patch. Still needs some review before commit. I am upping priority so it does not get missed when a D7 port is made.

#17

yched - June 25, 2009 - 11:26

Note that 'save default value on object create' is already in D7 with a different approach, which also accounts for programmatic node creation (node_save).
Backporting this would require some refactoring, so I personally won't go there.

Patch #14 looks fine, but I don't think I see the need for the additional

+      if (empty($node->nid)) {
+        $value = $items;
+      }
+      else {
+        $value = $node->$field_name;
+      }

Could someone test the attached patch and see if it works ?

AttachmentSize
cck_set_field_if_no_access-334945-17.patch 2.1 KB

#18

tpainton - June 25, 2009 - 16:42

UG. I have had this problem now for about 2 years. I am on drupal 5.. Any chance this can be backported? I have similar situation. Customers submit an order. The order has field_status "Received" or "Shipped". I don't want users mucking with this for obvious reasons so I used cck_field_perms to hide the field on the node creation form. Problem is, the default value of "received" isn't set so I have to go back through all the orders every day and set them to "Received". It takes a lot of time. Would be great if they were set to "received" by default. I can't upgrade to D6 as too many modules I uses just are not supported, namely Paypal Node.

I guess if it's not going to happen, I'll use a workflow..

#19

WorldFallz - June 25, 2009 - 16:46

Tested patch in #17 with current d6 dev code, works as expected. excellent!

#20

yched - June 25, 2009 - 22:11
Version:6.x-2.x-dev» 6.x-3.x-dev
Status:needs review» patch (to be ported)

Committed to 6.x-2.x branch.

Here's the same patch rolled for the 3.x branch, I don't think it should break anything with multigroups, but I'll let Markus chime in.
(I'm not sure what happens with multigroups if one of the fields is hidden by access permissions, BTW)

AttachmentSize
cck_set_field_if_no_access-334945-20.patch 2.09 KB

#21

yched - June 25, 2009 - 22:32

Forgot to re tpainton #18: No, this won't happen in D5. CCK D5 is feature-closed. With all the work on Field API in core, adding, debugging and maintaining features in 3 branches for 3 core versions is simply not doable. Unless someone steps up to be the CCK D5 maintainer.

#22

tpainton - June 26, 2009 - 14:36

I totally understand. Thanks for what you have already done.

#23

markus_petrux - June 28, 2009 - 04:43

Subscribing so I don't forget this issue.

PS: I just came back from a little break (just a week on holidays) and I'm still landing...

#24

markus_petrux - July 1, 2009 - 18:42
Status:patch (to be ported)» fixed

Committed to 6.x-3.x branch.

Indeed, the multigroup was in need of a minor adjustment during the rendering process of the form. The fix was pretty simple.

The multigroup (and also fieldgroup) modules check for the #access property of the form elements, but in the case of multigroups this also needed to ignore the fields of type 'value' during the rendering process. Otherwise, an empty row was rendered for each *hidden* field.

#25

electricmonk - July 14, 2009 - 06:57

I'd really like to see a full solution to this issue for D6 for either use of CCK (programmatic / interactive node creation).

#26

zdean - July 16, 2009 - 14:12

subscribe

#27

System Message - July 30, 2009 - 14:20
Status:fixed» closed

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

#28

droetker - October 23, 2009 - 22:08

I'd like to subscribe here too.
I've searched many, many other modules to get that functionality - bit there is no other way.
Please, could you fix that?
(I would help - but I don't know PHP at all, and Drupal coding even less)

#29

WorldFallz - October 24, 2009 - 13:10

huh? This issue is closed-- if you had bothered to read it you would know the fix has been committed to both the 2.x version (#20) and the 3.x version (#24).

#30

droetker - October 24, 2009 - 18:55

Yes, I bothered to read all the posts. But despite the "fixed" status I STILL have the problem here, with a fully updated drupal 6.14, CCK 2;
I have a date field that has a default value, and only admins can edit/view it due to permissions.
If an admin creates the node, the default date (today) is saved, but if another one creates the node, he doesn't see the field - and the date value afterwords is empty in the view.

So unless I didn't do anything horribly wrong I suppose this bug is not fixed?
(Please correct me if I am wrong)

#31

droetker - October 24, 2009 - 19:01

Forgot to mention - the normal user can view the field, but not edit it.
Despite that it gets NOT filled out.

#32

WorldFallz - October 24, 2009 - 19:05

The fact still remains that this issue has been committed and closed. Besides the fact commenting on a closed issue is useless, and the fact that no one has reopened this issue in the 4 months since the fix was committed (with over 100k cck users, someone would have reopened it if it really wasn't truly fixed), the fact that you have a problem with a date field means you should probably first post to the date issue queue.

#33

droetker - October 24, 2009 - 22:49

You're right - I must admit that the field I have the problem with is a date field.
I will post it there.
Thanks anyway.

 
 

Drupal is a registered trademark of Dries Buytaert.