|
4 | 4 |
|
5 | 5 | from graphene import Boolean, InputObjectType, Mutation, String |
6 | 6 |
|
7 | | -from infrahub.core.constants import ComputedAttributeKind |
| 7 | +from infrahub.core.account import ObjectPermission |
| 8 | +from infrahub.core.constants import ComputedAttributeKind, PermissionAction, PermissionDecision |
8 | 9 | from infrahub.core.manager import NodeManager |
9 | 10 | from infrahub.core.registry import registry |
10 | 11 | from infrahub.database import retry_db_transaction |
11 | | -from infrahub.exceptions import NodeNotFoundError, ValidationError |
| 12 | +from infrahub.exceptions import NodeNotFoundError, PermissionDeniedError, ValidationError |
12 | 13 |
|
13 | 14 | if TYPE_CHECKING: |
14 | 15 | from graphql import GraphQLResolveInfo |
@@ -46,6 +47,28 @@ async def mutate( |
46 | 47 | ): |
47 | 48 | raise ValidationError(input_value=f"{node_schema.kind}.{target_attribute.name} is not a computed attribute") |
48 | 49 |
|
| 50 | + required_decision = PermissionDecision.ALLOW_OTHER |
| 51 | + if context.branch.name == registry.default_branch: |
| 52 | + required_decision = PermissionDecision.ALLOW_DEFAULT |
| 53 | + |
| 54 | + has_update_permission = False |
| 55 | + for permission_backend in registry.permission_backends: |
| 56 | + if has_update_permission := await permission_backend.has_permission( |
| 57 | + db=context.db, |
| 58 | + account_session=context.active_account_session, |
| 59 | + permission=ObjectPermission( |
| 60 | + namespace=node_schema.namespace, |
| 61 | + name=node_schema.name, |
| 62 | + action=PermissionAction.UPDATE.value, |
| 63 | + decision=required_decision.value, |
| 64 | + ), |
| 65 | + branch=context.branch, |
| 66 | + ): |
| 67 | + break |
| 68 | + |
| 69 | + if not has_update_permission: |
| 70 | + raise PermissionDeniedError(message="You don't have the required permission to update this object.") |
| 71 | + |
49 | 72 | if not ( |
50 | 73 | target_node := await NodeManager.get_one( |
51 | 74 | db=context.db, kind=node_schema.kind, id=str(data.id), branch=context.branch |
|
0 commit comments