digitalfabrik / integreat-cms

Simplified content management back end for the Integreat App - a multilingual information platform for newcomers
https://digitalfabrik.github.io/integreat-cms/
Apache License 2.0
55 stars 33 forks source link

`TypeError` when non-staff user tries to grant page permissions #2284

Closed timobrembeck closed 1 year ago

timobrembeck commented 1 year ago

Describe the Bug

At the moment, an error occurs when a non-staff member tries to grant additional page permissions

Steps to Reproduce

  1. Login as "management"
  2. Go to page form
  3. Try to add the observer to the authors of the page
  4. See error

Expected Behavior

The observer should be able to edit the page

Actual Behavior

An error occurs:

May 17 10:25:10 ERROR integreat_cms.cms.views.pages.page_actions - argument of type 'ManyRelatedManager' is not iterable
Traceback (most recent call last):
  File "/home/integreat/integreat-cms/integreat_cms/cms/views/pages/page_actions.py", line 548, in grant_page_permission_ajax
    if page.region not in request.user.regions:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'ManyRelatedManager' is not iterable

Additional Information

Traceback ``` May 17 10:25:10 DEBUG integreat_cms.cms.views.pages.page_actions - [AJAX] > wants to grant the permission to edit May 17 10:25:10 ERROR integreat_cms.cms.views.pages.page_actions - argument of type 'ManyRelatedManager' is not iterable Traceback (most recent call last): File "/home/integreat/integreat-cms/integreat_cms/cms/views/pages/page_actions.py", line 548, in grant_page_permission_ajax if page.region not in request.user.regions: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument of type 'ManyRelatedManager' is not iterable May 17 10:25:10 DEBUG integreat_cms.cms.views.pages.page_actions - Ein Fehler ist aufgetreten. Bitte kontaktieren Sie eine:n Administrator:in. ```
svenseeberg commented 1 year ago

Good catch :+1: I only grepped for the region name and did therefore not stumble over this error message. Can/Do we want to add the request URL to all logged errors? :D

timobrembeck commented 1 year ago

Can/Do we want to add the request URL to all logged errors? :D

Normally, this should already be the case, I guess the problem here is that we have a generic try-catch of all exceptions, which caused the less verbose error log message... I guess we should fix this instead :see_no_evil:

https://github.com/digitalfabrik/integreat-cms/blob/a1f4719f7a823374bab8c466e1b52213917a5237/integreat_cms/cms/views/pages/page_actions.py#L606-L609