1
0
Fork 0

Allow users to temporarily deactivate their accounts (#2324)

This commit is contained in:
Mouse Reeve 2022-11-10 13:40:54 -08:00 committed by GitHub
parent 3ebd957d3d
commit eae1866992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 333 additions and 39 deletions

View file

@ -47,6 +47,7 @@ def site_link():
return f"{protocol}://{DOMAIN}"
# pylint: disable=too-many-public-methods
class User(OrderedCollectionPageMixin, AbstractUser):
"""a user who wants to read books"""
@ -169,6 +170,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
max_length=255, choices=DeactivationReason, null=True, blank=True
)
deactivation_date = models.DateTimeField(null=True, blank=True)
allow_reactivation = models.BooleanField(default=False)
confirmation_code = models.CharField(max_length=32, default=new_access_code)
name_field = "username"
@ -367,12 +369,28 @@ class User(OrderedCollectionPageMixin, AbstractUser):
self.create_shelves()
def delete(self, *args, **kwargs):
"""deactivate rather than delete a user"""
"""We don't actually delete the database entry"""
# pylint: disable=attribute-defined-outside-init
self.is_active = False
# skip the logic in this class's save()
super().save(*args, **kwargs)
def deactivate(self):
"""Disable the user but allow them to reactivate"""
# pylint: disable=attribute-defined-outside-init
self.is_active = False
self.deactivation_reason = "self_deactivation"
self.allow_reactivation = True
super().save(broadcast=False)
def reactivate(self):
"""Now you want to come back, huh?"""
# pylint: disable=attribute-defined-outside-init
self.is_active = True
self.deactivation_reason = None
self.allow_reactivation = False
super().save(broadcast=False)
@property
def local_path(self):
"""this model doesn't inherit bookwyrm model, so here we are"""