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

Allocated Group Error Handling #249

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions wildlifecompliance/components/legal_case/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,13 @@ 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)

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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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')

Expand Down
8 changes: 4 additions & 4 deletions wildlifecompliance/components/offence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export default {
return res
}
} catch(err) {
this.errorResponse = 'Error:' + err.statusText;
this.errorResponse = 'Error:' + err.bodyText;
}

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading