mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-22 07:48:13 +00:00
Chore: share one base class for the method-mapped permission classes (#14458)
* Chore: share one base class for the method-mapped permission classes ViewDocumentsPermissions, TrashPermissions, PaperlessNotePermissions and AcknowledgeTasksPermissions each repeated the same has_permission body and disagreed on HTTP methods missing from their perms_map. GlobalPermissionsByMethod now holds that logic once. HEAD is checked against the GET entry and a method missing from the map is denied. The task acknowledge map gains OPTIONS, now requiring change_paperlesstask like POST instead of being open to any authenticated user. The global statistics and system status checks also share their active and authenticated preamble. * Chore: type GlobalPermissionsByMethod.perms_map keys as HTTP methods perms_map accepted any string key, so a misspelled method or a HEAD entry would never match. Keys are now a Literal of the mappable methods, without HEAD, and the map is typed read-only.
This commit is contained in:
1 parent
040ceb8503
commit
b904881472
3 files changed
+91
-50
No files matched your search
@@ -1001,6 +1001,21 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(len(response.data), 10)
|
||||
|
||||
def test_search_autocomplete_head_requires_view_document(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A user without the global view document permission
|
||||
WHEN:
|
||||
- A HEAD request is made for autocomplete
|
||||
THEN:
|
||||
- It is rejected like the equivalent GET request
|
||||
"""
|
||||
self.client.force_authenticate(user=UserFactory())
|
||||
|
||||
response = self.client.head("/api/search/autocomplete/?term=test")
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_search_autocomplete_respect_permissions(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
|
||||
Reference in new issue
Block a user