Skip to content

Commit

Permalink
Updates for better audit logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Nov 26, 2024
1 parent 2098303 commit f34d146
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ class Meta:
verbose_name_plural = _("Commission users")


auditlog.register(User, exclude_fields=["password"])
auditlog.register(User, exclude_fields=["password", "last_login"])
auditlog.register(GroupProxy)
11 changes: 9 additions & 2 deletions backend/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,12 @@ def _remove_votes_supports_candidates(self):
candidate.delete()

# Remove support that the organization has given
CandidateSupporter.objects.filter(user__organization=self).delete()
for supporter in CandidateSupporter.objects.filter(user__organization=self):
supporter.delete()

# Remove votes that the organization has given
CandidateVote.objects.filter(user__organization=self).delete()
for vote in CandidateVote.objects.filter(user__organization=self):
vote.delete()

def save(self, *args, **kwargs):
create = False if self.id else True
Expand Down Expand Up @@ -1009,6 +1011,11 @@ def save(self, *args, **kwargs):


base_exclude_fields = ["created", "modified"]
organization_exclude_fields = base_exclude_fields + [
"ngohub_last_update_ended",
"ngohub_last_update_started",
"filename_cache",
]
auditlog.register(Organization, exclude_fields=base_exclude_fields)
auditlog.register(Candidate, exclude_fields=base_exclude_fields)
auditlog.register(CandidateVote, exclude_fields=base_exclude_fields)
Expand Down
4 changes: 3 additions & 1 deletion backend/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,9 @@ def reset_candidate_confirmations(
if request.user.pk != user_request_pk:
raise PermissionDenied(_("Cannot delete another user's confirmations"))

CandidateConfirmation.objects.filter(user=request.user).delete()
for confirmation in CandidateConfirmation.objects.filter(user=request.user):
confirmation.delete()

messages.success(request, _("Confirmations successfully deleted"))

return redirect(reverse("candidates"))
Expand Down

0 comments on commit f34d146

Please sign in to comment.