66from fastapi .security import HTTPAuthorizationCredentials , HTTPBearer
77from sqlalchemy import select
88
9- from testgen .common .auth import authorize_token , decode_jwt_token
9+ from testgen .common .auth import AuthError , authorize_token , decode_jwt_token
10+ from testgen .common .enums import PublicJobKey
1011from testgen .common .models import Session , _current_session_wrapper , get_current_session
11- from testgen .common .models .job_execution import PUBLIC_JOB_KEYS , JobExecution
12+ from testgen .common .models .job_execution import JobExecution
1213from testgen .common .models .project_membership import ProjectMembership
1314from testgen .common .models .table_group import TableGroup
1415from testgen .common .models .test_suite import TestSuite
@@ -47,7 +48,7 @@ def get_authorized_user(credentials: HTTPAuthorizationCredentials = _bearer_secu
4748
4849 try :
4950 payload = decode_jwt_token (credentials .credentials )
50- except ValueError :
51+ except AuthError :
5152 raise _invalid from None
5253
5354 username = payload .get ("username" )
@@ -57,7 +58,7 @@ def get_authorized_user(credentials: HTTPAuthorizationCredentials = _bearer_secu
5758 session = get_current_session ()
5859 try :
5960 return authorize_token (credentials .credentials , username , session )
60- except ValueError :
61+ except AuthError :
6162 raise _invalid from None
6263
6364
@@ -122,15 +123,15 @@ def dependency(test_suite_id: UUID, user: User = _require_user) -> TestSuite:
122123def resolve_job (permission : str , * extra_filters ):
123124 """Resolve a JobExecution by ``job_id`` path param and verify project permission.
124125
125- Only jobs whose ``job_key`` is in ``PUBLIC_JOB_KEYS`` are exposed via the API.
126+ Only externally-triggerable jobs (``PublicJobKey``) are exposed via the API.
126127 Internal kinds (score rollups, recalculations, monitor runs) are filtered out
127128 by construction. Extra ORM clauses are appended to the WHERE clause to further
128129 restrict by job_key when a caller wants a single kind.
129130 """
130131 def dependency (job_id : UUID , user : User = _require_user ) -> JobExecution :
131132 query = select (JobExecution ).where (
132133 JobExecution .id == job_id ,
133- JobExecution .job_key .in_ (PUBLIC_JOB_KEYS ),
134+ JobExecution .job_key .in_ (list ( PublicJobKey ) ),
134135 * extra_filters ,
135136 )
136137 return _check_access (get_current_session ().scalars (query ).first (), user , permission )
0 commit comments