Problem/Motivation
After upgrading nodeaccess from 1.4 to 1.6, the nodeaccess_grants_form does not contain the table with the roles selected in the module's settings. A notice is displayed:
Notice: Undefined index: values in nodeaccess_grants_form() (Line 223 of sites/all/modules/nodeaccess/nodeaccess.module).
Before the update, the code in nodeaccess_grants_form() was different. The allowed roles for the grant tab where selected first, then the ones already assigned to the node where added (left join).
I'm not sure how this is supposed to work with the new code. nodeaccess_get_grants() only gets the grants that are already assigned to the node. theme_nodeaccess_grants_form() seems to be responsible for building the table, but $form['rid'] is empty so nothing happens here.
Am I doing something wrong? Updated the permissions after the update and ran updb...
Steps to reproduce:
- Go to the "Grants" tab on any node (i.e. /node/1234/grant ).
- You'll find that the roles table simply isn't there.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#16 | nodeaccess-grant_form_empty-3032070-16.patch | 2.18 KB | ckng |
| |||
#12 | nodeaccess-grants-form-empty-3032070-12.patch | 1.52 KB | LeDucDuBleuet |
|
Comments
Comment #2
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedI noticed the same here and I believe the problem is in the nodeaccess_get_grants() function.
This query only returns existing roles access, we are missing the roles without access that are used to construct the table.
I can see a few things wrong on this query but I could not make it work in this style...
In the attached patch, I am simply using the query from the previous module version and it works well.
Is there some advantages to use one style of query versus another in this case? More performance? Or is it a personal preference?
As for the undefined index notice itself, I suggest we use :
Thank you.
Comment #3
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedI believe the priority of this bug report should be set to major.
Please set it back to normal if this is not the case.
Thank you.
Comment #4
Chase. CreditAttribution: Chase. commentedI tried staying closer to the current code. The attached patch should have the same affect as the one in #2.
I'm unsure, though, if changing nodeaccess_get_grants() like this creates problems for other callers other than nodeaccess_grants_form()
Comment #6
Chase. CreditAttribution: Chase. commentedReuploaded the patch file after testing failed. Sorry, first time contributing.
Comment #7
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commented@Chase Did you test your patch? I just did and it fails to return the current access status for the roles.
If I may ask, why would we prefer this style of query which was introduced only in version 1.6?
What's wrong with the previous query which was working perfectly? Do we absolutely need to convert it to the other style?
Personally, I will always prefer the one that is working! ;-)
Anyway, my proposed patch is working for anybody looking for a quick fix.
And maybe the maintainer can decide what to do to fix this for good?
I also looked into potential issues for the other callers of nodeaccess_get_grants() and we are all good in that regard in my opinion.
Thank you.
Comment #8
Chase. CreditAttribution: Chase. commentedTo be honest, I only checked the resulting SQL query and the results, which looked fine. I personally don't like one query style better than the other, just thought changing less code might be preferred.
Comment #9
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedOk then, in the meantime, I suggest we hide the non-working patch to speed up the process. Thank you for your time.
Comment #10
jastraat CreditAttribution: jastraat at Technivant commented> If I may ask, why would we prefer this style of query which was introduced only in version 1.6?
I'm guessing this style of query was used for "compatibility issues with SQL queries regarding PostgreSQL"
However I don't know enough about PostgreSQL to determine if the change to nodeaccess_get_grants() was truly necessary.
Comment #11
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedOk I finally got the query working using the same style as in 1.6! :-)
New patch attached needs review.
Thank you!
Comment #12
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedAfter some more testing, I realized this was still working only for nodes with custom permissions already set.
As it turns out, the first "one line" query was always working simply because it was looking in the right table not because of its style! :-)
We have to look into node_access table instead of the nodeaccess table used in the new query with the db_select.
Also, the conditions have to be inside the leftjoin, if not, we get an undesired where clause like this:
And we want this to get the same results as the original query:
New patch attached, needs review.
Thank you!
Comment #13
luenemannPatch looks good.
Thank you!
Comment #14
caspervoogt CreditAttribution: caspervoogt commentedpatch #12 works great. Thanks!
Comment #15
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commentedComment #16
ckngRole alias is optional, role form is not displaying due to the missing $grant->name. Attached patch resolve the case without alias.
BTW, shouldn't alias be check_plain'ed in all places?
Comment #17
BBC#16 solved the problem for me. Thanks @ckng!
Comment #18
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commented@ckng You are absolutely right. I did not notice this since the
is also removed in the patch for issue #2140819.
RTBC
Thank you
Comment #19
cindyr CreditAttribution: cindyr commented#16 worked for me too
Comment #20
Kevin Morse CreditAttribution: Kevin Morse commented#16 works for me also.
Comment #21
phil@pdale.net CreditAttribution: phil@pdale.net commentedAfter I applied #16 all existing roles added prior to the nodeaccess 1.6 update show in the nodeaccess_grants_form. However, If you add a new role after the update it doesn't appear.
Comment #22
phil@pdale.net CreditAttribution: phil@pdale.net commentedIn addition, if you search for an individual user you get the error:
Notice: Undefined index: uid in nodeaccess_grants_form() (line 239 of /home/lucaster/public_html/drupal/sites/all/modules/nodeaccess/nodeaccess.module).
Warning: array_keys() expects parameter 1 to be array, null given in nodeaccess_grants_form() (line 239 of /home/lucaster/public_html/drupal/sites/all/modules/nodeaccess/nodeaccess.module).
Comment #23
LeDucDuBleuet CreditAttribution: LeDucDuBleuet as a volunteer commented@phil@pdale.net Yes, there are many bugs to fix in version 1.6, please see : #3033025: Nodeaccess: Multiple issues with version 1.6
Comment #24
ssaccone CreditAttribution: ssaccone commentedHi, we just updated to Nodeaccess 1.6 (core 7.64) and now we can't add new content: we get "Undefined index...line 223" whenever we click the "Grant" tab, so pages can't be made public (anonymous can view). I assume the issue you're working on here is the root cause, is that right? Is there a workaround? Perhaps configure Nodeaccess to make all new pages public by default? Or should we just wait for the new version? Thanks!
Comment #25
alison#16 worked great for us -- and actually, even when I added a role to "allowed roles", it was reflected on the "grants" tab of individual nodes.
@phil@pdale.net Just a thought -- did you check whether the role you enabled via "allowed roles" was also enabled for the content type of the node you're looking at? (i.e. /admin/config/people/nodeaccess#edit-department-landing where "department-landing" is your ctype machine name)
Comment #26
D_Wicz CreditAttribution: D_Wicz commented#16 did work us. Tested and working for our site.
Thank you LeDucDuBleuet and ckng.
Comment #27
troybthompson CreditAttribution: troybthompson commented#16 worked when it was empty, but then I added another role and the list doesn't update.
Comment #28
danrod#16 worked for me too, thanks for the patch, but I am having the same issue mentioned on comment #27
Comment #29
alisonComment #30
alisonComment #31
alisonComment #33
alisonFor the "added another role and the list doesn't update" problem in #27: see #3032449: Change to nodeaccess_get_role_aliases() prevents adding new allowed roles