Skip to content

Commit

Permalink
Merge pull request #4494 from mirumee/4289/Change-logged-user-email-a…
Browse files Browse the repository at this point in the history
…nd-names

Add mutation for deleting account
  • Loading branch information
maarcingebala committed Jul 19, 2019
2 parents abfcf33 + d849171 commit 40e7cb2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix voucher limit value when checkbox unchecked - #4456 by @benekex2
- New menu design - #4476 by @benekex2
- Mutation for changing logged user first and last name - #4489 by @fowczarek
- Add mutation for deleting account - #4494 by @fowczarek
- New translations:
- Greek
- Fix searches and pickers - #4487 by @dominik-zeglen
Expand Down
17 changes: 17 additions & 0 deletions saleor/graphql/account/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ def perform_mutation(cls, root, info, **data):
return super().perform_mutation(root, info, **data)


class AccountRequestDeletion(BaseMutation):
class Meta:
description = (
"Sends an email with the account removal link for the logged-in user."
)

@classmethod
def check_permissions(cls, user):
return user.is_authenticated

@classmethod
def perform_mutation(cls, root, info, **data):
user = info.context.user
emails.send_account_delete_confirmation_email.delay(str(user.token), user.email)
return AccountRequestDeletion()


class UserDelete(UserDeleteMixin, ModelDeleteMutation):
class Meta:
abstract = True
Expand Down
2 changes: 2 additions & 0 deletions saleor/graphql/account/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .enums import CountryCodeEnum
from .filters import CustomerFilter, StaffUserFilter
from .mutations import (
AccountRequestDeletion,
AccountUpdate,
AddressCreate,
AddressDelete,
Expand Down Expand Up @@ -111,6 +112,7 @@ class AccountMutations(graphene.ObjectType):

logged_user_update = LoggedUserUpdate.Field()
account_update = AccountUpdate.Field()
account_request_deletion = AccountRequestDeletion.Field()

staff_create = StaffCreate.Field()
staff_delete = StaffDelete.Field()
Expand Down
5 changes: 5 additions & 0 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ input AccountInput {
defaultShippingAddress: AddressInput
}

type AccountRequestDeletion {
errors: [Error!]
}

type AccountUpdate {
errors: [Error!]
user: User
Expand Down Expand Up @@ -1667,6 +1671,7 @@ type Mutations {
customerSetDefaultAddress(id: ID!, type: AddressTypeEnum!): CustomerSetDefaultAddress
loggedUserUpdate(input: UserAddressInput!): LoggedUserUpdate
accountUpdate(input: AccountInput!): AccountUpdate
accountRequestDeletion: AccountRequestDeletion
staffCreate(input: StaffCreateInput!): StaffCreate
staffDelete(id: ID!): StaffDelete
staffBulkDelete(ids: [ID]!): StaffBulkDelete
Expand Down
37 changes: 37 additions & 0 deletions tests/api/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,43 @@ def test_logged_customer_update_anonymous_user(api_client, query):
assert_no_permission(response)


ACCOUNT_REQUEST_DELETION_QUERY = """
mutation accountRequestDeletion {
accountRequestDeletion {
errors {
field
message
}
}
}
"""


@patch("saleor.account.emails.send_account_delete_confirmation_email.delay")
def test_account_request_deletion(
send_account_delete_confirmation_email_mock, user_api_client
):
user = user_api_client.user

response = user_api_client.post_graphql(ACCOUNT_REQUEST_DELETION_QUERY)
content = get_graphql_content(response)
data = content["data"]["accountRequestDeletion"]

assert not data["errors"]
send_account_delete_confirmation_email_mock.assert_called_once_with(
str(user.token), user.email
)


@patch("saleor.account.emails.send_account_delete_confirmation_email.delay")
def test_account_request_deletion_anonymous_user(
send_account_delete_confirmation_email_mock, api_client
):
response = api_client.post_graphql(ACCOUNT_REQUEST_DELETION_QUERY, {})
assert_no_permission(response)
send_account_delete_confirmation_email_mock.assert_not_called()


@patch(
"saleor.graphql.account.utils.account_events.staff_user_deleted_a_customer_event"
)
Expand Down

0 comments on commit 40e7cb2

Please sign in to comment.