Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add missing entry for permission checks changes (#19599)

Marcin Wcisłob410358502a1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 50644f971c..35f72904f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,15 @@ All notable, unreleased changes to this project will be documented in this file.
- Removed the deprecated `orderAddNote` mutation, along with the `OrderAddNote` type and `OrderAddNoteInput` input. Use the `orderNoteAdd` mutation instead.
- Removed the `DIGITAL_LINKS` value from the `OrderEventsEmailsEnum` enum and the `DIGITAL_LINK_DOWNLOADED` value from the `CustomerEventsEnum` enum. Events with these types were deleted in 3.23, along with the legacy digital content feature that emitted them.
- Removed the always-empty `digital_lines` key from the fulfillment confirmation notification payload. Use `physical_lines`, which holds every line of the fulfillment.
+- Attribute value and bulk attribute mutations now require the permission matching the attribute's type: `MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES` for `PRODUCT_TYPE` attributes and `MANAGE_PAGE_TYPES_AND_ATTRIBUTES` for `PAGE_TYPE` attributes. Previously each mutation required a single fixed permission regardless of the attribute's type, which let a requestor modify attributes of a type they were not authorized for - #19595 by @wcislo-saleor
+
+ The affected mutations and their previously required permission:
+ - `attributeValueCreate` — previously `MANAGE_PRODUCTS`; `PRODUCT_TYPE` attributes now require `MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES` and `PAGE_TYPE` attributes now require `MANAGE_PAGE_TYPES_AND_ATTRIBUTES`
+ - `attributeValueUpdate`, `attributeValueDelete`, `attributeReorderValues` — previously `MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES`; unchanged for `PRODUCT_TYPE` attributes, but `PAGE_TYPE` attributes now require `MANAGE_PAGE_TYPES_AND_ATTRIBUTES`.
+ - `attributeBulkDelete`, `attributeValueBulkDelete` — previously `MANAGE_PAGE_TYPES_AND_ATTRIBUTES`; unchanged for `PAGE_TYPE` attributes, but `PRODUCT_TYPE` attributes now require `MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES`. When the call targets both types, both permissions are required.
+ - `attributeBulkCreate` and `attributeBulkUpdate` already resolved the permission from the attribute type. They now reject an attribute type that has no permission mapped, instead of falling back to `MANAGE_PAGE_TYPES_AND_ATTRIBUTES`.
+
+ To upgrade, grant staff members and apps the permission matching the attribute types they operate on. A requestor holding only `MANAGE_PRODUCTS` can no longer create attribute values.
- Providing an empty `attributes` list (`null` or `[]`) in `where` filters for pages, products, and product variants now matches no objects instead of being ignored.
### GraphQL API
diff --git a/saleor/graphql/attribute/mutations/attribute_value_update.py b/saleor/graphql/attribute/mutations/attribute_value_update.py
index d7b9208d43..104af63e56 100644
--- a/saleor/graphql/attribute/mutations/attribute_value_update.py
+++ b/saleor/graphql/attribute/mutations/attribute_value_update.py
@@ -13,7 +13,7 @@ from ...core import ResolveInfo
from ...core.context import ChannelContext
from ...core.mutations import ModelWithExtRefMutation
from ...core.types import AttributeError
-from ...core.utils import WebhookEventInfo, from_global_id_or_error
+from ...core.utils import WebhookEventInfo
from ...plugins.dataloaders import get_plugin_manager_promise
from ..types import Attribute, AttributeValue
from .attribute_update import AttributeValueUpdateInput
@@ -76,7 +76,7 @@ class AttributeValueUpdate(AttributeValueCreate, ModelWithExtRefMutation):
# Concrete permission is checked once the value's attribute type is known.
check_any_attribute_type_permission(cls, info.context)
object_id = cls.get_object_id(**data)
- _, pk = from_global_id_or_error(object_id, AttributeValue, raise_error=True)
+ pk = cls.get_global_id_or_error(object_id, only_type=AttributeValue)
attribute_types = models.AttributeValue.objects.filter(pk=pk).values_list(
"attribute__type", flat=True
)
diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py
index 7214ba227a..ce38518dd3 100644
--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py
+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py
@@ -738,3 +738,28 @@ def test_authorization(
else:
assert_no_permission(response)
assert value.name == original_name
+
+
+def test_invalid_id_returns_error(
+ staff_api_client,
+ permission_manage_product_types_and_attributes,
+):
+ """A malformed ID must be reported in `errors`, not as a top-level error."""
+ # given
+ staff_api_client.user.user_permissions.add(
+ permission_manage_product_types_and_attributes
+ )
+ invalid_id = "not-a-global-id"
+ variables = {"id": invalid_id, "input": {"name": "Crimson name"}}
+
+ # when
+ response = staff_api_client.post_graphql(UPDATE_ATTRIBUTE_VALUE_MUTATION, variables)
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["attributeValueUpdate"]
+ assert len(data["errors"]) == 1
+ error = data["errors"][0]
+ assert error["field"] == "id"
+ assert error["code"] == AttributeErrorCode.GRAPHQL_ERROR.name
+ assert error["message"] == f"Invalid ID: {invalid_id}. Expected: AttributeValue."