Skip to content

Commit

Permalink
OP-2163: added possibility to configure check for delete operation
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Nov 21, 2024
1 parent 97851f1 commit 7a60398
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions individual/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"check_individual_delete": True,
"check_group_individual_update": True,
"check_group_create": True,
"check_group_delete": True,
"individual_schema": "{}",
"individual_accept_enrolment": "individual_service.create_accept_enrolment_task",
"validation_import_valid_items_workflow": "individual-import-valid-items",
Expand Down Expand Up @@ -61,6 +62,7 @@ class IndividualConfig(AppConfig):
check_individual_delete = None
check_group_individual_update = None
check_group_create = None
check_group_delete = None
python_individual_import_workflow_group = None
python_individual_import_workflow_name = None
individual_schema = None
Expand Down
6 changes: 5 additions & 1 deletion individual/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ def _mutate(cls, user, **data):
if ids:
with transaction.atomic():
for identifier in ids:
service.delete({'id': identifier})
obj_data = {'id': identifier}
if IndividualConfig.check_group_delete:
service.create_delete_task(obj_data)
else:
service.delete(obj_data)

class Input(OpenIMISMutation.Input):
ids = graphene.List(graphene.UUID)
Expand Down
7 changes: 6 additions & 1 deletion individual/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ def __init__(self, user, validation_class=IndividualDataSourceValidation):
super().__init__(user, validation_class)


class GroupService(BaseService, CreateCheckerLogicServiceMixin, UpdateCheckerLogicServiceMixin):
class GroupService(
BaseService,
CreateCheckerLogicServiceMixin,
UpdateCheckerLogicServiceMixin,
DeleteCheckerLogicServiceMixin
):
OBJECT_TYPE = Group

def __init__(self, user, validation_class=GroupValidation):
Expand Down
28 changes: 28 additions & 0 deletions individual/tests/group_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,34 @@ def test_update_group_individuals(self):
# self.assertFalse(individual2.id in individual_ids)
self.assertTrue(individual3.id in individual_ids)

def test_delete_group_with_individual(self):
individual1 = self.__create_individual()
individual2 = self.__create_individual()
individual3 = self.__create_individual()
payload_individuals = {
'code': str(datetime.now()),
'individuals_data': [
{'individual_id': str(individual1.id)},
{'individual_id': str(individual2.id)},
]
}
result = self.service.create(payload_individuals)
self.assertTrue(result.get('success', False), result.get('detail', "No details provided"))
uuid = result.get('data', {}).get('uuid', None)
query = self.query_all.filter(uuid=uuid)
group = query.first()
self.assertEqual(query.count(), 1)
self.assertEqual(str(group.id), uuid)
group_individual_query = self.group_individual_query_all.filter(group=group)
self.assertEqual(group_individual_query.count(), 2)
delete_payload = {'id': uuid}
result = self.service.delete(delete_payload)
self.assertTrue(result.get('success', False), result.get('detail', "No details provided"))
query = self.query_all.filter(uuid=uuid)
self.assertEqual(query.count(), 0)
group_individual_query = self.group_individual_query_all.filter(group=group)
self.assertEqual(group_individual_query.count(), 0)

@classmethod
def __create_individual(cls):
object_data = {
Expand Down

0 comments on commit 7a60398

Please sign in to comment.