mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 04:36:34 +00:00
Federate shelve activities when switching editions
This commit is contained in:
parent
5dbacb3524
commit
8a1800ea26
2 changed files with 31 additions and 1 deletions
|
@ -237,3 +237,28 @@ class ViewActions(TestCase):
|
|||
resp = actions.password_reset(request)
|
||||
self.assertEqual(resp.template_name, 'password_reset.html')
|
||||
self.assertTrue(models.PasswordReset.objects.exists())
|
||||
|
||||
def test_switch_edition(self):
|
||||
''' updates user's relationships to a book '''
|
||||
work = models.Work.objects.create(title='test work')
|
||||
edition1 = models.Edition.objects.create(
|
||||
title='first ed', parent_work=work)
|
||||
edition2 = models.Edition.objects.create(
|
||||
title='second ed', parent_work=work)
|
||||
shelf = models.Shelf.objects.create(
|
||||
name='Test Shelf', user=self.local_user)
|
||||
shelf.books.add(edition1)
|
||||
models.ReadThrough.objects.create(
|
||||
user=self.local_user, book=edition1)
|
||||
|
||||
self.assertEqual(models.ShelfBook.objects.get().book, edition1)
|
||||
self.assertEqual(models.ReadThrough.objects.get().book, edition1)
|
||||
request = self.factory.post('', {
|
||||
'edition': edition2.id
|
||||
})
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
actions.switch_edition(request)
|
||||
|
||||
self.assertEqual(models.ShelfBook.objects.get().book, edition2)
|
||||
self.assertEqual(models.ReadThrough.objects.get().book, edition2)
|
||||
|
|
|
@ -18,6 +18,7 @@ from django.utils import timezone
|
|||
from django.views.decorators.http import require_GET, require_POST
|
||||
|
||||
from bookwyrm import books_manager
|
||||
from bookwyrm.broadcast import broadcast
|
||||
from bookwyrm import forms, models, outgoing
|
||||
from bookwyrm import goodreads_import
|
||||
from bookwyrm.emailing import password_reset_email
|
||||
|
@ -256,12 +257,16 @@ def switch_edition(request):
|
|||
new_edition = get_object_or_404(models.Edition, id=edition_id)
|
||||
shelfbooks = models.ShelfBook.objects.filter(
|
||||
book__parent_work=new_edition.parent_work,
|
||||
added_by=request.user
|
||||
shelf__user=request.user
|
||||
)
|
||||
for shelfbook in shelfbooks.all():
|
||||
broadcast(request.user, shelfbook.to_remove_activity(request.user))
|
||||
|
||||
shelfbook.book = new_edition
|
||||
shelfbook.save()
|
||||
|
||||
broadcast(request.user, shelfbook.to_add_activity(request.user))
|
||||
|
||||
readthroughs = models.ReadThrough.objects.filter(
|
||||
book__parent_work=new_edition.parent_work,
|
||||
user=request.user
|
||||
|
|
Loading…
Reference in a new issue