Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Df/update permissions max cases #34810

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion corehq/apps/domain/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,8 @@ class DomainInternalForm(forms.Form, SubAreaMixin):
required=False,
)

def __init__(self, domain, can_edit_eula, *args, **kwargs):
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
Expand Down Expand Up @@ -1266,6 +1267,13 @@ def __init__(self, domain, can_edit_eula, *args, **kwargs):
),
)

if not self.user.is_staff:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for self.user to be None? If yes, this will throw AttributeError. If not, the user arg in the constructor could be changed to a required keyword-only argument:

def __init__(self, domain, can_edit_eula, *args, user, **kwargs):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible for self.user to be None since the dispatch in EditInternalDomainInfoView has the login_and_domain_required decorator.

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 {
Expand Down
5 changes: 3 additions & 2 deletions corehq/apps/domain/views/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.user,
self.request.POST)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think user still has to be passed as a keyword argument, and as is it will raise TypeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that

initial = {
'countries': self.domain_object.deployment.countries,
'is_test': self.domain_object.is_test,
Expand Down Expand Up @@ -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):
Expand Down
Loading