fix(compliance): address code review feedback - add aria-busy, input validation, use IntegrityError
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -19,6 +19,7 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
from app.database import get_db
|
from app.database import get_db
|
||||||
from app.utils.compliance_service import (
|
from app.utils.compliance_service import (
|
||||||
|
COMPLIANCE_TEMPLATES,
|
||||||
apply_template,
|
apply_template,
|
||||||
evaluate_template_status,
|
evaluate_template_status,
|
||||||
get_all_templates,
|
get_all_templates,
|
||||||
@@ -153,6 +154,9 @@ async def apply_compliance_template(name: str, db: DbSession, admin: AdminUser)
|
|||||||
Writes all template settings to the database and evaluates the resulting
|
Writes all template settings to the database and evaluates the resulting
|
||||||
compliance status.
|
compliance status.
|
||||||
"""
|
"""
|
||||||
|
if name not in COMPLIANCE_TEMPLATES:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Template '{name}' not found")
|
||||||
|
|
||||||
template = get_template_by_name(db, name)
|
template = get_template_by_name(db, name)
|
||||||
if template is None:
|
if template is None:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Template '{name}' not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Template '{name}' not found")
|
||||||
|
|||||||
@@ -155,9 +155,11 @@
|
|||||||
</button>
|
</button>
|
||||||
<button @click="applyTemplate(tmpl.name)"
|
<button @click="applyTemplate(tmpl.name)"
|
||||||
:disabled="tmpl._applying"
|
:disabled="tmpl._applying"
|
||||||
|
:aria-busy="tmpl._applying"
|
||||||
class="inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 min-h-[44px] min-w-[44px]"
|
class="inline-flex items-center px-4 py-2 text-sm font-medium rounded-md text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 min-h-[44px] min-w-[44px]"
|
||||||
:class="tmpl._applying ? 'bg-gray-400 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'"
|
:class="tmpl._applying ? 'bg-gray-400 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'"
|
||||||
:aria-label="'Apply ' + tmpl.display_name + ' template'">
|
:aria-label="'Apply ' + tmpl.display_name + ' template'"
|
||||||
|
aria-live="polite">>
|
||||||
<i class="fas mr-1.5" :class="tmpl._applying ? 'fa-spinner animate-spin' : 'fa-bolt'" aria-hidden="true"></i>
|
<i class="fas mr-1.5" :class="tmpl._applying ? 'fa-spinner animate-spin' : 'fa-bolt'" aria-hidden="true"></i>
|
||||||
<span x-text="tmpl._applying ? 'Applying…' : 'Apply Template'"></span>
|
<span x-text="tmpl._applying ? 'Applying…' : 'Apply Template'"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import pytest
|
|||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ class TestComplianceTemplateModel:
|
|||||||
settings_json="{}",
|
settings_json="{}",
|
||||||
)
|
)
|
||||||
ct_session.add(t2)
|
ct_session.add(t2)
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(IntegrityError):
|
||||||
ct_session.commit()
|
ct_session.commit()
|
||||||
ct_session.rollback()
|
ct_session.rollback()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user