Skip to content

Commit

Permalink
Correcting a validation check and displaying all errors instead of on…
Browse files Browse the repository at this point in the history
…e by one
  • Loading branch information
Fancien authored and vildead committed Jan 20, 2023
1 parent 0da1540 commit 5941e8e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions web/views/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,18 @@ class AccessEditView(CheckerMixin, UpdateView, AjaxViewMixin):

def form_valid(self, form):
"""If access status is Active, only data stewards can edit it"""
if self.object.status == StatusChoices.active and not self.request.user.is_part_of(Groups.DATA_STEWARD.value):
original_object = self.model.objects.get(pk=self.object.id)
if original_object.status == StatusChoices.active and not self.request.user.is_part_of(Groups.DATA_STEWARD.value):
form.add_error(None, "Only data stewards can edit active accesses, please contact one")
return super().form_invalid(form)

"""If the form is valid, check that remark is updated then save the associated model and add to the dataset"""
if "access_notes" not in form.changed_data:
form.add_error("access_notes", "Changes must be justified. Please update this field")
return super().form_invalid(form)

if StatusChoices.active.name in form.data.get("status") and not self.request.user.is_part_of(Groups.DATA_STEWARD.value):
form.add_error("status", "Only data stewards are allowed to activate accesses, please contact one")

if form.errors:
return super().form_invalid(form)

self.object = form.save(commit=False)
Expand Down

0 comments on commit 5941e8e

Please sign in to comment.