Skip to content

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

Make redirect_url optional in register mutation by setting

Tomasz Szymański25d9faa1a140
diff --git a/saleor/account/emails.py b/saleor/account/emails.py
index 1719b58c3e..1e1b419a5c 100644
--- a/saleor/account/emails.py
+++ b/saleor/account/emails.py
@@ -114,10 +114,7 @@ def _send_account_delete_confirmation_email_with_url(
recipient_email, redirect_url, token
):
params = urlencode({"token": token})
- delete_url = "%(redirect_url)s?%(params)s" % {
- "redirect_url": redirect_url,
- "params": params,
- }
+ delete_url = prepare_url(params, redirect_url)
_send_delete_confirmation_email(recipient_email, delete_url)
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index afacea9799..9dbb021606 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -33,7 +33,7 @@ class AccountRegisterInput(graphene.InputObjectType):
description=(
"Base of frontend URL that will be needed to create confirmation URL."
),
- required=True,
+ required=settings.ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL,
)
@@ -65,6 +65,9 @@ class AccountRegister(ModelMutation):
@classmethod
def clean_input(cls, info, instance, data, input_cls=None):
+ if not settings.ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL:
+ return super().clean_input(info, instance, data, input_cls=None)
+
try:
validate_storefront_url(data["redirect_url"])
except ValidationError as error:
diff --git a/saleor/settings.py b/saleor/settings.py
index 89b2cc010a..92503b2ecd 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -130,7 +130,7 @@ EMAIL_USE_TLS = email_config["EMAIL_USE_TLS"]
EMAIL_USE_SSL = email_config["EMAIL_USE_SSL"]
# If enabled, make sure you have set proper storefront address in ALLOWED_CLIENT_HOSTS.
-ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = os.environ.get(
+ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = get_bool_from_env(
"ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL", True
)
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 6666b0380a..09de4ff6ed 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -577,29 +577,32 @@ def test_user_with_cancelled_fulfillments(
assert fulfillments[1]["status"] == FulfillmentStatus.CANCELED.upper()
-ACCOUNT_REGISTER_MUTATION = """
- mutation RegisterAccount(
- $password: String!,
- $email: String!,
- $redirectUrl: String!
- ) {
- accountRegister(
- input: {
- password: $password,
- email: $email,
- redirectUrl: $redirectUrl
- }
- ) {
- errors {
- field
- message
- }
- user {
- id
- }
- }
- }
-"""
+def _build_account_register_query(requires_redirect=True):
+ field_declaration = "$redirectUrl: String!" if requires_redirect else ""
+ var_declaration = "redirectUrl: $redirectUrl" if requires_redirect else ""
+ return f"""
+ mutation RegisterAccount(
+ $password: String!,
+ $email: String!,
+ {field_declaration}
+ ) {{
+ accountRegister(
+ input: {{
+ password: $password,
+ email: $email,
+ {var_declaration}
+ }}
+ ) {{
+ errors {{
+ field
+ message
+ }}
+ user {{
+ id
+ }}
+ }}
+ }}
+ """
@override_settings(
@@ -613,7 +616,7 @@ def test_customer_register(send_account_confirmation_email_mock, user_api_client
"password": "Password",
"redirectUrl": "http://localhost:3000",
}
- query = ACCOUNT_REGISTER_MUTATION
+ query = _build_account_register_query(requires_redirect=True)
mutation_name = "accountRegister"
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -640,7 +643,9 @@ def test_customer_register_disabled_email_confirmation(
send_account_confirmation_email_mock, user_api_client
):
variables = {"email": "[email protected]", "password": "Password"}
- user_api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
+ user_api_client.post_graphql(
+ _build_account_register_query(requires_redirect=False), variables
+ )
assert send_account_confirmation_email_mock.delay.call_count == 0