Skip to content

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

Review corrections

Piotr Grundas148608270870
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5972b6ba79..593de50497 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,7 +29,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Validate discount value for percentage vouchers and sales - #7033 by @d-wysocki
- Optimize children field on Category type - #7045 by @IKarbowiak
- Added support for querying objects by metadata fields - #6683 by @LeOndaz
-- Add text attribute input - #7059 by @piotrgrundas
+- Add rich text attribute input - #7059 by @piotrgrundas
- Avoid using `get_plugins_manager` method - #7052 by @IKarbowiak
- Add benchmarks for triggered product and variants webhooks - #7061 by @d-wysocki
- Extend `Transaction` type with gateway response and `Payment` type with filter - #7062 by @IKarbowiak
diff --git a/saleor/attribute/migrations/0008_auto_20210406_1628.py b/saleor/attribute/migrations/0008_auto_20210407_0632.py
similarity index 74%
rename from saleor/attribute/migrations/0008_auto_20210406_1628.py
rename to saleor/attribute/migrations/0008_auto_20210407_0632.py
index 0c32b86a7a..e7b874e97e 100644
--- a/saleor/attribute/migrations/0008_auto_20210406_1628.py
+++ b/saleor/attribute/migrations/0008_auto_20210407_0632.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.1.7 on 2021-04-06 16:28
+# Generated by Django 3.1.7 on 2021-04-07 06:32
from django.db import migrations, models
@@ -22,6 +22,15 @@ class Migration(migrations.Migration):
sanitizer=saleor.core.utils.editorjs.clean_editor_js,
),
),
+ migrations.AddField(
+ model_name="attributevaluetranslation",
+ name="rich_text",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
migrations.AlterField(
model_name="attribute",
name="input_type",
diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.py
index 4c8dddb5db..432c09e995 100644
--- a/saleor/attribute/models/base.py
+++ b/saleor/attribute/models/base.py
@@ -216,6 +216,7 @@ class AttributeValueTranslation(models.Model):
AttributeValue, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=100)
+ rich_text = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
class Meta:
unique_together = (("language_code", "attribute_value"),)
diff --git a/saleor/csv/tests/export/products_data/test_handle_relations_data.py b/saleor/csv/tests/export/products_data/test_handle_relations_data.py
index 367fdeb823..f01c375af1 100644
--- a/saleor/csv/tests/export/products_data/test_handle_relations_data.py
+++ b/saleor/csv/tests/export/products_data/test_handle_relations_data.py
@@ -861,7 +861,7 @@ def test_add_file_attribute_info_to_data(product):
assert result[pk][expected_header] == {"http://mirumee.com/media/" + test_url}
-def test_add_text_attribute_info_to_data(product):
+def test_add_rich_text_attribute_info_to_data(product):
# given
pk = product.pk
slug = "testtxt"
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index 2a614f935f..a079650c7c 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -2535,7 +2535,7 @@ def test_create_product_description_plaintext(
assert product.description_plaintext == description
-def test_create_product_with_text_attribute(
+def test_create_product_with_rich_text_attribute(
staff_api_client,
product_type,
category,
@@ -5636,7 +5636,7 @@ def test_product_type_create_mutation(
assert tax_code == "wine"
-def test_create_product_type_with_text_attribute(
+def test_create_product_type_with_rich_text_attribute(
staff_api_client,
product_type,
permission_manage_product_types_and_attributes,
diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.py
index 9827819fe2..0017458d15 100644
--- a/saleor/graphql/product/tests/test_variant.py
+++ b/saleor/graphql/product/tests/test_variant.py
@@ -1057,7 +1057,7 @@ def test_create_variant_invalid_variant_attributes(
@patch("saleor.plugins.manager.PluginsManager.product_variant_created")
-def test_create_variant_with_text_attribute(
+def test_create_variant_with_rich_text_attribute(
created_webhook_mock,
permission_manage_products,
product,
@@ -1108,60 +1108,6 @@ def test_create_variant_with_text_attribute(
created_webhook_mock.assert_called_once_with(product.variants.last())
-def test_create_variant_with_text_attribute_length_exceeded(
- permission_manage_products,
- product,
- product_type,
- staff_api_client,
- rich_text_attribute,
- warehouse,
-):
- query = CREATE_VARIANT_MUTATION
- product_id = graphene.Node.to_global_id("Product", product.pk)
- sku = "1"
- price = 1.32
- cost_price = 3.22
- weight = 10.22
-
- product_type.variant_attributes.add(rich_text_attribute)
- attr_id = graphene.Node.to_global_id("Attribute", rich_text_attribute.id)
-
- stocks = [
- {
- "warehouse": graphene.Node.to_global_id("Warehouse", warehouse.pk),
- "quantity": 20,
- }
- ]
- variables = {
- "productId": product_id,
- "sku": sku,
- "stocks": stocks,
- "costPrice": cost_price,
- "price": price,
- "weight": weight,
- "attributes": [
- {"id": attr_id, "values": ["long text" * 100]},
- ],
- "trackInventory": True,
- }
- response = staff_api_client.post_graphql(
- query, variables, permissions=[permission_manage_products]
- )
- content = get_graphql_content(response)
-
- data = content["data"]["productVariantCreate"]
- errors = data["productErrors"]
-
- assert not data["productVariant"]
- assert len(errors) == 1
- assert errors[0] == {
- "attributes": [attr_id],
- "code": ProductErrorCode.INVALID.name,
- "field": "attributes",
- "message": "Attribute value length is exceeded.",
- }
-
-
def test_product_variant_update_with_new_attributes(
staff_api_client, permission_manage_products, product, size_attribute
):
@@ -1461,7 +1407,7 @@ def test_update_product_variant_with_current_attribute(
@patch("saleor.plugins.manager.PluginsManager.product_variant_updated")
-def test_update_variant_with_text_attribute(
+def test_update_variant_with_rich_text_attribute(
product_variant_updated,
permission_manage_products,
product,
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 1ff5f7cc71..ccbe80b12d 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -632,6 +632,7 @@ type AttributeValueTranslate {
type AttributeValueTranslation implements Node {
id: ID!
name: String!
+ richText: JSONString
language: LanguageDisplay!
}
diff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.py
index f36b569646..9a438d3c58 100644
--- a/saleor/graphql/translations/tests/test_translations.py
+++ b/saleor/graphql/translations/tests/test_translations.py
@@ -1,3 +1,5 @@
+import json
+
import graphene
import pytest
from django.contrib.auth.models import Permission
@@ -403,7 +405,9 @@ def test_attribute_translation(user_api_client, color_attribute):
def test_attribute_value_translation(user_api_client, pink_attribute_value):
- pink_attribute_value.translations.create(language_code="pl", name="Różowy")
+ pink_attribute_value.translations.create(
+ language_code="pl", name="Różowy", rich_text=dummy_editorjs("Pink")
+ )
query = """
query {
@@ -413,6 +417,7 @@ def test_attribute_value_translation(user_api_client, pink_attribute_value):
values {
translation(languageCode: PL) {
name
+ richText
language {
code
}
@@ -434,6 +439,9 @@ def test_attribute_value_translation(user_api_client, pink_attribute_value):
attribute_value = data["attributes"]["edges"][0]["node"]["values"][-1]
assert attribute_value["translation"]["name"] == "Różowy"
+ assert attribute_value["translation"]["richText"] == json.dumps(
+ dummy_editorjs("Pink")
+ )
assert attribute_value["translation"]["language"]["code"] == "PL"
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index 2deb61ad78..61e7c27da3 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -54,7 +54,7 @@ class AttributeValueTranslation(BaseTranslationType):
class Meta:
model = attribute_models.AttributeValueTranslation
interfaces = [graphene.relay.Node]
- only_fields = BASIC_TRANSLATABLE_FIELDS
+ only_fields = BASIC_TRANSLATABLE_FIELDS + ["rich_text"]
class AttributeValueTranslatableContent(CountableDjangoObjectType):
diff --git a/saleor/settings.py b/saleor/settings.py
index 94ad4d4009..2299bf50c3 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -263,7 +263,6 @@ INSTALLED_APPS = [
"django_countries",
"django_filters",
"phonenumber_field",
- "django_extensions",
]