Disable preview images generation for remote users

This commit is contained in:
Joachim 2022-12-17 11:39:10 +01:00
parent d86e6a6949
commit 8c34b23c35
2 changed files with 26 additions and 1 deletions

View file

@ -459,6 +459,9 @@ def generate_user_preview_image_task(user_id):
user = models.User.objects.get(id=user_id) user = models.User.objects.get(id=user_id)
if not user.local:
return
texts = { texts = {
"text_one": user.display_name, "text_one": user.display_name,
"text_three": f"@{user.localname}@{settings.DOMAIN}", "text_three": f"@{user.localname}@{settings.DOMAIN}",

View file

@ -46,6 +46,19 @@ class PreviewImages(TestCase):
), ),
) )
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.remote_user = models.User.objects.create_user(
"rat",
"rat@rat.com",
"ratword",
local=False,
remote_id="https://example.com/users/rat",
inbox="https://example.com/users/rat/inbox",
outbox="https://example.com/users/rat/outbox",
)
self.work = models.Work.objects.create(title="Test Work") self.work = models.Work.objects.create(title="Test Work")
self.edition = models.Edition.objects.create( self.edition = models.Edition.objects.create(
title="Example Edition", title="Example Edition",
@ -114,7 +127,7 @@ class PreviewImages(TestCase):
self.local_user.refresh_from_db() self.local_user.refresh_from_db()
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile) self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
self.assertIsNotNone(self.local_user.preview_image) self.assertTrue(self.local_user.preview_image)
self.assertEqual( self.assertEqual(
self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH
) )
@ -122,6 +135,15 @@ class PreviewImages(TestCase):
self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT
) )
def test_remote_user_preview(self, *args, **kwargs):
"""a remote user doesnt get a user preview"""
generate_user_preview_image_task(self.remote_user.id)
self.remote_user.refresh_from_db()
self.assertFalse(self.remote_user.preview_image)
def test_generate_user_preview_images_task(self, *args, **kwargs): def test_generate_user_preview_images_task(self, *args, **kwargs):
"""test task's external calls""" """test task's external calls"""
with patch("bookwyrm.preview_images.generate_preview_image") as generate_mock: with patch("bookwyrm.preview_images.generate_preview_image") as generate_mock: