Skip to content

Commit

Permalink
[MDS-6334] Fix condition category bad request (#3397)
Browse files Browse the repository at this point in the history
* Change validation to not use static data

* Change dump_only from True to False
  • Loading branch information
sggerard authored Jan 30, 2025
1 parent b75dc55 commit c07dc36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class PermitConditions(SoftDeleteMixin, AuditMixin, Base):
class _ModelSchema(Base._ModelSchema):
permit_condition_id = fields.Integer(dump_only=True)
permit_condition_guid = fields.UUID(dump_only=True)
condition_category_code = FieldTemplate(
field=fields.String, one_of="PermitConditionCategory"
)
condition_category_code = fields.String(dump_only=False)
condition_type_code = FieldTemplate(
field=fields.String, one_of="PermitConditionType"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from app.api.utils.access_decorators import MINESPACE_PROPONENT, VIEW_ALL, requires_role_edit_permit, requires_any_of
from app.api.utils.resources_mixins import UserMixin
from app.api.mines.permits.permit.models.permit import Permit
from app.api.mines.permits.permit_conditions.models.permit_condition_category import PermitConditionCategory
from app.api.mines.mine.models.mine import Mine
from app.api.utils.include.user_info import User

Expand All @@ -32,6 +33,9 @@ def post(self, mine_guid, permit_guid, permit_amendment_guid):
try:
permit_condition = PermitConditions._schema().load(request.json['permit_condition'])

if not PermitConditionCategory.find_by_permit_condition_category_code(permit_condition.condition_category_code):
raise BadRequest('condition_category_code is invalid')

if permit_condition.top_level_parent_permit_condition_id is not None:
top_condition = PermitConditions.find_by_permit_condition_id(permit_condition.top_level_parent_permit_condition_id)
top_condition.permit_condition_status_code = 'NST'
Expand Down Expand Up @@ -88,6 +92,8 @@ def put(self, mine_guid, permit_guid, permit_amendment_guid, permit_condition_gu
old_display_order = old_condition.display_order
old_category_code = old_condition.condition_category_code
new_category_code = request_data.get("condition_category_code", None)
if not PermitConditionCategory.find_by_permit_condition_category_code(new_category_code):
raise BadRequest('condition_category_code is invalid')
changed_category = old_category_code != new_category_code
new_status_code = request_data.get("permit_condition_status_code",None)
changed_status = old_condition.permit_condition_status_code != new_status_code
Expand Down

0 comments on commit c07dc36

Please sign in to comment.