add the option to mark users as deleted instead of actually deleting them from the db#672
Conversation
Theophile-Madet
left a comment
There was a problem hiding this comment.
The class NonDeleted(models.Manager) is nice for default filtering.
I think we want to keep the default delete() as it is, there's too much uncertainty about what happens when we override it.
There are many tests failing, do you want to look into them or do you need help?
tapir/coop/templates/coop/tags/user_coop_share_ownership_list_tag.html
Outdated
Show resolved
Hide resolved
…ted "Therefore, you should not override get_queryset() to filter out any rows. If you do so, Django will return incomplete results."
…d-instead-of-actually-deleting-them-from-the-db
Theophile-Madet
left a comment
There was a problem hiding this comment.
Looks better, I think the next big thing is tests for ShareOwnerDeleteView.
| class ShareOwnerDeleteView( | ||
| LoginRequiredMixin, | ||
| PermissionRequiredMixin, | ||
| generic.DeleteView, |
There was a problem hiding this comment.
Should this be a FormView since we're not actually deleting the object?
There was a problem hiding this comment.
as far as I understand, deleteview inherits from a formview and provides this nice confirmation form, otherwise I would need to create the logic of conformation, right?
There was a problem hiding this comment.
You already have a custom template and a custom form_valid(), so there's nothing left from DeleteView that we are using.
There was a problem hiding this comment.
Wouldn't we need to create extra form for a FormView? Also, I like the DeleteView so make it more clear that we delete ShareOwners here. If you don't have a strong opinion, I'd like to leave it here
There was a problem hiding this comment.
I still think DeleteView is not correct since we don't delete the objects. Using DeleteView is but overriding everything that is specific to delete view doesn't make sense. The intention is already clear from the class name (although that name should probably be ShareOwnerSoftDeleteView instead of ShareOwnerDeleteView).
You can use UpdateView as parent class, it's 2 lines more:
class ShareOwnerDeleteView(
LoginRequiredMixin,
PermissionRequiredMixin,
generic.UpdateView,
):
permission_required = PERMISSION_GROUP_MANAGE
model = ShareOwner
template_name = "coop/shareowner_confirm_delete.html"
fields = []…d-instead-of-actually-deleting-them-from-the-db # Conflicts: # tapir/translations/locale/de/LC_MESSAGES/django.po
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
…-as-deleted-instead-of-actually-deleting-them-from-the-db' into 328-add-the-option-to-mark-users-as-deleted-instead-of-actually-deleting-them-from-the-db
|
Edit: Solved, 1. was because DeleteView was actually deleting users with calling super() of course
Have to investigate more... |
…tpResponseRedirect now
…d-instead-of-actually-deleting-them-from-the-db # Conflicts: # tapir/translations/locale/de/LC_MESSAGES/django.po
|
It seems to work now. However, when going to a deleted user's page, it fails with |
You'll need to change this line to use cls.annotate_share_owner_queryset_with_investing_status_at_datetime(
ShareOwner.objects.filter(id=share_owner.id), at_datetime
).first() |
…d-instead-of-actually-deleting-them-from-the-db # Conflicts: # tapir/translations/locale/de/LC_MESSAGES/django.po
I think that would make things more complicated, since all the calls of is_investing would return the deleted members included. Maybe it's easier to disable the shareowner-card |
|
|
Theophile-Madet
left a comment
There was a problem hiding this comment.
Most comments are suggestions for test names and other small things. The main thing is still the usage of DeleteView vs another generic view.
| self.deleted_at = timezone.now() | ||
| self.save(update_fields=["deleted_at"], using=using) | ||
|
|
||
| def hard_delete(self, using=None, keep_parents=False): |
There was a problem hiding this comment.
I think we should either:
- keep
hard_deleteand overridedeleteto always throw an error and give the hint that either soft or hard delete should be used - remove
hard_deleteand keep the normaldelete
Otherwise hard_delete doesn't do anything.
| class ShareOwnerDeleteView( | ||
| LoginRequiredMixin, | ||
| PermissionRequiredMixin, | ||
| generic.DeleteView, |
There was a problem hiding this comment.
I still think DeleteView is not correct since we don't delete the objects. Using DeleteView is but overriding everything that is specific to delete view doesn't make sense. The intention is already clear from the class name (although that name should probably be ShareOwnerSoftDeleteView instead of ShareOwnerDeleteView).
You can use UpdateView as parent class, it's 2 lines more:
class ShareOwnerDeleteView(
LoginRequiredMixin,
PermissionRequiredMixin,
generic.UpdateView,
):
permission_required = PERMISSION_GROUP_MANAGE
model = ShareOwner
template_name = "coop/shareowner_confirm_delete.html"
fields = []|
|
||
| def test_ShareOwnerDeleteView_shareOwnerdeletedAt_hasDate(self): | ||
| self.login_as_vorstand() | ||
| tapir_user = TapirUserFactory() |
There was a problem hiding this comment.
Could we just use a ShareOwnerFactory?
| all_users = ShareOwner.everything.all() | ||
| self.assertNotIn(share_owner, all_users) | ||
|
|
||
| def test_delete_cannotDeleteOwnAccount(self): |
There was a problem hiding this comment.
This is already done in tapir/coop/tests/test_shareowner_delete_view.py, right? Then we can remove this test
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Resolves #328