Skip to content

Commit

Permalink
Fix bulk edit to respect searched tags (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker authored Sep 26, 2023
1 parent 9b8929e commit ef585ac
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>Archived bookmarks</h2>
</div>
</div>

<form class="bookmark-actions" action="{% url 'bookmarks:archived.action' %}?q={{ bookmark_list.filters.query }}&return_url={{ bookmark_list.return_url }}"
<form class="bookmark-actions" action="{% url 'bookmarks:archived.action' %}?q={{ bookmark_list.filters.query|urlencode }}&return_url={{ bookmark_list.return_url }}"
method="post">
{% csrf_token %}
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_archive' %}
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>Bookmarks</h2>
</div>
</div>

<form class="bookmark-actions" action="{% url 'bookmarks:index.action' %}?q={{ bookmark_list.filters.query }}&return_url={{ bookmark_list.return_url }}"
<form class="bookmark-actions" action="{% url 'bookmarks:index.action' %}?q={{ bookmark_list.filters.query|urlencode }}&return_url={{ bookmark_list.return_url }}"
method="post" autocomplete="off">
{% csrf_token %}
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_unarchive' %}
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/shared.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2>Shared bookmarks</h2>
{% bookmark_search bookmark_list.filters tag_cloud.tags mode='shared' %}
</div>

<form class="bookmark-actions" action="{% url 'bookmarks:shared.action' %}?return_url={{ bookmark_list.return_url }}"
<form class="bookmark-actions" action="{% url 'bookmarks:shared.action' %}?q={{ bookmark_list.filters.query|urlencode }}&return_url={{ bookmark_list.return_url }}"
method="post">
{% csrf_token %}

Expand Down
10 changes: 10 additions & 0 deletions bookmarks/tests/test_bookmark_archived_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,13 @@ def test_allowed_bulk_actions_with_sharing_enabled(self):
<option value="bulk_unshare">Unshare</option>
</select>
''', html)

def test_url_encode_bookmark_actions_url(self):
url = reverse('bookmarks:archived') + '?q=%23foo'
response = self.client.get(url)
html = response.content.decode()
soup = self.make_soup(html)
actions_form = soup.select('form.bookmark-actions')[0]

self.assertEqual(actions_form.attrs['action'],
'/bookmarks/archived/action?q=%23foo&return_url=%2Fbookmarks%2Farchived%3Fq%3D%2523foo')
10 changes: 10 additions & 0 deletions bookmarks/tests/test_bookmark_index_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,13 @@ def test_allowed_bulk_actions_with_sharing_enabled(self):
<option value="bulk_unshare">Unshare</option>
</select>
''', html)

def test_url_encode_bookmark_actions_url(self):
url = reverse('bookmarks:index') + '?q=%23foo'
response = self.client.get(url)
html = response.content.decode()
soup = self.make_soup(html)
actions_form = soup.select('form.bookmark-actions')[0]

self.assertEqual(actions_form.attrs['action'],
'/bookmarks/action?q=%23foo&return_url=%2Fbookmarks%3Fq%3D%2523foo')
14 changes: 12 additions & 2 deletions bookmarks/tests/test_bookmark_shared_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from django.urls import reverse

from bookmarks.models import Bookmark, Tag, UserProfile
from bookmarks.tests.helpers import BookmarkFactoryMixin, collapse_whitespace
from bookmarks.tests.helpers import BookmarkFactoryMixin, collapse_whitespace, HtmlTestMixin


class BookmarkSharedViewTestCase(TestCase, BookmarkFactoryMixin):
class BookmarkSharedViewTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin):

def authenticate(self) -> None:
user = self.get_or_create_test_user()
Expand Down Expand Up @@ -334,3 +334,13 @@ def test_should_open_bookmarks_in_same_page_if_specified_in_user_profile(self):
response = self.client.get(reverse('bookmarks:shared'))

self.assertVisibleBookmarks(response, visible_bookmarks, '_self')

def test_url_encode_bookmark_actions_url(self):
url = reverse('bookmarks:shared') + '?q=%23foo'
response = self.client.get(url)
html = response.content.decode()
soup = self.make_soup(html)
actions_form = soup.select('form.bookmark-actions')[0]

self.assertEqual(actions_form.attrs['action'],
'/bookmarks/shared/action?q=%23foo&return_url=%2Fbookmarks%2Fshared%3Fq%3D%2523foo')

0 comments on commit ef585ac

Please sign in to comment.