From 4337cb546adc30c97f2fe91bb2af054fc17fc1d7 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 30 Apr 2024 07:13:05 +0000 Subject: [PATCH] Update: submission errors shown properly for cases and inspections, no allocated group errors made clearer --- wildlifecompliance/components/legal_case/api.py | 13 +++++++++---- wildlifecompliance/components/offence/models.py | 8 ++++---- .../internal/inspection/create_inspection_modal.vue | 2 +- .../internal/legal_case/create_legal_case_modal.vue | 7 ++++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/wildlifecompliance/components/legal_case/api.py b/wildlifecompliance/components/legal_case/api.py index 32fdc7acb..f1aac0cdc 100644 --- a/wildlifecompliance/components/legal_case/api.py +++ b/wildlifecompliance/components/legal_case/api.py @@ -456,7 +456,6 @@ def add_associated_persons(self, instance, request): instance.save() def check_authorised_to_update(self,request): - print("check_authorised_to_update") instance = self.get_object() user = self.request.user user_auth_groups = ComplianceManagementSystemGroupPermission.objects.filter(emailuser=user) @@ -464,8 +463,6 @@ def check_authorised_to_update(self,request): return instance.assigned_to_id == user.id and user_auth_groups.filter(group__id__in=instance.allowed_groups).exists() def check_authorised_to_create(self,request): - print("check_authorised_to_create") - #TODO adjust auth if needed (may need to allow all officers/managers to create/update regardless of region) region_id = None if not request.data.get('region_id') else request.data.get('region_id') district_id = None if not request.data.get('district_id') else request.data.get('district_id') user = self.request.user @@ -1207,6 +1204,14 @@ def workflow_action(self, request, instance=None, create_legal_case=None, *args, save_comms_log_document_obj(instance, workflow_entry, doc) temp_doc_collection.delete() + try: + region_id = None if not request.data.get('region_id') else request.data.get('region_id') + district_id = None if not request.data.get('district_id') else request.data.get('district_id') + allocated_group = ComplianceManagementSystemGroup.objects.get(district_id=district_id, region_id=region_id, name=settings.GROUP_OFFICER) + except Exception as e: + error_str = "No " + settings.GROUP_OFFICER + " group exists for provided region/district" + raise serializers.ValidationError(error_str) + ## Set Inspection status depending on workflow type workflow_type = request.data.get('workflow_type') if workflow_type == 'close': @@ -1238,7 +1243,7 @@ def workflow_action(self, request, instance=None, create_legal_case=None, *args, instance.district_id = None if not request.data.get('district_id') else request.data.get('district_id') instance.assigned_to_id = None if not request.data.get('assigned_to_id') else request.data.get('assigned_to_id') instance.legal_case_priority_id = None if not request.data.get('legal_case_priority_id') else request.data.get('legal_case_priority_id') - instance.allocated_group = ComplianceManagementSystemGroup.objects.get(district=instance.district, region=instance.region, name=settings.GROUP_OFFICER) if not request.data.get('allocated_group_id') else request.data.get('allocated_group_id') + instance.allocated_group = allocated_group if not request.data.get('allocated_group_id') else request.data.get('allocated_group_id') instance.call_email_id = None if not request.data.get('call_email_id') else request.data.get('call_email_id') instance.details = None if not request.data.get('details') else request.data.get('details') diff --git a/wildlifecompliance/components/offence/models.py b/wildlifecompliance/components/offence/models.py index 44f23d9ec..21a1cc2a9 100644 --- a/wildlifecompliance/components/offence/models.py +++ b/wildlifecompliance/components/offence/models.py @@ -149,10 +149,10 @@ def get_allocated_group(region_id, district_id): # permissions = Permission.objects.filter(codename=codename, content_type_id=compliance_content_type.id) # 3. Find groups which has the permission(s) determined above in the regionDistrict. - - group = ComplianceManagementSystemGroup.objects.get(name=settings.GROUP_OFFICER, region_id=region_id, district_id=district_id) - - return group + try: + return ComplianceManagementSystemGroup.objects.get(name=settings.GROUP_OFFICER, region_id=region_id, district_id=district_id) + except: + return None @property # Rewrite for Region District models diff --git a/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/inspection/create_inspection_modal.vue b/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/inspection/create_inspection_modal.vue index 0a80baca7..3f495e6ee 100644 --- a/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/inspection/create_inspection_modal.vue +++ b/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/inspection/create_inspection_modal.vue @@ -338,7 +338,7 @@ export default { return res } } catch(err) { - this.errorResponse = 'Error:' + err.statusText; + this.errorResponse = 'Error:' + err.bodyText; } }, diff --git a/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/legal_case/create_legal_case_modal.vue b/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/legal_case/create_legal_case_modal.vue index 4d455b342..67e08b0c7 100644 --- a/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/legal_case/create_legal_case_modal.vue +++ b/wildlifecompliance/frontend/wildlifecompliance/src/components/internal/legal_case/create_legal_case_modal.vue @@ -209,7 +209,7 @@ export default { this.temporary_document_collection_id = val; }, updateDistricts: function() { - // this.district_id = null; + this.district_id = null; this.availableDistricts = []; for (let region of this.regions) { if (this.region_id === region.id) { @@ -332,8 +332,9 @@ export default { return res } } catch(err) { - this.errorResponse = 'Error:' + err.statusText; - } + console.log(err); + this.errorResponse = 'Error:' + err.bodyText; + } }, //createDocumentActionUrl: async function(done) {