Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add more privilges control for editing staff
Unknownac75e5199c9c
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pyindex c7e891ce4b..34e56e1789 100644--- a/saleor/dashboard/customer/forms.py+++ b/saleor/dashboard/customer/forms.py@@ -44,10 +44,21 @@ class CustomerForm(forms.ModelForm):def __init__(self, *args, **kwargs):self.user = kwargs.pop('user', None)super().__init__(*args, **kwargs)- # disable 'is_active' checkbox if user edits his own account++ # Only user with managing staff privilege or superuser+ # can assign other user as staff+ self.fields['is_staff'].disabled = True+ if self.user and (+ self.user.has_perms(['account.manage_staff'])+ or self.user.is_superuser):+ self.fields['is_staff'].disabled = False++ # Disable editing following fields if user edits his own accountif self.user == self.instance:- self.fields['is_active'].disabled = True+ self.fields['email'].disabled = Trueself.fields['note'].disabled = True+ self.fields['is_active'].disabled = True+ self.fields['is_staff'].disabled = Trueaddress = self.instance.default_billing_addressif not address:diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex 3c12bddc56..15f077ac9b 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -41,8 +41,15 @@ class StaffForm(forms.ModelForm):if self.user and self.user.is_superuser:self.fields['is_superuser'].disabled = False- if (self.user == self.instance- or (self.instance and self.instance.is_superuser)):+ # Disable users editing their own following fields+ if self.user == self.instance:+ self.fields['is_active'].disabled = True+ self.fields['is_staff'].disabled = True+ self.fields['is_superuser'].disabled = True++ # Non-superuser couldn't edit superuser's profile+ if (self.user and not self.user.is_superuser+ and self.instance.is_superuser):self.fields['email'].disabled = Trueself.fields['user_permissions'].disabled = Trueself.fields['is_active'].disabled = True