Skip to content

Commit

Permalink
Merge branch '3.0' into resource-pools
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj authored Sep 14, 2023
2 parents a95dda0 + 1f90bb1 commit 63c1def
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gns3server/api/routes/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from . import roles
from . import acl
from . import pools
from . import privileges

from .dependencies.authentication import get_current_active_user

Expand Down Expand Up @@ -61,6 +62,13 @@
tags=["Roles"]
)

router.include_router(
privileges.router,
dependencies=[Depends(get_current_active_user)],
prefix="/access/privileges",
tags=["Privileges"]
)

router.include_router(
acl.router,
prefix="/access/acl",
Expand Down
43 changes: 43 additions & 0 deletions gns3server/api/routes/controller/privileges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Software Name : GNS3 server
# Version: 3
# SPDX-FileCopyrightText: Copyright (c) 2023 Orange Business Services
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This software is distributed under the GPL-3.0 or any later version,
# the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt
# or see the "LICENSE" file for more details.
#
# Author: Sylvain MATHIEU
#

"""
API route for privileges
"""

from typing import List
from gns3server.db.repositories.rbac import RbacRepository
from .dependencies.database import get_repository
from fastapi import APIRouter, Depends
import logging

from gns3server import schemas

log = logging.getLogger(__name__)
router = APIRouter()


@router.get(
"",
response_model=List[schemas.Privilege],
)
async def get_privileges(
rbac_repo: RbacRepository = Depends(get_repository(RbacRepository))
) -> List[schemas.Privilege]:
"""
Get all privileges.
Required privilege: None
"""

return await rbac_repo.get_privileges()
25 changes: 25 additions & 0 deletions tests/api/routes/controller/test_privileges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Software Name : GNS3 server
# Version: 3
# SPDX-FileCopyrightText: Copyright (c) 2023 Orange Business Services
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This software is distributed under the GPL-3.0 or any later version,
# the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt
# or see the "LICENSE" file for more details.
#
# Author: Sylvain MATHIEU
#

import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

pytestmark = pytest.mark.asyncio


class TestPrivilegesRoute:

async def test_get_privileges(self, app: FastAPI, client: AsyncClient) -> None:
response = await client.get(app.url_path_for("get_privileges"))
assert response.status_code == status.HTTP_200_OK

0 comments on commit 63c1def

Please sign in to comment.