mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-13 21:49:26 +02:00
Make bookmark list actions configurable (#666)
* Make bookmark list actions configurable * Add upgrade notice
This commit is contained in:
@@ -61,6 +61,20 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
||||
|
||||
def assertViewLink(
|
||||
self, html: str, bookmark: Bookmark, return_url=reverse("bookmarks:index")
|
||||
):
|
||||
self.assertViewLinkCount(html, bookmark, return_url=return_url)
|
||||
|
||||
def assertNoViewLink(
|
||||
self, html: str, bookmark: Bookmark, return_url=reverse("bookmarks:index")
|
||||
):
|
||||
self.assertViewLinkCount(html, bookmark, count=0, return_url=return_url)
|
||||
|
||||
def assertViewLinkCount(
|
||||
self,
|
||||
html: str,
|
||||
bookmark: Bookmark,
|
||||
count=1,
|
||||
return_url=reverse("bookmarks:index"),
|
||||
):
|
||||
details_url = reverse("bookmarks:details", args=[bookmark.id])
|
||||
details_modal_url = reverse("bookmarks:details_modal", args=[bookmark.id])
|
||||
@@ -69,7 +83,37 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
||||
<a ld-modal modal-url="{details_modal_url}?return_url={return_url}" href="{details_url}">View</a>
|
||||
""",
|
||||
html,
|
||||
count=1,
|
||||
count=count,
|
||||
)
|
||||
|
||||
def assertEditLinkCount(self, html: str, bookmark: Bookmark, count=1):
|
||||
edit_url = reverse("bookmarks:edit", args=[bookmark.id])
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<a href="{edit_url}?return_url=/bookmarks">Edit</a>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
|
||||
def assertArchiveLinkCount(self, html: str, bookmark: Bookmark, count=1):
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<button type="submit" name="archive" value="{bookmark.id}"
|
||||
class="btn btn-link btn-sm">Archive</button>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
|
||||
def assertDeleteLinkCount(self, html: str, bookmark: Bookmark, count=1):
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<button ld-confirm-button type="submit" name="remove" value="{bookmark.id}"
|
||||
class="btn btn-link btn-sm">Remove</button>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
|
||||
def assertBookmarkActions(self, html: str, bookmark: Bookmark):
|
||||
@@ -79,33 +123,9 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
||||
self.assertBookmarkActionsCount(html, bookmark, count=0)
|
||||
|
||||
def assertBookmarkActionsCount(self, html: str, bookmark: Bookmark, count=1):
|
||||
# Edit link
|
||||
edit_url = reverse("bookmarks:edit", args=[bookmark.id])
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<a href="{edit_url}?return_url=/bookmarks">Edit</a>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
# Archive link
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<button type="submit" name="archive" value="{bookmark.id}"
|
||||
class="btn btn-link btn-sm">Archive</button>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
# Delete link
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<button ld-confirm-button type="submit" name="remove" value="{bookmark.id}"
|
||||
class="btn btn-link btn-sm">Remove</button>
|
||||
""",
|
||||
html,
|
||||
count=count,
|
||||
)
|
||||
self.assertEditLinkCount(html, bookmark, count=count)
|
||||
self.assertArchiveLinkCount(html, bookmark, count=count)
|
||||
self.assertDeleteLinkCount(html, bookmark, count=count)
|
||||
|
||||
def assertShareInfo(self, html: str, bookmark: Bookmark):
|
||||
self.assertShareInfoCount(html, bookmark, 1)
|
||||
@@ -535,6 +555,54 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
||||
self.assertBookmarkActions(html, bookmark)
|
||||
self.assertNoShareInfo(html, bookmark)
|
||||
|
||||
def test_hide_view_link(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
profile = self.get_or_create_test_user().profile
|
||||
profile.display_view_bookmark_action = False
|
||||
profile.save()
|
||||
|
||||
html = self.render_template()
|
||||
self.assertViewLinkCount(html, bookmark, count=0)
|
||||
self.assertEditLinkCount(html, bookmark, count=1)
|
||||
self.assertArchiveLinkCount(html, bookmark, count=1)
|
||||
self.assertDeleteLinkCount(html, bookmark, count=1)
|
||||
|
||||
def test_hide_edit_link(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
profile = self.get_or_create_test_user().profile
|
||||
profile.display_edit_bookmark_action = False
|
||||
profile.save()
|
||||
|
||||
html = self.render_template()
|
||||
self.assertViewLinkCount(html, bookmark, count=1)
|
||||
self.assertEditLinkCount(html, bookmark, count=0)
|
||||
self.assertArchiveLinkCount(html, bookmark, count=1)
|
||||
self.assertDeleteLinkCount(html, bookmark, count=1)
|
||||
|
||||
def test_hide_archive_link(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
profile = self.get_or_create_test_user().profile
|
||||
profile.display_archive_bookmark_action = False
|
||||
profile.save()
|
||||
|
||||
html = self.render_template()
|
||||
self.assertViewLinkCount(html, bookmark, count=1)
|
||||
self.assertEditLinkCount(html, bookmark, count=1)
|
||||
self.assertArchiveLinkCount(html, bookmark, count=0)
|
||||
self.assertDeleteLinkCount(html, bookmark, count=1)
|
||||
|
||||
def test_hide_remove_link(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
profile = self.get_or_create_test_user().profile
|
||||
profile.display_remove_bookmark_action = False
|
||||
profile.save()
|
||||
|
||||
html = self.render_template()
|
||||
self.assertViewLinkCount(html, bookmark, count=1)
|
||||
self.assertEditLinkCount(html, bookmark, count=1)
|
||||
self.assertArchiveLinkCount(html, bookmark, count=1)
|
||||
self.assertDeleteLinkCount(html, bookmark, count=0)
|
||||
|
||||
def test_show_share_info_for_non_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
|
@@ -33,6 +33,10 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
"enable_favicons": False,
|
||||
"tag_search": UserProfile.TAG_SEARCH_STRICT,
|
||||
"display_url": False,
|
||||
"display_view_bookmark_action": True,
|
||||
"display_edit_bookmark_action": True,
|
||||
"display_archive_bookmark_action": True,
|
||||
"display_remove_bookmark_action": True,
|
||||
"permanent_notes": False,
|
||||
"custom_css": "",
|
||||
}
|
||||
@@ -67,6 +71,10 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
"enable_favicons": True,
|
||||
"tag_search": UserProfile.TAG_SEARCH_LAX,
|
||||
"display_url": True,
|
||||
"display_view_bookmark_action": False,
|
||||
"display_edit_bookmark_action": False,
|
||||
"display_archive_bookmark_action": False,
|
||||
"display_remove_bookmark_action": False,
|
||||
"permanent_notes": True,
|
||||
"custom_css": "body { background-color: #000; }",
|
||||
}
|
||||
@@ -104,6 +112,22 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
)
|
||||
self.assertEqual(self.user.profile.tag_search, form_data["tag_search"])
|
||||
self.assertEqual(self.user.profile.display_url, form_data["display_url"])
|
||||
self.assertEqual(
|
||||
self.user.profile.display_view_bookmark_action,
|
||||
form_data["display_view_bookmark_action"],
|
||||
)
|
||||
self.assertEqual(
|
||||
self.user.profile.display_edit_bookmark_action,
|
||||
form_data["display_edit_bookmark_action"],
|
||||
)
|
||||
self.assertEqual(
|
||||
self.user.profile.display_archive_bookmark_action,
|
||||
form_data["display_archive_bookmark_action"],
|
||||
)
|
||||
self.assertEqual(
|
||||
self.user.profile.display_remove_bookmark_action,
|
||||
form_data["display_remove_bookmark_action"],
|
||||
)
|
||||
self.assertEqual(
|
||||
self.user.profile.permanent_notes, form_data["permanent_notes"]
|
||||
)
|
||||
|
@@ -40,7 +40,7 @@ class ToastsViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
# Should render toasts container
|
||||
self.assertContains(response, '<div class="toasts">')
|
||||
# Should render two toasts
|
||||
self.assertContains(response, '<div class="toast">', count=2)
|
||||
self.assertContains(response, '<div class="toast d-flex">', count=2)
|
||||
|
||||
def test_should_not_render_acknowledged_toasts(self):
|
||||
self.create_toast(acknowledged=True)
|
||||
@@ -81,9 +81,9 @@ class ToastsViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
def test_toast_content(self):
|
||||
toast = self.create_toast()
|
||||
expected_toast = f"""
|
||||
<div class="toast">
|
||||
<div class="toast d-flex">
|
||||
{toast.message}
|
||||
<button type="submit" name="toast" value="{toast.id}" class="btn btn-clear float-right"></button>
|
||||
<button type="submit" name="toast" value="{toast.id}" class="btn btn-clear"></button>
|
||||
</div>
|
||||
"""
|
||||
|
||||
|
Reference in New Issue
Block a user