Coverage for /home/airflow/.local/lib/python3.12/site-packages/airflow/api_fastapi/core_api/routes/ui/teams.py: 67%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 14:22 +0000

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19from typing import Annotated 

20 

21from fastapi import Depends, HTTPException, status 

22from sqlalchemy import select 

23 

24from airflow.api_fastapi.common.db.common import SessionDep, paginated_select 

25from airflow.api_fastapi.common.parameters import ( 

26 QueryLimit, 

27 QueryOffset, 

28 SortParam, 

29) 

30from airflow.api_fastapi.common.router import AirflowRouter 

31from airflow.api_fastapi.core_api.datamodels.ui.teams import TeamCollectionResponse, TeamResponse 

32from airflow.api_fastapi.core_api.security import ( 

33 ReadableTeamsFilterDep, 

34 requires_authenticated, 

35) 

36from airflow.configuration import conf 

37from airflow.models.team import Team 

38 

39teams_router = AirflowRouter(tags=["Teams"], prefix="/teams") 

40 

41 

42@teams_router.get( 

43 path="", 

44 dependencies=[Depends(requires_authenticated())], 

45) 

46def list_teams( 

47 limit: QueryLimit, 

48 offset: QueryOffset, 

49 order_by: Annotated[ 

50 SortParam, 

51 Depends(SortParam(["name"], Team).dynamic_depends()), 

52 ], 

53 readable_teams_filter: ReadableTeamsFilterDep, 

54 session: SessionDep, 

55) -> TeamCollectionResponse: 

56 if not conf.getboolean("core", "multi_team"): 

57 raise HTTPException( 

58 status.HTTP_403_FORBIDDEN, "Multi-team mode is not configured in the Airflow environment" 

59 ) 

60 

61 select_stmt, total_entries = paginated_select( 

62 statement=select(Team), 

63 filters=[readable_teams_filter], 

64 order_by=order_by, 

65 offset=offset, 

66 limit=limit, 

67 session=session, 

68 ) 

69 teams = [ 

70 TeamResponse(**row._mapping) if not isinstance(row, Team) else row 

71 for row in session.scalars(select_stmt) 

72 ] 

73 return TeamCollectionResponse( 

74 teams=teams, 

75 total_entries=total_entries, 

76 )