mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-26 01:16:16 +00:00
Enhancement: bulk delete objects (#5688)
This commit is contained in:
@@ -717,7 +717,7 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
GIVEN:
|
||||
- Existing objects
|
||||
WHEN:
|
||||
- bulk_edit_object_perms API endpoint is called
|
||||
- bulk_edit_objects API endpoint is called with set_permissions operation
|
||||
THEN:
|
||||
- Permissions and / or owner are changed
|
||||
"""
|
||||
@@ -733,11 +733,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
}
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id],
|
||||
"object_type": "tags",
|
||||
"operation": "set_permissions",
|
||||
"permissions": permissions,
|
||||
},
|
||||
),
|
||||
@@ -748,11 +749,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.assertIn(self.user1, get_users_with_perms(self.t1))
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.c1.id],
|
||||
"object_type": "correspondents",
|
||||
"operation": "set_permissions",
|
||||
"permissions": permissions,
|
||||
},
|
||||
),
|
||||
@@ -763,11 +765,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.assertIn(self.user1, get_users_with_perms(self.c1))
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.dt1.id],
|
||||
"object_type": "document_types",
|
||||
"operation": "set_permissions",
|
||||
"permissions": permissions,
|
||||
},
|
||||
),
|
||||
@@ -778,11 +781,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.assertIn(self.user1, get_users_with_perms(self.dt1))
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.sp1.id],
|
||||
"object_type": "storage_paths",
|
||||
"operation": "set_permissions",
|
||||
"permissions": permissions,
|
||||
},
|
||||
),
|
||||
@@ -793,11 +797,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.assertIn(self.user1, get_users_with_perms(self.sp1))
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id],
|
||||
"object_type": "tags",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user3.id,
|
||||
},
|
||||
),
|
||||
@@ -808,11 +813,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.assertEqual(Tag.objects.get(pk=self.t2.id).owner, self.user3)
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.sp1.id],
|
||||
"object_type": "storage_paths",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user3.id,
|
||||
},
|
||||
),
|
||||
@@ -827,7 +833,7 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
GIVEN:
|
||||
- Existing objects
|
||||
WHEN:
|
||||
- bulk_edit_object_perms API endpoint is called with merge=True or merge=False (default)
|
||||
- bulk_edit_objects API endpoint is called with set_permissions operation with merge=True or merge=False (default)
|
||||
THEN:
|
||||
- Permissions and / or owner are replaced or merged, depending on the merge flag
|
||||
"""
|
||||
@@ -848,13 +854,14 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
|
||||
# merge=True
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id],
|
||||
"object_type": "tags",
|
||||
"owner": self.user1.id,
|
||||
"permissions": permissions,
|
||||
"operation": "set_permissions",
|
||||
"merge": True,
|
||||
},
|
||||
),
|
||||
@@ -877,12 +884,13 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
|
||||
# merge=False (default)
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id],
|
||||
"object_type": "tags",
|
||||
"permissions": permissions,
|
||||
"operation": "set_permissions",
|
||||
"merge": False,
|
||||
},
|
||||
),
|
||||
@@ -900,7 +908,7 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
GIVEN:
|
||||
- Objects owned by user other than logged in user
|
||||
WHEN:
|
||||
- bulk_edit_object_perms API endpoint is called
|
||||
- bulk_edit_objects API endpoint is called with set_permissions operation
|
||||
THEN:
|
||||
- User is not able to change permissions
|
||||
"""
|
||||
@@ -909,11 +917,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
self.client.force_authenticate(user=self.user1)
|
||||
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id],
|
||||
"object_type": "tags",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user1.id,
|
||||
},
|
||||
),
|
||||
@@ -928,17 +937,18 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
GIVEN:
|
||||
- Existing objects
|
||||
WHEN:
|
||||
- bulk_edit_object_perms API endpoint is called with invalid params
|
||||
- bulk_edit_objects API endpoint is called with set_permissions operation with invalid params
|
||||
THEN:
|
||||
- Validation fails
|
||||
"""
|
||||
# not a list
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": self.t1.id,
|
||||
"object_type": "tags",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user1.id,
|
||||
},
|
||||
),
|
||||
@@ -949,7 +959,7 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
|
||||
# not a list of ints
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": ["one"],
|
||||
@@ -964,11 +974,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
|
||||
# duplicates
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [self.t1.id, self.t2.id, self.t1.id],
|
||||
"object_type": "tags",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user1.id,
|
||||
},
|
||||
),
|
||||
@@ -979,11 +990,12 @@ class TestBulkEditObjectPermissions(APITestCase):
|
||||
|
||||
# not a valid object type
|
||||
response = self.client.post(
|
||||
"/api/bulk_edit_object_perms/",
|
||||
"/api/bulk_edit_objects/",
|
||||
json.dumps(
|
||||
{
|
||||
"objects": [1],
|
||||
"object_type": "madeup",
|
||||
"operation": "set_permissions",
|
||||
"owner": self.user1.id,
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user