forked from mirrors/bookwyrm
Functional un-discoverable setting
This commit is contained in:
parent
29130d5f44
commit
f849d785a5
1 changed files with 5 additions and 29 deletions
|
@ -146,36 +146,12 @@ def update_rank_on_shelving(sender, instance, *args, **kwargs):
|
||||||
# pylint: disable=unused-argument, too-many-arguments
|
# pylint: disable=unused-argument, too-many-arguments
|
||||||
def add_new_user(sender, instance, created, **kwargs):
|
def add_new_user(sender, instance, created, **kwargs):
|
||||||
"""a new user, wow how cool"""
|
"""a new user, wow how cool"""
|
||||||
if not created or not instance.local:
|
if created and instance.local:
|
||||||
return
|
# a new user is found, create suggestions for them
|
||||||
# a new user is found, create suggestions for them
|
suggested_users.rerank_user_suggestions(instance)
|
||||||
suggested_users.rerank_user_suggestions(instance)
|
|
||||||
|
|
||||||
|
# TODO: this happens on every save, not just when discoverability changes
|
||||||
if instance.discoverable:
|
if instance.discoverable:
|
||||||
# idk why this would happen, but the new user is already discoverable
|
|
||||||
# so we should add them to the suggestions
|
|
||||||
suggested_users.rerank_obj(instance, update_only=False)
|
suggested_users.rerank_obj(instance, update_only=False)
|
||||||
|
elif not created:
|
||||||
|
|
||||||
@receiver(signals.pre_save, sender=models.User)
|
|
||||||
# pylint: disable=unused-argument, too-many-arguments
|
|
||||||
def set_discoverability(sender, instance, **kwargs):
|
|
||||||
"""make a user (un)discoverable"""
|
|
||||||
if not instance.id:
|
|
||||||
# this means the user was created, which is handled in `add_new_user`
|
|
||||||
return
|
|
||||||
|
|
||||||
was_discoverable = models.User.objects.get(id=instance.id).discoverable
|
|
||||||
if was_discoverable == instance.discoverable:
|
|
||||||
# no change in discoverability, who cares
|
|
||||||
return
|
|
||||||
|
|
||||||
# the user is newly available
|
|
||||||
if instance.discoverable:
|
|
||||||
# add this user to all suitable stores
|
|
||||||
suggested_users.rerank_obj(instance, update_only=False)
|
|
||||||
|
|
||||||
# the user is newly un-available
|
|
||||||
else:
|
|
||||||
# remove this user from all suitable stores
|
|
||||||
suggested_users.remove_object_from_related_stores(instance)
|
suggested_users.remove_object_from_related_stores(instance)
|
||||||
|
|
Loading…
Reference in a new issue