Skip to content

Commit

Permalink
Cases are floating when user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
remyvdwereld committed Sep 17, 2024
1 parent 8feb896 commit b8a888a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/web/users/templates/users/user_federation_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

{% block main %}
<h2>Gebruiker verwijderen</h2>
<p class="u-margin-bottom-2x">Weet je zeker dat de gebruiker '{{ object.username }}' wilt verwijderen?</p>
<p class="u-margin-bottom-2x">Weet je zeker dat je gebruiker <strong>'{{ object.username }}'</strong> wilt verwijderen?</p>
{% if cases %}
<p>De onderstaande cliënten hebben na het verwijderen van deze gebruiker geen persoonlijk begeleider meer in de omslagroute.</p>
<p>De onderstaande cliënten hebben na het verwijderen van deze gebruiker geen persoonlijk begeleider meer in de omslagroute en zullen aan jou worden toegekend.</p>
<ul>
{% for case in cases %}
<li>cliënt id: {{ case.id }}</li>
Expand Down
20 changes: 20 additions & 0 deletions app/web/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,26 @@ def get_queryset(self):

def test_func(self):
return auth_test(self.request.user, [PB_FEDERATIE_BEHEERDER, FEDERATIE_BEHEERDER, WONEN])


def post(self, request, *args, **kwargs):
# Get user who will be deleted
deleted_user = self.get_object()
# Get all cases from the deleted user's profile
deleted_user_profile_cases = deleted_user.profile.cases.all()

# Loop through all cases in profile
for profile_case in deleted_user_profile_cases:
# Check if case exists in other profiles
profiles_with_case_count = Profile.objects.filter(cases=profile_case).count()
if profiles_with_case_count <= 1:
# There is no other profile with this case
# Add this case to current user
self.request.user.profile.cases.add(profile_case)

# Delete user profile as well
deleted_user.profile.delete()
return super().delete(request, *args, **kwargs)


class OIDCAuthenticationRequestView(DatapuntOIDCAuthenticationRequestView):
Expand Down

0 comments on commit b8a888a

Please sign in to comment.