Skip to content

[MDS-6334] Fix condition category bad request #3397

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

Merged
merged 2 commits into from
Jan 30, 2025
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
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
Loading