i really have no better description for this patch than look and see.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eaton’s picture

This a great little patch. Is there any way we can move it into form_render, however? I'd like to see form_render turn into plain old render(), to be used with content arrays, link arrays, and more. the access flag would be a great built-in addition to all of those, not just forms...

In either case, though, a big +1. If necessary, this bit can be moved to the rendering function by a later patch when it's actually needed in non-form settings.

chx’s picture

FileSize
500 bytes

One less line and much better code thanks to Steven.

eaton’s picture

After talking to chx and Steven, I agree -- this is a building task, not a rendering task. +1.

moshe weitzman’s picture

code looks fine. do we have any use case for this in core or contrib? i suppose we could use this on the node form for admin stuff?

killes@www.drop.org’s picture

I think I have a use case: profile forms. These are currently either available or not. With this patch I could make them available based on user role or what I like. Great for social software like Drupal.

chx’s picture

FileSize
499 bytes

timcn is just right. it's value not #value.

kkaefer’s picture

Cool patch! +1 from me. (Applying the patch doesn't make sense as it isn't used anywhere.)

kkaefer’s picture

There is still an issue with this patch: if you set #input is TRUE if the #type is value. Is it possible to inject values via a manipulated POST request despite #access being FALSE?

kkaefer’s picture

I should not move around parts of sentences without checking afterwards if the grammar is still correct ;-)

chx’s picture

FileSize
954 bytes

Now, if access is FALSE you won't even get near POST.

moshe weitzman’s picture

I would like to see one implementation in this patch. perhaps try the path.module field on the node form .. .also, what about fieldsets that have lots of protected fields. does developer ahve to set same access param on all of them. should we do a kind of inheritance like menu.module does? perhaps thats scope creep.

adrian’s picture

very needed, and very obvious =)

+1

adrian’s picture

Status: Needs review » Needs work
   if (isset($form['#access']) && !$form['access']) {

isn't that supposed to be :

   if (isset($form['#access']) && !$form['#access']) {
chx’s picture

Status: Needs work » Needs review
FileSize
955 bytes

I only forgot to repost the patch, it was ready:

chx@toshiba:/var/www/head$ ls -l *acc*
-rw-r--r--  1 chx chx 955 2006-08-09 12:55 access.patch
moshe weitzman’s picture

FileSize
10.65 KB

chx last patch hasd a problem - it was possible to deny access to input fields but the corresponding fieldset was still visible. I moved the deny code up out of the input conditional and it seems to work. furthermore, you may now place #access on the fieldset and the interior fields are all omitted. @chx - please check my form.ionc change.

i went ahead and changed all the node form admin bits to use this mechanism instead of conditional form insertion. The node form is now not person specific, and all elements can be cached once once this one gets in: http://drupal.org/node/38798

I really like this patch, because a module can now use form_alter() to change the #access param to show/hide admin bits as needed. Now that these bits are in the $form definition, the module developer has lots of added power.

chx’s picture

Status: Needs review » Needs work

#8 applies. The children of a denied fieldset must also be denied. Handing down the #access is simple, use the #tree handdown code for example.

moshe weitzman’s picture

Status: Needs work » Needs review
FileSize
11.07 KB

chx informs me that we must pass #access element to children like we do for #tree. patch attached.

kkaefer’s picture

I have some questions on this patch:

  • Why is $posted undefined if #access => TRUE?
  • Why is it still allowed to alter children that have #access => TRUE while the parent denies the access?
kkaefer’s picture

FileSize
11.58 KB

Updated the patch. Please review it. I can't guarantee that it's absolutely right what I've done.

chx’s picture

I did a code review and much like what I see. I hoped we can cut some code... this is great.

webchick’s picture

Status: Needs review » Needs work

No longer applies.

asimmonds’s picture

Status: Needs work » Needs review
FileSize
11.6 KB

Rerolled against HEAD, hopefully I haven't made a mess...

asimmonds’s picture

FileSize
11.37 KB

Second time lucky...

eaton’s picture

FileSize
11.88 KB

Here's the re-rolled version with a three-line addition that makes the #access flag apply to rendering elements as well. This means that node rendering and (if moshe's patch to profiles goes through) profile rendering can use the same #access conventions for display as well.

This is, indeed, very cool.

chx’s picture

FileSize
9.95 KB

Good idea, but then we can move back #access check to #input TRUE elements in the form build where it originally was before Moshe wanted to apply it to fieldsets (which is, of course, a very good idea). Also, there is no need to muck with the #type, as the the denied access element is simply not rendered regards less of type. All is not needed that we make sure that $posted FALSE in the appropriate case. This saves some code.

Dries’s picture

I like this patch, but so far, the only thing it does is removing an if (user_access('foo')) test. Any by doing so, it makes Drupal a little bit slower. So, I'm still interested in one or more killer use-cases that demonstrate that a simple if-test around the form isn't up to the job ...

Any _relevant_ use cases? And why is this better than an if-test?

chx’s picture

FileSize
0 bytes

Now I leave it to Moshe to answer your question, I just submit a fix.

chx’s picture

FileSize
10.06 KB

Hey! Where did that patch go???

eaton’s picture

Dries:

One of the biggest use cases for this is that modules, using alter functions, can *impose* viewing/access restrictions on specific fields even if they are not inherent to the field. By adding conditional #access flags to a form, a node content array, or (with moshe's patch) the fields of a profile, site-specific, user-specific, etc access control schemes could be imposed without hacking core modules.

moshe weitzman’s picture

@Dries - IMO, the issue here is ease of use for developers. In their form_alter hooks, it is much easier to alter an element which is present than one that is not. For example, imagine a site that wants to let a certain class of users alter the sticky flag without 'administer nodes' perm. With this patch, the developer just has to set $form[options][sticky][#access] = TRUE in hook_form_alter(). He knows which element to change just by clicking on the tab in devel.module.

Without this patch, the developer has to inject the whole form element himself which means figuring out where it comes from. Before you know it, we have a frustrated developer. This is about improving learnability for developers. There are *many* developers who are good enough to alter an array element but not good enough to grok form submission particulars.

eaton’s picture

It's also important to note that this makes the presence or absence of a particular form element, field, etc something that is directly died to *user access* rather than a particular workflow. There are place, for example, that we conditionally build chunks of form based on whether the screen is in edit or add mode, whether a particular parent record has been chosen, etc, in addition to user access.

By making the structure of the forms the same regardless of user access -- but then embedding access info in the form itself -- we reduce the risk of confusion and bizarre form-building contortions in those complicated cases.

That's my feeling, at least. :)

webchick’s picture

+1 to the use case outlined by moshe @ #30

To use a specific example, a recent client wanted to control the order that a few nodes appeared on the front page. The quickest and easiest way to do this was to simply render the "Authored On" field and let users change the value. However, there are access controls hard-coded in node.module to prevent access to this field by anyone other than node administrators. So I had to make a new field with a custom submit function to update the $node->created date after the fact. Not the most intuitive thing.

With access controls on form elements, this would've been a one-liner.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

i tried to inject a custom path when i was not permissioned to do so. my request was properly ignored. Various forms are behaving as expected ... RTBC.

Dries’s picture

Committed to CVS HEAD. Thanks.

webchick’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)