|
17 | 17 | from infrahub.api.exceptions import SchemaNotValidError |
18 | 18 | from infrahub.core import registry |
19 | 19 | from infrahub.core.branch import Branch # noqa: TCH001 |
| 20 | +from infrahub.core.constants import GlobalPermissions, PermissionDecision |
20 | 21 | from infrahub.core.migrations.schema.models import SchemaApplyMigrationData |
21 | 22 | from infrahub.core.models import ( # noqa: TCH001 |
22 | 23 | SchemaBranchHash, |
|
27 | 28 | from infrahub.core.schema.constants import SchemaNamespace # noqa: TCH001 |
28 | 29 | from infrahub.core.validators.models.validate_migration import SchemaValidateMigrationData |
29 | 30 | from infrahub.database import InfrahubDatabase # noqa: TCH001 |
30 | | -from infrahub.exceptions import MigrationError |
| 31 | +from infrahub.exceptions import MigrationError, PermissionDeniedError |
31 | 32 | from infrahub.log import get_logger |
32 | 33 | from infrahub.message_bus import Meta, messages |
33 | 34 | from infrahub.services import services |
|
38 | 39 | if TYPE_CHECKING: |
39 | 40 | from typing_extensions import Self |
40 | 41 |
|
| 42 | + from infrahub.auth import AccountSession |
41 | 43 | from infrahub.core.schema.schema_branch import SchemaBranch |
42 | 44 | from infrahub.services import InfrahubServices |
43 | 45 |
|
@@ -240,8 +242,17 @@ async def load_schema( |
240 | 242 | background_tasks: BackgroundTasks, |
241 | 243 | db: InfrahubDatabase = Depends(get_db), |
242 | 244 | branch: Branch = Depends(get_branch_dep), |
243 | | - _: Any = Depends(get_current_user), |
| 245 | + account_session: AccountSession = Depends(get_current_user), |
244 | 246 | ) -> SchemaUpdate: |
| 247 | + for permission_backend in registry.permission_backends: |
| 248 | + if not await permission_backend.has_permission( |
| 249 | + db=db, |
| 250 | + account_id=account_session.account_id, |
| 251 | + permission=f"global:{GlobalPermissions.MANAGE_SCHEMA.value}:{PermissionDecision.ALLOW.value}", |
| 252 | + branch=branch, |
| 253 | + ): |
| 254 | + raise PermissionDeniedError("You are not allowed to manage the schema") |
| 255 | + |
245 | 256 | service: InfrahubServices = request.app.state.service |
246 | 257 | log.info("schema_load_request", branch=branch.name) |
247 | 258 |
|
|
0 commit comments