- Issue created by @softpol
- Status changed to Postponed: needs info
about 1 year ago 12:10am 31 October 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Can we get steps to reproduce here, starting from install Drupal
Thanks
- π§πͺBelgium softpol
Main parameters of the website:
- Drupal-versie: 9.5.11
- Webserver: Apache/2.4.56 (Debian)
- Database versie: 10.5.21-MariaDB-0+deb11u1
- PHP versie: 8.1.21
Steps to produce the problem:
1. create a content type
2. Add a number of fields (e.g. of type "entity reference", text, file) to the content type[so far, so good: all pages of that content type can be visited by an unregistered user]
3. add a field of type "comments" [not sure if this is the correct english field type name, as I translated it from Dutch - the machine name is field_blog_comments]
[an unregistered vistor now gets a blank screen with the message:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function hasPermission() on null in Drupal\comment\CommentManager->forbiddenMessage() (line 160 of core/modules/comment/src/CommentManager.php).]
- π§πͺBelgium softpol
Noβ¦
I created the sandbox https://master-gahutiy2psj6zbxspb1qabbkeov4rt0c.tugboatqa.com.
Then added some taxonomy terms (Auteur, Jaargang and Categorie) and a content type "Jaarboekartikel" with 6 fields (Auteur, Jaargang, Categorie, Nabeschouwing, PDF and Reactie).
Then created /node/1 with that content type. Uploaded a PDF file "Onbeschikbaar.pdf".
Logged out and accessed the page as unregistered user. This succeeds on this sandbox, but on my production site, I get a"The website encountered an unexpected error. Please try again later.
Error: Call to a member function hasPermission() on null in Drupal\comment\CommentManager->forbiddenMessage() (line 160 of core/modules/comment/src/CommentManager.php)." - π§πͺBelgium softpol
How to reproduce:
1. Allow anonymous visitor to "see comments"
2. Create a blog with "open for comments"
3. Add (and approve) a comment
4. Anonymous visitor tries to read the Blog => gets a white screen, with an error message (see above) at the top.The error does not show up when:
- anonymous visitor is disallowed to "see comments"; or
- blog has no comments. - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
I can't reproduce this with a fresh install.
Looking at that code path, it would indicate you're missing the 'Authenticated user' role - i.e. a role with ID 'authenticated'
Is it possible you've deleted this role or it has been deleted as part of a configuration dependency issue?
- π§πͺBelgium softpol
I only have 2 system roles: (admin and anonymous) and 1 user-defined role "bestuurslid" (= board member).
I certainly have not intentionally removed the "authenticated user" role, but some Googling learned me that it may happen by removing a module.But so far, Google could not tell me how to restore a system role (apart from digging directly in the database?). This problem is lingering around for quite some time here, so recent backups will not be very helpfulβ¦
My test server has the same problem. It was loaded with a production image with the backup_migrate module.BTW: there is also another problem that may be related to the above: I cannot assign a role to an existing account. I get a message "Illegal choice authenticated in Rollen element.". Assigning a role when creating an account does work.
- π§πͺBelgium gorkagr
Hi!
For restoring your missing role, you can do either:
- create it via the UI and set the machine name "authenticated"
or
- if you have a second drupal site, get the file from config/sync/user.role.authenticated.yml, copy it into the faulty site, open it with the editor to double check first you dont have any permission you should not, and then run with drush a config import (drush cim) so it is restored.Most likely, if you dont have that role, the problems might come from there
- π§πͺBelgium gorkagr
Taking a look at the code lines of your error:
$this->authenticatedCanPostComments = $this->entityTypeManager ->getStorage('user_role') ->load(RoleInterface::AUTHENTICATED_ID) ->hasPermission('post comments');
the code is trying to load the 'authenticated' user. If you are missing it from your system, then it will be null and hasPermission will fail obviously.
So try to restore the user as I have mentioned before :)
- π§πͺBelgium softpol
I recreated the 'Authenticated user' role on my testserver (via the UI) and the problem indeed looks to be gone. WIll tomorrow do the same on the production server.
Many thanks for helping me with this strange problem. - Status changed to Fixed
12 months ago 7:43pm 3 January 2024 - π§πͺBelgium gorkagr
As it seems to be fixed, we can set the issue as fixed I believe :)
Automatically closed - issue fixed for 2 weeks with no activity.