From 5397f5890d7e4f3489caf31ceaa66dc55e7bb062 Mon Sep 17 00:00:00 2001 From: dfadil Date: Mon, 24 Jun 2024 10:42:21 -0400 Subject: [PATCH 1/3] disabled custom max update field for non-admins --- corehq/apps/domain/forms.py | 8 ++++++++ corehq/apps/domain/views/internal.py | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/corehq/apps/domain/forms.py b/corehq/apps/domain/forms.py index cedbea91bf8e..cb0897050e6b 100644 --- a/corehq/apps/domain/forms.py +++ b/corehq/apps/domain/forms.py @@ -1168,6 +1168,7 @@ class DomainInternalForm(forms.Form, SubAreaMixin): ) def __init__(self, domain, can_edit_eula, *args, **kwargs): + self.user = kwargs.pop('user', None) super(DomainInternalForm, self).__init__(*args, **kwargs) self.domain = domain self.can_edit_eula = can_edit_eula @@ -1266,6 +1267,13 @@ def __init__(self, domain, can_edit_eula, *args, **kwargs): ), ) + if not self.user.is_staff: + self.fields['auto_case_update_limit'].disabled = True + self.fields['auto_case_update_limit'].help_text = ( + 'Case update rule limits are only modifiable by Dimagi admins. ' + 'Please reach out to support@dimagi.com if you wish to update this setting.' + ) + @property def current_values(self): return { diff --git a/corehq/apps/domain/views/internal.py b/corehq/apps/domain/views/internal.py index 3de9ede8262a..fea49af6f3d2 100644 --- a/corehq/apps/domain/views/internal.py +++ b/corehq/apps/domain/views/internal.py @@ -97,7 +97,8 @@ def dispatch(self, request, *args, **kwargs): def internal_settings_form(self): can_edit_eula = toggles.CAN_EDIT_EULA.enabled(self.request.couch_user.username) if self.request.method == 'POST': - return DomainInternalForm(self.request.domain, can_edit_eula, self.request.POST) + return DomainInternalForm(self.request.domain, can_edit_eula, + self.request.POST, user=self.request.user) initial = { 'countries': self.domain_object.deployment.countries, 'is_test': self.domain_object.is_test, @@ -150,7 +151,7 @@ def internal_settings_form(self): initial['active_ucr_expressions'] = AllowedUCRExpressionSettings.get_allowed_ucr_expressions( domain_name=self.domain_object.name ) - return DomainInternalForm(self.request.domain, can_edit_eula, initial=initial) + return DomainInternalForm(self.request.domain, can_edit_eula, initial=initial, user=self.request.user) @property def page_context(self): From e120d2d9fdf8e5db1ac304c482e12ff98d70b1f1 Mon Sep 17 00:00:00 2001 From: dfadil Date: Mon, 24 Jun 2024 16:02:30 -0400 Subject: [PATCH 2/3] made user a required keyword-only arg --- corehq/apps/domain/forms.py | 4 ++-- corehq/apps/domain/views/internal.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/corehq/apps/domain/forms.py b/corehq/apps/domain/forms.py index cb0897050e6b..45f4a79e072b 100644 --- a/corehq/apps/domain/forms.py +++ b/corehq/apps/domain/forms.py @@ -1167,8 +1167,8 @@ class DomainInternalForm(forms.Form, SubAreaMixin): required=False, ) - def __init__(self, domain, can_edit_eula, *args, **kwargs): - self.user = kwargs.pop('user', None) + def __init__(self, domain, can_edit_eula, *args, user, **kwargs): + self.user = user super(DomainInternalForm, self).__init__(*args, **kwargs) self.domain = domain self.can_edit_eula = can_edit_eula diff --git a/corehq/apps/domain/views/internal.py b/corehq/apps/domain/views/internal.py index fea49af6f3d2..bf38d6ae645e 100644 --- a/corehq/apps/domain/views/internal.py +++ b/corehq/apps/domain/views/internal.py @@ -97,8 +97,8 @@ def dispatch(self, request, *args, **kwargs): def internal_settings_form(self): can_edit_eula = toggles.CAN_EDIT_EULA.enabled(self.request.couch_user.username) if self.request.method == 'POST': - return DomainInternalForm(self.request.domain, can_edit_eula, - self.request.POST, user=self.request.user) + return DomainInternalForm(self.request.domain, can_edit_eula, self.request.user, + self.request.POST) initial = { 'countries': self.domain_object.deployment.countries, 'is_test': self.domain_object.is_test, From 07c8c3a9de5b4eccbb739595126f534adfae3163 Mon Sep 17 00:00:00 2001 From: dfadil Date: Tue, 25 Jun 2024 08:12:16 -0400 Subject: [PATCH 3/3] passed user as a keywork arg --- corehq/apps/domain/views/internal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corehq/apps/domain/views/internal.py b/corehq/apps/domain/views/internal.py index bf38d6ae645e..fea49af6f3d2 100644 --- a/corehq/apps/domain/views/internal.py +++ b/corehq/apps/domain/views/internal.py @@ -97,8 +97,8 @@ def dispatch(self, request, *args, **kwargs): def internal_settings_form(self): can_edit_eula = toggles.CAN_EDIT_EULA.enabled(self.request.couch_user.username) if self.request.method == 'POST': - return DomainInternalForm(self.request.domain, can_edit_eula, self.request.user, - self.request.POST) + return DomainInternalForm(self.request.domain, can_edit_eula, + self.request.POST, user=self.request.user) initial = { 'countries': self.domain_object.deployment.countries, 'is_test': self.domain_object.is_test,