generated from coulomb/repo-seed
Added rejection support for the rest of the candidate graph
This commit is contained in:
@@ -200,6 +200,72 @@ class RegistryService:
|
||||
self.store.update_repository_status(repository_id, "reviewing")
|
||||
return self.store.get_candidate_graph(repository_id, analysis_run_id)
|
||||
|
||||
def reject_candidate_capability(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_capability_id: int,
|
||||
*,
|
||||
notes: str = "",
|
||||
) -> CandidateGraph:
|
||||
self.store.reject_candidate_capability(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_capability_id,
|
||||
)
|
||||
self.store.create_review_decision(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
action="reject_candidate_capability",
|
||||
notes=notes,
|
||||
)
|
||||
self.store.update_repository_status(repository_id, "reviewing")
|
||||
return self.store.get_candidate_graph(repository_id, analysis_run_id)
|
||||
|
||||
def reject_candidate_feature(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_feature_id: int,
|
||||
*,
|
||||
notes: str = "",
|
||||
) -> CandidateGraph:
|
||||
self.store.reject_candidate_feature(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_feature_id,
|
||||
)
|
||||
self.store.create_review_decision(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
action="reject_candidate_feature",
|
||||
notes=notes,
|
||||
)
|
||||
self.store.update_repository_status(repository_id, "reviewing")
|
||||
return self.store.get_candidate_graph(repository_id, analysis_run_id)
|
||||
|
||||
def reject_candidate_evidence(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_evidence_id: int,
|
||||
*,
|
||||
notes: str = "",
|
||||
) -> CandidateGraph:
|
||||
self.store.reject_candidate_evidence(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_evidence_id,
|
||||
)
|
||||
self.store.create_review_decision(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
action="reject_candidate_evidence",
|
||||
notes=notes,
|
||||
)
|
||||
self.store.update_repository_status(repository_id, "reviewing")
|
||||
return self.store.get_candidate_graph(repository_id, analysis_run_id)
|
||||
|
||||
def edit_candidate_ability(
|
||||
self,
|
||||
repository_id: int,
|
||||
|
||||
@@ -441,6 +441,75 @@ class RegistryStore:
|
||||
(capability_id, repository_id, analysis_run_id),
|
||||
)
|
||||
|
||||
def reject_candidate_capability(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_capability_id: int,
|
||||
) -> None:
|
||||
with self.connect() as connection:
|
||||
cursor = connection.execute(
|
||||
"""
|
||||
UPDATE candidate_capabilities
|
||||
SET status = 'rejected'
|
||||
WHERE id = ?
|
||||
AND repository_id = ?
|
||||
AND analysis_run_id = ?
|
||||
AND status = 'candidate'
|
||||
""",
|
||||
(candidate_capability_id, repository_id, analysis_run_id),
|
||||
)
|
||||
if cursor.rowcount == 0:
|
||||
raise NotFoundError(
|
||||
"candidate capability "
|
||||
f"{candidate_capability_id} was not found for repository "
|
||||
f"{repository_id} analysis run {analysis_run_id}"
|
||||
)
|
||||
connection.execute(
|
||||
"""
|
||||
UPDATE candidate_features
|
||||
SET status = 'rejected'
|
||||
WHERE capability_id = ? AND repository_id = ? AND analysis_run_id = ?
|
||||
""",
|
||||
(candidate_capability_id, repository_id, analysis_run_id),
|
||||
)
|
||||
connection.execute(
|
||||
"""
|
||||
UPDATE candidate_evidence
|
||||
SET status = 'rejected'
|
||||
WHERE capability_id = ? AND repository_id = ? AND analysis_run_id = ?
|
||||
""",
|
||||
(candidate_capability_id, repository_id, analysis_run_id),
|
||||
)
|
||||
|
||||
def reject_candidate_feature(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_feature_id: int,
|
||||
) -> None:
|
||||
self._reject_candidate_leaf(
|
||||
table="candidate_features",
|
||||
label="candidate feature",
|
||||
repository_id=repository_id,
|
||||
analysis_run_id=analysis_run_id,
|
||||
candidate_id=candidate_feature_id,
|
||||
)
|
||||
|
||||
def reject_candidate_evidence(
|
||||
self,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_evidence_id: int,
|
||||
) -> None:
|
||||
self._reject_candidate_leaf(
|
||||
table="candidate_evidence",
|
||||
label="candidate evidence",
|
||||
repository_id=repository_id,
|
||||
analysis_run_id=analysis_run_id,
|
||||
candidate_id=candidate_evidence_id,
|
||||
)
|
||||
|
||||
def update_candidate_ability(
|
||||
self,
|
||||
repository_id: int,
|
||||
@@ -507,6 +576,33 @@ class RegistryStore:
|
||||
f"{repository_id} analysis run {analysis_run_id}"
|
||||
)
|
||||
|
||||
def _reject_candidate_leaf(
|
||||
self,
|
||||
*,
|
||||
table: str,
|
||||
label: str,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_id: int,
|
||||
) -> None:
|
||||
with self.connect() as connection:
|
||||
cursor = connection.execute(
|
||||
f"""
|
||||
UPDATE {table}
|
||||
SET status = 'rejected'
|
||||
WHERE id = ?
|
||||
AND repository_id = ?
|
||||
AND analysis_run_id = ?
|
||||
AND status = 'candidate'
|
||||
""",
|
||||
(candidate_id, repository_id, analysis_run_id),
|
||||
)
|
||||
if cursor.rowcount == 0:
|
||||
raise NotFoundError(
|
||||
f"{label} {candidate_id} was not found for repository "
|
||||
f"{repository_id} analysis run {analysis_run_id}"
|
||||
)
|
||||
|
||||
def create_review_decision(
|
||||
self,
|
||||
repository_id: int,
|
||||
|
||||
@@ -224,6 +224,78 @@ def reject_candidate_ability(
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.post(
|
||||
"/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-capabilities/{candidate_capability_id}/reject"
|
||||
)
|
||||
def reject_candidate_capability(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_capability_id: int,
|
||||
payload: CandidateRejection,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> dict[str, object]:
|
||||
try:
|
||||
return asdict(
|
||||
service.reject_candidate_capability(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_capability_id,
|
||||
notes=payload.notes,
|
||||
)
|
||||
)
|
||||
except NotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.post(
|
||||
"/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-features/{candidate_feature_id}/reject"
|
||||
)
|
||||
def reject_candidate_feature(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_feature_id: int,
|
||||
payload: CandidateRejection,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> dict[str, object]:
|
||||
try:
|
||||
return asdict(
|
||||
service.reject_candidate_feature(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_feature_id,
|
||||
notes=payload.notes,
|
||||
)
|
||||
)
|
||||
except NotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.post(
|
||||
"/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-evidence/{candidate_evidence_id}/reject"
|
||||
)
|
||||
def reject_candidate_evidence(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_evidence_id: int,
|
||||
payload: CandidateRejection,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> dict[str, object]:
|
||||
try:
|
||||
return asdict(
|
||||
service.reject_candidate_evidence(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_evidence_id,
|
||||
notes=payload.notes,
|
||||
)
|
||||
)
|
||||
except NotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.patch(
|
||||
"/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-abilities/{candidate_ability_id}"
|
||||
|
||||
@@ -330,6 +330,72 @@ def reject_candidate_ability_from_form(
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-capabilities/{candidate_capability_id}/reject"
|
||||
)
|
||||
def reject_candidate_capability_from_form(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_capability_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
service.reject_candidate_capability(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_capability_id,
|
||||
notes="Rejected from web UI",
|
||||
)
|
||||
return RedirectResponse(
|
||||
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
||||
status_code=303,
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-features/{candidate_feature_id}/reject"
|
||||
)
|
||||
def reject_candidate_feature_from_form(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_feature_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
service.reject_candidate_feature(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_feature_id,
|
||||
notes="Rejected from web UI",
|
||||
)
|
||||
return RedirectResponse(
|
||||
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
||||
status_code=303,
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-evidence/{candidate_evidence_id}/reject"
|
||||
)
|
||||
def reject_candidate_evidence_from_form(
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
candidate_evidence_id: int,
|
||||
service: RegistryService = Depends(get_service),
|
||||
) -> RedirectResponse:
|
||||
service.reject_candidate_evidence(
|
||||
repository_id,
|
||||
analysis_run_id,
|
||||
candidate_evidence_id,
|
||||
notes="Rejected from web UI",
|
||||
)
|
||||
return RedirectResponse(
|
||||
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
||||
status_code=303,
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
"/candidate-abilities/{candidate_ability_id}/edit"
|
||||
@@ -460,11 +526,11 @@ def render_candidate_capability(
|
||||
analysis_run_id: int,
|
||||
) -> str:
|
||||
features = "".join(
|
||||
f'<li>{escape(feature["name"])} <span class="pill">{escape(feature["type"])}</span> <span class="source">{escape(feature["location"])}</span></li>'
|
||||
render_candidate_feature(feature, repository_id, analysis_run_id)
|
||||
for feature in capability["features"]
|
||||
)
|
||||
evidence = "".join(
|
||||
f'<li>{escape(item["type"])} <span class="pill">{escape(item["strength"])}</span> <span class="source">{escape(item["reference"])}</span></li>'
|
||||
render_candidate_evidence(item, repository_id, analysis_run_id)
|
||||
for item in capability["evidence"]
|
||||
)
|
||||
return f"""
|
||||
@@ -472,6 +538,7 @@ def render_candidate_capability(
|
||||
<strong>{escape(capability['name'])}</strong>
|
||||
<span class="pill">{escape(capability['status'])}</span>
|
||||
<span class="pill">{capability['confidence']:.2f}</span>
|
||||
{render_candidate_reject_form('candidate-capabilities', capability, repository_id, analysis_run_id)}
|
||||
<p class="muted">{escape(capability['description'])}</p>
|
||||
{render_candidate_edit_form('candidate-capabilities', capability, repository_id, analysis_run_id)}
|
||||
{render_sources(capability['source_refs'])}
|
||||
@@ -483,6 +550,57 @@ def render_candidate_capability(
|
||||
"""
|
||||
|
||||
|
||||
def render_candidate_feature(
|
||||
feature: dict,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
) -> str:
|
||||
return f"""
|
||||
<li>
|
||||
{escape(feature["name"])}
|
||||
<span class="pill">{escape(feature["status"])}</span>
|
||||
<span class="pill">{escape(feature["type"])}</span>
|
||||
<span class="source">{escape(feature["location"])}</span>
|
||||
{render_candidate_reject_form('candidate-features', feature, repository_id, analysis_run_id)}
|
||||
</li>
|
||||
"""
|
||||
|
||||
|
||||
def render_candidate_evidence(
|
||||
evidence: dict,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
) -> str:
|
||||
return f"""
|
||||
<li>
|
||||
{escape(evidence["type"])}
|
||||
<span class="pill">{escape(evidence["status"])}</span>
|
||||
<span class="pill">{escape(evidence["strength"])}</span>
|
||||
<span class="source">{escape(evidence["reference"])}</span>
|
||||
{render_candidate_reject_form('candidate-evidence', evidence, repository_id, analysis_run_id)}
|
||||
</li>
|
||||
"""
|
||||
|
||||
|
||||
def render_candidate_reject_form(
|
||||
collection: str,
|
||||
candidate: dict,
|
||||
repository_id: int,
|
||||
analysis_run_id: int,
|
||||
) -> str:
|
||||
if candidate["status"] != "candidate":
|
||||
return ""
|
||||
action = (
|
||||
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
||||
f"/{collection}/{candidate['id']}/reject"
|
||||
)
|
||||
return f"""
|
||||
<form style="display:inline" method="post" action="{action}">
|
||||
<button class="secondary" type="submit">Reject</button>
|
||||
</form>
|
||||
"""
|
||||
|
||||
|
||||
def render_ability_map(ability_map: dict) -> str:
|
||||
abilities = ability_map.get("abilities", [])
|
||||
if not abilities:
|
||||
|
||||
Reference in New Issue
Block a user