diff --git a/bookwyrm/models/tag.py b/bookwyrm/models/tag.py index cb12d382..6e0ba8ab 100644 --- a/bookwyrm/models/tag.py +++ b/bookwyrm/models/tag.py @@ -66,7 +66,7 @@ class UserTag(BookWyrmModel): id='%s#remove' % self.remote_id, actor=user.remote_id, object=self.book.to_activity(), - target=self.to_activity(), + target=self.remote_id, ).serialize() diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index 38dff400..a01d8cfe 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -283,16 +283,6 @@ def to_markdown(content): return sanitizer.get_output() -def handle_untag(user, book, name): - ''' tag a book ''' - book = models.Book.objects.get(id=book) - tag = models.Tag.objects.get(name=name, book=book, user=user) - tag_activity = tag.to_remove_activity(user) - tag.delete() - - broadcast(user, tag_activity) - - def handle_favorite(user, status): ''' a user likes a status ''' try: diff --git a/bookwyrm/tests/test_view_actions.py b/bookwyrm/tests/test_view_actions.py index 98a57985..b5ed6751 100644 --- a/bookwyrm/tests/test_view_actions.py +++ b/bookwyrm/tests/test_view_actions.py @@ -374,3 +374,23 @@ class ViewActions(TestCase): self.assertEqual(tag.identifier, 'A+Tag%21%3F') self.assertEqual(user_tag.user, self.local_user) self.assertEqual(user_tag.book, self.book) + + + def test_untag(self): + ''' remove a tag from a book ''' + tag = models.Tag.objects.create(name='A Tag!?') + user_tag = models.UserTag.objects.create( + user=self.local_user, book=self.book, tag=tag) + request = self.factory.post( + '', { + 'user': self.local_user.id, + 'book': self.book.id, + 'name': tag.name, + }) + request.user = self.local_user + + with patch('bookwyrm.broadcast.broadcast_task.delay'): + actions.untag(request) + + self.assertTrue(models.Tag.objects.filter(name='A Tag!?').exists()) + self.assertFalse(models.UserTag.objects.exists()) diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index ca632ef9..a8f85c02 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -593,9 +593,16 @@ def tag(request): def untag(request): ''' untag a book ''' name = request.POST.get('name') + tag = get_object_or_404(models.Tag, name=name) book_id = request.POST.get('book') + book = get_object_or_404(models.Edition, id=book_id) - outgoing.handle_untag(request.user, book_id, name) + tag = get_object_or_404( + models.UserTag, tag=tag, book=book, user=request.user) + tag_activity = tag.to_remove_activity(request.user) + tag.delete() + + broadcast(request.user, tag_activity) return redirect('/book/%s' % book_id)