forked from mirrors/bookwyrm
Generate likely followers url for existing users
This commit is contained in:
parent
53d9ff87d9
commit
dc72df7339
3 changed files with 31 additions and 8 deletions
|
@ -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,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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, *_):
|
||||
|
|
Loading…
Reference in a new issue