diff --git a/accounts/schema/mutation.py b/accounts/schema/mutation.py index 0c0253d..8d9cbfa 100644 --- a/accounts/schema/mutation.py +++ b/accounts/schema/mutation.py @@ -25,6 +25,7 @@ AdminConfigurationCreateMutation, AdminConfigurationUpdateMutation, AdminConfigurationDeleteMutation, + RequestToDeleteMyAccountMutation, ) @@ -55,3 +56,4 @@ class Mutation(graphene.ObjectType): admin_configuration_create = AdminConfigurationCreateMutation.Field() admin_configuration_update = AdminConfigurationUpdateMutation.Field() admin_configuration_delete = AdminConfigurationDeleteMutation.Field() + request_to_delete_my_account = RequestToDeleteMyAccountMutation.Field() diff --git a/accounts/schema/mutations/__init__.py b/accounts/schema/mutations/__init__.py index 962ca5e..82bac93 100644 --- a/accounts/schema/mutations/__init__.py +++ b/accounts/schema/mutations/__init__.py @@ -10,3 +10,4 @@ from .confirm_consent_mutation import * from .admin_place_mutations import * from .admin_configuration_mutations import * +from .request_to_delete_my_account_mutation import * diff --git a/accounts/schema/mutations/request_to_delete_my_account_mutation.py b/accounts/schema/mutations/request_to_delete_my_account_mutation.py new file mode 100644 index 0000000..f138f0f --- /dev/null +++ b/accounts/schema/mutations/request_to_delete_my_account_mutation.py @@ -0,0 +1,17 @@ +import graphene +from graphql_jwt.decorators import login_required + + +class RequestToDeleteMyAccountMutation(graphene.Mutation): + class Arguments: + pass + + success = graphene.Boolean() + + @staticmethod + @login_required + def mutate(root, info): + user = info.context.user + success = True + + return RequestToDeleteMyAccountMutation(success=success) diff --git a/reports/schema/mutation.py b/reports/schema/mutation.py index 22bbcf1..25f3f76 100644 --- a/reports/schema/mutation.py +++ b/reports/schema/mutation.py @@ -6,6 +6,7 @@ ConvertToTestReportMutation, SubmitZeroReportMutation, SubmitIncidentReport, + EvaluateReportSimulation, SubmitFollowupReport, SubmitImage, SubmitUploadFile, @@ -30,6 +31,7 @@ class Mutation(graphene.ObjectType): convert_to_test_report = ConvertToTestReportMutation.Field() publish_report_type = PublishReportTypeMutation.Field() unpublish_report_type = UnPublishReportTypeMutation.Field() + evaluate_report_simulation = EvaluateReportSimulation.Field() admin_category_create = AdminCategoryCreateMutation.Field() admin_category_update = AdminCategoryUpdateMutation.Field() admin_category_delete = AdminCategoryDeleteMutation.Field() diff --git a/reports/schema/mutations/__init__.py b/reports/schema/mutations/__init__.py index cecaf1e..0dd6ca4 100644 --- a/reports/schema/mutations/__init__.py +++ b/reports/schema/mutations/__init__.py @@ -10,6 +10,7 @@ from .submit_image_mutation import * from .submit_upload_file_mutation import * from .submit_incident_report_mutation import * +from .evaluate_report_simulation_mutation import * from .submit_zero_report_mutation import * from .submit_followup_report_mutation import * from .convert_to_test_report_mutation import * diff --git a/reports/schema/mutations/evaluate_report_simulation_mutation.py b/reports/schema/mutations/evaluate_report_simulation_mutation.py new file mode 100644 index 0000000..aeaf7e0 --- /dev/null +++ b/reports/schema/mutations/evaluate_report_simulation_mutation.py @@ -0,0 +1,96 @@ +from datetime import datetime +from django.template import Context, Template +import graphene +from graphql_jwt.decorators import login_required +from graphene.types.generic import GenericScalar +from cases.models import CaseDefinition, NotificationTemplate +from common.eval import build_eval_obj, FormData + +from reports.models.report import IncidentReport +from reports.models.report_type import ReportType +from reports.schema.types import SimulationReportType +from django.template.defaultfilters import striptags + + +class EvaluateReportSimulation(graphene.Mutation): + class Arguments: + data = GenericScalar(required=True) + report_type_id = graphene.UUID(required=False) + renderer_data_template = graphene.String(required=True) + incident_date = graphene.Date(required=True) + report_id = graphene.UUID(required=False) + + result = graphene.Field(SimulationReportType) + + @staticmethod + @login_required + def mutate( + root, + info, + data, + report_type_id, + renderer_data_template, + incident_date, + report_id, + ): + renderer_data = "" + template = renderer_data_template + if template: + t = Template(template) + c = Context( + IncidentReport.build_data_context(data, report_id, incident_date) + ) + renderer_data = striptags(t.render(c)) + + reporter_notifications = [] + case_definitions = [] + if report_type_id is not None: + report_type = ReportType.objects.get(pk=report_type_id) + eval_context = build_eval_obj( + { + "data": data, + "form_data": FormData(data), + "report_date": datetime.now(), + "incident_date": incident_date, + "renderer_data": renderer_data, + "report_id": report_id, + "report_type": { + "id": report_type.id, + "name": report_type.name, + "category": report_type.category, + }, + } + ) + for template in NotificationTemplate.objects.filter( + type=NotificationTemplate.Type.REPORT, + report_type=report_type, + ): + if template.condition: + try: + if eval_context.eval(template.condition): + reporter_notifications.append( + {"id": template.id, "name": template.name} + ) + except: + pass + else: + reporter_notifications.append( + {"id": template.id, "name": template.name} + ) + + for definition in CaseDefinition.objects.filter(report_type=report_type): + try: + if eval_context.eval(definition.condition): + case_definitions.append( + {"id": definition.id, "description": definition.description} + ) + except: + pass + + return EvaluateReportSimulation( + result={ + "reporter_notifications": reporter_notifications, + "case_definitions": case_definitions, + "renderer_data": renderer_data, + } + ) diff --git a/reports/schema/types.py b/reports/schema/types.py index bfa78dd..0c6d4f6 100644 --- a/reports/schema/types.py +++ b/reports/schema/types.py @@ -409,3 +409,19 @@ class ReporterNoReport(graphene.ObjectType): class ReportDataSummaryType(graphene.ObjectType): result = graphene.String() + + +class SimulationCaseDefinitionType(graphene.ObjectType): + id = graphene.Int() + description = graphene.String() + + +class SimulationReporterNotificationType(graphene.ObjectType): + id = graphene.Int() + name = graphene.String() + + +class SimulationReportType(graphene.ObjectType): + reporter_notifications = graphene.List(SimulationReporterNotificationType) + case_definitions = graphene.List(SimulationCaseDefinitionType) + renderer_data = graphene.String()