Skip to content

Commit

Permalink
#57 Update user deletion logic and filter active users in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pphetra committed Jan 29, 2024
1 parent 70325ef commit 2afa2d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion accounts/schema/mutations/admin_authority_user_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,6 @@ def mutate(root, info, id):
else:
raise GraphQLError("Permission denied.")

delete_user.delete()
delete_user.is_active = False
delete_user.save(update_fields=("is_active",))
return {"success": True}
3 changes: 2 additions & 1 deletion accounts/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def get_queryset(cls, queryset, info):
)
elif user.is_authority_role_in([AuthorityUser.Role.REPORTER]):
raise GraphQLError("Permission denied")
queryset.prefetch_related("authority")
queryset = queryset.filter(is_active=True).prefetch_related("authority")

return queryset


Expand Down
13 changes: 10 additions & 3 deletions summaries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def export_inactive_reporter_xls(request):
AuthorityUser.objects.exclude(id__in=exclude)
.annotate(Count("username"))
.order_by("username")
.filter(authority__in=sub_authorities, role=AuthorityUser.Role.REPORTER)
.filter(
authority__in=sub_authorities,
role=AuthorityUser.Role.REPORTER,
is_active=True,
)
.values("username", "first_name", "last_name", "telephone", "authority__name")
)

Expand Down Expand Up @@ -130,7 +134,9 @@ def export_reporter_performance_xls(request):

rows = (
AuthorityUser.objects.filter(
authority__in=sub_authorities, role=AuthorityUser.Role.REPORTER
authority__in=sub_authorities,
role=AuthorityUser.Role.REPORTER,
is_active=True,
)
.annotate(
zero_reports=Subquery(zero_reports),
Expand Down Expand Up @@ -369,7 +375,8 @@ def export_zero_report_xls(request):
.order_by("-day")
.filter(
reported_by__in=AuthorityUser.objects.filter(
authority__in=sub_authorities
authority__in=sub_authorities,
is_active=True,
# , role=AuthorityUser.Role.REPORTER
),
)
Expand Down

0 comments on commit 2afa2d4

Please sign in to comment.