| 1 | from fastapi import APIRouter |
| 2 | from fastapi import Security |
| 3 | from loguru import logger |
| 4 | |
| 5 | from app.auth.utils import AuthHandler |
| 6 | from app.connectors.grafana.schema.user import UserOrganizationAddRequest |
| 7 | from app.connectors.grafana.schema.user import UserOrganizationAddResponse |
| 8 | from app.connectors.grafana.services.user import add_user_to_organization |
| 9 | |
| 10 | # App specific imports |
| 11 | |
| 12 | |
| 13 | grafana_user_router = APIRouter() |
| 14 | |
| 15 | |
| 16 | @grafana_user_router.post( |
| 17 | "/user/organization/add", |
| 18 | response_model=UserOrganizationAddResponse, |
| 19 | description="Add a user to a Grafana organization", |
| 20 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 21 | ) |
| 22 | async def add_user_organization_route( |
| 23 | request: UserOrganizationAddRequest, |
| 24 | ) -> UserOrganizationAddResponse: |
| 25 | """ |
| 26 | Endpoint to add a user to a Grafana organization. |
| 27 | |
| 28 | Args: |
| 29 | request (UserOrganizationAddRequest): The request body containing the user and organization data. |
| 30 | |
| 31 | Returns: |
| 32 | UserOrganizationAddResponse: The response containing the result of the user addition. |
| 33 | """ |
| 34 | logger.info("Adding user to Grafana organization") |
| 35 | response = await add_user_to_organization(request) |
| 36 | return response |