Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Required user argument for staff and customer form
Unknown714494026499
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pyindex 9d9ece88f5..ebab841aac 100644--- a/saleor/dashboard/customer/forms.py+++ b/saleor/dashboard/customer/forms.py@@ -42,7 +42,8 @@ class CustomerDeleteForm(forms.Form):class CustomerForm(forms.ModelForm):def __init__(self, *args, **kwargs):- self.user = kwargs.pop('user', None)+ # The user argument is required+ self.user = kwargs.pop('user')super().__init__(*args, **kwargs)# Disable editing following fields if user edits his own accountdiff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex df6c709a6b..a9939706bf 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -31,21 +31,20 @@ class StaffForm(forms.ModelForm):'User staff toggle', 'User is staff')}def __init__(self, *args, **kwargs):- self.user = kwargs.pop('user', None)+ # The user argument is required+ self.user = kwargs.pop('user')super().__init__(*args, **kwargs)# Non-superuser couldn't edit superuser's profile- if self.instance.is_superuser:- if self.user is None or not self.user.is_superuser:- self.fields['email'].disabled = True- self.fields['user_permissions'].disabled = True- self.fields['is_active'].disabled = True- self.fields['is_staff'].disabled = True+ if self.instance.is_superuser and not self.user.is_superuser:+ self.fields['email'].disabled = True+ self.fields['user_permissions'].disabled = True+ self.fields['is_active'].disabled = True+ self.fields['is_staff'].disabled = True# Disable editing other staff's email for non-superuser staff- if self.instance.is_staff:- if self.user is None or not self.user.is_superuser:- self.fields['email'].disabled = True+ if self.instance.is_staff and not self.user.is_superuser:+ self.fields['email'].disabled = True# Disable users editing their own following fields except for emailif self.user == self.instance:diff --git a/tests/dashboard/test_customer.py b/tests/dashboard/test_customer.pyindex b95c53c7f5..bc71d67f65 100644--- a/tests/dashboard/test_customer.py+++ b/tests/dashboard/test_customer.py@@ -50,19 +50,20 @@ def test_view_customer_create(admin_client):assert User.objects.filter(email='[email protected]').exists()-def test_add_customer_form():+def test_add_customer_form(staff_user):user_count = User.objects.count()- customer_form = CustomerForm({'email': '[email protected]'})+ customer_form = CustomerForm(+ {'email': '[email protected]'}, user=staff_user)customer_form.is_valid()customer_form.save()assert User.objects.count() == user_count + 1-def test_edit_customer_form(customer_user):+def test_edit_customer_form(customer_user, staff_user):customer = customer_usercustomer_form = CustomerForm({'first_name': 'Jan', 'last_name': 'Nowak', 'email': customer.email},- instance=customer)+ instance=customer, user=staff_user)customer_form.is_valid()customer_form.save()customer.refresh_from_db()diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.pyindex 5a380db2a9..4caecf2c7b 100644--- a/tests/dashboard/test_staff.py+++ b/tests/dashboard/test_staff.py@@ -30,9 +30,9 @@ def test_remove_staff_member(staff_user):assert not User.objects.filter(pk=staff_user.pk).exists()-def test_staff_form_not_valid(db):+def test_staff_form_not_valid(staff_user):data = {'user_permissions': 1}- form = StaffForm(data=data)+ form = StaffForm(data=data, user=staff_user)assert not form.is_valid()