Skip to content

Commit 82f8842

Browse files
authored
Merge pull request #4880 from opsmill/pog-computed-attribute-permissions
Verify permissions in computed_attribute mutation
2 parents e9c943e + 2437bf7 commit 82f8842

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

backend/infrahub/graphql/mutations/computed_attribute.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
from graphene import Boolean, InputObjectType, Mutation, String
66

7-
from infrahub.core.constants import ComputedAttributeKind
7+
from infrahub.core.account import ObjectPermission
8+
from infrahub.core.constants import ComputedAttributeKind, PermissionAction, PermissionDecision
89
from infrahub.core.manager import NodeManager
910
from infrahub.core.registry import registry
1011
from infrahub.database import retry_db_transaction
11-
from infrahub.exceptions import NodeNotFoundError, ValidationError
12+
from infrahub.exceptions import NodeNotFoundError, PermissionDeniedError, ValidationError
1213

1314
if TYPE_CHECKING:
1415
from graphql import GraphQLResolveInfo
@@ -46,6 +47,28 @@ async def mutate(
4647
):
4748
raise ValidationError(input_value=f"{node_schema.kind}.{target_attribute.name} is not a computed attribute")
4849

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+
4972
if not (
5073
target_node := await NodeManager.get_one(
5174
db=context.db, kind=node_schema.kind, id=str(data.id), branch=context.branch

0 commit comments

Comments
 (0)