Skip to content

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

fix attribute assignment permissions (#8899)

Paweł Kucharski02705228eaa9
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index e3ab1506d4..c62f1813f2 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -371,12 +371,7 @@ class ProductAttributeAssignmentUpdate(BaseMutation, VariantAssignmentValidation
error_type_class = ProductError
error_type_field = "product_errors"
-
- @classmethod
- def check_permissions(cls, context):
- return context.user.has_perm(
- ProductTypePermissions.MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES
- )
+ permissions = (ProductTypePermissions.MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES,)
@classmethod
def get_operations(
diff --git a/saleor/graphql/product/tests/test_attributes.py b/saleor/graphql/product/tests/test_attributes.py
index 88cf9228eb..64b483476c 100644
--- a/saleor/graphql/product/tests/test_attributes.py
+++ b/saleor/graphql/product/tests/test_attributes.py
@@ -851,6 +851,53 @@ def test_assignment_attribute_update_assigned_should_modify_variant_selection(
).variant_selection
+def test_assignment_attrib_update_assigned_should_modify_variant_selection_from_ext_app(
+ app_api_client,
+ permission_manage_product_types_and_attributes,
+ size_attribute,
+ color_attribute_without_values,
+):
+ """The productAttributeAssignmentUpdate mutation should modify
+ variant selection from external app when validation successful."""
+
+ product_type = ProductType.objects.create(name="Type", kind=ProductTypeKind.NORMAL)
+ attribute_1 = color_attribute_without_values
+ attribute_2 = size_attribute
+
+ app_api_client.app.permissions.add(permission_manage_product_types_and_attributes)
+
+ product_type.variant_attributes.add(
+ attribute_1, through_defaults={"variant_selection": False}
+ )
+ product_type.variant_attributes.add(
+ attribute_2, through_defaults={"variant_selection": True}
+ )
+ product_type_global_id = graphene.Node.to_global_id("ProductType", product_type.pk)
+
+ query = PRODUCT_ASSIGN_ATTR_UPDATE_QUERY
+ operations = [
+ {
+ "id": graphene.Node.to_global_id("Attribute", attribute_1.pk),
+ "variantSelection": True,
+ },
+ {
+ "id": graphene.Node.to_global_id("Attribute", attribute_2.pk),
+ "variantSelection": False,
+ },
+ ]
+ variables = {"productTypeId": product_type_global_id, "operations": operations}
+
+ content = get_graphql_content(app_api_client.post_graphql(query, variables))[
+ "data"
+ ]["productAttributeAssignmentUpdate"]
+
+ assert len(content["errors"]) == 0
+ assert AttributeVariant.objects.get(attribute_id=attribute_1.pk).variant_selection
+ assert not AttributeVariant.objects.get(
+ attribute_id=attribute_2.pk
+ ).variant_selection
+
+
def test_assign_page_attribute_to_product_type(
staff_api_client,
permission_manage_product_types_and_attributes,