issue when user is trying to refresh password:
I have a vocabulary “visibility_users_groups”
In contents: a field is based on this vocabulary entity.
In user profile: a field is also based on this same vocabulary entity.
I have installed “Access Policy” module
and added an acces policy (entity type = content; Policy type = groups)
and added a rule consequently, so that only allowed users can see allowed content
It works as expected :-), but...
I recently tried the "refresh password" process for a test user.
The user receives an email with link to "one shot" profile edit page.
This link drives him to a page with "refresh password" button.
When he clicks the button, instead of landing on the profile edit page he lands on error page where Access Policy seems to be the culprit (see attached file)
I spent a pair of hours trying to solve this issue, but without success and suddenly it works again, but I dont know what makes the difference (I tried so many things that I am lost: rebuilding rights, changing rule settings, uninstall/reinstall module, delete cache,.....) and this is annoying.
A bug? A random behaviour?
Any idea?
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | Field access.png | 32.35 KB | gilbertdelyon |
| #14 | user fields - form.png | 34.1 KB | gilbertdelyon |
| #14 | user fields.png | 42.66 KB | gilbertdelyon |
| #11 | 3419046-undefined-context-error.patch | 688 bytes | partdigital |
| #7 | access policy config.txt | 1.34 KB | gilbertdelyon |
Comments
Comment #2
gilbertdelyon commented30 minutes later, that's me again, and again it doesn't work (same error)
So, I rebuilt rights, and now it works.
For how long?
Comment #3
partdigital commentedH gilbertdelyon
Nice catch! Unfortunately I haven't been able to reproduce it either. Though, looking at some code I can see how theoretically it could happen.
This can happen when AccessRule::getValue(); is called before the context is set.
For example, it should happen like this:
If it never calls
setContextExecutoinContextit could trigger that error. Are you able to debug with xdebug and isolate where$access_rule->getValue();is being called in this context?Comment #4
gilbertdelyon commentedThanks for this prompt answer.
This morning it works again, without changing any thing in the settings. But I am not confident an I will test again periodically
I will do my best and help you and find the culprit event, but I am not a professional coder, only a part time hobbyist.
Another thing I noticed:
When Acces Policy module is running,
and when user opens the "edit profile" form
he doesn't see the “visibility_users_groups” field.
When the admin opens the "user profile" form he can see it.
This is good, because only the admin can set the user groups,
but I dont know if it's the normal behaviour.
And may be this is the reason of the issue?
Comment #5
gilbertdelyon commentedXdebug? I am not at all familiar with this tool. Seems it needs a learning curve. Sorry I will not be able to help in this way.
But in the meantime I found a way to trap the error more precisely, at least on my production site.
I explain how to:
Initial status:
A user, named “testuser”, tries to refresh his password. It works!
Repeat again a couple of times. Still works. So far so good.
Disconnect “testuser”
Connect as “admin”
Go to “admin/config/performances” and clear the cache.
(Notice: cache lifetime is set to 15 minutes on my site, may be not the best value?)
Disconnect “admin”
Now “testuser” tries again to refresh his password,
and BINGO! Here is the error in line 256.
Disconnect “testuser”
Try again to refresh password. It works!
Hope it can help.
Comment #6
partdigital commentedThanks for the step-by-step, that is very helpful!
Unfortunately I still can't reproduce it. Would you be willing to share an export of the access policies? Maybe there's something about the configuration that I'm not thinking of.
1. Go to /admin/config/development/configuration/single/export
2. Select Configuration Type > Access Policy
3. Select the access policy you want to export.
Comment #7
gilbertdelyon commentedSee attached file
Thanks in advance for your help
Only for memoty!
Something strange:Access is controled as expected in my main site with this config, but...
There is probably someting wrong in it because if I import it in a clone of the main site, and then delete cache and rebuilt rights, access control is not working at all.
An hour later:
if I import this config in a clone of the main site it works, but ONLY for new content.
I have rebuilt rights (admin/report/admin dashboard/rebuilt rights) but It doesn't work for existing content . I have to edit and resave save existing content to make Access Policy work
15 minutes later
I just remember the solution in this thread. !!
Comment #8
gilbertdelyon commentedMy site is running a custom subtheme of Bartik.
This subtheme has now been running for 2 years without any issue.
I can reproduce the error very easily
I just made some tests with native Bartik and also with Olivero, and...
In these themes I cannot reproduce the error.
So, the error could come from
- the fact I am using a subtheme
- or from my custom code
I will investigate and keep you informed.
Comment #9
gilbertdelyon commentedresult of investigations:
While running Bartik: I cannot reproduce the error
While running a subtheme of Bartik: I can easily reproduce the ERROR "line 256"
I have removed nearly everything from my subtheme so that it is now as simple as possible with only 2 files:
bartiksub.info.yml
bartiksub.theme
So, my conclusion is that the error is coming from the fact that I am using a subtheme.
What do you think?
Comment #10
partdigital commentedI added a new subtheme based on bartik but unfortunately I still couldn't reproduce it. Very mysterious.
My hunch is that it's related somehow to hiding the fields on the user's profile. I would try disabling the code and see if it stops happening.
Start with
access_policy_entity_field_access()inaccess_policy.moduleand work from there.Also, what over fields do you have on the user?
Comment #11
partdigital commentedHere is a patch to address the fatal error. I'm still curious why this would be called in this context but AccessRuleArguments are designed to work without the context so it's a good thing to add anyway.
Let me know if this resolves your issue.
Comment #12
gilbertdelyon commentedNOTICE: This post was written before your sent the pach
You are on the right way!
This is what I did:
in
access_policy.module(line 327This is the result:
bartik & bartiksub ("empty")
No more error. :-)
But of course the field is now displayed in user form, and this is not good ( I could hide it in css, bad practice )
Attach:
Crop of user fields
Crop of user fields form
Comment #13
gilbertdelyon commentedThe patch seems to work in my test site. :-))
I will test in production site and keep you informed.
I appreciate your prompt and efficient assistance. Thank you so much.
Comment #14
gilbertdelyon commentedComment #15
partdigital commentedAre you by chance restricting taxonomy terms with an Access Policy? In particular, Groupes Utilisateurs? If so, that may explain why
CurrentUser:;getValue();is being called in the first place.Comment #16
gilbertdelyon commentedNo, Acces Policy only uses "Groupes Utilisateurs" taxonomy terms for content acces control, but doesn't control acces to terms.
Comment #17
gilbertdelyon commentedThat's me again.
May be I was wrong in my privious post.
I dont intend to restrict access to "Groupes Utilisateurs" taxonomy terms, but may be I did it by mistake, or insufficient knowledge of Access Policy settings (there is a learning curve for me because translation in french is only partial and I still need to understand many things)
See attached file.
Field access.png
So, I just made a test after selecting "Libre" (free) instead of "Droits" (Rights).
It doesn't change the behaviour. Only the patch does a good job!
I tested it in production site and it also works.
Comment #18
partdigital commentedGlad to hear the patch worked! I'll commit that and then mark this as resolved :D
I was referring to something along the lines of Step #7 of the Restrict Content by Department tutorial. However, it sounds like you're not doing that.
Comment #19
gilbertdelyon commentedI can confirm-
- There is no "taxonomy" access rule in my settings
- Only one "content" access rule
Comment #20
partdigital commentedComment #22
partdigital commentedComment #23
gilbertdelyon commented