Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-2163: added possibility to configure check for delete operation #138

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
sniedzielski marked this conversation as resolved.
Show resolved Hide resolved

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()
sniedzielski marked this conversation as resolved.
Show resolved Hide resolved
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
Loading