Generate likely followers url for existing users

This commit is contained in:
Mouse Reeve 2021-08-28 10:41:16 -07:00
parent 53d9ff87d9
commit dc72df7339
3 changed files with 31 additions and 8 deletions

View file

@ -3,24 +3,47 @@
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations, models
from django.db.models import F, Value, CharField
from django.db.models.functions import Concat
def forwards_func(apps, schema_editor):
"""generate followers url"""
db_alias = schema_editor.connection.alias
apps.get_model("bookwyrm", "User").objects.using(db_alias).annotate(
generated_url=Concat(
F("remote_id"), Value("/followers"), output_field=CharField()
)
).update(followers_url=models.F("generated_url"))
def reverse_func(apps, schema_editor):
"""noop"""
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0085_user_saved_lists'),
("bookwyrm", "0085_user_saved_lists"),
]
operations = [
migrations.AddField(
model_name='user',
name='followers_url',
field=bookwyrm.models.fields.CharField(default='/followers', max_length=255),
model_name="user",
name="followers_url",
field=bookwyrm.models.fields.CharField(
default="/followers", max_length=255
),
preserve_default=False,
),
migrations.RunPython(forwards_func, reverse_func),
migrations.AlterField(
model_name='user',
name='followers',
field=models.ManyToManyField(through='bookwyrm.UserFollows', to=settings.AUTH_USER_MODEL),
model_name="user",
name="followers",
field=models.ManyToManyField(
related_name="following",
through="bookwyrm.UserFollows",
to=settings.AUTH_USER_MODEL,
),
),
]

View file

@ -88,6 +88,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
symmetrical=False,
through="UserFollows",
through_fields=("user_object", "user_subject"),
related_name="following",
)
follow_requests = models.ManyToManyField(
"self",

View file

@ -195,7 +195,6 @@ class ModelFields(TestCase):
instance.set_field_from_activity(model_instance, data)
self.assertEqual(model_instance.privacy_field, "followers")
@patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast")
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_privacy_field_set_activity_from_field(self, *_):