mirror of
https://github.com/sissbruecker/linkding.git
synced 2026-03-12 04:34:41 +08:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e50912df12 | ||
|
|
393d688247 | ||
|
|
6e38587174 | ||
|
|
123c6fe02a | ||
|
|
1b7731e506 | ||
|
|
df9f0095cc | ||
|
|
25470edb2c | ||
|
|
22a1fc80ad | ||
|
|
65f0eb2a04 | ||
|
|
82f86bf537 | ||
|
|
639629ddfe | ||
|
|
2b342c0d56 | ||
|
|
3ffec72d3e | ||
|
|
edd958fff6 | ||
|
|
2d22d6871e | ||
|
|
5e8f5b2c58 | ||
|
|
d5a83722de | ||
|
|
5d8fdebb7c | ||
|
|
f7bd6ccb31 | ||
|
|
e4ee0171be | ||
|
|
53d1f0c91b | ||
|
|
a6f35119cd | ||
|
|
68c163d943 | ||
|
|
bb6c5ca29e |
@@ -5,7 +5,6 @@
|
|||||||
!/bookmarks
|
!/bookmarks
|
||||||
!/siteroot
|
!/siteroot
|
||||||
|
|
||||||
!/background-tasks-wrapper.sh
|
|
||||||
!/bootstrap.sh
|
!/bootstrap.sh
|
||||||
!/LICENSE.txt
|
!/LICENSE.txt
|
||||||
!/manage.py
|
!/manage.py
|
||||||
|
|||||||
5
.github/workflows/main.yaml
vendored
5
.github/workflows/main.yaml
vendored
@@ -24,7 +24,9 @@ jobs:
|
|||||||
- name: Install Node dependencies
|
- name: Install Node dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Setup Python environment
|
- name: Setup Python environment
|
||||||
run: pip install -r requirements.txt -r requirements.dev.txt
|
run: |
|
||||||
|
pip install -r requirements.txt -r requirements.dev.txt
|
||||||
|
mkdir data
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: python manage.py test bookmarks.tests
|
run: python manage.py test bookmarks.tests
|
||||||
e2e_tests:
|
e2e_tests:
|
||||||
@@ -47,6 +49,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
pip install -r requirements.txt -r requirements.dev.txt
|
pip install -r requirements.txt -r requirements.dev.txt
|
||||||
playwright install chromium
|
playwright install chromium
|
||||||
|
mkdir data
|
||||||
- name: Run build
|
- name: Run build
|
||||||
run: |
|
run: |
|
||||||
npm run build
|
npm run build
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -191,3 +191,6 @@ typings/
|
|||||||
/tmp
|
/tmp
|
||||||
# Database file
|
# Database file
|
||||||
/data
|
/data
|
||||||
|
# ublock + chromium
|
||||||
|
/uBlock0.chromium
|
||||||
|
/chromium-profile
|
||||||
|
|||||||
44
CHANGELOG.md
44
CHANGELOG.md
@@ -1,5 +1,49 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.28.0 (09/04/2024)
|
||||||
|
|
||||||
|
### What's Changed
|
||||||
|
* Add option to disable SSL verification for OIDC by @akaSyntaax in https://github.com/sissbruecker/linkding/pull/684
|
||||||
|
* Add full backup method by @sissbruecker in https://github.com/sissbruecker/linkding/pull/686
|
||||||
|
* Truncate snapshot filename for long URLs by @sissbruecker in https://github.com/sissbruecker/linkding/pull/687
|
||||||
|
* Add option for customizing single-file timeout by @pettijohn in https://github.com/sissbruecker/linkding/pull/688
|
||||||
|
* Add option for passing arguments to single-file command by @pettijohn in https://github.com/sissbruecker/linkding/pull/691
|
||||||
|
* Fix typo by @tianheg in https://github.com/sissbruecker/linkding/pull/689
|
||||||
|
|
||||||
|
### New Contributors
|
||||||
|
* @akaSyntaax made their first contribution in https://github.com/sissbruecker/linkding/pull/684
|
||||||
|
* @pettijohn made their first contribution in https://github.com/sissbruecker/linkding/pull/688
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/sissbruecker/linkding/compare/v1.27.1...v1.28.0
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v1.27.1 (07/04/2024)
|
||||||
|
|
||||||
|
### What's Changed
|
||||||
|
* Fix HTML snapshot errors related to single-file-cli by @sissbruecker in https://github.com/sissbruecker/linkding/pull/683
|
||||||
|
* Replace django-background-tasks with huey by @sissbruecker in https://github.com/sissbruecker/linkding/pull/657
|
||||||
|
* Add Authelia OIDC example to docs by @hugo-vrijswijk in https://github.com/sissbruecker/linkding/pull/675
|
||||||
|
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/sissbruecker/linkding/compare/v1.27.0...v1.27.1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v1.27.0 (01/04/2024)
|
||||||
|
|
||||||
|
### What's Changed
|
||||||
|
* Archive snapshots of websites locally by @sissbruecker in https://github.com/sissbruecker/linkding/pull/672
|
||||||
|
* Add Railway hosting option by @tianheg in https://github.com/sissbruecker/linkding/pull/661
|
||||||
|
* Add how to for increasing the font size by @sissbruecker in https://github.com/sissbruecker/linkding/pull/667
|
||||||
|
|
||||||
|
### New Contributors
|
||||||
|
* @tianheg made their first contribution in https://github.com/sissbruecker/linkding/pull/661
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/sissbruecker/linkding/compare/v1.26.0...v1.27.0
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## v1.26.0 (30/03/2024)
|
## v1.26.0 (30/03/2024)
|
||||||
|
|
||||||
### What's Changed
|
### What's Changed
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ The name comes from:
|
|||||||
- Admin panel for user self-service and raw data access
|
- Admin panel for user self-service and raw data access
|
||||||
|
|
||||||
|
|
||||||
**Demo:** https://demo.linkding.link/ ([see here](https://github.com/sissbruecker/linkding/issues/408) if you have trouble accessing it)
|
**Demo:** https://demo.linkding.link/
|
||||||
|
|
||||||
**Screenshot:**
|
**Screenshot:**
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Wrapper script used by supervisord to first clear task locks before starting the background task processor
|
|
||||||
|
|
||||||
python manage.py clean_tasks
|
|
||||||
exec python manage.py process_tasks
|
|
||||||
@@ -1,22 +1,96 @@
|
|||||||
from background_task.admin import TaskAdmin, CompletedTaskAdmin
|
|
||||||
from background_task.models import Task, CompletedTask
|
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin, messages
|
||||||
from django.contrib.admin import AdminSite
|
from django.contrib.admin import AdminSite
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Count, QuerySet
|
from django.db.models import Count, QuerySet
|
||||||
|
from django.shortcuts import render
|
||||||
|
from django.urls import path
|
||||||
from django.utils.translation import ngettext, gettext
|
from django.utils.translation import ngettext, gettext
|
||||||
|
from huey.contrib.djhuey import HUEY as huey
|
||||||
from rest_framework.authtoken.admin import TokenAdmin
|
from rest_framework.authtoken.admin import TokenAdmin
|
||||||
from rest_framework.authtoken.models import TokenProxy
|
from rest_framework.authtoken.models import TokenProxy
|
||||||
|
|
||||||
from bookmarks.models import Bookmark, Tag, UserProfile, Toast, FeedToken
|
from bookmarks.models import Bookmark, BookmarkAsset, Tag, UserProfile, Toast, FeedToken
|
||||||
from bookmarks.services.bookmarks import archive_bookmark, unarchive_bookmark
|
from bookmarks.services.bookmarks import archive_bookmark, unarchive_bookmark
|
||||||
|
|
||||||
|
|
||||||
|
# Custom paginator to paginate through Huey tasks
|
||||||
|
class TaskPaginator(Paginator):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(self, 100)
|
||||||
|
self.task_count = huey.storage.queue_size()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count(self):
|
||||||
|
return self.task_count
|
||||||
|
|
||||||
|
def page(self, number):
|
||||||
|
limit = self.per_page
|
||||||
|
offset = (number - 1) * self.per_page
|
||||||
|
return self._get_page(
|
||||||
|
self.enqueued_items(limit, offset),
|
||||||
|
number,
|
||||||
|
self,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Copied from Huey's SqliteStorage with some modifications to allow pagination
|
||||||
|
def enqueued_items(self, limit, offset):
|
||||||
|
to_bytes = lambda b: bytes(b) if not isinstance(b, bytes) else b
|
||||||
|
sql = "select data from task where queue=? order by priority desc, id limit ? offset ?"
|
||||||
|
params = (huey.storage.name, limit, offset)
|
||||||
|
|
||||||
|
serialized_tasks = [
|
||||||
|
to_bytes(i) for i, in huey.storage.sql(sql, params, results=True)
|
||||||
|
]
|
||||||
|
return [huey.deserialize_task(task) for task in serialized_tasks]
|
||||||
|
|
||||||
|
|
||||||
|
# Custom view to display Huey tasks in the admin
|
||||||
|
def background_task_view(request):
|
||||||
|
page_number = int(request.GET.get("p", 1))
|
||||||
|
paginator = TaskPaginator()
|
||||||
|
page = paginator.get_page(page_number)
|
||||||
|
page_range = paginator.get_elided_page_range(page_number, on_each_side=2, on_ends=2)
|
||||||
|
context = {
|
||||||
|
**linkding_admin_site.each_context(request),
|
||||||
|
"title": "Background tasks",
|
||||||
|
"page": page,
|
||||||
|
"page_range": page_range,
|
||||||
|
"tasks": page.object_list,
|
||||||
|
}
|
||||||
|
return render(request, "admin/background_tasks.html", context)
|
||||||
|
|
||||||
|
|
||||||
class LinkdingAdminSite(AdminSite):
|
class LinkdingAdminSite(AdminSite):
|
||||||
site_header = "linkding administration"
|
site_header = "linkding administration"
|
||||||
site_title = "linkding Admin"
|
site_title = "linkding Admin"
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
custom_urls = [
|
||||||
|
path("tasks/", background_task_view, name="background_tasks"),
|
||||||
|
]
|
||||||
|
return custom_urls + urls
|
||||||
|
|
||||||
|
def get_app_list(self, request, app_label=None):
|
||||||
|
app_list = super().get_app_list(request, app_label)
|
||||||
|
app_list += [
|
||||||
|
{
|
||||||
|
"name": "Huey",
|
||||||
|
"app_label": "huey_app",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"name": "Queued tasks",
|
||||||
|
"object_name": "background_tasks",
|
||||||
|
"admin_url": "/admin/tasks/",
|
||||||
|
"view_only": True,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return app_list
|
||||||
|
|
||||||
|
|
||||||
class AdminBookmark(admin.ModelAdmin):
|
class AdminBookmark(admin.ModelAdmin):
|
||||||
list_display = ("resolved_title", "url", "is_archived", "owner", "date_added")
|
list_display = ("resolved_title", "url", "is_archived", "owner", "date_added")
|
||||||
@@ -125,6 +199,15 @@ class AdminBookmark(admin.ModelAdmin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AdminBookmarkAsset(admin.ModelAdmin):
|
||||||
|
list_display = ("display_name", "date_created", "status")
|
||||||
|
search_fields = (
|
||||||
|
"display_name",
|
||||||
|
"file",
|
||||||
|
)
|
||||||
|
list_filter = ("status",)
|
||||||
|
|
||||||
|
|
||||||
class AdminTag(admin.ModelAdmin):
|
class AdminTag(admin.ModelAdmin):
|
||||||
list_display = ("name", "bookmarks_count", "owner", "date_added")
|
list_display = ("name", "bookmarks_count", "owner", "date_added")
|
||||||
search_fields = ("name", "owner__username")
|
search_fields = ("name", "owner__username")
|
||||||
@@ -200,10 +283,9 @@ class AdminFeedToken(admin.ModelAdmin):
|
|||||||
|
|
||||||
linkding_admin_site = LinkdingAdminSite()
|
linkding_admin_site = LinkdingAdminSite()
|
||||||
linkding_admin_site.register(Bookmark, AdminBookmark)
|
linkding_admin_site.register(Bookmark, AdminBookmark)
|
||||||
|
linkding_admin_site.register(BookmarkAsset, AdminBookmarkAsset)
|
||||||
linkding_admin_site.register(Tag, AdminTag)
|
linkding_admin_site.register(Tag, AdminTag)
|
||||||
linkding_admin_site.register(User, AdminCustomUser)
|
linkding_admin_site.register(User, AdminCustomUser)
|
||||||
linkding_admin_site.register(TokenProxy, TokenAdmin)
|
linkding_admin_site.register(TokenProxy, TokenAdmin)
|
||||||
linkding_admin_site.register(Toast, AdminToast)
|
linkding_admin_site.register(Toast, AdminToast)
|
||||||
linkding_admin_site.register(FeedToken, AdminFeedToken)
|
linkding_admin_site.register(FeedToken, AdminFeedToken)
|
||||||
linkding_admin_site.register(Task, TaskAdmin)
|
|
||||||
linkding_admin_site.register(CompletedTask, CompletedTaskAdmin)
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from django.test import override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from playwright.sync_api import sync_playwright, expect
|
from playwright.sync_api import sync_playwright, expect
|
||||||
|
|
||||||
@@ -44,14 +45,17 @@ class BookmarkDetailsModalE2ETestCase(LinkdingE2ETestCase):
|
|||||||
details_modal = self.open_details_modal(bookmark)
|
details_modal = self.open_details_modal(bookmark)
|
||||||
details_modal.get_by_text("Archived", exact=False).click()
|
details_modal.get_by_text("Archived", exact=False).click()
|
||||||
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
# unarchive
|
# unarchive
|
||||||
url = reverse("bookmarks:archived")
|
url = reverse("bookmarks:archived")
|
||||||
self.page.goto(self.live_server_url + url)
|
self.page.goto(self.live_server_url + url)
|
||||||
|
self.resetReloads()
|
||||||
|
|
||||||
details_modal = self.open_details_modal(bookmark)
|
details_modal = self.open_details_modal(bookmark)
|
||||||
details_modal.get_by_text("Archived", exact=False).click()
|
details_modal.get_by_text("Archived", exact=False).click()
|
||||||
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
def test_toggle_unread(self):
|
def test_toggle_unread(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
@@ -66,11 +70,13 @@ class BookmarkDetailsModalE2ETestCase(LinkdingE2ETestCase):
|
|||||||
details_modal.get_by_text("Unread").click()
|
details_modal.get_by_text("Unread").click()
|
||||||
bookmark_item = self.locate_bookmark(bookmark.title)
|
bookmark_item = self.locate_bookmark(bookmark.title)
|
||||||
expect(bookmark_item.get_by_text("Unread")).to_be_visible()
|
expect(bookmark_item.get_by_text("Unread")).to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
# mark as read
|
# mark as read
|
||||||
details_modal.get_by_text("Unread").click()
|
details_modal.get_by_text("Unread").click()
|
||||||
bookmark_item = self.locate_bookmark(bookmark.title)
|
bookmark_item = self.locate_bookmark(bookmark.title)
|
||||||
expect(bookmark_item.get_by_text("Unread")).not_to_be_visible()
|
expect(bookmark_item.get_by_text("Unread")).not_to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
def test_toggle_shared(self):
|
def test_toggle_shared(self):
|
||||||
profile = self.get_or_create_test_user().profile
|
profile = self.get_or_create_test_user().profile
|
||||||
@@ -89,11 +95,13 @@ class BookmarkDetailsModalE2ETestCase(LinkdingE2ETestCase):
|
|||||||
details_modal.get_by_text("Shared").click()
|
details_modal.get_by_text("Shared").click()
|
||||||
bookmark_item = self.locate_bookmark(bookmark.title)
|
bookmark_item = self.locate_bookmark(bookmark.title)
|
||||||
expect(bookmark_item.get_by_text("Shared")).to_be_visible()
|
expect(bookmark_item.get_by_text("Shared")).to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
# unshare bookmark
|
# unshare bookmark
|
||||||
details_modal.get_by_text("Shared").click()
|
details_modal.get_by_text("Shared").click()
|
||||||
bookmark_item = self.locate_bookmark(bookmark.title)
|
bookmark_item = self.locate_bookmark(bookmark.title)
|
||||||
expect(bookmark_item.get_by_text("Shared")).not_to_be_visible()
|
expect(bookmark_item.get_by_text("Shared")).not_to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
def test_edit_return_url(self):
|
def test_edit_return_url(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
@@ -131,3 +139,33 @@ class BookmarkDetailsModalE2ETestCase(LinkdingE2ETestCase):
|
|||||||
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
expect(self.locate_bookmark(bookmark.title)).not_to_be_visible()
|
||||||
|
|
||||||
self.assertEqual(Bookmark.objects.count(), 0)
|
self.assertEqual(Bookmark.objects.count(), 0)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_snapshot_remove_snapshot(self):
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
|
||||||
|
with sync_playwright() as p:
|
||||||
|
url = reverse("bookmarks:index") + f"?q={bookmark.title}"
|
||||||
|
self.open(url, p)
|
||||||
|
|
||||||
|
details_modal = self.open_details_modal(bookmark)
|
||||||
|
asset_list = details_modal.locator(".assets")
|
||||||
|
|
||||||
|
# No snapshots initially
|
||||||
|
snapshot = asset_list.get_by_text("HTML snapshot from", exact=False)
|
||||||
|
expect(snapshot).not_to_be_visible()
|
||||||
|
|
||||||
|
# Create snapshot
|
||||||
|
details_modal.get_by_text("Create HTML snapshot", exact=False).click()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|
||||||
|
# Has new snapshots
|
||||||
|
expect(snapshot).to_be_visible()
|
||||||
|
|
||||||
|
# Create snapshot
|
||||||
|
asset_list.get_by_text("Remove", exact=False).click()
|
||||||
|
asset_list.get_by_text("Confirm", exact=False).click()
|
||||||
|
|
||||||
|
# Snapshot is removed
|
||||||
|
expect(snapshot).not_to_be_visible()
|
||||||
|
self.assertReloads(0)
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
self.locate_bulk_edit_toggle().click()
|
self.locate_bulk_edit_toggle().click()
|
||||||
|
|
||||||
checkboxes = page.locator("label[ld-bulk-edit-checkbox] input")
|
checkboxes = page.locator("label.bulk-edit-checkbox input")
|
||||||
self.assertEqual(6, checkboxes.count())
|
self.assertEqual(6, checkboxes.count())
|
||||||
for i in range(checkboxes.count()):
|
for i in range(checkboxes.count()):
|
||||||
expect(checkboxes.nth(i)).not_to_be_checked()
|
expect(checkboxes.nth(i)).not_to_be_checked()
|
||||||
@@ -264,13 +264,13 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
# Hide select across by toggling a single bookmark
|
# Hide select across by toggling a single bookmark
|
||||||
self.locate_bookmark("Bookmark 1").locator(
|
self.locate_bookmark("Bookmark 1").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
expect(self.locate_bulk_edit_select_across()).not_to_be_visible()
|
expect(self.locate_bulk_edit_select_across()).not_to_be_visible()
|
||||||
|
|
||||||
# Show select across again, verify it is unchecked
|
# Show select across again, verify it is unchecked
|
||||||
self.locate_bookmark("Bookmark 1").locator(
|
self.locate_bookmark("Bookmark 1").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
expect(self.locate_bulk_edit_select_across()).not_to_be_checked()
|
expect(self.locate_bulk_edit_select_across()).not_to_be_checked()
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
expect(bookmark_list).not_to_be_visible()
|
expect(bookmark_list).not_to_be_visible()
|
||||||
|
|
||||||
# Verify bulk edit checkboxes are reset
|
# Verify bulk edit checkboxes are reset
|
||||||
checkboxes = page.locator("label[ld-bulk-edit-checkbox] input")
|
checkboxes = page.locator("label.bulk-edit-checkbox input")
|
||||||
self.assertEqual(31, checkboxes.count())
|
self.assertEqual(31, checkboxes.count())
|
||||||
for i in range(checkboxes.count()):
|
for i in range(checkboxes.count()):
|
||||||
expect(checkboxes.nth(i)).not_to_be_checked()
|
expect(checkboxes.nth(i)).not_to_be_checked()
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
self.locate_bulk_edit_toggle().click()
|
self.locate_bulk_edit_toggle().click()
|
||||||
self.locate_bookmark("Bookmark 2").locator(
|
self.locate_bookmark("Bookmark 2").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
self.select_bulk_action("Archive")
|
self.select_bulk_action("Archive")
|
||||||
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
||||||
@@ -187,7 +187,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
self.locate_bulk_edit_toggle().click()
|
self.locate_bulk_edit_toggle().click()
|
||||||
self.locate_bookmark("Bookmark 2").locator(
|
self.locate_bookmark("Bookmark 2").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
self.select_bulk_action("Delete")
|
self.select_bulk_action("Delete")
|
||||||
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
||||||
@@ -230,7 +230,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
self.locate_bulk_edit_toggle().click()
|
self.locate_bulk_edit_toggle().click()
|
||||||
self.locate_bookmark("Archived Bookmark 2").locator(
|
self.locate_bookmark("Archived Bookmark 2").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
self.select_bulk_action("Unarchive")
|
self.select_bulk_action("Unarchive")
|
||||||
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
||||||
@@ -248,7 +248,7 @@ class BookmarkPagePartialUpdatesE2ETestCase(LinkdingE2ETestCase):
|
|||||||
|
|
||||||
self.locate_bulk_edit_toggle().click()
|
self.locate_bulk_edit_toggle().click()
|
||||||
self.locate_bookmark("Archived Bookmark 2").locator(
|
self.locate_bookmark("Archived Bookmark 2").locator(
|
||||||
"label[ld-bulk-edit-checkbox]"
|
"label.bulk-edit-checkbox"
|
||||||
).click()
|
).click()
|
||||||
self.select_bulk_action("Delete")
|
self.select_bulk_action("Delete")
|
||||||
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
self.locate_bulk_edit_bar().get_by_text("Execute").click()
|
||||||
|
|||||||
76
bookmarks/e2e/e2e_test_tag_cloud_modal.py
Normal file
76
bookmarks/e2e/e2e_test_tag_cloud_modal.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
from django.test import override_settings
|
||||||
|
from django.urls import reverse
|
||||||
|
from playwright.sync_api import sync_playwright, expect, Locator
|
||||||
|
|
||||||
|
from bookmarks.e2e.helpers import LinkdingE2ETestCase
|
||||||
|
from bookmarks.models import Bookmark
|
||||||
|
|
||||||
|
|
||||||
|
class TagCloudModalE2ETestCase(LinkdingE2ETestCase):
|
||||||
|
def test_show_modal_close_modal(self):
|
||||||
|
self.setup_bookmark(tags=[self.setup_tag(name="cooking")])
|
||||||
|
self.setup_bookmark(tags=[self.setup_tag(name="hiking")])
|
||||||
|
|
||||||
|
with sync_playwright() as p:
|
||||||
|
page = self.open(reverse("bookmarks:index"), p)
|
||||||
|
|
||||||
|
# use smaller viewport to make tags button visible
|
||||||
|
page.set_viewport_size({"width": 375, "height": 812})
|
||||||
|
|
||||||
|
# open tag cloud modal
|
||||||
|
modal_trigger = page.locator(".content-area-header").get_by_role(
|
||||||
|
"button", name="Tags"
|
||||||
|
)
|
||||||
|
modal_trigger.click()
|
||||||
|
|
||||||
|
# verify modal is visible
|
||||||
|
modal = page.locator(".modal")
|
||||||
|
expect(modal).to_be_visible()
|
||||||
|
expect(modal.locator(".modal-title")).to_have_text("Tags")
|
||||||
|
|
||||||
|
# close with close button
|
||||||
|
modal.locator("button.close").click()
|
||||||
|
expect(modal).to_be_hidden()
|
||||||
|
|
||||||
|
# open modal again
|
||||||
|
modal_trigger.click()
|
||||||
|
|
||||||
|
# close with backdrop
|
||||||
|
backdrop = modal.locator(".modal-overlay")
|
||||||
|
backdrop.click(position={"x": 0, "y": 0})
|
||||||
|
expect(modal).to_be_hidden()
|
||||||
|
|
||||||
|
def test_select_tag(self):
|
||||||
|
self.setup_bookmark(tags=[self.setup_tag(name="cooking")])
|
||||||
|
self.setup_bookmark(tags=[self.setup_tag(name="hiking")])
|
||||||
|
|
||||||
|
with sync_playwright() as p:
|
||||||
|
page = self.open(reverse("bookmarks:index"), p)
|
||||||
|
|
||||||
|
# use smaller viewport to make tags button visible
|
||||||
|
page.set_viewport_size({"width": 375, "height": 812})
|
||||||
|
|
||||||
|
# open tag cloud modal
|
||||||
|
modal_trigger = page.locator(".content-area-header").get_by_role(
|
||||||
|
"button", name="Tags"
|
||||||
|
)
|
||||||
|
modal_trigger.click()
|
||||||
|
|
||||||
|
# verify tags are displayed
|
||||||
|
modal = page.locator(".modal")
|
||||||
|
unselected_tags = modal.locator(".unselected-tags")
|
||||||
|
expect(unselected_tags.get_by_text("cooking")).to_be_visible()
|
||||||
|
expect(unselected_tags.get_by_text("hiking")).to_be_visible()
|
||||||
|
|
||||||
|
# select tag
|
||||||
|
unselected_tags.get_by_text("cooking").click()
|
||||||
|
|
||||||
|
# open modal again
|
||||||
|
modal_trigger.click()
|
||||||
|
|
||||||
|
# verify tag is selected, other tag is not visible anymore
|
||||||
|
selected_tags = modal.locator(".selected-tags")
|
||||||
|
expect(selected_tags.get_by_text("cooking")).to_be_visible()
|
||||||
|
|
||||||
|
expect(unselected_tags.get_by_text("cooking")).not_to_be_visible()
|
||||||
|
expect(unselected_tags.get_by_text("hiking")).not_to_be_visible()
|
||||||
@@ -39,6 +39,9 @@ class LinkdingE2ETestCase(LiveServerTestCase, BookmarkFactoryMixin):
|
|||||||
def assertReloads(self, count: int):
|
def assertReloads(self, count: int):
|
||||||
self.assertEqual(self.num_loads, count)
|
self.assertEqual(self.num_loads, count)
|
||||||
|
|
||||||
|
def resetReloads(self):
|
||||||
|
self.num_loads = 0
|
||||||
|
|
||||||
def locate_bookmark_list(self):
|
def locate_bookmark_list(self):
|
||||||
return self.page.locator("ul[ld-bookmark-list]")
|
return self.page.locator("ul[ld-bookmark-list]")
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ class LinkdingE2ETestCase(LiveServerTestCase, BookmarkFactoryMixin):
|
|||||||
return self.page.locator(".bulk-edit-bar")
|
return self.page.locator(".bulk-edit-bar")
|
||||||
|
|
||||||
def locate_bulk_edit_select_all(self):
|
def locate_bulk_edit_select_all(self):
|
||||||
return self.locate_bulk_edit_bar().locator("label[ld-bulk-edit-checkbox][all]")
|
return self.locate_bulk_edit_bar().locator("label.bulk-edit-checkbox.all")
|
||||||
|
|
||||||
def locate_bulk_edit_select_across(self):
|
def locate_bulk_edit_select_across(self):
|
||||||
return self.locate_bulk_edit_bar().locator("label.select-across")
|
return self.locate_bulk_edit_bar().locator("label.select-across")
|
||||||
|
|||||||
@@ -1,67 +1,8 @@
|
|||||||
import { registerBehavior, swapContent } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
class BookmarkPage {
|
class BookmarkItem extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this.element = element;
|
super(element);
|
||||||
this.form = element.querySelector("form.bookmark-actions");
|
|
||||||
this.form.addEventListener("submit", this.onFormSubmit.bind(this));
|
|
||||||
|
|
||||||
this.bookmarkList = element.querySelector(".bookmark-list-container");
|
|
||||||
this.tagCloud = element.querySelector(".tag-cloud-container");
|
|
||||||
|
|
||||||
document.addEventListener("bookmark-page-refresh", () => {
|
|
||||||
this.refresh();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async onFormSubmit(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const url = this.form.action;
|
|
||||||
const formData = new FormData(this.form);
|
|
||||||
formData.append(event.submitter.name, event.submitter.value);
|
|
||||||
|
|
||||||
await fetch(url, {
|
|
||||||
method: "POST",
|
|
||||||
body: formData,
|
|
||||||
redirect: "manual", // ignore redirect
|
|
||||||
});
|
|
||||||
await this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
async refresh() {
|
|
||||||
const query = window.location.search;
|
|
||||||
const bookmarksUrl = this.element.getAttribute("bookmarks-url");
|
|
||||||
const tagsUrl = this.element.getAttribute("tags-url");
|
|
||||||
Promise.all([
|
|
||||||
fetch(`${bookmarksUrl}${query}`).then((response) => response.text()),
|
|
||||||
fetch(`${tagsUrl}${query}`).then((response) => response.text()),
|
|
||||||
]).then(([bookmarkListHtml, tagCloudHtml]) => {
|
|
||||||
swapContent(this.bookmarkList, bookmarkListHtml);
|
|
||||||
swapContent(this.tagCloud, tagCloudHtml);
|
|
||||||
|
|
||||||
// Dispatch list updated event
|
|
||||||
const listElement = this.bookmarkList.querySelector(
|
|
||||||
"ul[data-bookmarks-total]",
|
|
||||||
);
|
|
||||||
const bookmarksTotal =
|
|
||||||
(listElement && listElement.dataset.bookmarksTotal) || 0;
|
|
||||||
|
|
||||||
this.bookmarkList.dispatchEvent(
|
|
||||||
new CustomEvent("bookmark-list-updated", {
|
|
||||||
bubbles: true,
|
|
||||||
detail: { bookmarksTotal },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBehavior("ld-bookmark-page", BookmarkPage);
|
|
||||||
|
|
||||||
class BookmarkItem {
|
|
||||||
constructor(element) {
|
|
||||||
this.element = element;
|
|
||||||
|
|
||||||
// Toggle notes
|
// Toggle notes
|
||||||
const notesToggle = element.querySelector(".toggle-notes");
|
const notesToggle = element.querySelector(".toggle-notes");
|
||||||
@@ -72,9 +13,11 @@ class BookmarkItem {
|
|||||||
// Add tooltip to title if it is truncated
|
// Add tooltip to title if it is truncated
|
||||||
const titleAnchor = element.querySelector(".title > a");
|
const titleAnchor = element.querySelector(".title > a");
|
||||||
const titleSpan = titleAnchor.querySelector("span");
|
const titleSpan = titleAnchor.querySelector("span");
|
||||||
if (titleSpan.offsetWidth > titleAnchor.offsetWidth) {
|
requestAnimationFrame(() => {
|
||||||
titleAnchor.dataset.tooltip = titleSpan.textContent;
|
if (titleSpan.offsetWidth > titleAnchor.offsetWidth) {
|
||||||
}
|
titleAnchor.dataset.tooltip = titleSpan.textContent;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggleNotes(event) {
|
onToggleNotes(event) {
|
||||||
|
|||||||
@@ -1,46 +1,60 @@
|
|||||||
import { registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
class BulkEdit {
|
class BulkEdit extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this.element = element;
|
super(element);
|
||||||
|
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.actionSelect = element.querySelector("select[name='bulk_action']");
|
|
||||||
this.tagAutoComplete = element.querySelector(".tag-autocomplete");
|
|
||||||
this.selectAcross = element.querySelector("label.select-across");
|
|
||||||
|
|
||||||
element.addEventListener(
|
this.onToggleActive = this.onToggleActive.bind(this);
|
||||||
"bulk-edit-toggle-active",
|
this.onToggleAll = this.onToggleAll.bind(this);
|
||||||
this.onToggleActive.bind(this),
|
this.onToggleBookmark = this.onToggleBookmark.bind(this);
|
||||||
);
|
this.onActionSelected = this.onActionSelected.bind(this);
|
||||||
element.addEventListener(
|
|
||||||
"bulk-edit-toggle-all",
|
|
||||||
this.onToggleAll.bind(this),
|
|
||||||
);
|
|
||||||
element.addEventListener(
|
|
||||||
"bulk-edit-toggle-bookmark",
|
|
||||||
this.onToggleBookmark.bind(this),
|
|
||||||
);
|
|
||||||
element.addEventListener(
|
|
||||||
"bookmark-list-updated",
|
|
||||||
this.onListUpdated.bind(this),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.actionSelect.addEventListener(
|
this.init();
|
||||||
"change",
|
// Reset when bookmarks are refreshed
|
||||||
this.onActionSelected.bind(this),
|
document.addEventListener("refresh-bookmark-list-done", () => this.init());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get allCheckbox() {
|
init() {
|
||||||
return this.element.querySelector("[ld-bulk-edit-checkbox][all] input");
|
// Update elements
|
||||||
}
|
this.activeToggle = this.element.querySelector(".bulk-edit-active-toggle");
|
||||||
|
this.actionSelect = this.element.querySelector(
|
||||||
|
"select[name='bulk_action']",
|
||||||
|
);
|
||||||
|
this.tagAutoComplete = this.element.querySelector(".tag-autocomplete");
|
||||||
|
this.selectAcross = this.element.querySelector("label.select-across");
|
||||||
|
this.allCheckbox = this.element.querySelector(
|
||||||
|
".bulk-edit-checkbox.all input",
|
||||||
|
);
|
||||||
|
this.bookmarkCheckboxes = Array.from(
|
||||||
|
this.element.querySelectorAll(".bulk-edit-checkbox:not(.all) input"),
|
||||||
|
);
|
||||||
|
|
||||||
get bookmarkCheckboxes() {
|
// Remove previous listeners if elements are the same
|
||||||
return [
|
this.activeToggle.removeEventListener("click", this.onToggleActive);
|
||||||
...this.element.querySelectorAll(
|
this.actionSelect.removeEventListener("change", this.onActionSelected);
|
||||||
"[ld-bulk-edit-checkbox]:not([all]) input",
|
this.allCheckbox.removeEventListener("change", this.onToggleAll);
|
||||||
),
|
this.bookmarkCheckboxes.forEach((checkbox) => {
|
||||||
];
|
checkbox.removeEventListener("change", this.onToggleBookmark);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset checkbox states
|
||||||
|
this.reset();
|
||||||
|
|
||||||
|
// Update total number of bookmarks
|
||||||
|
const totalHolder = this.element.querySelector("[data-bookmarks-total]");
|
||||||
|
const total = totalHolder?.dataset.bookmarksTotal || 0;
|
||||||
|
const totalSpan = this.selectAcross.querySelector("span.total");
|
||||||
|
totalSpan.textContent = total;
|
||||||
|
|
||||||
|
// Add new listeners
|
||||||
|
this.activeToggle.addEventListener("click", this.onToggleActive);
|
||||||
|
this.actionSelect.addEventListener("change", this.onActionSelected);
|
||||||
|
this.allCheckbox.addEventListener("change", this.onToggleAll);
|
||||||
|
this.bookmarkCheckboxes.forEach((checkbox) => {
|
||||||
|
checkbox.addEventListener("change", this.onToggleBookmark);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggleActive() {
|
onToggleActive() {
|
||||||
@@ -81,16 +95,6 @@ class BulkEdit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onListUpdated(event) {
|
|
||||||
// Reset checkbox states
|
|
||||||
this.reset();
|
|
||||||
|
|
||||||
// Update total number of bookmarks
|
|
||||||
const total = event.detail.bookmarksTotal;
|
|
||||||
const totalSpan = this.selectAcross.querySelector("span.total");
|
|
||||||
totalSpan.textContent = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSelectAcross(allChecked) {
|
updateSelectAcross(allChecked) {
|
||||||
if (allChecked) {
|
if (allChecked) {
|
||||||
this.selectAcross.classList.remove("d-none");
|
this.selectAcross.classList.remove("d-none");
|
||||||
@@ -109,33 +113,4 @@ class BulkEdit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BulkEditActiveToggle {
|
|
||||||
constructor(element) {
|
|
||||||
this.element = element;
|
|
||||||
element.addEventListener("click", this.onClick.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
onClick() {
|
|
||||||
this.element.dispatchEvent(
|
|
||||||
new CustomEvent("bulk-edit-toggle-active", { bubbles: true }),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BulkEditCheckbox {
|
|
||||||
constructor(element) {
|
|
||||||
this.element = element;
|
|
||||||
element.addEventListener("change", this.onChange.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange() {
|
|
||||||
const type = this.element.hasAttribute("all") ? "all" : "bookmark";
|
|
||||||
this.element.dispatchEvent(
|
|
||||||
new CustomEvent(`bulk-edit-toggle-${type}`, { bubbles: true }),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBehavior("ld-bulk-edit", BulkEdit);
|
registerBehavior("ld-bulk-edit", BulkEdit);
|
||||||
registerBehavior("ld-bulk-edit-active-toggle", BulkEditActiveToggle);
|
|
||||||
registerBehavior("ld-bulk-edit-checkbox", BulkEditCheckbox);
|
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
import { registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
class ConfirmButtonBehavior {
|
class ConfirmButtonBehavior extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
const button = element;
|
super(element);
|
||||||
button.dataset.type = button.type;
|
element.dataset.type = element.type;
|
||||||
button.dataset.name = button.name;
|
element.dataset.name = element.name;
|
||||||
button.dataset.value = button.value;
|
element.dataset.value = element.value;
|
||||||
button.removeAttribute("type");
|
element.removeAttribute("type");
|
||||||
button.removeAttribute("name");
|
element.removeAttribute("name");
|
||||||
button.removeAttribute("value");
|
element.removeAttribute("value");
|
||||||
button.addEventListener("click", this.onClick.bind(this));
|
element.addEventListener("click", this.onClick.bind(this));
|
||||||
this.button = button;
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
Behavior.interacting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick(event) {
|
onClick(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Behavior.interacting = true;
|
||||||
|
|
||||||
const container = document.createElement("span");
|
const container = document.createElement("span");
|
||||||
container.className = "confirmation";
|
container.className = "confirmation";
|
||||||
|
|
||||||
const icon = this.button.getAttribute("confirm-icon");
|
const icon = this.element.getAttribute("ld-confirm-icon");
|
||||||
if (icon) {
|
if (icon) {
|
||||||
const iconElement = document.createElementNS(
|
const iconElement = document.createElementNS(
|
||||||
"http://www.w3.org/2000/svg",
|
"http://www.w3.org/2000/svg",
|
||||||
@@ -31,27 +35,27 @@ class ConfirmButtonBehavior {
|
|||||||
container.append(iconElement);
|
container.append(iconElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
const question = this.button.getAttribute("confirm-question");
|
const question = this.element.getAttribute("ld-confirm-question");
|
||||||
if (question) {
|
if (question) {
|
||||||
const questionElement = document.createElement("span");
|
const questionElement = document.createElement("span");
|
||||||
questionElement.innerText = question;
|
questionElement.innerText = question;
|
||||||
container.append(question);
|
container.append(question);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttonClasses = Array.from(this.button.classList.values())
|
const buttonClasses = Array.from(this.element.classList.values())
|
||||||
.filter((cls) => cls.startsWith("btn"))
|
.filter((cls) => cls.startsWith("btn"))
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
const cancelButton = document.createElement(this.button.nodeName);
|
const cancelButton = document.createElement(this.element.nodeName);
|
||||||
cancelButton.type = "button";
|
cancelButton.type = "button";
|
||||||
cancelButton.innerText = question ? "No" : "Cancel";
|
cancelButton.innerText = question ? "No" : "Cancel";
|
||||||
cancelButton.className = `${buttonClasses} mr-1`;
|
cancelButton.className = `${buttonClasses} mr-1`;
|
||||||
cancelButton.addEventListener("click", this.reset.bind(this));
|
cancelButton.addEventListener("click", this.reset.bind(this));
|
||||||
|
|
||||||
const confirmButton = document.createElement(this.button.nodeName);
|
const confirmButton = document.createElement(this.element.nodeName);
|
||||||
confirmButton.type = this.button.dataset.type;
|
confirmButton.type = this.element.dataset.type;
|
||||||
confirmButton.name = this.button.dataset.name;
|
confirmButton.name = this.element.dataset.name;
|
||||||
confirmButton.value = this.button.dataset.value;
|
confirmButton.value = this.element.dataset.value;
|
||||||
confirmButton.innerText = question ? "Yes" : "Confirm";
|
confirmButton.innerText = question ? "Yes" : "Confirm";
|
||||||
confirmButton.className = buttonClasses;
|
confirmButton.className = buttonClasses;
|
||||||
confirmButton.addEventListener("click", this.reset.bind(this));
|
confirmButton.addEventListener("click", this.reset.bind(this));
|
||||||
@@ -59,14 +63,15 @@ class ConfirmButtonBehavior {
|
|||||||
container.append(cancelButton, confirmButton);
|
container.append(cancelButton, confirmButton);
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
this.button.before(container);
|
this.element.before(container);
|
||||||
this.button.classList.add("d-none");
|
this.element.classList.add("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
Behavior.interacting = false;
|
||||||
this.container.remove();
|
this.container.remove();
|
||||||
this.button.classList.remove("d-none");
|
this.element.classList.remove("d-none");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
class DropdownBehavior {
|
class DropdownBehavior extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this.element = element;
|
super(element);
|
||||||
this.opened = false;
|
this.opened = false;
|
||||||
this.onOutsideClick = this.onOutsideClick.bind(this);
|
this.onOutsideClick = this.onOutsideClick.bind(this);
|
||||||
|
|
||||||
|
|||||||
48
bookmarks/frontend/behaviors/fetch.js
Normal file
48
bookmarks/frontend/behaviors/fetch.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { Behavior, fireEvents, registerBehavior, swap } from "./index";
|
||||||
|
|
||||||
|
class FetchBehavior extends Behavior {
|
||||||
|
constructor(element) {
|
||||||
|
super(element);
|
||||||
|
|
||||||
|
const eventName = element.getAttribute("ld-on");
|
||||||
|
const interval = parseInt(element.getAttribute("ld-interval")) * 1000;
|
||||||
|
|
||||||
|
this.onFetch = this.onFetch.bind(this);
|
||||||
|
this.onInterval = this.onInterval.bind(this);
|
||||||
|
|
||||||
|
element.addEventListener(eventName, this.onFetch);
|
||||||
|
if (interval) {
|
||||||
|
this.intervalId = setInterval(this.onInterval, interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (this.intervalId) {
|
||||||
|
clearInterval(this.intervalId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async onFetch(maybeEvent) {
|
||||||
|
if (maybeEvent) {
|
||||||
|
maybeEvent.preventDefault();
|
||||||
|
}
|
||||||
|
const url = this.element.getAttribute("ld-fetch");
|
||||||
|
const html = await fetch(url).then((response) => response.text());
|
||||||
|
|
||||||
|
const target = this.element.getAttribute("ld-target");
|
||||||
|
const select = this.element.getAttribute("ld-select");
|
||||||
|
swap(this.element, html, { target, select });
|
||||||
|
|
||||||
|
const events = this.element.getAttribute("ld-fire");
|
||||||
|
fireEvents(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
onInterval() {
|
||||||
|
if (Behavior.interacting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.onFetch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerBehavior("ld-fetch", FetchBehavior);
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import { registerBehavior, swap } from "./index";
|
import { Behavior, fireEvents, registerBehavior } from "./index";
|
||||||
|
|
||||||
class FormBehavior {
|
class FormBehavior extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this.element = element;
|
super(element);
|
||||||
element.addEventListener("submit", this.onFormSubmit.bind(this));
|
|
||||||
|
element.addEventListener("submit", this.onSubmit.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async onFormSubmit(event) {
|
async onSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const url = this.element.action;
|
const url = this.element.action;
|
||||||
@@ -21,34 +22,23 @@ class FormBehavior {
|
|||||||
redirect: "manual", // ignore redirect
|
redirect: "manual", // ignore redirect
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dispatch refresh events
|
const events = this.element.getAttribute("ld-fire");
|
||||||
const refreshEvents = this.element.getAttribute("refresh-events");
|
if (fireEvents) {
|
||||||
if (refreshEvents) {
|
fireEvents(events);
|
||||||
refreshEvents.split(",").forEach((eventName) => {
|
|
||||||
document.dispatchEvent(new CustomEvent(eventName));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh form
|
|
||||||
await this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
async refresh() {
|
|
||||||
const refreshUrl = this.element.getAttribute("refresh-url");
|
|
||||||
const html = await fetch(refreshUrl).then((response) => response.text());
|
|
||||||
swap(this.element, html);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormAutoSubmitBehavior {
|
class AutoSubmitBehavior extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this.element = element;
|
super(element);
|
||||||
this.element.addEventListener("change", () => {
|
|
||||||
const form = this.element.closest("form");
|
element.addEventListener("change", () => {
|
||||||
|
const form = element.closest("form");
|
||||||
form.dispatchEvent(new Event("submit", { cancelable: true }));
|
form.dispatchEvent(new Event("submit", { cancelable: true }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerBehavior("ld-form", FormBehavior);
|
registerBehavior("ld-form", FormBehavior);
|
||||||
registerBehavior("ld-form-auto-submit", FormAutoSubmitBehavior);
|
registerBehavior("ld-auto-submit", AutoSubmitBehavior);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
|
class GlobalShortcuts extends Behavior {
|
||||||
|
constructor(element) {
|
||||||
|
super(element);
|
||||||
|
|
||||||
class GlobalShortcuts {
|
|
||||||
constructor() {
|
|
||||||
document.addEventListener("keydown", this.onKeyDown.bind(this));
|
document.addEventListener("keydown", this.onKeyDown.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,35 @@
|
|||||||
const behaviorRegistry = {};
|
const behaviorRegistry = {};
|
||||||
|
const debug = false;
|
||||||
|
|
||||||
|
const mutationObserver = new MutationObserver((mutations) => {
|
||||||
|
mutations.forEach((mutation) => {
|
||||||
|
mutation.removedNodes.forEach((node) => {
|
||||||
|
if (node instanceof HTMLElement && !node.isConnected) {
|
||||||
|
destroyBehaviors(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mutation.addedNodes.forEach((node) => {
|
||||||
|
if (node instanceof HTMLElement && node.isConnected) {
|
||||||
|
applyBehaviors(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
mutationObserver.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export class Behavior {
|
||||||
|
constructor(element) {
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Behavior.interacting = false;
|
||||||
|
|
||||||
export function registerBehavior(name, behavior) {
|
export function registerBehavior(name, behavior) {
|
||||||
behaviorRegistry[name] = behavior;
|
behaviorRegistry[name] = behavior;
|
||||||
@@ -33,18 +64,82 @@ export function applyBehaviors(container, behaviorNames = null) {
|
|||||||
|
|
||||||
const behaviorInstance = new behavior(element);
|
const behaviorInstance = new behavior(element);
|
||||||
element.__behaviors.push(behaviorInstance);
|
element.__behaviors.push(behaviorInstance);
|
||||||
|
if (debug) {
|
||||||
|
console.log(
|
||||||
|
`[Behavior] ${behaviorInstance.constructor.name} initialized`,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function swap(element, html) {
|
export function destroyBehaviors(element) {
|
||||||
const dom = new DOMParser().parseFromString(html, "text/html");
|
const behaviorNames = Object.keys(behaviorRegistry);
|
||||||
const newElement = dom.body.firstChild;
|
|
||||||
element.replaceWith(newElement);
|
behaviorNames.forEach((behaviorName) => {
|
||||||
applyBehaviors(newElement);
|
const elements = Array.from(element.querySelectorAll(`[${behaviorName}]`));
|
||||||
|
elements.push(element);
|
||||||
|
|
||||||
|
elements.forEach((element) => {
|
||||||
|
if (!element.__behaviors) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
element.__behaviors.forEach((behavior) => {
|
||||||
|
behavior.destroy();
|
||||||
|
if (debug) {
|
||||||
|
console.log(`[Behavior] ${behavior.constructor.name} destroyed`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
delete element.__behaviors;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function swapContent(element, html) {
|
export function swap(element, html, options) {
|
||||||
element.innerHTML = html;
|
const dom = new DOMParser().parseFromString(html, "text/html");
|
||||||
applyBehaviors(element);
|
|
||||||
|
let targetElement = element;
|
||||||
|
let strategy = "innerHTML";
|
||||||
|
if (options.target) {
|
||||||
|
const parts = options.target.split("|");
|
||||||
|
targetElement =
|
||||||
|
parts[0] === "self" ? element : document.querySelector(parts[0]);
|
||||||
|
strategy = parts[1] || "innerHTML";
|
||||||
|
}
|
||||||
|
|
||||||
|
let contents = Array.from(dom.body.children);
|
||||||
|
if (options.select) {
|
||||||
|
contents = Array.from(dom.querySelectorAll(options.select));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (strategy) {
|
||||||
|
case "append":
|
||||||
|
targetElement.append(...contents);
|
||||||
|
break;
|
||||||
|
case "outerHTML":
|
||||||
|
targetElement.parentElement.replaceChild(contents[0], targetElement);
|
||||||
|
break;
|
||||||
|
case "innerHTML":
|
||||||
|
default:
|
||||||
|
Array.from(targetElement.children).forEach((child) => {
|
||||||
|
child.remove();
|
||||||
|
});
|
||||||
|
targetElement.append(...contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fireEvents(events) {
|
||||||
|
if (!events) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
events.split(",").forEach((eventName) => {
|
||||||
|
const targets = Array.from(
|
||||||
|
document.querySelectorAll(`[ld-on='${eventName}']`),
|
||||||
|
);
|
||||||
|
targets.push(document);
|
||||||
|
targets.forEach((target) => {
|
||||||
|
target.dispatchEvent(new CustomEvent(eventName));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,97 +1,20 @@
|
|||||||
import { applyBehaviors, registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
|
|
||||||
class ModalBehavior {
|
class ModalBehavior extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
const toggle = element;
|
super(element);
|
||||||
toggle.addEventListener("click", this.onToggleClick.bind(this));
|
|
||||||
this.toggle = toggle;
|
|
||||||
}
|
|
||||||
|
|
||||||
async onToggleClick(event) {
|
const modalOverlay = element.querySelector(".modal-overlay");
|
||||||
// Ignore Ctrl + click
|
const closeButton = element.querySelector("button.close");
|
||||||
if (event.ctrlKey || event.metaKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
// Create modal either by teleporting existing content or fetching from URL
|
|
||||||
const modal = this.toggle.hasAttribute("modal-content")
|
|
||||||
? this.createFromContent()
|
|
||||||
: await this.createFromUrl();
|
|
||||||
|
|
||||||
if (!modal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register close handlers
|
|
||||||
const modalOverlay = modal.querySelector(".modal-overlay");
|
|
||||||
const closeButton = modal.querySelector("button.close");
|
|
||||||
modalOverlay.addEventListener("click", this.onClose.bind(this));
|
modalOverlay.addEventListener("click", this.onClose.bind(this));
|
||||||
closeButton.addEventListener("click", this.onClose.bind(this));
|
closeButton.addEventListener("click", this.onClose.bind(this));
|
||||||
|
|
||||||
document.body.append(modal);
|
|
||||||
applyBehaviors(document.body);
|
|
||||||
this.modal = modal;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createFromUrl() {
|
|
||||||
const url = this.toggle.getAttribute("modal-url");
|
|
||||||
const modalHtml = await fetch(url).then((response) => response.text());
|
|
||||||
const parser = new DOMParser();
|
|
||||||
const doc = parser.parseFromString(modalHtml, "text/html");
|
|
||||||
return doc.querySelector(".modal");
|
|
||||||
}
|
|
||||||
|
|
||||||
createFromContent() {
|
|
||||||
const contentSelector = this.toggle.getAttribute("modal-content");
|
|
||||||
const content = document.querySelector(contentSelector);
|
|
||||||
if (!content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Todo: make title configurable, only used for tag cloud for now
|
|
||||||
const modal = document.createElement("div");
|
|
||||||
modal.classList.add("modal", "active");
|
|
||||||
modal.innerHTML = `
|
|
||||||
<div class="modal-overlay" aria-label="Close"></div>
|
|
||||||
<div class="modal-container">
|
|
||||||
<div class="modal-header d-flex justify-between align-center">
|
|
||||||
<div class="modal-title h5">Tags</div>
|
|
||||||
<button class="close">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
|
||||||
<path d="M18 6l-12 12"></path>
|
|
||||||
<path d="M6 6l12 12"></path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="content"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
const contentOwner = content.parentElement;
|
|
||||||
const contentContainer = modal.querySelector(".content");
|
|
||||||
contentContainer.append(content);
|
|
||||||
this.content = content;
|
|
||||||
this.contentOwner = contentOwner;
|
|
||||||
|
|
||||||
return modal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
// Teleport content back
|
this.element.classList.add("closing");
|
||||||
if (this.content && this.contentOwner) {
|
this.element.addEventListener("animationend", (event) => {
|
||||||
this.contentOwner.append(this.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove modal
|
|
||||||
this.modal.classList.add("closing");
|
|
||||||
this.modal.addEventListener("animationend", (event) => {
|
|
||||||
if (event.animationName === "fade-out") {
|
if (event.animationName === "fade-out") {
|
||||||
this.modal.remove();
|
this.element.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { registerBehavior } from "./index";
|
import { Behavior, registerBehavior } from "./index";
|
||||||
import TagAutoCompleteComponent from "../components/TagAutocomplete.svelte";
|
import TagAutoCompleteComponent from "../components/TagAutocomplete.svelte";
|
||||||
import { ApiClient } from "../api";
|
import { ApiClient } from "../api";
|
||||||
|
|
||||||
class TagAutocomplete {
|
class TagAutocomplete extends Behavior {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
|
super(element);
|
||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
const apiBaseUrl = document.documentElement.dataset.apiBaseUrl || "";
|
const apiBaseUrl = document.documentElement.dataset.apiBaseUrl || "";
|
||||||
const apiClient = new ApiClient(apiBaseUrl);
|
const apiClient = new ApiClient(apiBaseUrl);
|
||||||
|
|||||||
@@ -150,17 +150,27 @@
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-autocomplete-input {
|
||||||
|
box-sizing: border-box;
|
||||||
|
height: var(--control-size);
|
||||||
|
min-height: var(--control-size);
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-autocomplete-input input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.form-autocomplete.small .form-autocomplete-input {
|
.form-autocomplete.small .form-autocomplete-input {
|
||||||
height: var(--control-size-sm);
|
height: var(--control-size-sm);
|
||||||
min-height: var(--control-size-sm);
|
min-height: var(--control-size-sm);
|
||||||
padding: 0.05rem 0.3rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-autocomplete.small .form-autocomplete-input input {
|
.form-autocomplete.small .form-autocomplete-input input {
|
||||||
width: 100%;
|
padding: 0.05rem 0.3rem;
|
||||||
height: 100%;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-size: var(--font-size-sm);
|
font-size: var(--font-size-sm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import "./behaviors/bookmark-page";
|
|||||||
import "./behaviors/bulk-edit";
|
import "./behaviors/bulk-edit";
|
||||||
import "./behaviors/confirm-button";
|
import "./behaviors/confirm-button";
|
||||||
import "./behaviors/dropdown";
|
import "./behaviors/dropdown";
|
||||||
|
import "./behaviors/fetch";
|
||||||
import "./behaviors/form";
|
import "./behaviors/form";
|
||||||
import "./behaviors/modal";
|
import "./behaviors/modal";
|
||||||
import "./behaviors/global-shortcuts";
|
import "./behaviors/global-shortcuts";
|
||||||
|
|||||||
@@ -24,3 +24,8 @@ class Command(BaseCommand):
|
|||||||
source_db.close()
|
source_db.close()
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(f"Backup created at {destination}"))
|
self.stdout.write(self.style.SUCCESS(f"Backup created at {destination}"))
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.WARNING(
|
||||||
|
"This backup method is deprecated and may be removed in the future. Please use the full_backup command instead, which creates backup zip file with all contents of the data folder."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
from background_task.models import Task, CompletedTask
|
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = "Remove task locks and clear completed task history"
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
# Remove task locks
|
|
||||||
# If the background task processor exited while executing tasks, these tasks would still be marked as locked,
|
|
||||||
# even though no process is working on them, and would prevent the task processor from picking the next task in
|
|
||||||
# the queue
|
|
||||||
Task.objects.all().update(locked_by=None, locked_at=None)
|
|
||||||
# Clear task history to prevent them from bloating the DB
|
|
||||||
CompletedTask.objects.all().delete()
|
|
||||||
62
bookmarks/management/commands/full_backup.py
Normal file
62
bookmarks/management/commands/full_backup.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Creates a backup of the linkding data folder"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument("backup_file", type=str, help="Backup zip file destination")
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
backup_file = options["backup_file"]
|
||||||
|
with zipfile.ZipFile(backup_file, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
||||||
|
# Backup the database
|
||||||
|
self.stdout.write("Create database backup...")
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
backup_db_file = os.path.join(temp_dir, "db.sqlite3")
|
||||||
|
self.backup_database(backup_db_file)
|
||||||
|
zip_file.write(backup_db_file, "db.sqlite3")
|
||||||
|
|
||||||
|
# Backup the assets folder
|
||||||
|
if not os.path.exists(os.path.join("data", "assets")):
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.WARNING("No assets folder found. Skipping...")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.stdout.write("Backup bookmark assets...")
|
||||||
|
assets_folder = os.path.join("data", "assets")
|
||||||
|
for root, _, files in os.walk(assets_folder):
|
||||||
|
for file in files:
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
zip_file.write(file_path, os.path.join("assets", file))
|
||||||
|
|
||||||
|
# Backup the favicons folder
|
||||||
|
if not os.path.exists(os.path.join("data", "favicons")):
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.WARNING("No favicons folder found. Skipping...")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.stdout.write("Backup bookmark favicons...")
|
||||||
|
favicons_folder = os.path.join("data", "favicons")
|
||||||
|
for root, _, files in os.walk(favicons_folder):
|
||||||
|
for file in files:
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
zip_file.write(file_path, os.path.join("favicons", file))
|
||||||
|
|
||||||
|
self.stdout.write(self.style.SUCCESS(f"Backup created at {backup_file}"))
|
||||||
|
|
||||||
|
def backup_database(self, backup_db_file):
|
||||||
|
def progress(status, remaining, total):
|
||||||
|
self.stdout.write(f"Copied {total-remaining} of {total} pages...")
|
||||||
|
|
||||||
|
source_db = sqlite3.connect(os.path.join("data", "db.sqlite3"))
|
||||||
|
backup_db = sqlite3.connect(backup_db_file)
|
||||||
|
with backup_db:
|
||||||
|
source_db.backup(backup_db, pages=50, progress=progress)
|
||||||
|
backup_db.close()
|
||||||
|
source_db.close()
|
||||||
75
bookmarks/management/commands/migrate_tasks.py
Normal file
75
bookmarks/management/commands/migrate_tasks.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Migrate tasks from django-background-tasks to Huey"
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
db = sqlite3.connect(os.path.join("data", "db.sqlite3"))
|
||||||
|
|
||||||
|
# Check if background_task table exists
|
||||||
|
cursor = db.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='background_task'"
|
||||||
|
)
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
self.stdout.write(
|
||||||
|
"Legacy task table does not exist. Skipping task migration"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Load legacy tasks
|
||||||
|
cursor.execute("SELECT id, task_name, task_params FROM background_task")
|
||||||
|
legacy_tasks = cursor.fetchall()
|
||||||
|
|
||||||
|
if len(legacy_tasks) == 0:
|
||||||
|
self.stdout.write("No legacy tasks found. Skipping task migration")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.stdout.write(
|
||||||
|
f"Found {len(legacy_tasks)} legacy tasks. Migrating to Huey..."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Migrate tasks to Huey
|
||||||
|
succeeded_tasks = []
|
||||||
|
for task in legacy_tasks:
|
||||||
|
task_id = task[0]
|
||||||
|
task_name = task[1]
|
||||||
|
task_params_json = task[2]
|
||||||
|
try:
|
||||||
|
task_params = json.loads(task_params_json)
|
||||||
|
function_params = task_params[0]
|
||||||
|
|
||||||
|
# Resolve task function
|
||||||
|
module_name, func_name = task_name.rsplit(".", 1)
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
func = getattr(module, func_name)
|
||||||
|
|
||||||
|
# Call task function
|
||||||
|
func(*function_params)
|
||||||
|
succeeded_tasks.append(task_id)
|
||||||
|
except Exception:
|
||||||
|
self.stderr.write(f"Error migrating task [{task_id}] {task_name}")
|
||||||
|
|
||||||
|
self.stdout.write(f"Migrated {len(succeeded_tasks)} tasks successfully")
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
try:
|
||||||
|
placeholders = ", ".join("?" for _ in succeeded_tasks)
|
||||||
|
sql = f"DELETE FROM background_task WHERE id IN ({placeholders})"
|
||||||
|
cursor.execute(sql, succeeded_tasks)
|
||||||
|
db.commit()
|
||||||
|
self.stdout.write(
|
||||||
|
f"Deleted {len(succeeded_tasks)} migrated tasks from legacy table"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
self.stderr.write("Error cleaning up legacy tasks")
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
db.close()
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
import gzip
|
import gzip
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -10,16 +13,23 @@ class SingeFileError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def create_snapshot(url: str, filepath: str):
|
def create_snapshot(url: str, filepath: str):
|
||||||
singlefile_path = settings.LD_SINGLEFILE_PATH
|
singlefile_path = settings.LD_SINGLEFILE_PATH
|
||||||
singlefile_options = settings.LD_SINGLEFILE_OPTIONS
|
# parse options to list of arguments
|
||||||
|
ublock_options = shlex.split(settings.LD_SINGLEFILE_UBLOCK_OPTIONS)
|
||||||
|
custom_options = shlex.split(settings.LD_SINGLEFILE_OPTIONS)
|
||||||
temp_filepath = filepath + ".tmp"
|
temp_filepath = filepath + ".tmp"
|
||||||
|
# concat lists
|
||||||
|
args = [singlefile_path] + ublock_options + custom_options + [url, temp_filepath]
|
||||||
try:
|
try:
|
||||||
command = f"{singlefile_path} '{url}' {singlefile_options} {temp_filepath}"
|
# Use start_new_session=True to create a new process group
|
||||||
subprocess.run(command, check=True, shell=True)
|
process = subprocess.Popen(args, start_new_session=True)
|
||||||
|
process.wait(timeout=settings.LD_SINGLEFILE_TIMEOUT_SEC)
|
||||||
|
|
||||||
# single-file doesn't return exit codes apparently, so check if the file was created
|
# check if the file was created
|
||||||
if not os.path.exists(temp_filepath):
|
if not os.path.exists(temp_filepath):
|
||||||
raise SingeFileError("Failed to create snapshot")
|
raise SingeFileError("Failed to create snapshot")
|
||||||
|
|
||||||
@@ -29,5 +39,20 @@ def create_snapshot(url: str, filepath: str):
|
|||||||
shutil.copyfileobj(raw_file, gz_file)
|
shutil.copyfileobj(raw_file, gz_file)
|
||||||
|
|
||||||
os.remove(temp_filepath)
|
os.remove(temp_filepath)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
# First try to terminate properly
|
||||||
|
try:
|
||||||
|
logger.error(
|
||||||
|
"Timeout expired while creating snapshot. Terminating process..."
|
||||||
|
)
|
||||||
|
process.terminate()
|
||||||
|
process.wait(timeout=20)
|
||||||
|
raise SingeFileError("Timeout expired while creating snapshot")
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
# Kill the whole process group, which should also clean up any chromium
|
||||||
|
# processes spawned by single-file
|
||||||
|
logger.error("Timeout expired while terminating. Killing process...")
|
||||||
|
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
||||||
|
raise SingeFileError("Timeout expired while creating snapshot")
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
raise SingeFileError(f"Failed to create snapshot: {error.stderr}")
|
raise SingeFileError(f"Failed to create snapshot: {error.stderr}")
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import waybackpy
|
import waybackpy
|
||||||
from background_task import background
|
|
||||||
from background_task.models import Task
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from waybackpy.exceptions import WaybackError, TooManyRequestsError, NoCDXRecordFound
|
|
||||||
from django.utils import timezone, formats
|
from django.utils import timezone, formats
|
||||||
|
from huey import crontab
|
||||||
|
from huey.contrib.djhuey import HUEY as huey
|
||||||
|
from huey.exceptions import TaskLockedException
|
||||||
|
from waybackpy.exceptions import WaybackError, TooManyRequestsError, NoCDXRecordFound
|
||||||
|
|
||||||
import bookmarks.services.wayback
|
import bookmarks.services.wayback
|
||||||
from bookmarks.models import Bookmark, BookmarkAsset, UserProfile
|
from bookmarks.models import Bookmark, BookmarkAsset, UserProfile
|
||||||
@@ -18,6 +21,35 @@ from bookmarks.services.website_loader import DEFAULT_USER_AGENT
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# Create custom decorator for Huey tasks that implements exponential backoff
|
||||||
|
# Taken from: https://huey.readthedocs.io/en/latest/guide.html#tips-and-tricks
|
||||||
|
# Retry 1: 60
|
||||||
|
# Retry 2: 240
|
||||||
|
# Retry 3: 960
|
||||||
|
# Retry 4: 3840
|
||||||
|
# Retry 5: 15360
|
||||||
|
def task(retries=5, retry_delay=15, retry_backoff=4):
|
||||||
|
def deco(fn):
|
||||||
|
@functools.wraps(fn)
|
||||||
|
def inner(*args, **kwargs):
|
||||||
|
task = kwargs.pop("task")
|
||||||
|
try:
|
||||||
|
return fn(*args, **kwargs)
|
||||||
|
except TaskLockedException as exc:
|
||||||
|
# Task locks are currently only used as workaround to enforce
|
||||||
|
# running specific types of tasks (e.g. singlefile snapshots)
|
||||||
|
# sequentially. In that case don't reduce the number of retries.
|
||||||
|
task.retries = retries
|
||||||
|
raise exc
|
||||||
|
except Exception as exc:
|
||||||
|
task.retry_delay *= retry_backoff
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
return huey.task(retries=retries, retry_delay=retry_delay, context=True)(inner)
|
||||||
|
|
||||||
|
return deco
|
||||||
|
|
||||||
|
|
||||||
def is_web_archive_integration_active(user: User) -> bool:
|
def is_web_archive_integration_active(user: User) -> bool:
|
||||||
background_tasks_enabled = not settings.LD_DISABLE_BACKGROUND_TASKS
|
background_tasks_enabled = not settings.LD_DISABLE_BACKGROUND_TASKS
|
||||||
web_archive_integration_enabled = (
|
web_archive_integration_enabled = (
|
||||||
@@ -67,7 +99,7 @@ def _create_snapshot(bookmark: Bookmark):
|
|||||||
logger.info(f"Successfully created new snapshot for bookmark:. url={bookmark.url}")
|
logger.info(f"Successfully created new snapshot for bookmark:. url={bookmark.url}")
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _create_web_archive_snapshot_task(bookmark_id: int, force_update: bool):
|
def _create_web_archive_snapshot_task(bookmark_id: int, force_update: bool):
|
||||||
try:
|
try:
|
||||||
bookmark = Bookmark.objects.get(id=bookmark_id)
|
bookmark = Bookmark.objects.get(id=bookmark_id)
|
||||||
@@ -96,7 +128,7 @@ def _create_web_archive_snapshot_task(bookmark_id: int, force_update: bool):
|
|||||||
_load_newest_snapshot(bookmark)
|
_load_newest_snapshot(bookmark)
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _load_web_archive_snapshot_task(bookmark_id: int):
|
def _load_web_archive_snapshot_task(bookmark_id: int):
|
||||||
try:
|
try:
|
||||||
bookmark = Bookmark.objects.get(id=bookmark_id)
|
bookmark = Bookmark.objects.get(id=bookmark_id)
|
||||||
@@ -114,13 +146,14 @@ def schedule_bookmarks_without_snapshots(user: User):
|
|||||||
_schedule_bookmarks_without_snapshots_task(user.id)
|
_schedule_bookmarks_without_snapshots_task(user.id)
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _schedule_bookmarks_without_snapshots_task(user_id: int):
|
def _schedule_bookmarks_without_snapshots_task(user_id: int):
|
||||||
user = get_user_model().objects.get(id=user_id)
|
user = get_user_model().objects.get(id=user_id)
|
||||||
bookmarks_without_snapshots = Bookmark.objects.filter(
|
bookmarks_without_snapshots = Bookmark.objects.filter(
|
||||||
web_archive_snapshot_url__exact="", owner=user
|
web_archive_snapshot_url__exact="", owner=user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: Implement bulk task creation
|
||||||
for bookmark in bookmarks_without_snapshots:
|
for bookmark in bookmarks_without_snapshots:
|
||||||
# To prevent rate limit errors from the Wayback API only try to load the latest snapshots instead of creating
|
# To prevent rate limit errors from the Wayback API only try to load the latest snapshots instead of creating
|
||||||
# new ones when processing bookmarks in bulk
|
# new ones when processing bookmarks in bulk
|
||||||
@@ -138,7 +171,7 @@ def load_favicon(user: User, bookmark: Bookmark):
|
|||||||
_load_favicon_task(bookmark.id)
|
_load_favicon_task(bookmark.id)
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _load_favicon_task(bookmark_id: int):
|
def _load_favicon_task(bookmark_id: int):
|
||||||
try:
|
try:
|
||||||
bookmark = Bookmark.objects.get(id=bookmark_id)
|
bookmark = Bookmark.objects.get(id=bookmark_id)
|
||||||
@@ -162,19 +195,15 @@ def schedule_bookmarks_without_favicons(user: User):
|
|||||||
_schedule_bookmarks_without_favicons_task(user.id)
|
_schedule_bookmarks_without_favicons_task(user.id)
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _schedule_bookmarks_without_favicons_task(user_id: int):
|
def _schedule_bookmarks_without_favicons_task(user_id: int):
|
||||||
user = get_user_model().objects.get(id=user_id)
|
user = get_user_model().objects.get(id=user_id)
|
||||||
bookmarks = Bookmark.objects.filter(favicon_file__exact="", owner=user)
|
bookmarks = Bookmark.objects.filter(favicon_file__exact="", owner=user)
|
||||||
tasks = []
|
|
||||||
|
|
||||||
|
# TODO: Implement bulk task creation
|
||||||
for bookmark in bookmarks:
|
for bookmark in bookmarks:
|
||||||
task = Task.objects.new_task(
|
_load_favicon_task(bookmark.id)
|
||||||
task_name="bookmarks.services.tasks._load_favicon_task", args=(bookmark.id,)
|
pass
|
||||||
)
|
|
||||||
tasks.append(task)
|
|
||||||
|
|
||||||
Task.objects.bulk_create(tasks)
|
|
||||||
|
|
||||||
|
|
||||||
def schedule_refresh_favicons(user: User):
|
def schedule_refresh_favicons(user: User):
|
||||||
@@ -182,19 +211,14 @@ def schedule_refresh_favicons(user: User):
|
|||||||
_schedule_refresh_favicons_task(user.id)
|
_schedule_refresh_favicons_task(user.id)
|
||||||
|
|
||||||
|
|
||||||
@background()
|
@task()
|
||||||
def _schedule_refresh_favicons_task(user_id: int):
|
def _schedule_refresh_favicons_task(user_id: int):
|
||||||
user = get_user_model().objects.get(id=user_id)
|
user = get_user_model().objects.get(id=user_id)
|
||||||
bookmarks = Bookmark.objects.filter(owner=user)
|
bookmarks = Bookmark.objects.filter(owner=user)
|
||||||
tasks = []
|
|
||||||
|
|
||||||
|
# TODO: Implement bulk task creation
|
||||||
for bookmark in bookmarks:
|
for bookmark in bookmarks:
|
||||||
task = Task.objects.new_task(
|
_load_favicon_task(bookmark.id)
|
||||||
task_name="bookmarks.services.tasks._load_favicon_task", args=(bookmark.id,)
|
|
||||||
)
|
|
||||||
tasks.append(task)
|
|
||||||
|
|
||||||
Task.objects.bulk_create(tasks)
|
|
||||||
|
|
||||||
|
|
||||||
def is_html_snapshot_feature_active() -> bool:
|
def is_html_snapshot_feature_active() -> bool:
|
||||||
@@ -205,6 +229,26 @@ def create_html_snapshot(bookmark: Bookmark):
|
|||||||
if not is_html_snapshot_feature_active():
|
if not is_html_snapshot_feature_active():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
asset = _create_snapshot_asset(bookmark)
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
|
||||||
|
def create_html_snapshots(bookmark_list: List[Bookmark]):
|
||||||
|
if not is_html_snapshot_feature_active():
|
||||||
|
return
|
||||||
|
|
||||||
|
assets_to_create = []
|
||||||
|
for bookmark in bookmark_list:
|
||||||
|
asset = _create_snapshot_asset(bookmark)
|
||||||
|
assets_to_create.append(asset)
|
||||||
|
|
||||||
|
BookmarkAsset.objects.bulk_create(assets_to_create)
|
||||||
|
|
||||||
|
|
||||||
|
MAX_SNAPSHOT_FILENAME_LENGTH = 192
|
||||||
|
|
||||||
|
|
||||||
|
def _create_snapshot_asset(bookmark: Bookmark) -> BookmarkAsset:
|
||||||
timestamp = formats.date_format(timezone.now(), "SHORT_DATE_FORMAT")
|
timestamp = formats.date_format(timezone.now(), "SHORT_DATE_FORMAT")
|
||||||
asset = BookmarkAsset(
|
asset = BookmarkAsset(
|
||||||
bookmark=bookmark,
|
bookmark=bookmark,
|
||||||
@@ -213,8 +257,7 @@ def create_html_snapshot(bookmark: Bookmark):
|
|||||||
display_name=f"HTML snapshot from {timestamp}",
|
display_name=f"HTML snapshot from {timestamp}",
|
||||||
status=BookmarkAsset.STATUS_PENDING,
|
status=BookmarkAsset.STATUS_PENDING,
|
||||||
)
|
)
|
||||||
asset.save()
|
return asset
|
||||||
_create_html_snapshot_task(asset.id)
|
|
||||||
|
|
||||||
|
|
||||||
def _generate_snapshot_filename(asset: BookmarkAsset) -> str:
|
def _generate_snapshot_filename(asset: BookmarkAsset) -> str:
|
||||||
@@ -227,10 +270,33 @@ def _generate_snapshot_filename(asset: BookmarkAsset) -> str:
|
|||||||
formatted_datetime = asset.date_created.strftime("%Y-%m-%d_%H%M%S")
|
formatted_datetime = asset.date_created.strftime("%Y-%m-%d_%H%M%S")
|
||||||
sanitized_url = "".join(sanitize_char(char) for char in asset.bookmark.url)
|
sanitized_url = "".join(sanitize_char(char) for char in asset.bookmark.url)
|
||||||
|
|
||||||
|
# Calculate the length of the non-URL parts of the filename
|
||||||
|
non_url_length = len(f"{asset.asset_type}{formatted_datetime}__.html.gz")
|
||||||
|
# Calculate the maximum length for the URL part
|
||||||
|
max_url_length = MAX_SNAPSHOT_FILENAME_LENGTH - non_url_length
|
||||||
|
# Truncate the URL if necessary
|
||||||
|
sanitized_url = sanitized_url[:max_url_length]
|
||||||
|
|
||||||
return f"{asset.asset_type}_{formatted_datetime}_{sanitized_url}.html.gz"
|
return f"{asset.asset_type}_{formatted_datetime}_{sanitized_url}.html.gz"
|
||||||
|
|
||||||
|
|
||||||
@background()
|
# singe-file does not support running multiple instances in parallel, so we can
|
||||||
|
# not queue up multiple snapshot tasks at once. Instead, schedule a periodic
|
||||||
|
# task that grabs a number of pending assets and creates snapshots for them in
|
||||||
|
# sequence. The task uses a lock to ensure that a new task isn't scheduled
|
||||||
|
# before the previous one has finished.
|
||||||
|
@huey.periodic_task(crontab(minute="*"))
|
||||||
|
@huey.lock_task("schedule-html-snapshots-lock")
|
||||||
|
def _schedule_html_snapshots_task():
|
||||||
|
# Get five pending assets
|
||||||
|
assets = BookmarkAsset.objects.filter(status=BookmarkAsset.STATUS_PENDING).order_by(
|
||||||
|
"date_created"
|
||||||
|
)[:5]
|
||||||
|
|
||||||
|
for asset in assets:
|
||||||
|
_create_html_snapshot_task(asset.id)
|
||||||
|
|
||||||
|
|
||||||
def _create_html_snapshot_task(asset_id: int):
|
def _create_html_snapshot_task(asset_id: int):
|
||||||
try:
|
try:
|
||||||
asset = BookmarkAsset.objects.get(id=asset_id)
|
asset = BookmarkAsset.objects.get(id=asset_id)
|
||||||
@@ -246,13 +312,34 @@ def _create_html_snapshot_task(asset_id: int):
|
|||||||
asset.status = BookmarkAsset.STATUS_COMPLETE
|
asset.status = BookmarkAsset.STATUS_COMPLETE
|
||||||
asset.file = filename
|
asset.file = filename
|
||||||
asset.gzip = True
|
asset.gzip = True
|
||||||
|
asset.save()
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Successfully created HTML snapshot for bookmark. url={asset.bookmark.url}"
|
f"Successfully created HTML snapshot for bookmark. url={asset.bookmark.url}"
|
||||||
)
|
)
|
||||||
except singlefile.SingeFileError as error:
|
except Exception as error:
|
||||||
asset.status = BookmarkAsset.STATUS_FAILURE
|
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Failed to create HTML snapshot for bookmark. url={asset.bookmark.url}",
|
f"Failed to HTML snapshot for bookmark. url={asset.bookmark.url}",
|
||||||
exc_info=error,
|
exc_info=error,
|
||||||
)
|
)
|
||||||
asset.save()
|
asset.status = BookmarkAsset.STATUS_FAILURE
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
|
||||||
|
def create_missing_html_snapshots(user: User) -> int:
|
||||||
|
if not is_html_snapshot_feature_active():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
bookmarks_without_snapshots = Bookmark.objects.filter(owner=user).exclude(
|
||||||
|
bookmarkasset__asset_type=BookmarkAsset.TYPE_SNAPSHOT,
|
||||||
|
bookmarkasset__status__in=[
|
||||||
|
BookmarkAsset.STATUS_PENDING,
|
||||||
|
BookmarkAsset.STATUS_COMPLETE,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
bookmarks_without_snapshots |= Bookmark.objects.filter(owner=user).exclude(
|
||||||
|
bookmarkasset__asset_type=BookmarkAsset.TYPE_SNAPSHOT
|
||||||
|
)
|
||||||
|
|
||||||
|
create_html_snapshots(list(bookmarks_without_snapshots))
|
||||||
|
|
||||||
|
return bookmarks_without_snapshots.count()
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ li[ld-bookmark-item] {
|
|||||||
position: relative;
|
position: relative;
|
||||||
margin-top: $unit-2;
|
margin-top: $unit-2;
|
||||||
|
|
||||||
[ld-bulk-edit-checkbox].form-checkbox {
|
.form-checkbox.bulk-edit-checkbox {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ $bulk-edit-transition-duration: 400ms;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* All checkbox */
|
/* All checkbox */
|
||||||
[ld-bulk-edit-checkbox][all].form-checkbox {
|
.form-checkbox.bulk-edit-checkbox.all {
|
||||||
display: block;
|
display: block;
|
||||||
width: $bulk-edit-toggle-width;
|
width: $bulk-edit-toggle-width;
|
||||||
margin: 0 0 0 $bulk-edit-toggle-offset;
|
margin: 0 0 0 $bulk-edit-toggle-offset;
|
||||||
@@ -331,7 +331,7 @@ $bulk-edit-transition-duration: 400ms;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Bookmark checkboxes */
|
/* Bookmark checkboxes */
|
||||||
li[ld-bookmark-item] [ld-bulk-edit-checkbox].form-checkbox {
|
li[ld-bookmark-item] .form-checkbox.bulk-edit-checkbox {
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: $bulk-edit-toggle-width;
|
width: $bulk-edit-toggle-width;
|
||||||
@@ -350,7 +350,7 @@ $bulk-edit-transition-duration: 400ms;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active li[ld-bookmark-item] [ld-bulk-edit-checkbox].form-checkbox {
|
&.active li[ld-bookmark-item] .form-checkbox.bulk-edit-checkbox {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|||||||
2
bookmarks/tasks.py
Normal file
2
bookmarks/tasks.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Expose task modules to Huey Django extension
|
||||||
|
import bookmarks.services.tasks
|
||||||
39
bookmarks/templates/admin/background_tasks.html
Normal file
39
bookmarks/templates/admin/background_tasks.html
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{% extends "admin/base_site.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<table style="width: 100%">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Args</th>
|
||||||
|
<th>Retries</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for task in tasks %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ task.id }}</td>
|
||||||
|
<td>{{ task.name }}</td>
|
||||||
|
<td>{{ task.args }}</td>
|
||||||
|
<td>{{ task.retries }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class="paginator">
|
||||||
|
{% if page.paginator.num_pages > 1 %}
|
||||||
|
{% for page_number in page_range %}
|
||||||
|
{% if page_number == page.number %}
|
||||||
|
<span class="this-page">{{ page_number }}</span>
|
||||||
|
{% elif page_number == '…' %}
|
||||||
|
<span>…</span>
|
||||||
|
{% else %}
|
||||||
|
<a href="?p={{ page_number }}">{{ page_number }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{{ page.paginator.count }} tasks
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
@@ -4,11 +4,7 @@
|
|||||||
{% load bookmarks %}
|
{% load bookmarks %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="bookmarks-page grid columns-md-1"
|
<div ld-bulk-edit class="bookmarks-page grid columns-md-1">
|
||||||
ld-bulk-edit
|
|
||||||
ld-bookmark-page
|
|
||||||
bookmarks-url="{% url 'bookmarks:partials.bookmark_list.archived' %}"
|
|
||||||
tags-url="{% url 'bookmarks:partials.tag_cloud.archived' %}">
|
|
||||||
|
|
||||||
{# Bookmark list #}
|
{# Bookmark list #}
|
||||||
<section class="content-area col-2">
|
<section class="content-area col-2">
|
||||||
@@ -17,17 +13,22 @@
|
|||||||
<div class="header-controls">
|
<div class="header-controls">
|
||||||
{% bookmark_search bookmark_list.search tag_cloud.tags mode='archived' %}
|
{% bookmark_search bookmark_list.search tag_cloud.tags mode='archived' %}
|
||||||
{% include 'bookmarks/bulk_edit/toggle.html' %}
|
{% include 'bookmarks/bulk_edit/toggle.html' %}
|
||||||
<button ld-modal modal-content=".tag-cloud" class="btn ml-2 show-md">Tags</button>
|
<button ld-fetch="{{ bookmark_list.tag_modal_url }}" ld-target="body|append" ld-on="click"
|
||||||
|
class="btn ml-2 show-md">Tags
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="bookmark-actions"
|
<form ld-form ld-fire="refresh-bookmark-list,refresh-tag-cloud"
|
||||||
|
class="bookmark-actions"
|
||||||
action="{{ bookmark_list.action_url|safe }}"
|
action="{{ bookmark_list.action_url|safe }}"
|
||||||
method="post" autocomplete="off">
|
method="post" autocomplete="off">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_archive' %}
|
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_archive' %}
|
||||||
|
|
||||||
<div class="bookmark-list-container">
|
<div ld-fetch="{{ bookmark_list.refresh_url }}" ld-on="refresh-bookmark-list"
|
||||||
|
ld-fire="refresh-bookmark-list-done"
|
||||||
|
class="bookmark-list-container">
|
||||||
{% include 'bookmarks/bookmark_list.html' %}
|
{% include 'bookmarks/bookmark_list.html' %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -38,7 +39,8 @@
|
|||||||
<div class="content-area-header">
|
<div class="content-area-header">
|
||||||
<h2>Tags</h2>
|
<h2>Tags</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-cloud-container">
|
<div ld-fetch="{{ tag_cloud.refresh_url }}" ld-on="refresh-tag-cloud"
|
||||||
|
class="tag-cloud-container">
|
||||||
{% include 'bookmarks/tag_cloud.html' %}
|
{% include 'bookmarks/tag_cloud.html' %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{% for bookmark_item in bookmark_list.items %}
|
{% for bookmark_item in bookmark_list.items %}
|
||||||
<li ld-bookmark-item{% if bookmark_item.css_classes %} class="{{ bookmark_item.css_classes }}"{% endif %}>
|
<li ld-bookmark-item{% if bookmark_item.css_classes %} class="{{ bookmark_item.css_classes }}"{% endif %}>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<label ld-bulk-edit-checkbox class="form-checkbox">
|
<label class="form-checkbox bulk-edit-checkbox">
|
||||||
<input type="checkbox" name="bookmark_id" value="{{ bookmark_item.id }}">
|
<input type="checkbox" name="bookmark_id" value="{{ bookmark_item.id }}">
|
||||||
<i class="form-icon"></i>
|
<i class="form-icon"></i>
|
||||||
</label>
|
</label>
|
||||||
@@ -81,8 +81,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{# View link is visible for both owned and shared bookmarks #}
|
{# View link is visible for both owned and shared bookmarks #}
|
||||||
{% if bookmark_list.show_view_action %}
|
{% if bookmark_list.show_view_action %}
|
||||||
<a ld-modal
|
<a ld-fetch="{% url 'bookmarks:details_modal' bookmark_item.id %}?return_url={{ bookmark_list.return_url|urlencode }}"
|
||||||
modal-url="{% url 'bookmarks:details_modal' bookmark_item.id %}?return_url={{ bookmark_list.return_url|urlencode }}"
|
ld-on="click" ld-target="body|append"
|
||||||
href="{% url 'bookmarks:details' bookmark_item.id %}">View</a>
|
href="{% url 'bookmarks:details' bookmark_item.id %}">View</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if bookmark_item.is_editable %}
|
{% if bookmark_item.is_editable %}
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
{% if bookmark_item.show_mark_as_read %}
|
{% if bookmark_item.show_mark_as_read %}
|
||||||
<button type="submit" name="mark_as_read" value="{{ bookmark_item.id }}"
|
<button type="submit" name="mark_as_read" value="{{ bookmark_item.id }}"
|
||||||
class="btn btn-link btn-sm btn-icon"
|
class="btn btn-link btn-sm btn-icon"
|
||||||
ld-confirm-button confirm-icon="ld-icon-read" confirm-question="Mark as read?">
|
ld-confirm-button ld-confirm-icon="ld-icon-read" ld-confirm-question="Mark as read?">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||||
<use xlink:href="#ld-icon-unread"></use>
|
<use xlink:href="#ld-icon-unread"></use>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -128,7 +128,7 @@
|
|||||||
{% if bookmark_item.show_unshare %}
|
{% if bookmark_item.show_unshare %}
|
||||||
<button type="submit" name="unshare" value="{{ bookmark_item.id }}"
|
<button type="submit" name="unshare" value="{{ bookmark_item.id }}"
|
||||||
class="btn btn-link btn-sm btn-icon"
|
class="btn btn-link btn-sm btn-icon"
|
||||||
ld-confirm-button confirm-icon="ld-icon-unshare" confirm-question="Unshare?">
|
ld-confirm-button ld-confirm-icon="ld-icon-unshare" ld-confirm-question="Unshare?">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||||
<use xlink:href="#ld-icon-share"></use>
|
<use xlink:href="#ld-icon-share"></use>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{% htmlmin %}
|
{% htmlmin %}
|
||||||
<div class="bulk-edit-bar">
|
<div class="bulk-edit-bar">
|
||||||
<div class="bulk-edit-actions bg-gray">
|
<div class="bulk-edit-actions bg-gray">
|
||||||
<label ld-bulk-edit-checkbox all class="form-checkbox">
|
<label class="form-checkbox bulk-edit-checkbox all">
|
||||||
<input type="checkbox">
|
<input type="checkbox">
|
||||||
<i class="form-icon"></i>
|
<i class="form-icon"></i>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<button ld-bulk-edit-active-toggle class="btn hide-sm ml-2" title="Bulk edit">
|
<button class="btn hide-sm ml-2 bulk-edit-active-toggle" title="Bulk edit">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="20px"
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="20px"
|
||||||
height="20px">
|
height="20px">
|
||||||
<path
|
<path
|
||||||
|
|||||||
@@ -1,37 +1,44 @@
|
|||||||
{% if details.assets %}
|
<div {% if details.has_pending_assets %}
|
||||||
<div class="assets">
|
ld-fetch="{% url 'bookmarks:details_assets' details.bookmark.id %}"
|
||||||
{% for asset in details.assets %}
|
ld-interval="5" ld-target="self|outerHTML"
|
||||||
<div class="asset" data-asset-id="{{ asset.id }}">
|
{% endif %}>
|
||||||
<div class="asset-icon {{ asset.icon_classes }}">
|
{% if details.assets %}
|
||||||
{% include 'bookmarks/details/asset_icon.html' %}
|
<div class="assets">
|
||||||
</div>
|
{% for asset in details.assets %}
|
||||||
<div class="asset-text truncate {{ asset.text_classes }}">
|
<div class="asset" data-asset-id="{{ asset.id }}">
|
||||||
|
<div class="asset-icon {{ asset.icon_classes }}">
|
||||||
|
{% include 'bookmarks/details/asset_icon.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="asset-text truncate {{ asset.text_classes }}">
|
||||||
<span>
|
<span>
|
||||||
{{ asset.display_name }}
|
{{ asset.display_name }}
|
||||||
{% if asset.status == 'pending' %}(queued){% endif %}
|
{% if asset.status == 'pending' %}(queued){% endif %}
|
||||||
{% if asset.status == 'failure' %}(failed){% endif %}
|
{% if asset.status == 'failure' %}(failed){% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% if asset.file_size %}
|
{% if asset.file_size %}
|
||||||
<span class="filesize">{{ asset.file_size|filesizeformat }}</span>
|
<span class="filesize">{{ asset.file_size|filesizeformat }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="asset-actions">
|
||||||
|
{% if asset.file %}
|
||||||
|
<a class="btn btn-link" href="{% url 'bookmarks:assets.view' asset.id %}" target="_blank">View</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if details.is_editable %}
|
||||||
|
<button ld-confirm-button type="submit" name="remove_asset" value="{{ asset.id }}" class="btn btn-link">
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="asset-actions">
|
{% endfor %}
|
||||||
{% if asset.file %}
|
</div>
|
||||||
<a class="btn btn-link" href="{% url 'bookmarks:assets.view' asset.id %}" target="_blank">View</a>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% if details.is_editable %}
|
|
||||||
<button ld-confirm-button type="submit" name="remove_asset" value="{{ asset.id }}" class="btn btn-link">
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if details.is_editable %}
|
{% if details.is_editable %}
|
||||||
<div class="assets-actions">
|
<div class="assets-actions">
|
||||||
<button type="submit" name="create_snapshot" class="btn btn-link">Create HTML snapshot</button>
|
<button type="submit" name="create_snapshot" class="btn btn-link"
|
||||||
</div>
|
{% if details.has_pending_assets %}disabled{% endif %}>Create HTML snapshot
|
||||||
{% endif %}
|
</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load shared %}
|
{% load shared %}
|
||||||
|
|
||||||
<form ld-form action="{% url 'bookmarks:details' details.bookmark.id %}"
|
<form ld-form ld-fire="refresh-bookmark-list,refresh-tag-cloud,refresh-details"
|
||||||
refresh-url="{% url 'bookmarks:partials.details_form' details.bookmark.id %}"
|
action="{% url 'bookmarks:details' details.bookmark.id %}"
|
||||||
refresh-events="bookmark-page-refresh"
|
|
||||||
method="post">
|
method="post">
|
||||||
<div class="weblinks">
|
<div class="weblinks">
|
||||||
<a class="weblink" href="{{ details.bookmark.url }}" rel="noopener"
|
<a class="weblink" href="{{ details.bookmark.url }}" rel="noopener"
|
||||||
@@ -35,14 +34,14 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-switch">
|
<label class="form-switch">
|
||||||
<input ld-form-auto-submit type="checkbox" name="is_archived"
|
<input ld-auto-submit type="checkbox" name="is_archived"
|
||||||
{% if details.bookmark.is_archived %}checked{% endif %}>
|
{% if details.bookmark.is_archived %}checked{% endif %}>
|
||||||
<i class="form-icon"></i> Archived
|
<i class="form-icon"></i> Archived
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-switch">
|
<label class="form-switch">
|
||||||
<input ld-form-auto-submit type="checkbox" name="unread"
|
<input ld-auto-submit type="checkbox" name="unread"
|
||||||
{% if details.bookmark.unread %}checked{% endif %}>
|
{% if details.bookmark.unread %}checked{% endif %}>
|
||||||
<i class="form-icon"></i> Unread
|
<i class="form-icon"></i> Unread
|
||||||
</label>
|
</label>
|
||||||
@@ -50,7 +49,7 @@
|
|||||||
{% if details.profile.enable_sharing %}
|
{% if details.profile.enable_sharing %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-switch">
|
<label class="form-switch">
|
||||||
<input ld-form-auto-submit type="checkbox" name="shared"
|
<input ld-auto-submit type="checkbox" name="shared"
|
||||||
{% if details.bookmark.shared %}checked{% endif %}>
|
{% if details.bookmark.shared %}checked{% endif %}>
|
||||||
<i class="form-icon"></i> Shared
|
<i class="form-icon"></i> Shared
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<div class="modal active bookmark-details">
|
<div ld-modal
|
||||||
|
ld-fetch="{% url 'bookmarks:details_modal' details.bookmark.id %}" ld-on="refresh-details"
|
||||||
|
ld-select=".content" ld-target=".modal.bookmark-details .content|outerHTML"
|
||||||
|
class="modal active bookmark-details">
|
||||||
<div class="modal-overlay" aria-label="Close"></div>
|
<div class="modal-overlay" aria-label="Close"></div>
|
||||||
<div class="modal-container">
|
<div class="modal-container">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
{% load bookmarks %}
|
{% load bookmarks %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="bookmarks-page grid columns-md-1"
|
<div ld-bulk-edit class="bookmarks-page grid columns-md-1">
|
||||||
ld-bulk-edit
|
|
||||||
ld-bookmark-page
|
|
||||||
bookmarks-url="{% url 'bookmarks:partials.bookmark_list.active' %}"
|
|
||||||
tags-url="{% url 'bookmarks:partials.tag_cloud.active' %}">
|
|
||||||
|
|
||||||
{# Bookmark list #}
|
{# Bookmark list #}
|
||||||
<section class="content-area col-2">
|
<section class="content-area col-2">
|
||||||
@@ -17,17 +13,22 @@
|
|||||||
<div class="header-controls">
|
<div class="header-controls">
|
||||||
{% bookmark_search bookmark_list.search tag_cloud.tags %}
|
{% bookmark_search bookmark_list.search tag_cloud.tags %}
|
||||||
{% include 'bookmarks/bulk_edit/toggle.html' %}
|
{% include 'bookmarks/bulk_edit/toggle.html' %}
|
||||||
<button ld-modal modal-content=".tag-cloud" class="btn ml-2 show-md">Tags</button>
|
<button ld-fetch="{{ bookmark_list.tag_modal_url }}" ld-target="body|append" ld-on="click"
|
||||||
|
class="btn ml-2 show-md">Tags
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="bookmark-actions"
|
<form ld-form ld-fire="refresh-bookmark-list,refresh-tag-cloud"
|
||||||
|
class="bookmark-actions"
|
||||||
action="{{ bookmark_list.action_url|safe }}"
|
action="{{ bookmark_list.action_url|safe }}"
|
||||||
method="post" autocomplete="off">
|
method="post" autocomplete="off">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_unarchive' %}
|
{% include 'bookmarks/bulk_edit/bar.html' with disable_actions='bulk_unarchive' %}
|
||||||
|
|
||||||
<div class="bookmark-list-container">
|
<div ld-fetch="{{ bookmark_list.refresh_url }}" ld-on="refresh-bookmark-list"
|
||||||
|
ld-fire="refresh-bookmark-list-done"
|
||||||
|
class="bookmark-list-container">
|
||||||
{% include 'bookmarks/bookmark_list.html' %}
|
{% include 'bookmarks/bookmark_list.html' %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -38,7 +39,8 @@
|
|||||||
<div class="content-area-header">
|
<div class="content-area-header">
|
||||||
<h2>Tags</h2>
|
<h2>Tags</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-cloud-container">
|
<div ld-fetch="{{ tag_cloud.refresh_url }}" ld-on="refresh-tag-cloud"
|
||||||
|
class="tag-cloud-container">
|
||||||
{% include 'bookmarks/tag_cloud.html' %}
|
{% include 'bookmarks/tag_cloud.html' %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -4,10 +4,7 @@
|
|||||||
{% load bookmarks %}
|
{% load bookmarks %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="bookmarks-page grid columns-md-1"
|
<div class="bookmarks-page grid columns-md-1">
|
||||||
ld-bookmark-page
|
|
||||||
bookmarks-url="{% url 'bookmarks:partials.bookmark_list.shared' %}"
|
|
||||||
tags-url="{% url 'bookmarks:partials.tag_cloud.shared' %}">
|
|
||||||
|
|
||||||
{# Bookmark list #}
|
{# Bookmark list #}
|
||||||
<section class="content-area col-2">
|
<section class="content-area col-2">
|
||||||
@@ -15,15 +12,20 @@
|
|||||||
<h2>Shared bookmarks</h2>
|
<h2>Shared bookmarks</h2>
|
||||||
<div class="header-controls">
|
<div class="header-controls">
|
||||||
{% bookmark_search bookmark_list.search tag_cloud.tags mode='shared' %}
|
{% bookmark_search bookmark_list.search tag_cloud.tags mode='shared' %}
|
||||||
<button ld-modal modal-content=".tag-cloud" class="btn ml-2 show-md">Tags</button>
|
<button ld-fetch="{{ bookmark_list.tag_modal_url }}" ld-target="body|append" ld-on="click"
|
||||||
|
class="btn ml-2 show-md">Tags
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="bookmark-actions" action="{{ bookmark_list.action_url|safe }}"
|
<form ld-form ld-fire="refresh-bookmark-list,refresh-tag-cloud"
|
||||||
method="post">
|
class="bookmark-actions"
|
||||||
|
action="{{ bookmark_list.action_url|safe }}"
|
||||||
|
method="post" autocomplete="off">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<div ld-fetch="{{ bookmark_list.refresh_url }}" ld-on="refresh-bookmark-list"
|
||||||
<div class="bookmark-list-container">
|
ld-fire="refresh-bookmark-list-done"
|
||||||
|
class="bookmark-list-container">
|
||||||
{% include 'bookmarks/bookmark_list.html' %}
|
{% include 'bookmarks/bookmark_list.html' %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -41,7 +43,8 @@
|
|||||||
<div class="content-area-header">
|
<div class="content-area-header">
|
||||||
<h2>Tags</h2>
|
<h2>Tags</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-cloud-container">
|
<div ld-fetch="{{ tag_cloud.refresh_url }}" ld-on="refresh-tag-cloud"
|
||||||
|
class="tag-cloud-container">
|
||||||
{% include 'bookmarks/tag_cloud.html' %}
|
{% include 'bookmarks/tag_cloud.html' %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
21
bookmarks/templates/bookmarks/tag_modal.html
Normal file
21
bookmarks/templates/bookmarks/tag_modal.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<div ld-modal class="modal active">
|
||||||
|
<div class="modal-overlay" aria-label="Close"></div>
|
||||||
|
<div class="modal-container">
|
||||||
|
<div class="modal-header d-flex justify-between align-center">
|
||||||
|
<div class="modal-title h5">Tags</div>
|
||||||
|
<button class="close">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2"
|
||||||
|
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
|
<path d="M18 6l-12 12"></path>
|
||||||
|
<path d="M6 6l12 12"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="content">
|
||||||
|
{% include 'bookmarks/tag_cloud.html' %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
{# Profile section #}
|
{# Profile section #}
|
||||||
<section class="content-area">
|
<section class="content-area">
|
||||||
|
{% if success_message %}
|
||||||
|
<div class="toast toast-success mb-4">{{ success_message }}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if error_message %}
|
||||||
|
<div class="toast toast-error mb-4">{{ error_message }}</div>
|
||||||
|
{% endif %}
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
<p>
|
<p>
|
||||||
<a href="{% url 'change_password' %}">Change password</a>
|
<a href="{% url 'change_password' %}">Change password</a>
|
||||||
@@ -120,13 +126,6 @@
|
|||||||
{% if request.user_profile.enable_favicons and enable_refresh_favicons %}
|
{% if request.user_profile.enable_favicons and enable_refresh_favicons %}
|
||||||
<button class="btn mt-2" name="refresh_favicons">Refresh Favicons</button>
|
<button class="btn mt-2" name="refresh_favicons">Refresh Favicons</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if refresh_favicons_success_message %}
|
|
||||||
<div class="has-success">
|
|
||||||
<p class="form-input-hint">
|
|
||||||
{{ refresh_favicons_success_message }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ form.web_archive_integration.id_for_label }}" class="form-label">Internet Archive
|
<label for="{{ form.web_archive_integration.id_for_label }}" class="form-label">Internet Archive
|
||||||
@@ -173,6 +172,7 @@
|
|||||||
Automatically creates HTML snapshots when adding bookmarks. Alternatively, when disabled, snapshots can be
|
Automatically creates HTML snapshots when adding bookmarks. Alternatively, when disabled, snapshots can be
|
||||||
created manually in the details view of a bookmark.
|
created manually in the details view of a bookmark.
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn mt-2" name="create_missing_html_snapshots">Create missing HTML snapshots</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -189,13 +189,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="submit" name="update_profile" value="Save" class="btn btn-primary mt-2">
|
<input type="submit" name="update_profile" value="Save" class="btn btn-primary mt-2">
|
||||||
{% if update_profile_success_message %}
|
|
||||||
<div class="has-success">
|
|
||||||
<p class="form-input-hint">
|
|
||||||
{{ update_profile_success_message }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
@@ -224,20 +217,6 @@
|
|||||||
<input class="form-input" type="file" name="import_file">
|
<input class="form-input" type="file" name="import_file">
|
||||||
<input type="submit" class="input-group-btn btn btn-primary" value="Upload">
|
<input type="submit" class="input-group-btn btn btn-primary" value="Upload">
|
||||||
</div>
|
</div>
|
||||||
{% if import_success_message %}
|
|
||||||
<div class="has-success">
|
|
||||||
<p class="form-input-hint">
|
|
||||||
{{ import_success_message }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if import_errors_message %}
|
|
||||||
<div class="has-error">
|
|
||||||
<p class="form-input-hint">
|
|
||||||
{{ import_errors_message }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -94,15 +94,10 @@ class BookmarkArchivedViewTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
|||||||
)
|
)
|
||||||
|
|
||||||
def assertBulkActionForm(self, response, url: str):
|
def assertBulkActionForm(self, response, url: str):
|
||||||
html = collapse_whitespace(response.content.decode())
|
soup = self.make_soup(response.content.decode())
|
||||||
needle = collapse_whitespace(
|
form = soup.select_one("form.bookmark-actions")
|
||||||
f"""
|
self.assertIsNotNone(form)
|
||||||
<form class="bookmark-actions"
|
self.assertEqual(form.attrs["action"], url)
|
||||||
action="{url}"
|
|
||||||
method="post" autocomplete="off">
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
self.assertIn(needle, html)
|
|
||||||
|
|
||||||
def test_should_list_archived_and_user_owned_bookmarks(self):
|
def test_should_list_archived_and_user_owned_bookmarks(self):
|
||||||
other_user = User.objects.create_user(
|
other_user = User.objects.create_user(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
@@ -105,17 +106,11 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
|||||||
def test_access_with_sharing(self):
|
def test_access_with_sharing(self):
|
||||||
self.details_route_sharing_access_test(self.get_view_name(), True)
|
self.details_route_sharing_access_test(self.get_view_name(), True)
|
||||||
|
|
||||||
def test_form_partial_access(self):
|
def test_assets_access(self):
|
||||||
# form partial is only used when submitting forms, which should be only
|
self.details_route_access_test("bookmarks:details_assets", True)
|
||||||
# accessible to the owner of the bookmark. As such assume it requires
|
|
||||||
# login.
|
|
||||||
self.details_route_access_test("bookmarks:partials.details_form", False)
|
|
||||||
|
|
||||||
def test_form_partial_access_with_sharing(self):
|
def test_assets_access_with_sharing(self):
|
||||||
# form partial is only used when submitting forms, which should be only
|
self.details_route_sharing_access_test("bookmarks:details_assets", True)
|
||||||
# accessible to the owner of the bookmark. As such assume it requires
|
|
||||||
# login.
|
|
||||||
self.details_route_sharing_access_test("bookmarks:partials.details_form", False)
|
|
||||||
|
|
||||||
def test_displays_title(self):
|
def test_displays_title(self):
|
||||||
# with title
|
# with title
|
||||||
@@ -765,6 +760,27 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
|||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
self.assertTrue(BookmarkAsset.objects.filter(id=asset.id).exists())
|
self.assertTrue(BookmarkAsset.objects.filter(id=asset.id).exists())
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_assets_refresh_when_having_pending_asset(self):
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
asset = self.setup_asset(bookmark, status=BookmarkAsset.STATUS_COMPLETE)
|
||||||
|
fetch_url = reverse("bookmarks:details_assets", args=[bookmark.id])
|
||||||
|
|
||||||
|
# no pending asset
|
||||||
|
soup = self.get_details(bookmark)
|
||||||
|
files_section = self.find_section(soup, "Files")
|
||||||
|
assets_wrapper = files_section.find("div", {"ld-fetch": fetch_url})
|
||||||
|
self.assertIsNone(assets_wrapper)
|
||||||
|
|
||||||
|
# with pending asset
|
||||||
|
asset.status = BookmarkAsset.STATUS_PENDING
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
soup = self.get_details(bookmark)
|
||||||
|
files_section = self.find_section(soup, "Files")
|
||||||
|
assets_wrapper = files_section.find("div", {"ld-fetch": fetch_url})
|
||||||
|
self.assertIsNotNone(assets_wrapper)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
def test_create_snapshot(self):
|
def test_create_snapshot(self):
|
||||||
with patch.object(
|
with patch.object(
|
||||||
@@ -776,6 +792,28 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
|||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
mock_create_html_snapshot_task.assert_called_with(bookmark.id)
|
|
||||||
|
|
||||||
self.assertEqual(bookmark.bookmarkasset_set.count(), 1)
|
self.assertEqual(bookmark.bookmarkasset_set.count(), 1)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_snapshot_is_disabled_when_having_pending_asset(self):
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
asset = self.setup_asset(bookmark, status=BookmarkAsset.STATUS_COMPLETE)
|
||||||
|
|
||||||
|
# no pending asset
|
||||||
|
soup = self.get_details(bookmark)
|
||||||
|
files_section = self.find_section(soup, "Files")
|
||||||
|
create_button = files_section.find(
|
||||||
|
"button", string=re.compile("Create HTML snapshot")
|
||||||
|
)
|
||||||
|
self.assertFalse(create_button.has_attr("disabled"))
|
||||||
|
|
||||||
|
# with pending asset
|
||||||
|
asset.status = BookmarkAsset.STATUS_PENDING
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
soup = self.get_details(bookmark)
|
||||||
|
files_section = self.find_section(soup, "Files")
|
||||||
|
create_button = files_section.find(
|
||||||
|
"button", string=re.compile("Create HTML snapshot")
|
||||||
|
)
|
||||||
|
self.assertTrue(create_button.has_attr("disabled"))
|
||||||
|
|||||||
@@ -94,15 +94,10 @@ class BookmarkIndexViewTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def assertBulkActionForm(self, response, url: str):
|
def assertBulkActionForm(self, response, url: str):
|
||||||
html = collapse_whitespace(response.content.decode())
|
soup = self.make_soup(response.content.decode())
|
||||||
needle = collapse_whitespace(
|
form = soup.select_one("form.bookmark-actions")
|
||||||
f"""
|
self.assertIsNotNone(form)
|
||||||
<form class="bookmark-actions"
|
self.assertEqual(form.attrs["action"], url)
|
||||||
action="{url}"
|
|
||||||
method="post" autocomplete="off">
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
self.assertIn(needle, html)
|
|
||||||
|
|
||||||
def test_should_list_unarchived_and_user_owned_bookmarks(self):
|
def test_should_list_unarchived_and_user_owned_bookmarks(self):
|
||||||
other_user = User.objects.create_user(
|
other_user = User.objects.create_user(
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
|||||||
details_modal_url = reverse("bookmarks:details_modal", args=[bookmark.id])
|
details_modal_url = reverse("bookmarks:details_modal", args=[bookmark.id])
|
||||||
self.assertInHTML(
|
self.assertInHTML(
|
||||||
f"""
|
f"""
|
||||||
<a ld-modal modal-url="{details_modal_url}?return_url={return_url}" href="{details_url}">View</a>
|
<a ld-fetch="{details_modal_url}?return_url={return_url}"
|
||||||
|
ld-on="click" ld-target="body|append"
|
||||||
|
href="{details_url}">View</a>
|
||||||
""",
|
""",
|
||||||
html,
|
html,
|
||||||
count=count,
|
count=count,
|
||||||
@@ -216,7 +218,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
|||||||
f"""
|
f"""
|
||||||
<button type="submit" name="unshare" value="{bookmark.id}"
|
<button type="submit" name="unshare" value="{bookmark.id}"
|
||||||
class="btn btn-link btn-sm btn-icon"
|
class="btn btn-link btn-sm btn-icon"
|
||||||
ld-confirm-button confirm-icon="ld-icon-unshare" confirm-question="Unshare?">
|
ld-confirm-button ld-confirm-icon="ld-icon-unshare" ld-confirm-question="Unshare?">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||||
<use xlink:href="#ld-icon-share"></use>
|
<use xlink:href="#ld-icon-share"></use>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -232,7 +234,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
|||||||
f"""
|
f"""
|
||||||
<button type="submit" name="mark_as_read" value="{bookmark.id}"
|
<button type="submit" name="mark_as_read" value="{bookmark.id}"
|
||||||
class="btn btn-link btn-sm btn-icon"
|
class="btn btn-link btn-sm btn-icon"
|
||||||
ld-confirm-button confirm-icon="ld-icon-read" confirm-question="Mark as read?">
|
ld-confirm-button ld-confirm-icon="ld-icon-read" ld-confirm-question="Mark as read?">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||||
<use xlink:href="#ld-icon-unread"></use>
|
<use xlink:href="#ld-icon-unread"></use>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -782,10 +784,16 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
|
|||||||
|
|
||||||
def test_note_cleans_html(self):
|
def test_note_cleans_html(self):
|
||||||
self.setup_bookmark(notes='<script>alert("test")</script>')
|
self.setup_bookmark(notes='<script>alert("test")</script>')
|
||||||
|
self.setup_bookmark(
|
||||||
|
notes='<b ld-fetch="https://example.com" ld-on="click">bold text</b>'
|
||||||
|
)
|
||||||
html = self.render_template()
|
html = self.render_template()
|
||||||
|
|
||||||
note_html = '<script>alert("test")</script>'
|
note_html = '<script>alert("test")</script>'
|
||||||
self.assertNotes(html, note_html, 1)
|
self.assertIn(note_html, html, 1)
|
||||||
|
|
||||||
|
note_html = "<b>bold text</b>"
|
||||||
|
self.assertIn(note_html, html, 1)
|
||||||
|
|
||||||
def test_notes_are_hidden_initially_by_default(self):
|
def test_notes_are_hidden_initially_by_default(self):
|
||||||
self.setup_bookmark(notes="Test note")
|
self.setup_bookmark(notes="Test note")
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import os.path
|
import os.path
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import waybackpy
|
import waybackpy
|
||||||
from background_task.models import Task
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from huey.contrib.djhuey import HUEY as huey
|
||||||
from waybackpy.exceptions import WaybackError
|
from waybackpy.exceptions import WaybackError
|
||||||
|
|
||||||
import bookmarks.services.favicon_loader
|
import bookmarks.services.favicon_loader
|
||||||
import bookmarks.services.wayback
|
import bookmarks.services.wayback
|
||||||
from bookmarks.models import BookmarkAsset, UserProfile
|
from bookmarks.models import BookmarkAsset, UserProfile
|
||||||
from bookmarks.services import tasks, singlefile
|
from bookmarks.services import tasks, singlefile
|
||||||
from bookmarks.tests.helpers import BookmarkFactoryMixin, disable_logging
|
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||||
|
|
||||||
|
|
||||||
def create_wayback_machine_save_api_mock(
|
def create_wayback_machine_save_api_mock(
|
||||||
@@ -36,27 +35,45 @@ class MockCdxSnapshot:
|
|||||||
datetime_timestamp: datetime.datetime
|
datetime_timestamp: datetime.datetime
|
||||||
|
|
||||||
|
|
||||||
def create_cdx_server_api_mock(
|
|
||||||
archive_url: str | None = "https://example.com/newest_snapshot",
|
|
||||||
fail_loading_snapshot=False,
|
|
||||||
):
|
|
||||||
mock_api = mock.Mock()
|
|
||||||
|
|
||||||
if fail_loading_snapshot:
|
|
||||||
mock_api.newest.side_effect = WaybackError
|
|
||||||
elif archive_url:
|
|
||||||
mock_api.newest.return_value = MockCdxSnapshot(
|
|
||||||
archive_url, datetime.datetime.now()
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
mock_api.newest.return_value = None
|
|
||||||
|
|
||||||
return mock_api
|
|
||||||
|
|
||||||
|
|
||||||
class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
huey.immediate = True
|
||||||
|
huey.results = True
|
||||||
|
huey.store_none = True
|
||||||
|
|
||||||
|
self.mock_save_api = mock.Mock(
|
||||||
|
archive_url="https://example.com/created_snapshot"
|
||||||
|
)
|
||||||
|
self.mock_save_api_patcher = mock.patch.object(
|
||||||
|
waybackpy, "WaybackMachineSaveAPI", return_value=self.mock_save_api
|
||||||
|
)
|
||||||
|
self.mock_save_api_patcher.start()
|
||||||
|
|
||||||
|
self.mock_cdx_api = mock.Mock()
|
||||||
|
self.mock_cdx_api.newest.return_value = MockCdxSnapshot(
|
||||||
|
"https://example.com/newest_snapshot", datetime.datetime.now()
|
||||||
|
)
|
||||||
|
self.mock_cdx_api_patcher = mock.patch.object(
|
||||||
|
bookmarks.services.wayback,
|
||||||
|
"CustomWaybackMachineCDXServerAPI",
|
||||||
|
return_value=self.mock_cdx_api,
|
||||||
|
)
|
||||||
|
self.mock_cdx_api_patcher.start()
|
||||||
|
|
||||||
|
self.mock_load_favicon_patcher = mock.patch(
|
||||||
|
"bookmarks.services.favicon_loader.load_favicon"
|
||||||
|
)
|
||||||
|
self.mock_load_favicon = self.mock_load_favicon_patcher.start()
|
||||||
|
self.mock_load_favicon.return_value = "https_example_com.png"
|
||||||
|
|
||||||
|
self.mock_singlefile_create_snapshot_patcher = mock.patch(
|
||||||
|
"bookmarks.services.singlefile.create_snapshot",
|
||||||
|
)
|
||||||
|
self.mock_singlefile_create_snapshot = (
|
||||||
|
self.mock_singlefile_create_snapshot_patcher.start()
|
||||||
|
)
|
||||||
|
|
||||||
user = self.get_or_create_test_user()
|
user = self.get_or_create_test_user()
|
||||||
user.profile.web_archive_integration = (
|
user.profile.web_archive_integration = (
|
||||||
UserProfile.WEB_ARCHIVE_INTEGRATION_ENABLED
|
UserProfile.WEB_ARCHIVE_INTEGRATION_ENABLED
|
||||||
@@ -64,157 +81,100 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
user.profile.enable_favicons = True
|
user.profile.enable_favicons = True
|
||||||
user.profile.save()
|
user.profile.save()
|
||||||
|
|
||||||
@disable_logging
|
def tearDown(self):
|
||||||
def run_pending_task(self, task_function: Any):
|
self.mock_save_api_patcher.stop()
|
||||||
func = getattr(task_function, "task_function", None)
|
self.mock_cdx_api_patcher.stop()
|
||||||
task = Task.objects.all()[0]
|
self.mock_load_favicon_patcher.stop()
|
||||||
self.assertEqual(task_function.name, task.task_name)
|
self.mock_singlefile_create_snapshot_patcher.stop()
|
||||||
args, kwargs = task.params()
|
huey.storage.flush_results()
|
||||||
func(*args, **kwargs)
|
huey.immediate = False
|
||||||
task.delete()
|
|
||||||
|
|
||||||
@disable_logging
|
def executed_count(self):
|
||||||
def run_all_pending_tasks(self, task_function: Any):
|
return len(huey.all_results())
|
||||||
func = getattr(task_function, "task_function", None)
|
|
||||||
tasks = Task.objects.all()
|
|
||||||
|
|
||||||
for task in tasks:
|
|
||||||
self.assertEqual(task_function.name, task.task_name)
|
|
||||||
args, kwargs = task.params()
|
|
||||||
func(*args, **kwargs)
|
|
||||||
task.delete()
|
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_update_snapshot_url(self):
|
def test_create_web_archive_snapshot_should_update_snapshot_url(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_save_api = create_wayback_machine_save_api_mock()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
tasks.create_web_archive_snapshot(
|
bookmark.refresh_from_db()
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
mock_save_api.save.assert_called_once()
|
self.mock_save_api.save.assert_called_once()
|
||||||
self.assertEqual(
|
self.assertEqual(self.executed_count(), 1)
|
||||||
bookmark.web_archive_snapshot_url,
|
self.assertEqual(
|
||||||
"https://example.com/created_snapshot",
|
bookmark.web_archive_snapshot_url,
|
||||||
)
|
"https://example.com/created_snapshot",
|
||||||
|
)
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_handle_missing_bookmark_id(self):
|
def test_create_web_archive_snapshot_should_handle_missing_bookmark_id(self):
|
||||||
mock_save_api = create_wayback_machine_save_api_mock()
|
tasks._create_web_archive_snapshot_task(123, False)
|
||||||
|
|
||||||
with mock.patch.object(
|
self.assertEqual(self.executed_count(), 1)
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.mock_save_api.save.assert_not_called()
|
||||||
):
|
|
||||||
tasks._create_web_archive_snapshot_task(123, False)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
mock_save_api.save.assert_not_called()
|
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_skip_if_snapshot_exists(self):
|
def test_create_web_archive_snapshot_should_skip_if_snapshot_exists(self):
|
||||||
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
||||||
mock_save_api = create_wayback_machine_save_api_mock()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
self.mock_save_api.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
tasks.create_web_archive_snapshot(
|
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
mock_save_api.assert_not_called()
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
self.mock_save_api.assert_not_called()
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_force_update_snapshot(self):
|
def test_create_web_archive_snapshot_should_force_update_snapshot(self):
|
||||||
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
||||||
mock_save_api = create_wayback_machine_save_api_mock(
|
self.mock_save_api.archive_url = "https://other.com"
|
||||||
archive_url="https://other.com"
|
|
||||||
|
tasks.create_web_archive_snapshot(
|
||||||
|
self.get_or_create_test_user(), bookmark, True
|
||||||
)
|
)
|
||||||
|
bookmark.refresh_from_db()
|
||||||
|
|
||||||
with mock.patch.object(
|
self.assertEqual(bookmark.web_archive_snapshot_url, "https://other.com")
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
|
||||||
):
|
|
||||||
tasks.create_web_archive_snapshot(
|
|
||||||
self.get_or_create_test_user(), bookmark, True
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
self.assertEqual(bookmark.web_archive_snapshot_url, "https://other.com")
|
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_use_newest_snapshot_as_fallback(self):
|
def test_create_web_archive_snapshot_should_use_newest_snapshot_as_fallback(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_save_api = create_wayback_machine_save_api_mock(fail_on_save=True)
|
self.mock_save_api.save.side_effect = WaybackError
|
||||||
mock_cdx_api = create_cdx_server_api_mock()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
with mock.patch.object(
|
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks.create_web_archive_snapshot(
|
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
bookmark.refresh_from_db()
|
bookmark.refresh_from_db()
|
||||||
mock_cdx_api.newest.assert_called_once()
|
self.mock_cdx_api.newest.assert_called_once()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"https://example.com/newest_snapshot",
|
"https://example.com/newest_snapshot",
|
||||||
bookmark.web_archive_snapshot_url,
|
bookmark.web_archive_snapshot_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_ignore_missing_newest_snapshot(self):
|
def test_create_web_archive_snapshot_should_ignore_missing_newest_snapshot(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_save_api = create_wayback_machine_save_api_mock(fail_on_save=True)
|
self.mock_save_api.save.side_effect = WaybackError
|
||||||
mock_cdx_api = create_cdx_server_api_mock(archive_url=None)
|
self.mock_cdx_api.newest.return_value = None
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
with mock.patch.object(
|
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks.create_web_archive_snapshot(
|
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
bookmark.refresh_from_db()
|
bookmark.refresh_from_db()
|
||||||
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_ignore_newest_snapshot_errors(self):
|
def test_create_web_archive_snapshot_should_ignore_newest_snapshot_errors(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_save_api = create_wayback_machine_save_api_mock(fail_on_save=True)
|
self.mock_save_api.save.side_effect = WaybackError
|
||||||
mock_cdx_api = create_cdx_server_api_mock(fail_loading_snapshot=True)
|
self.mock_cdx_api.newest.side_effect = WaybackError
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
with mock.patch.object(
|
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks.create_web_archive_snapshot(
|
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
bookmark.refresh_from_db()
|
bookmark.refresh_from_db()
|
||||||
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_not_save_stale_bookmark_data(self):
|
def test_create_web_archive_snapshot_should_not_save_stale_bookmark_data(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_save_api = create_wayback_machine_save_api_mock()
|
|
||||||
|
|
||||||
# update bookmark during API call to check that saving
|
# update bookmark during API call to check that saving
|
||||||
# the snapshot does not overwrite updated bookmark data
|
# the snapshot does not overwrite updated bookmark data
|
||||||
@@ -222,99 +182,64 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark.title = "Updated title"
|
bookmark.title = "Updated title"
|
||||||
bookmark.save()
|
bookmark.save()
|
||||||
|
|
||||||
mock_save_api.save.side_effect = mock_save_impl
|
self.mock_save_api.save.side_effect = mock_save_impl
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks.create_web_archive_snapshot(
|
||||||
waybackpy, "WaybackMachineSaveAPI", return_value=mock_save_api
|
self.get_or_create_test_user(), bookmark, False
|
||||||
):
|
)
|
||||||
tasks.create_web_archive_snapshot(
|
bookmark.refresh_from_db()
|
||||||
self.get_or_create_test_user(), bookmark, False
|
|
||||||
)
|
|
||||||
self.run_pending_task(tasks._create_web_archive_snapshot_task)
|
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
self.assertEqual(bookmark.title, "Updated title")
|
self.assertEqual(bookmark.title, "Updated title")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"https://example.com/created_snapshot",
|
"https://example.com/created_snapshot",
|
||||||
bookmark.web_archive_snapshot_url,
|
bookmark.web_archive_snapshot_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_update_snapshot_url(self):
|
def test_load_web_archive_snapshot_should_update_snapshot_url(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_cdx_api = create_cdx_server_api_mock()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks._load_web_archive_snapshot_task(bookmark.id)
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(bookmark.id)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
bookmark.refresh_from_db()
|
bookmark.refresh_from_db()
|
||||||
mock_cdx_api.newest.assert_called_once()
|
|
||||||
self.assertEqual(
|
self.assertEqual(self.executed_count(), 1)
|
||||||
"https://example.com/newest_snapshot", bookmark.web_archive_snapshot_url
|
self.mock_cdx_api.newest.assert_called_once()
|
||||||
)
|
self.assertEqual(
|
||||||
|
"https://example.com/newest_snapshot", bookmark.web_archive_snapshot_url
|
||||||
|
)
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_handle_missing_bookmark_id(self):
|
def test_load_web_archive_snapshot_should_handle_missing_bookmark_id(self):
|
||||||
mock_cdx_api = create_cdx_server_api_mock()
|
tasks._load_web_archive_snapshot_task(123)
|
||||||
|
|
||||||
with mock.patch.object(
|
self.assertEqual(self.executed_count(), 1)
|
||||||
bookmarks.services.wayback,
|
self.mock_cdx_api.newest.assert_not_called()
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(123)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
mock_cdx_api.newest.assert_not_called()
|
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_skip_if_snapshot_exists(self):
|
def test_load_web_archive_snapshot_should_skip_if_snapshot_exists(self):
|
||||||
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
||||||
mock_cdx_api = create_cdx_server_api_mock()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks._load_web_archive_snapshot_task(bookmark.id)
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(bookmark.id)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
mock_cdx_api.newest.assert_not_called()
|
self.assertEqual(self.executed_count(), 1)
|
||||||
|
self.mock_cdx_api.newest.assert_not_called()
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_handle_missing_snapshot(self):
|
def test_load_web_archive_snapshot_should_handle_missing_snapshot(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_cdx_api = create_cdx_server_api_mock(archive_url=None)
|
self.mock_cdx_api.newest.return_value = None
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks._load_web_archive_snapshot_task(bookmark.id)
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(bookmark.id)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_handle_wayback_errors(self):
|
def test_load_web_archive_snapshot_should_handle_wayback_errors(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_cdx_api = create_cdx_server_api_mock(fail_loading_snapshot=True)
|
self.mock_cdx_api.newest.side_effect = WaybackError
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks._load_web_archive_snapshot_task(bookmark.id)
|
||||||
bookmarks.services.wayback,
|
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(bookmark.id)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
|
|
||||||
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
self.assertEqual("", bookmark.web_archive_snapshot_url)
|
||||||
|
|
||||||
def test_load_web_archive_snapshot_should_not_save_stale_bookmark_data(self):
|
def test_load_web_archive_snapshot_should_not_save_stale_bookmark_data(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
mock_cdx_api = create_cdx_server_api_mock()
|
|
||||||
|
|
||||||
# update bookmark during API call to check that saving
|
# update bookmark during API call to check that saving
|
||||||
# the snapshot does not overwrite updated bookmark data
|
# the snapshot does not overwrite updated bookmark data
|
||||||
@@ -323,32 +248,26 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark.save()
|
bookmark.save()
|
||||||
return mock.DEFAULT
|
return mock.DEFAULT
|
||||||
|
|
||||||
mock_cdx_api.newest.side_effect = mock_newest_impl
|
self.mock_cdx_api.newest.side_effect = mock_newest_impl
|
||||||
|
|
||||||
with mock.patch.object(
|
tasks._load_web_archive_snapshot_task(bookmark.id)
|
||||||
bookmarks.services.wayback,
|
bookmark.refresh_from_db()
|
||||||
"CustomWaybackMachineCDXServerAPI",
|
|
||||||
return_value=mock_cdx_api,
|
|
||||||
):
|
|
||||||
tasks._load_web_archive_snapshot_task(bookmark.id)
|
|
||||||
self.run_pending_task(tasks._load_web_archive_snapshot_task)
|
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
self.assertEqual("Updated title", bookmark.title)
|
self.assertEqual("Updated title", bookmark.title)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"https://example.com/newest_snapshot", bookmark.web_archive_snapshot_url
|
"https://example.com/newest_snapshot", bookmark.web_archive_snapshot_url
|
||||||
)
|
)
|
||||||
|
|
||||||
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_create_web_archive_snapshot_should_not_run_when_background_tasks_are_disabled(
|
def test_create_web_archive_snapshot_should_not_run_when_background_tasks_are_disabled(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
|
|
||||||
tasks.create_web_archive_snapshot(
|
tasks.create_web_archive_snapshot(
|
||||||
self.get_or_create_test_user(), bookmark, False
|
self.get_or_create_test_user(), bookmark, False
|
||||||
)
|
)
|
||||||
|
self.assertEqual(self.executed_count(), 0)
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
|
||||||
|
|
||||||
def test_create_web_archive_snapshot_should_not_run_when_web_archive_integration_is_disabled(
|
def test_create_web_archive_snapshot_should_not_run_when_web_archive_integration_is_disabled(
|
||||||
self,
|
self,
|
||||||
@@ -363,7 +282,7 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.get_or_create_test_user(), bookmark, False
|
self.get_or_create_test_user(), bookmark, False
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_snapshots_should_load_snapshot_for_all_bookmarks_without_snapshot(
|
def test_schedule_bookmarks_without_snapshots_should_load_snapshot_for_all_bookmarks_without_snapshot(
|
||||||
self,
|
self,
|
||||||
@@ -377,16 +296,9 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
self.setup_bookmark(web_archive_snapshot_url="https://example.com")
|
||||||
|
|
||||||
tasks.schedule_bookmarks_without_snapshots(user)
|
tasks.schedule_bookmarks_without_snapshots(user)
|
||||||
self.run_pending_task(tasks._schedule_bookmarks_without_snapshots_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.executed_count(), 4)
|
||||||
self.assertEqual(task_list.count(), 3)
|
self.assertEqual(self.mock_cdx_api.newest.call_count, 3)
|
||||||
|
|
||||||
for task in task_list:
|
|
||||||
self.assertEqual(
|
|
||||||
task.task_name,
|
|
||||||
"bookmarks.services.tasks._load_web_archive_snapshot_task",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_snapshots_should_only_update_user_owned_bookmarks(
|
def test_schedule_bookmarks_without_snapshots_should_only_update_user_owned_bookmarks(
|
||||||
self,
|
self,
|
||||||
@@ -403,10 +315,8 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(user=other_user)
|
self.setup_bookmark(user=other_user)
|
||||||
|
|
||||||
tasks.schedule_bookmarks_without_snapshots(user)
|
tasks.schedule_bookmarks_without_snapshots(user)
|
||||||
self.run_pending_task(tasks._schedule_bookmarks_without_snapshots_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.mock_cdx_api.newest.call_count, 3)
|
||||||
self.assertEqual(task_list.count(), 3)
|
|
||||||
|
|
||||||
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_schedule_bookmarks_without_snapshots_should_not_run_when_background_tasks_are_disabled(
|
def test_schedule_bookmarks_without_snapshots_should_not_run_when_background_tasks_are_disabled(
|
||||||
@@ -414,7 +324,7 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
):
|
):
|
||||||
tasks.schedule_bookmarks_without_snapshots(self.user)
|
tasks.schedule_bookmarks_without_snapshots(self.user)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_snapshots_should_not_run_when_web_archive_integration_is_disabled(
|
def test_schedule_bookmarks_without_snapshots_should_not_run_when_web_archive_integration_is_disabled(
|
||||||
self,
|
self,
|
||||||
@@ -425,44 +335,32 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.user.profile.save()
|
self.user.profile.save()
|
||||||
tasks.schedule_bookmarks_without_snapshots(self.user)
|
tasks.schedule_bookmarks_without_snapshots(self.user)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_load_favicon_should_create_favicon_file(self):
|
def test_load_favicon_should_create_favicon_file(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
|
|
||||||
with mock.patch(
|
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
||||||
"bookmarks.services.favicon_loader.load_favicon"
|
bookmark.refresh_from_db()
|
||||||
) as mock_load_favicon:
|
|
||||||
mock_load_favicon.return_value = "https_example_com.png"
|
|
||||||
|
|
||||||
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
self.assertEqual(self.executed_count(), 1)
|
||||||
self.run_pending_task(tasks._load_favicon_task)
|
self.assertEqual(bookmark.favicon_file, "https_example_com.png")
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
self.assertEqual(bookmark.favicon_file, "https_example_com.png")
|
|
||||||
|
|
||||||
def test_load_favicon_should_update_favicon_file(self):
|
def test_load_favicon_should_update_favicon_file(self):
|
||||||
bookmark = self.setup_bookmark(favicon_file="https_example_com.png")
|
bookmark = self.setup_bookmark(favicon_file="https_example_com.png")
|
||||||
|
|
||||||
with mock.patch(
|
self.mock_load_favicon.return_value = "https_example_updated_com.png"
|
||||||
"bookmarks.services.favicon_loader.load_favicon"
|
|
||||||
) as mock_load_favicon:
|
|
||||||
mock_load_favicon.return_value = "https_example_updated_com.png"
|
|
||||||
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
|
||||||
self.run_pending_task(tasks._load_favicon_task)
|
|
||||||
|
|
||||||
mock_load_favicon.assert_called()
|
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
||||||
bookmark.refresh_from_db()
|
|
||||||
self.assertEqual(bookmark.favicon_file, "https_example_updated_com.png")
|
bookmark.refresh_from_db()
|
||||||
|
self.mock_load_favicon.assert_called_once()
|
||||||
|
self.assertEqual(bookmark.favicon_file, "https_example_updated_com.png")
|
||||||
|
|
||||||
def test_load_favicon_should_handle_missing_bookmark(self):
|
def test_load_favicon_should_handle_missing_bookmark(self):
|
||||||
with mock.patch(
|
tasks._load_favicon_task(123)
|
||||||
"bookmarks.services.favicon_loader.load_favicon"
|
|
||||||
) as mock_load_favicon:
|
|
||||||
tasks._load_favicon_task(123)
|
|
||||||
self.run_pending_task(tasks._load_favicon_task)
|
|
||||||
|
|
||||||
mock_load_favicon.assert_not_called()
|
self.mock_load_favicon.assert_not_called()
|
||||||
|
|
||||||
def test_load_favicon_should_not_save_stale_bookmark_data(self):
|
def test_load_favicon_should_not_save_stale_bookmark_data(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
@@ -474,24 +372,20 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark.save()
|
bookmark.save()
|
||||||
return "https_example_com.png"
|
return "https_example_com.png"
|
||||||
|
|
||||||
with mock.patch(
|
self.mock_load_favicon.side_effect = mock_load_favicon_impl
|
||||||
"bookmarks.services.favicon_loader.load_favicon"
|
|
||||||
) as mock_load_favicon:
|
|
||||||
mock_load_favicon.side_effect = mock_load_favicon_impl
|
|
||||||
|
|
||||||
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
||||||
self.run_pending_task(tasks._load_favicon_task)
|
bookmark.refresh_from_db()
|
||||||
bookmark.refresh_from_db()
|
|
||||||
|
|
||||||
self.assertEqual(bookmark.title, "Updated title")
|
self.assertEqual(bookmark.title, "Updated title")
|
||||||
self.assertEqual(bookmark.favicon_file, "https_example_com.png")
|
self.assertEqual(bookmark.favicon_file, "https_example_com.png")
|
||||||
|
|
||||||
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_load_favicon_should_not_run_when_background_tasks_are_disabled(self):
|
def test_load_favicon_should_not_run_when_background_tasks_are_disabled(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_load_favicon_should_not_run_when_favicon_feature_is_disabled(self):
|
def test_load_favicon_should_not_run_when_favicon_feature_is_disabled(self):
|
||||||
self.user.profile.enable_favicons = False
|
self.user.profile.enable_favicons = False
|
||||||
@@ -500,7 +394,7 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
tasks.load_favicon(self.get_or_create_test_user(), bookmark)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_favicons_should_load_favicon_for_all_bookmarks_without_favicon(
|
def test_schedule_bookmarks_without_favicons_should_load_favicon_for_all_bookmarks_without_favicon(
|
||||||
self,
|
self,
|
||||||
@@ -514,15 +408,9 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(favicon_file="https_example_com.png")
|
self.setup_bookmark(favicon_file="https_example_com.png")
|
||||||
|
|
||||||
tasks.schedule_bookmarks_without_favicons(user)
|
tasks.schedule_bookmarks_without_favicons(user)
|
||||||
self.run_pending_task(tasks._schedule_bookmarks_without_favicons_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.executed_count(), 4)
|
||||||
self.assertEqual(task_list.count(), 3)
|
self.assertEqual(self.mock_load_favicon.call_count, 3)
|
||||||
|
|
||||||
for task in task_list:
|
|
||||||
self.assertEqual(
|
|
||||||
task.task_name, "bookmarks.services.tasks._load_favicon_task"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_favicons_should_only_update_user_owned_bookmarks(
|
def test_schedule_bookmarks_without_favicons_should_only_update_user_owned_bookmarks(
|
||||||
self,
|
self,
|
||||||
@@ -539,19 +427,17 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(user=other_user)
|
self.setup_bookmark(user=other_user)
|
||||||
|
|
||||||
tasks.schedule_bookmarks_without_favicons(user)
|
tasks.schedule_bookmarks_without_favicons(user)
|
||||||
self.run_pending_task(tasks._schedule_bookmarks_without_favicons_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.mock_load_favicon.call_count, 3)
|
||||||
self.assertEqual(task_list.count(), 3)
|
|
||||||
|
|
||||||
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_schedule_bookmarks_without_favicons_should_not_run_when_background_tasks_are_disabled(
|
def test_schedule_bookmarks_without_favicons_should_not_run_when_background_tasks_are_disabled(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
bookmark = self.setup_bookmark()
|
self.setup_bookmark()
|
||||||
tasks.schedule_bookmarks_without_favicons(self.get_or_create_test_user())
|
tasks.schedule_bookmarks_without_favicons(self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_bookmarks_without_favicons_should_not_run_when_favicon_feature_is_disabled(
|
def test_schedule_bookmarks_without_favicons_should_not_run_when_favicon_feature_is_disabled(
|
||||||
self,
|
self,
|
||||||
@@ -559,10 +445,10 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.user.profile.enable_favicons = False
|
self.user.profile.enable_favicons = False
|
||||||
self.user.profile.save()
|
self.user.profile.save()
|
||||||
|
|
||||||
bookmark = self.setup_bookmark()
|
self.setup_bookmark()
|
||||||
tasks.schedule_bookmarks_without_favicons(self.get_or_create_test_user())
|
tasks.schedule_bookmarks_without_favicons(self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_refresh_favicons_should_update_favicon_for_all_bookmarks(self):
|
def test_schedule_refresh_favicons_should_update_favicon_for_all_bookmarks(self):
|
||||||
user = self.get_or_create_test_user()
|
user = self.get_or_create_test_user()
|
||||||
@@ -574,15 +460,9 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(favicon_file="https_example_com.png")
|
self.setup_bookmark(favicon_file="https_example_com.png")
|
||||||
|
|
||||||
tasks.schedule_refresh_favicons(user)
|
tasks.schedule_refresh_favicons(user)
|
||||||
self.run_pending_task(tasks._schedule_refresh_favicons_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.executed_count(), 7)
|
||||||
self.assertEqual(task_list.count(), 6)
|
self.assertEqual(self.mock_load_favicon.call_count, 6)
|
||||||
|
|
||||||
for task in task_list:
|
|
||||||
self.assertEqual(
|
|
||||||
task.task_name, "bookmarks.services.tasks._load_favicon_task"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_schedule_refresh_favicons_should_only_update_user_owned_bookmarks(self):
|
def test_schedule_refresh_favicons_should_only_update_user_owned_bookmarks(self):
|
||||||
user = self.get_or_create_test_user()
|
user = self.get_or_create_test_user()
|
||||||
@@ -597,10 +477,8 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark(user=other_user)
|
self.setup_bookmark(user=other_user)
|
||||||
|
|
||||||
tasks.schedule_refresh_favicons(user)
|
tasks.schedule_refresh_favicons(user)
|
||||||
self.run_pending_task(tasks._schedule_refresh_favicons_task)
|
|
||||||
|
|
||||||
task_list = Task.objects.all()
|
self.assertEqual(self.mock_load_favicon.call_count, 3)
|
||||||
self.assertEqual(task_list.count(), 3)
|
|
||||||
|
|
||||||
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_schedule_refresh_favicons_should_not_run_when_background_tasks_are_disabled(
|
def test_schedule_refresh_favicons_should_not_run_when_background_tasks_are_disabled(
|
||||||
@@ -609,14 +487,14 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark()
|
self.setup_bookmark()
|
||||||
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_REFRESH_FAVICONS=False)
|
@override_settings(LD_ENABLE_REFRESH_FAVICONS=False)
|
||||||
def test_schedule_refresh_favicons_should_not_run_when_refresh_is_disabled(self):
|
def test_schedule_refresh_favicons_should_not_run_when_refresh_is_disabled(self):
|
||||||
self.setup_bookmark()
|
self.setup_bookmark()
|
||||||
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
def test_schedule_refresh_favicons_should_not_run_when_favicon_feature_is_disabled(
|
def test_schedule_refresh_favicons_should_not_run_when_favicon_feature_is_disabled(
|
||||||
self,
|
self,
|
||||||
@@ -627,13 +505,14 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.setup_bookmark()
|
self.setup_bookmark()
|
||||||
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
tasks.schedule_refresh_favicons(self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(self.executed_count(), 0)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
def test_create_html_snapshot_should_create_pending_asset(self):
|
def test_create_html_snapshot_should_create_pending_asset(self):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
|
|
||||||
with mock.patch("bookmarks.services.monolith.create_snapshot"):
|
# Mock the task function to avoid running it immediately
|
||||||
|
with mock.patch("bookmarks.services.tasks._create_html_snapshot_task"):
|
||||||
tasks.create_html_snapshot(bookmark)
|
tasks.create_html_snapshot(bookmark)
|
||||||
self.assertEqual(BookmarkAsset.objects.count(), 1)
|
self.assertEqual(BookmarkAsset.objects.count(), 1)
|
||||||
|
|
||||||
@@ -652,18 +531,24 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
def test_create_html_snapshot_should_update_file_info(self):
|
def test_create_html_snapshot_should_update_file_info(self):
|
||||||
bookmark = self.setup_bookmark(url="https://example.com")
|
bookmark = self.setup_bookmark(url="https://example.com")
|
||||||
|
|
||||||
with mock.patch("bookmarks.services.singlefile.create_snapshot") as mock_create:
|
with mock.patch(
|
||||||
tasks.create_html_snapshot(bookmark)
|
"bookmarks.services.tasks._generate_snapshot_filename"
|
||||||
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
) as mock_generate:
|
||||||
asset.date_created = datetime.datetime(2021, 1, 2, 3, 44, 55)
|
|
||||||
asset.save()
|
|
||||||
expected_filename = "snapshot_2021-01-02_034455_https___example.com.html.gz"
|
expected_filename = "snapshot_2021-01-02_034455_https___example.com.html.gz"
|
||||||
|
mock_generate.return_value = expected_filename
|
||||||
|
|
||||||
self.run_pending_task(tasks._create_html_snapshot_task)
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
BookmarkAsset.objects.get(bookmark=bookmark)
|
||||||
|
|
||||||
mock_create.assert_called_once_with(
|
# Run periodic task to process the snapshot
|
||||||
|
tasks._schedule_html_snapshots_task()
|
||||||
|
|
||||||
|
self.mock_singlefile_create_snapshot.assert_called_once_with(
|
||||||
"https://example.com",
|
"https://example.com",
|
||||||
os.path.join(settings.LD_ASSET_FOLDER, expected_filename),
|
os.path.join(
|
||||||
|
settings.LD_ASSET_FOLDER,
|
||||||
|
expected_filename,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
||||||
@@ -671,43 +556,144 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.assertEqual(asset.file, expected_filename)
|
self.assertEqual(asset.file, expected_filename)
|
||||||
self.assertTrue(asset.gzip)
|
self.assertTrue(asset.gzip)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_html_snapshot_truncate_filename(self):
|
||||||
|
# Create a bookmark with a very long URL
|
||||||
|
long_url = "http://" + "a" * 300 + ".com"
|
||||||
|
bookmark = self.setup_bookmark(url=long_url)
|
||||||
|
|
||||||
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
BookmarkAsset.objects.get(bookmark=bookmark)
|
||||||
|
|
||||||
|
# Run periodic task to process the snapshot
|
||||||
|
tasks._schedule_html_snapshots_task()
|
||||||
|
|
||||||
|
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
||||||
|
self.assertEqual(len(asset.file), 192)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
def test_create_html_snapshot_should_handle_error(self):
|
def test_create_html_snapshot_should_handle_error(self):
|
||||||
bookmark = self.setup_bookmark(url="https://example.com")
|
bookmark = self.setup_bookmark(url="https://example.com")
|
||||||
|
|
||||||
with mock.patch("bookmarks.services.singlefile.create_snapshot") as mock_create:
|
self.mock_singlefile_create_snapshot.side_effect = singlefile.SingeFileError(
|
||||||
mock_create.side_effect = singlefile.SingeFileError("Error")
|
"Error"
|
||||||
|
)
|
||||||
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
|
||||||
tasks.create_html_snapshot(bookmark)
|
# Run periodic task to process the snapshot
|
||||||
self.run_pending_task(tasks._create_html_snapshot_task)
|
tasks._schedule_html_snapshots_task()
|
||||||
|
|
||||||
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
asset = BookmarkAsset.objects.get(bookmark=bookmark)
|
||||||
self.assertEqual(asset.status, BookmarkAsset.STATUS_FAILURE)
|
self.assertEqual(asset.status, BookmarkAsset.STATUS_FAILURE)
|
||||||
self.assertEqual(asset.file, "")
|
self.assertEqual(asset.file, "")
|
||||||
self.assertFalse(asset.gzip)
|
self.assertFalse(asset.gzip)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
def test_create_html_snapshot_should_handle_missing_bookmark(self):
|
def test_create_html_snapshot_should_handle_missing_bookmark(self):
|
||||||
with mock.patch("bookmarks.services.singlefile.create_snapshot") as mock_create:
|
tasks._create_html_snapshot_task(123)
|
||||||
tasks._create_html_snapshot_task(123)
|
|
||||||
self.run_pending_task(tasks._create_html_snapshot_task)
|
|
||||||
|
|
||||||
mock_create.assert_not_called()
|
self.mock_singlefile_create_snapshot.assert_not_called()
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=False)
|
@override_settings(LD_ENABLE_SNAPSHOTS=False)
|
||||||
def test_create_html_snapshot_should_not_run_when_single_file_is_disabled(
|
def test_create_html_snapshot_should_not_create_asset_when_single_file_is_disabled(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
tasks.create_html_snapshot(bookmark)
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(BookmarkAsset.objects.count(), 0)
|
||||||
|
|
||||||
@override_settings(LD_ENABLE_SNAPSHOTS=True, LD_DISABLE_BACKGROUND_TASKS=True)
|
@override_settings(LD_ENABLE_SNAPSHOTS=True, LD_DISABLE_BACKGROUND_TASKS=True)
|
||||||
def test_create_html_snapshot_should_not_run_when_background_tasks_are_disabled(
|
def test_create_html_snapshot_should_not_create_asset_when_background_tasks_are_disabled(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
tasks.create_html_snapshot(bookmark)
|
tasks.create_html_snapshot(bookmark)
|
||||||
|
|
||||||
self.assertEqual(Task.objects.count(), 0)
|
self.assertEqual(BookmarkAsset.objects.count(), 0)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_missing_html_snapshots(self):
|
||||||
|
bookmarks_with_snapshots = []
|
||||||
|
bookmarks_without_snapshots = []
|
||||||
|
|
||||||
|
# setup bookmarks with snapshots
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
self.setup_asset(
|
||||||
|
bookmark=bookmark,
|
||||||
|
asset_type=BookmarkAsset.TYPE_SNAPSHOT,
|
||||||
|
status=BookmarkAsset.STATUS_COMPLETE,
|
||||||
|
)
|
||||||
|
bookmarks_with_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
self.setup_asset(
|
||||||
|
bookmark=bookmark,
|
||||||
|
asset_type=BookmarkAsset.TYPE_SNAPSHOT,
|
||||||
|
status=BookmarkAsset.STATUS_PENDING,
|
||||||
|
)
|
||||||
|
bookmarks_with_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
# setup bookmarks without snapshots
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
bookmarks_without_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
self.setup_asset(
|
||||||
|
bookmark=bookmark,
|
||||||
|
asset_type=BookmarkAsset.TYPE_SNAPSHOT,
|
||||||
|
status=BookmarkAsset.STATUS_FAILURE,
|
||||||
|
)
|
||||||
|
bookmarks_without_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
self.setup_asset(
|
||||||
|
bookmark=bookmark,
|
||||||
|
asset_type="some_other_type",
|
||||||
|
status=BookmarkAsset.STATUS_PENDING,
|
||||||
|
)
|
||||||
|
bookmarks_without_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
bookmark = self.setup_bookmark()
|
||||||
|
self.setup_asset(
|
||||||
|
bookmark=bookmark,
|
||||||
|
asset_type="some_other_type",
|
||||||
|
status=BookmarkAsset.STATUS_COMPLETE,
|
||||||
|
)
|
||||||
|
bookmarks_without_snapshots.append(bookmark)
|
||||||
|
|
||||||
|
initial_assets = list(BookmarkAsset.objects.all())
|
||||||
|
initial_assets_count = len(initial_assets)
|
||||||
|
initial_asset_ids = [asset.id for asset in initial_assets]
|
||||||
|
count = tasks.create_missing_html_snapshots(self.get_or_create_test_user())
|
||||||
|
|
||||||
|
self.assertEqual(count, 4)
|
||||||
|
self.assertEqual(BookmarkAsset.objects.count(), initial_assets_count + count)
|
||||||
|
|
||||||
|
for bookmark in bookmarks_without_snapshots:
|
||||||
|
new_assets = BookmarkAsset.objects.filter(bookmark=bookmark).exclude(
|
||||||
|
id__in=initial_asset_ids
|
||||||
|
)
|
||||||
|
self.assertEqual(new_assets.count(), 1)
|
||||||
|
|
||||||
|
for bookmark in bookmarks_with_snapshots:
|
||||||
|
new_assets = BookmarkAsset.objects.filter(bookmark=bookmark).exclude(
|
||||||
|
id__in=initial_asset_ids
|
||||||
|
)
|
||||||
|
self.assertEqual(new_assets.count(), 0)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_missing_html_snapshots_respects_current_user(self):
|
||||||
|
self.setup_bookmark()
|
||||||
|
self.setup_bookmark()
|
||||||
|
self.setup_bookmark()
|
||||||
|
|
||||||
|
other_user = self.setup_user()
|
||||||
|
self.setup_bookmark(user=other_user)
|
||||||
|
self.setup_bookmark(user=other_user)
|
||||||
|
self.setup_bookmark(user=other_user)
|
||||||
|
|
||||||
|
count = tasks.create_missing_html_snapshots(self.get_or_create_test_user())
|
||||||
|
|
||||||
|
self.assertEqual(count, 3)
|
||||||
|
self.assertEqual(BookmarkAsset.objects.count(), count)
|
||||||
|
|||||||
@@ -49,3 +49,15 @@ class OidcSupportTest(TestCase):
|
|||||||
base_settings.AUTHENTICATION_BACKENDS,
|
base_settings.AUTHENTICATION_BACKENDS,
|
||||||
)
|
)
|
||||||
del os.environ["LD_ENABLE_OIDC"] # Remove the temporary environment variable
|
del os.environ["LD_ENABLE_OIDC"] # Remove the temporary environment variable
|
||||||
|
|
||||||
|
def test_default_settings(self):
|
||||||
|
os.environ["LD_ENABLE_OIDC"] = "True"
|
||||||
|
base_settings = importlib.import_module("siteroot.settings.base")
|
||||||
|
importlib.reload(base_settings)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
True,
|
||||||
|
base_settings.OIDC_VERIFY_SSL,
|
||||||
|
)
|
||||||
|
|
||||||
|
del os.environ["LD_ENABLE_OIDC"]
|
||||||
|
|||||||
@@ -44,6 +44,24 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
|
|
||||||
return {**form_data, **overrides}
|
return {**form_data, **overrides}
|
||||||
|
|
||||||
|
def assertSuccessMessage(self, html, message: str, count=1):
|
||||||
|
self.assertInHTML(
|
||||||
|
f"""
|
||||||
|
<div class="toast toast-success mb-4">{ message }</div>
|
||||||
|
""",
|
||||||
|
html,
|
||||||
|
count=count,
|
||||||
|
)
|
||||||
|
|
||||||
|
def assertErrorMessage(self, html, message: str, count=1):
|
||||||
|
self.assertInHTML(
|
||||||
|
f"""
|
||||||
|
<div class="toast toast-error mb-4">{ message }</div>
|
||||||
|
""",
|
||||||
|
html,
|
||||||
|
count=count,
|
||||||
|
)
|
||||||
|
|
||||||
def test_should_render_successfully(self):
|
def test_should_render_successfully(self):
|
||||||
response = self.client.get(reverse("bookmarks:settings.general"))
|
response = self.client.get(reverse("bookmarks:settings.general"))
|
||||||
|
|
||||||
@@ -138,12 +156,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.user.profile.permanent_notes, form_data["permanent_notes"]
|
self.user.profile.permanent_notes, form_data["permanent_notes"]
|
||||||
)
|
)
|
||||||
self.assertEqual(self.user.profile.custom_css, form_data["custom_css"])
|
self.assertEqual(self.user.profile.custom_css, form_data["custom_css"])
|
||||||
self.assertInHTML(
|
self.assertSuccessMessage(html, "Profile updated")
|
||||||
"""
|
|
||||||
<p class="form-input-hint">Profile updated</p>
|
|
||||||
""",
|
|
||||||
html,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_update_profile_should_not_be_called_without_respective_form_action(self):
|
def test_update_profile_should_not_be_called_without_respective_form_action(self):
|
||||||
form_data = {
|
form_data = {
|
||||||
@@ -156,13 +169,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(self.user.profile.theme, UserProfile.THEME_AUTO)
|
self.assertEqual(self.user.profile.theme, UserProfile.THEME_AUTO)
|
||||||
self.assertInHTML(
|
self.assertSuccessMessage(html, "Profile updated", count=0)
|
||||||
"""
|
|
||||||
<p class="form-input-hint">Profile updated</p>
|
|
||||||
""",
|
|
||||||
html,
|
|
||||||
count=0,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_enable_favicons_should_schedule_icon_update(self):
|
def test_enable_favicons_should_schedule_icon_update(self):
|
||||||
with patch.object(
|
with patch.object(
|
||||||
@@ -210,13 +217,8 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
html = response.content.decode()
|
html = response.content.decode()
|
||||||
|
|
||||||
mock_schedule_refresh_favicons.assert_called_once()
|
mock_schedule_refresh_favicons.assert_called_once()
|
||||||
self.assertInHTML(
|
self.assertSuccessMessage(
|
||||||
"""
|
html, "Scheduled favicon update. This may take a while..."
|
||||||
<p class="form-input-hint">
|
|
||||||
Scheduled favicon update. This may take a while...
|
|
||||||
</p>
|
|
||||||
""",
|
|
||||||
html,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_refresh_favicons_should_not_be_called_without_respective_form_action(self):
|
def test_refresh_favicons_should_not_be_called_without_respective_form_action(self):
|
||||||
@@ -230,14 +232,8 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
html = response.content.decode()
|
html = response.content.decode()
|
||||||
|
|
||||||
mock_schedule_refresh_favicons.assert_not_called()
|
mock_schedule_refresh_favicons.assert_not_called()
|
||||||
self.assertInHTML(
|
self.assertSuccessMessage(
|
||||||
"""
|
html, "Scheduled favicon update. This may take a while...", count=0
|
||||||
<p class="form-input-hint">
|
|
||||||
Scheduled favicon update. This may take a while...
|
|
||||||
</p>
|
|
||||||
""",
|
|
||||||
html,
|
|
||||||
count=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_refresh_favicons_should_be_visible_when_favicons_enabled_in_profile(self):
|
def test_refresh_favicons_should_be_visible_when_favicons_enabled_in_profile(self):
|
||||||
@@ -365,3 +361,57 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
with patch.object(requests, "get", return_value=latest_version_response_mock):
|
with patch.object(requests, "get", return_value=latest_version_response_mock):
|
||||||
version_info = get_version_info(random.random())
|
version_info = get_version_info(random.random())
|
||||||
self.assertEqual(version_info, app_version)
|
self.assertEqual(version_info, app_version)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_missing_html_snapshots(self):
|
||||||
|
with patch.object(
|
||||||
|
tasks, "create_missing_html_snapshots"
|
||||||
|
) as mock_create_missing_html_snapshots:
|
||||||
|
mock_create_missing_html_snapshots.return_value = 5
|
||||||
|
form_data = {
|
||||||
|
"create_missing_html_snapshots": "",
|
||||||
|
}
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("bookmarks:settings.general"), form_data
|
||||||
|
)
|
||||||
|
html = response.content.decode()
|
||||||
|
|
||||||
|
mock_create_missing_html_snapshots.assert_called_once()
|
||||||
|
self.assertSuccessMessage(
|
||||||
|
html, "Queued 5 missing snapshots. This may take a while..."
|
||||||
|
)
|
||||||
|
|
||||||
|
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||||
|
def test_create_missing_html_snapshots_no_missing_snapshots(self):
|
||||||
|
with patch.object(
|
||||||
|
tasks, "create_missing_html_snapshots"
|
||||||
|
) as mock_create_missing_html_snapshots:
|
||||||
|
mock_create_missing_html_snapshots.return_value = 0
|
||||||
|
form_data = {
|
||||||
|
"create_missing_html_snapshots": "",
|
||||||
|
}
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("bookmarks:settings.general"), form_data
|
||||||
|
)
|
||||||
|
html = response.content.decode()
|
||||||
|
|
||||||
|
mock_create_missing_html_snapshots.assert_called_once()
|
||||||
|
self.assertSuccessMessage(html, "No missing snapshots found.")
|
||||||
|
|
||||||
|
def test_create_missing_html_snapshots_should_not_be_called_without_respective_form_action(
|
||||||
|
self,
|
||||||
|
):
|
||||||
|
with patch.object(
|
||||||
|
tasks, "create_missing_html_snapshots"
|
||||||
|
) as mock_create_missing_html_snapshots:
|
||||||
|
mock_create_missing_html_snapshots.return_value = 5
|
||||||
|
form_data = {}
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("bookmarks:settings.general"), form_data
|
||||||
|
)
|
||||||
|
html = response.content.decode()
|
||||||
|
|
||||||
|
mock_create_missing_html_snapshots.assert_not_called()
|
||||||
|
self.assertSuccessMessage(
|
||||||
|
html, "Queued 5 missing snapshots. This may take a while...", count=0
|
||||||
|
)
|
||||||
|
|||||||
@@ -11,19 +11,27 @@ class SettingsImportViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
user = self.get_or_create_test_user()
|
user = self.get_or_create_test_user()
|
||||||
self.client.force_login(user)
|
self.client.force_login(user)
|
||||||
|
|
||||||
def assertFormSuccessHint(self, response, text: str):
|
def assertSuccessMessage(self, response, message: str):
|
||||||
self.assertContains(response, '<div class="has-success">')
|
self.assertInHTML(
|
||||||
self.assertContains(response, text)
|
f"""
|
||||||
|
<div class="toast toast-success mb-4">{ message }</div>
|
||||||
|
""",
|
||||||
|
response.content.decode("utf-8"),
|
||||||
|
)
|
||||||
|
|
||||||
def assertNoFormSuccessHint(self, response):
|
def assertNoSuccessMessage(self, response):
|
||||||
self.assertNotContains(response, '<div class="has-success">')
|
self.assertNotContains(response, '<div class="toast toast-success mb-4">')
|
||||||
|
|
||||||
def assertFormErrorHint(self, response, text: str):
|
def assertErrorMessage(self, response, message: str):
|
||||||
self.assertContains(response, '<div class="has-error">')
|
self.assertInHTML(
|
||||||
self.assertContains(response, text)
|
f"""
|
||||||
|
<div class="toast toast-error mb-4">{ message }</div>
|
||||||
|
""",
|
||||||
|
response.content.decode("utf-8"),
|
||||||
|
)
|
||||||
|
|
||||||
def assertNoFormErrorHint(self, response):
|
def assertNoErrorMessage(self, response):
|
||||||
self.assertNotContains(response, '<div class="has-error">')
|
self.assertNotContains(response, '<div class="toast toast-error mb-4">')
|
||||||
|
|
||||||
def test_should_import_successfully(self):
|
def test_should_import_successfully(self):
|
||||||
with open(
|
with open(
|
||||||
@@ -36,10 +44,10 @@ class SettingsImportViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
||||||
self.assertFormSuccessHint(
|
self.assertSuccessMessage(
|
||||||
response, "3 bookmarks were successfully imported"
|
response, "3 bookmarks were successfully imported."
|
||||||
)
|
)
|
||||||
self.assertNoFormErrorHint(response)
|
self.assertNoErrorMessage(response)
|
||||||
|
|
||||||
def test_should_check_authentication(self):
|
def test_should_check_authentication(self):
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
@@ -53,8 +61,8 @@ class SettingsImportViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
response = self.client.post(reverse("bookmarks:settings.import"), follow=True)
|
response = self.client.post(reverse("bookmarks:settings.import"), follow=True)
|
||||||
|
|
||||||
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
||||||
self.assertNoFormSuccessHint(response)
|
self.assertNoSuccessMessage(response)
|
||||||
self.assertFormErrorHint(response, "Please select a file to import.")
|
self.assertErrorMessage(response, "Please select a file to import.")
|
||||||
|
|
||||||
@disable_logging
|
@disable_logging
|
||||||
def test_should_show_hint_if_import_raises_exception(self):
|
def test_should_show_hint_if_import_raises_exception(self):
|
||||||
@@ -68,8 +76,8 @@ class SettingsImportViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
||||||
self.assertNoFormSuccessHint(response)
|
self.assertNoSuccessMessage(response)
|
||||||
self.assertFormErrorHint(
|
self.assertErrorMessage(
|
||||||
response, "An error occurred during bookmark import."
|
response, "An error occurred during bookmark import."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,10 +95,13 @@ class SettingsImportViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
self.assertRedirects(response, reverse("bookmarks:settings.general"))
|
||||||
self.assertFormSuccessHint(
|
self.assertSuccessMessage(
|
||||||
response, "2 bookmarks were successfully imported"
|
response, "2 bookmarks were successfully imported."
|
||||||
|
)
|
||||||
|
self.assertErrorMessage(
|
||||||
|
response,
|
||||||
|
"1 bookmarks could not be imported. Please check the logs for more details.",
|
||||||
)
|
)
|
||||||
self.assertFormErrorHint(response, "1 bookmarks could not be imported")
|
|
||||||
|
|
||||||
def test_should_respect_map_private_flag_option(self):
|
def test_should_respect_map_private_flag_option(self):
|
||||||
with open(
|
with open(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import gzip
|
import gzip
|
||||||
import os
|
import os
|
||||||
from unittest import mock
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from bookmarks.services import singlefile
|
from bookmarks.services import singlefile
|
||||||
|
|
||||||
@@ -24,9 +24,11 @@ class SingleFileServiceTestCase(TestCase):
|
|||||||
file.write(self.html_content)
|
file.write(self.html_content)
|
||||||
|
|
||||||
def test_create_snapshot(self):
|
def test_create_snapshot(self):
|
||||||
with mock.patch("subprocess.run") as mock_run:
|
mock_process = mock.Mock()
|
||||||
mock_run.side_effect = self.create_test_file
|
mock_process.wait.return_value = 0
|
||||||
|
self.create_test_file()
|
||||||
|
|
||||||
|
with mock.patch("subprocess.Popen", return_value=mock_process):
|
||||||
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(self.html_filepath))
|
self.assertTrue(os.path.exists(self.html_filepath))
|
||||||
@@ -38,13 +40,80 @@ class SingleFileServiceTestCase(TestCase):
|
|||||||
|
|
||||||
def test_create_snapshot_failure(self):
|
def test_create_snapshot_failure(self):
|
||||||
# subprocess fails - which it probably doesn't as single-file doesn't return exit codes
|
# subprocess fails - which it probably doesn't as single-file doesn't return exit codes
|
||||||
with mock.patch("subprocess.run") as mock_run:
|
with mock.patch("subprocess.Popen") as mock_popen:
|
||||||
mock_run.side_effect = subprocess.CalledProcessError(1, "command")
|
mock_popen.side_effect = subprocess.CalledProcessError(1, "command")
|
||||||
|
|
||||||
with self.assertRaises(singlefile.SingeFileError):
|
with self.assertRaises(singlefile.SingeFileError):
|
||||||
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
# so also check that it raises error if output file isn't created
|
# so also check that it raises error if output file isn't created
|
||||||
with mock.patch("subprocess.run") as mock_run:
|
with mock.patch("subprocess.Popen"):
|
||||||
with self.assertRaises(singlefile.SingeFileError):
|
with self.assertRaises(singlefile.SingeFileError):
|
||||||
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
|
def test_create_snapshot_empty_options(self):
|
||||||
|
mock_process = mock.Mock()
|
||||||
|
mock_process.wait.return_value = 0
|
||||||
|
self.create_test_file()
|
||||||
|
|
||||||
|
with mock.patch("subprocess.Popen") as mock_popen:
|
||||||
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
|
expected_args = [
|
||||||
|
"single-file",
|
||||||
|
'--browser-arg="--headless=new"',
|
||||||
|
'--browser-arg="--user-data-dir=./chromium-profile"',
|
||||||
|
'--browser-arg="--no-sandbox"',
|
||||||
|
'--browser-arg="--load-extension=uBlock0.chromium"',
|
||||||
|
"http://example.com",
|
||||||
|
self.html_filepath + ".tmp",
|
||||||
|
]
|
||||||
|
mock_popen.assert_called_with(expected_args, start_new_session=True)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
LD_SINGLEFILE_OPTIONS='--some-option "some value" --another-option "another value" --third-option="third value"'
|
||||||
|
)
|
||||||
|
def test_create_snapshot_custom_options(self):
|
||||||
|
mock_process = mock.Mock()
|
||||||
|
mock_process.wait.return_value = 0
|
||||||
|
self.create_test_file()
|
||||||
|
|
||||||
|
with mock.patch("subprocess.Popen") as mock_popen:
|
||||||
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
|
expected_args = [
|
||||||
|
"single-file",
|
||||||
|
'--browser-arg="--headless=new"',
|
||||||
|
'--browser-arg="--user-data-dir=./chromium-profile"',
|
||||||
|
'--browser-arg="--no-sandbox"',
|
||||||
|
'--browser-arg="--load-extension=uBlock0.chromium"',
|
||||||
|
"--some-option",
|
||||||
|
"some value",
|
||||||
|
"--another-option",
|
||||||
|
"another value",
|
||||||
|
"--third-option=third value",
|
||||||
|
"http://example.com",
|
||||||
|
self.html_filepath + ".tmp",
|
||||||
|
]
|
||||||
|
mock_popen.assert_called_with(expected_args, start_new_session=True)
|
||||||
|
|
||||||
|
def test_create_snapshot_default_timeout_setting(self):
|
||||||
|
mock_process = mock.Mock()
|
||||||
|
mock_process.wait.return_value = 0
|
||||||
|
self.create_test_file()
|
||||||
|
|
||||||
|
with mock.patch("subprocess.Popen", return_value=mock_process):
|
||||||
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
|
mock_process.wait.assert_called_with(timeout=120)
|
||||||
|
|
||||||
|
@override_settings(LD_SINGLEFILE_TIMEOUT_SEC=180)
|
||||||
|
def test_create_snapshot_custom_timeout_setting(self):
|
||||||
|
mock_process = mock.Mock()
|
||||||
|
mock_process.wait.return_value = 0
|
||||||
|
self.create_test_file()
|
||||||
|
|
||||||
|
with mock.patch("subprocess.Popen", return_value=mock_process):
|
||||||
|
singlefile.create_snapshot("http://example.com", self.html_filepath)
|
||||||
|
|
||||||
|
mock_process.wait.assert_called_with(timeout=180)
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ urlpatterns = [
|
|||||||
views.bookmarks.details_modal,
|
views.bookmarks.details_modal,
|
||||||
name="details_modal",
|
name="details_modal",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"bookmarks/<int:bookmark_id>/details_assets",
|
||||||
|
views.bookmarks.details_assets,
|
||||||
|
name="details_assets",
|
||||||
|
),
|
||||||
# Assets
|
# Assets
|
||||||
path(
|
path(
|
||||||
"assets/<int:asset_id>",
|
"assets/<int:asset_id>",
|
||||||
@@ -61,6 +66,11 @@ urlpatterns = [
|
|||||||
partials.active_tag_cloud,
|
partials.active_tag_cloud,
|
||||||
name="partials.tag_cloud.active",
|
name="partials.tag_cloud.active",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"bookmarks/partials/tag-modal/active",
|
||||||
|
partials.active_tag_modal,
|
||||||
|
name="partials.tag_modal.active",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"bookmarks/partials/bookmark-list/archived",
|
"bookmarks/partials/bookmark-list/archived",
|
||||||
partials.archived_bookmark_list,
|
partials.archived_bookmark_list,
|
||||||
@@ -71,6 +81,11 @@ urlpatterns = [
|
|||||||
partials.archived_tag_cloud,
|
partials.archived_tag_cloud,
|
||||||
name="partials.tag_cloud.archived",
|
name="partials.tag_cloud.archived",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"bookmarks/partials/tag-modal/archived",
|
||||||
|
partials.archived_tag_modal,
|
||||||
|
name="partials.tag_modal.archived",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"bookmarks/partials/bookmark-list/shared",
|
"bookmarks/partials/bookmark-list/shared",
|
||||||
partials.shared_bookmark_list,
|
partials.shared_bookmark_list,
|
||||||
@@ -82,9 +97,9 @@ urlpatterns = [
|
|||||||
name="partials.tag_cloud.shared",
|
name="partials.tag_cloud.shared",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"bookmarks/partials/details-form/<int:bookmark_id>",
|
"bookmarks/partials/tag-modal/shared",
|
||||||
partials.details_form,
|
partials.shared_tag_modal,
|
||||||
name="partials.details_form",
|
name="partials.tag_modal.shared",
|
||||||
),
|
),
|
||||||
# Settings
|
# Settings
|
||||||
path("settings", views.settings.general, name="settings.index"),
|
path("settings", views.settings.general, name="settings.index"),
|
||||||
|
|||||||
@@ -172,6 +172,10 @@ def details_modal(request, bookmark_id: int):
|
|||||||
return _details(request, bookmark_id, "bookmarks/details_modal.html")
|
return _details(request, bookmark_id, "bookmarks/details_modal.html")
|
||||||
|
|
||||||
|
|
||||||
|
def details_assets(request, bookmark_id: int):
|
||||||
|
return _details(request, bookmark_id, "bookmarks/details/assets.html")
|
||||||
|
|
||||||
|
|
||||||
def convert_tag_string(tag_string: str):
|
def convert_tag_string(tag_string: str):
|
||||||
# Tag strings coming from inputs are space-separated, however services.bookmarks functions expect comma-separated
|
# Tag strings coming from inputs are space-separated, however services.bookmarks functions expect comma-separated
|
||||||
# strings
|
# strings
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import Http404
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from bookmarks.models import Bookmark
|
|
||||||
from bookmarks.views.partials import contexts
|
from bookmarks.views.partials import contexts
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +22,13 @@ def active_tag_cloud(request):
|
|||||||
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def active_tag_modal(request):
|
||||||
|
tag_cloud_context = contexts.ActiveTagCloudContext(request)
|
||||||
|
|
||||||
|
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def archived_bookmark_list(request):
|
def archived_bookmark_list(request):
|
||||||
bookmark_list_context = contexts.ArchivedBookmarkListContext(request)
|
bookmark_list_context = contexts.ArchivedBookmarkListContext(request)
|
||||||
@@ -43,6 +48,12 @@ def archived_tag_cloud(request):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
def archived_tag_modal(request):
|
||||||
|
tag_cloud_context = contexts.ArchivedTagCloudContext(request)
|
||||||
|
|
||||||
|
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
||||||
|
|
||||||
|
|
||||||
def shared_bookmark_list(request):
|
def shared_bookmark_list(request):
|
||||||
bookmark_list_context = contexts.SharedBookmarkListContext(request)
|
bookmark_list_context = contexts.SharedBookmarkListContext(request)
|
||||||
|
|
||||||
@@ -53,20 +64,13 @@ def shared_bookmark_list(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def shared_tag_cloud(request):
|
def shared_tag_cloud(request):
|
||||||
tag_cloud_context = contexts.SharedTagCloudContext(request)
|
tag_cloud_context = contexts.SharedTagCloudContext(request)
|
||||||
|
|
||||||
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
def shared_tag_modal(request):
|
||||||
def details_form(request, bookmark_id: int):
|
tag_cloud_context = contexts.SharedTagCloudContext(request)
|
||||||
try:
|
|
||||||
bookmark = Bookmark.objects.get(pk=bookmark_id, owner=request.user)
|
|
||||||
except Bookmark.DoesNotExist:
|
|
||||||
raise Http404("Bookmark does not exist")
|
|
||||||
|
|
||||||
details_context = contexts.BookmarkDetailsContext(request, bookmark)
|
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
||||||
|
|
||||||
return render(request, "bookmarks/details/form.html", {"details": details_context})
|
|
||||||
|
|||||||
@@ -23,6 +23,113 @@ DEFAULT_PAGE_SIZE = 30
|
|||||||
CJK_RE = re.compile(r"[\u4e00-\u9fff]+")
|
CJK_RE = re.compile(r"[\u4e00-\u9fff]+")
|
||||||
|
|
||||||
|
|
||||||
|
class RequestContext:
|
||||||
|
index_view = "bookmarks:index"
|
||||||
|
action_view = "bookmarks:index.action"
|
||||||
|
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.active"
|
||||||
|
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.active"
|
||||||
|
tag_modal_partial_view = "bookmarks:partials.tag_modal.active"
|
||||||
|
|
||||||
|
def __init__(self, request: WSGIRequest):
|
||||||
|
self.request = request
|
||||||
|
self.index_url = reverse(self.index_view)
|
||||||
|
self.action_url = reverse(self.action_view)
|
||||||
|
self.bookmark_list_partial_url = reverse(self.bookmark_list_partial_view)
|
||||||
|
self.tag_cloud_partial_url = reverse(self.tag_cloud_partial_view)
|
||||||
|
self.tag_modal_partial_url = reverse(self.tag_modal_partial_view)
|
||||||
|
self.query_params = request.GET.copy()
|
||||||
|
self.query_params.pop("details", None)
|
||||||
|
|
||||||
|
def get_url(self, view_url: str, add: dict = None, remove: dict = None) -> str:
|
||||||
|
query_params = self.query_params.copy()
|
||||||
|
if add:
|
||||||
|
query_params.update(add)
|
||||||
|
if remove:
|
||||||
|
for key in remove:
|
||||||
|
query_params.pop(key, None)
|
||||||
|
encoded_params = query_params.urlencode()
|
||||||
|
return view_url + "?" + encoded_params if encoded_params else view_url
|
||||||
|
|
||||||
|
def index(self) -> str:
|
||||||
|
return self.get_url(self.index_url)
|
||||||
|
|
||||||
|
def action(self, return_url: str) -> str:
|
||||||
|
return self.get_url(self.action_url, add={"return_url": return_url})
|
||||||
|
|
||||||
|
def bookmark_list_partial(self) -> str:
|
||||||
|
return self.get_url(self.bookmark_list_partial_url)
|
||||||
|
|
||||||
|
def tag_cloud_partial(self) -> str:
|
||||||
|
return self.get_url(self.tag_cloud_partial_url)
|
||||||
|
|
||||||
|
def tag_modal_partial(self) -> str:
|
||||||
|
return self.get_url(self.tag_modal_partial_url)
|
||||||
|
|
||||||
|
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||||
|
raise Exception("Must be implemented by subclass")
|
||||||
|
|
||||||
|
def get_tag_query_set(self, search: BookmarkSearch):
|
||||||
|
raise Exception("Must be implemented by subclass")
|
||||||
|
|
||||||
|
|
||||||
|
class ActiveBookmarksContext(RequestContext):
|
||||||
|
index_view = "bookmarks:index"
|
||||||
|
action_view = "bookmarks:index.action"
|
||||||
|
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.active"
|
||||||
|
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.active"
|
||||||
|
tag_modal_partial_view = "bookmarks:partials.tag_modal.active"
|
||||||
|
|
||||||
|
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||||
|
return queries.query_bookmarks(
|
||||||
|
self.request.user, self.request.user_profile, search
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_tag_query_set(self, search: BookmarkSearch):
|
||||||
|
return queries.query_bookmark_tags(
|
||||||
|
self.request.user, self.request.user_profile, search
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ArchivedBookmarksContext(RequestContext):
|
||||||
|
index_view = "bookmarks:archived"
|
||||||
|
action_view = "bookmarks:archived.action"
|
||||||
|
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.archived"
|
||||||
|
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.archived"
|
||||||
|
tag_modal_partial_view = "bookmarks:partials.tag_modal.archived"
|
||||||
|
|
||||||
|
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||||
|
return queries.query_archived_bookmarks(
|
||||||
|
self.request.user, self.request.user_profile, search
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_tag_query_set(self, search: BookmarkSearch):
|
||||||
|
return queries.query_archived_bookmark_tags(
|
||||||
|
self.request.user, self.request.user_profile, search
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SharedBookmarksContext(RequestContext):
|
||||||
|
index_view = "bookmarks:shared"
|
||||||
|
action_view = "bookmarks:shared.action"
|
||||||
|
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.shared"
|
||||||
|
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.shared"
|
||||||
|
tag_modal_partial_view = "bookmarks:partials.tag_modal.shared"
|
||||||
|
|
||||||
|
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||||
|
user = User.objects.filter(username=search.user).first()
|
||||||
|
public_only = not self.request.user.is_authenticated
|
||||||
|
return queries.query_shared_bookmarks(
|
||||||
|
user, self.request.user_profile, search, public_only
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_tag_query_set(self, search: BookmarkSearch):
|
||||||
|
user = User.objects.filter(username=search.user).first()
|
||||||
|
public_only = not self.request.user.is_authenticated
|
||||||
|
return queries.query_shared_bookmark_tags(
|
||||||
|
user, self.request.user_profile, search, public_only
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BookmarkItem:
|
class BookmarkItem:
|
||||||
def __init__(self, bookmark: Bookmark, user: User, profile: UserProfile) -> None:
|
def __init__(self, bookmark: Bookmark, user: User, profile: UserProfile) -> None:
|
||||||
self.bookmark = bookmark
|
self.bookmark = bookmark
|
||||||
@@ -67,7 +174,10 @@ class BookmarkItem:
|
|||||||
|
|
||||||
|
|
||||||
class BookmarkListContext:
|
class BookmarkListContext:
|
||||||
|
request_context = RequestContext
|
||||||
|
|
||||||
def __init__(self, request: WSGIRequest) -> None:
|
def __init__(self, request: WSGIRequest) -> None:
|
||||||
|
request_context = self.request_context(request)
|
||||||
user = request.user
|
user = request.user
|
||||||
user_profile = request.user_profile
|
user_profile = request.user_profile
|
||||||
|
|
||||||
@@ -76,7 +186,7 @@ class BookmarkListContext:
|
|||||||
self.request.GET, user_profile.search_preferences
|
self.request.GET, user_profile.search_preferences
|
||||||
)
|
)
|
||||||
|
|
||||||
query_set = self.get_bookmark_query_set()
|
query_set = request_context.get_bookmark_query_set(self.search)
|
||||||
page_number = request.GET.get("page")
|
page_number = request.GET.get("page")
|
||||||
paginator = Paginator(query_set, DEFAULT_PAGE_SIZE)
|
paginator = Paginator(query_set, DEFAULT_PAGE_SIZE)
|
||||||
bookmarks_page = paginator.get_page(page_number)
|
bookmarks_page = paginator.get_page(page_number)
|
||||||
@@ -86,16 +196,15 @@ class BookmarkListContext:
|
|||||||
self.items = [
|
self.items = [
|
||||||
BookmarkItem(bookmark, user, user_profile) for bookmark in bookmarks_page
|
BookmarkItem(bookmark, user, user_profile) for bookmark in bookmarks_page
|
||||||
]
|
]
|
||||||
|
|
||||||
self.is_empty = paginator.count == 0
|
self.is_empty = paginator.count == 0
|
||||||
self.bookmarks_page = bookmarks_page
|
self.bookmarks_page = bookmarks_page
|
||||||
self.bookmarks_total = paginator.count
|
self.bookmarks_total = paginator.count
|
||||||
self.return_url = self.generate_return_url(
|
|
||||||
self.search, self.get_base_url(), page_number
|
self.return_url = request_context.index()
|
||||||
)
|
self.action_url = request_context.action(return_url=self.return_url)
|
||||||
self.action_url = self.generate_action_url(
|
self.refresh_url = request_context.bookmark_list_partial()
|
||||||
self.search, self.get_base_action_url(), self.return_url
|
self.tag_modal_url = request_context.tag_modal_partial()
|
||||||
)
|
|
||||||
self.link_target = user_profile.bookmark_link_target
|
self.link_target = user_profile.bookmark_link_target
|
||||||
self.date_display = user_profile.bookmark_date_display
|
self.date_display = user_profile.bookmark_date_display
|
||||||
self.description_display = user_profile.bookmark_description_display
|
self.description_display = user_profile.bookmark_description_display
|
||||||
@@ -131,55 +240,17 @@ class BookmarkListContext:
|
|||||||
else base_action_url + "?" + query_string
|
else base_action_url + "?" + query_string
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_base_url(self):
|
|
||||||
raise Exception("Must be implemented by subclass")
|
|
||||||
|
|
||||||
def get_base_action_url(self):
|
|
||||||
raise Exception("Must be implemented by subclass")
|
|
||||||
|
|
||||||
def get_bookmark_query_set(self):
|
|
||||||
raise Exception("Must be implemented by subclass")
|
|
||||||
|
|
||||||
|
|
||||||
class ActiveBookmarkListContext(BookmarkListContext):
|
class ActiveBookmarkListContext(BookmarkListContext):
|
||||||
def get_base_url(self):
|
request_context = ActiveBookmarksContext
|
||||||
return reverse("bookmarks:index")
|
|
||||||
|
|
||||||
def get_base_action_url(self):
|
|
||||||
return reverse("bookmarks:index.action")
|
|
||||||
|
|
||||||
def get_bookmark_query_set(self):
|
|
||||||
return queries.query_bookmarks(
|
|
||||||
self.request.user, self.request.user_profile, self.search
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ArchivedBookmarkListContext(BookmarkListContext):
|
class ArchivedBookmarkListContext(BookmarkListContext):
|
||||||
def get_base_url(self):
|
request_context = ArchivedBookmarksContext
|
||||||
return reverse("bookmarks:archived")
|
|
||||||
|
|
||||||
def get_base_action_url(self):
|
|
||||||
return reverse("bookmarks:archived.action")
|
|
||||||
|
|
||||||
def get_bookmark_query_set(self):
|
|
||||||
return queries.query_archived_bookmarks(
|
|
||||||
self.request.user, self.request.user_profile, self.search
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SharedBookmarkListContext(BookmarkListContext):
|
class SharedBookmarkListContext(BookmarkListContext):
|
||||||
def get_base_url(self):
|
request_context = SharedBookmarksContext
|
||||||
return reverse("bookmarks:shared")
|
|
||||||
|
|
||||||
def get_base_action_url(self):
|
|
||||||
return reverse("bookmarks:shared.action")
|
|
||||||
|
|
||||||
def get_bookmark_query_set(self):
|
|
||||||
user = User.objects.filter(username=self.search.user).first()
|
|
||||||
public_only = not self.request.user.is_authenticated
|
|
||||||
return queries.query_shared_bookmarks(
|
|
||||||
user, self.request.user_profile, self.search, public_only
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TagGroup:
|
class TagGroup:
|
||||||
@@ -218,7 +289,10 @@ class TagGroup:
|
|||||||
|
|
||||||
|
|
||||||
class TagCloudContext:
|
class TagCloudContext:
|
||||||
|
request_context = RequestContext
|
||||||
|
|
||||||
def __init__(self, request: WSGIRequest) -> None:
|
def __init__(self, request: WSGIRequest) -> None:
|
||||||
|
request_context = self.request_context(request)
|
||||||
user_profile = request.user_profile
|
user_profile = request.user_profile
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
@@ -226,7 +300,7 @@ class TagCloudContext:
|
|||||||
self.request.GET, user_profile.search_preferences
|
self.request.GET, user_profile.search_preferences
|
||||||
)
|
)
|
||||||
|
|
||||||
query_set = self.get_tag_query_set()
|
query_set = request_context.get_tag_query_set(self.search)
|
||||||
tags = list(query_set)
|
tags = list(query_set)
|
||||||
selected_tags = self.get_selected_tags(tags)
|
selected_tags = self.get_selected_tags(tags)
|
||||||
unique_tags = utils.unique(tags, key=lambda x: str.lower(x.name))
|
unique_tags = utils.unique(tags, key=lambda x: str.lower(x.name))
|
||||||
@@ -242,8 +316,7 @@ class TagCloudContext:
|
|||||||
self.selected_tags = unique_selected_tags
|
self.selected_tags = unique_selected_tags
|
||||||
self.has_selected_tags = has_selected_tags
|
self.has_selected_tags = has_selected_tags
|
||||||
|
|
||||||
def get_tag_query_set(self):
|
self.refresh_url = request_context.tag_cloud_partial()
|
||||||
raise Exception("Must be implemented by subclass")
|
|
||||||
|
|
||||||
def get_selected_tags(self, tags: List[Tag]):
|
def get_selected_tags(self, tags: List[Tag]):
|
||||||
parsed_query = queries.parse_query_string(self.search.q)
|
parsed_query = queries.parse_query_string(self.search.q)
|
||||||
@@ -256,26 +329,15 @@ class TagCloudContext:
|
|||||||
|
|
||||||
|
|
||||||
class ActiveTagCloudContext(TagCloudContext):
|
class ActiveTagCloudContext(TagCloudContext):
|
||||||
def get_tag_query_set(self):
|
request_context = ActiveBookmarksContext
|
||||||
return queries.query_bookmark_tags(
|
|
||||||
self.request.user, self.request.user_profile, self.search
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ArchivedTagCloudContext(TagCloudContext):
|
class ArchivedTagCloudContext(TagCloudContext):
|
||||||
def get_tag_query_set(self):
|
request_context = ArchivedBookmarksContext
|
||||||
return queries.query_archived_bookmark_tags(
|
|
||||||
self.request.user, self.request.user_profile, self.search
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SharedTagCloudContext(TagCloudContext):
|
class SharedTagCloudContext(TagCloudContext):
|
||||||
def get_tag_query_set(self):
|
request_context = SharedBookmarksContext
|
||||||
user = User.objects.filter(username=self.search.user).first()
|
|
||||||
public_only = not self.request.user.is_authenticated
|
|
||||||
return queries.query_shared_bookmark_tags(
|
|
||||||
user, self.request.user_profile, self.search, public_only
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BookmarkAssetItem:
|
class BookmarkAssetItem:
|
||||||
@@ -328,3 +390,6 @@ class BookmarkDetailsContext:
|
|||||||
self.assets = [
|
self.assets = [
|
||||||
BookmarkAssetItem(asset) for asset in bookmark.bookmarkasset_set.all()
|
BookmarkAssetItem(asset) for asset in bookmark.bookmarkasset_set.all()
|
||||||
]
|
]
|
||||||
|
self.has_pending_assets = any(
|
||||||
|
asset.status == BookmarkAsset.STATUS_PENDING for asset in self.assets
|
||||||
|
)
|
||||||
|
|||||||
@@ -25,12 +25,10 @@ def general(request):
|
|||||||
profile_form = None
|
profile_form = None
|
||||||
enable_refresh_favicons = django_settings.LD_ENABLE_REFRESH_FAVICONS
|
enable_refresh_favicons = django_settings.LD_ENABLE_REFRESH_FAVICONS
|
||||||
has_snapshot_support = django_settings.LD_ENABLE_SNAPSHOTS
|
has_snapshot_support = django_settings.LD_ENABLE_SNAPSHOTS
|
||||||
update_profile_success_message = None
|
success_message = _find_message_with_tag(
|
||||||
refresh_favicons_success_message = None
|
|
||||||
import_success_message = _find_message_with_tag(
|
|
||||||
messages.get_messages(request), "bookmark_import_success"
|
messages.get_messages(request), "bookmark_import_success"
|
||||||
)
|
)
|
||||||
import_errors_message = _find_message_with_tag(
|
error_message = _find_message_with_tag(
|
||||||
messages.get_messages(request), "bookmark_import_errors"
|
messages.get_messages(request), "bookmark_import_errors"
|
||||||
)
|
)
|
||||||
version_info = get_version_info(get_ttl_hash())
|
version_info = get_version_info(get_ttl_hash())
|
||||||
@@ -38,12 +36,18 @@ def general(request):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if "update_profile" in request.POST:
|
if "update_profile" in request.POST:
|
||||||
profile_form = update_profile(request)
|
profile_form = update_profile(request)
|
||||||
update_profile_success_message = "Profile updated"
|
success_message = "Profile updated"
|
||||||
if "refresh_favicons" in request.POST:
|
if "refresh_favicons" in request.POST:
|
||||||
tasks.schedule_refresh_favicons(request.user)
|
tasks.schedule_refresh_favicons(request.user)
|
||||||
refresh_favicons_success_message = (
|
success_message = "Scheduled favicon update. This may take a while..."
|
||||||
"Scheduled favicon update. This may take a while..."
|
if "create_missing_html_snapshots" in request.POST:
|
||||||
)
|
count = tasks.create_missing_html_snapshots(request.user)
|
||||||
|
if count > 0:
|
||||||
|
success_message = (
|
||||||
|
f"Queued {count} missing snapshots. This may take a while..."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
success_message = "No missing snapshots found."
|
||||||
|
|
||||||
if not profile_form:
|
if not profile_form:
|
||||||
profile_form = UserProfileForm(instance=request.user_profile)
|
profile_form = UserProfileForm(instance=request.user_profile)
|
||||||
@@ -55,10 +59,8 @@ def general(request):
|
|||||||
"form": profile_form,
|
"form": profile_form,
|
||||||
"enable_refresh_favicons": enable_refresh_favicons,
|
"enable_refresh_favicons": enable_refresh_favicons,
|
||||||
"has_snapshot_support": has_snapshot_support,
|
"has_snapshot_support": has_snapshot_support,
|
||||||
"update_profile_success_message": update_profile_success_message,
|
"success_message": success_message,
|
||||||
"refresh_favicons_success_message": refresh_favicons_success_message,
|
"error_message": error_message,
|
||||||
"import_success_message": import_success_message,
|
|
||||||
"import_errors_message": import_errors_message,
|
|
||||||
"version_info": version_info,
|
"version_info": version_info,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ python manage.py migrate
|
|||||||
python manage.py enable_wal
|
python manage.py enable_wal
|
||||||
# Create initial superuser if defined in options / environment variables
|
# Create initial superuser if defined in options / environment variables
|
||||||
python manage.py create_initial_superuser
|
python manage.py create_initial_superuser
|
||||||
|
# Migrate legacy background tasks to Huey
|
||||||
|
python manage.py migrate_tasks
|
||||||
|
|
||||||
# Ensure the DB folder is owned by the right user
|
# Ensure folders are owned by the right user
|
||||||
chown -R www-data: /etc/linkding/data
|
chown -R www-data: /etc/linkding/data
|
||||||
|
|
||||||
# Start background task processor using supervisord, unless explicitly disabled
|
# Start background task processor using supervisord, unless explicitly disabled
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ RUN pip install -U pip && pip install -r requirements.txt -r requirements.dev.tx
|
|||||||
COPY . .
|
COPY . .
|
||||||
COPY --from=node-build /etc/linkding .
|
COPY --from=node-build /etc/linkding .
|
||||||
# run Django part of the build
|
# run Django part of the build
|
||||||
RUN python manage.py compilescss && \
|
RUN mkdir data && \
|
||||||
|
python manage.py compilescss && \
|
||||||
python manage.py collectstatic --ignore=*.scss && \
|
python manage.py collectstatic --ignore=*.scss && \
|
||||||
python manage.py compilescss --delete-files
|
python manage.py compilescss --delete-files
|
||||||
|
|
||||||
@@ -98,8 +99,31 @@ CMD curl -f http://localhost:${LD_SERVER_PORT:-9090}/${LD_CONTEXT_PATH}health ||
|
|||||||
CMD ["./bootstrap.sh"]
|
CMD ["./bootstrap.sh"]
|
||||||
|
|
||||||
|
|
||||||
|
FROM node:18-alpine AS ublock-build
|
||||||
|
WORKDIR /etc/linkding
|
||||||
|
# Install necessary tools
|
||||||
|
RUN apk add --no-cache curl jq unzip
|
||||||
|
# Fetch the latest release tag
|
||||||
|
# Download the library
|
||||||
|
# Unzip the library
|
||||||
|
RUN TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name') && \
|
||||||
|
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip && \
|
||||||
|
curl -L -o uBlock0.zip $DOWNLOAD_URL && \
|
||||||
|
unzip uBlock0.zip
|
||||||
|
# Patch assets.json to enable easylist-cookies by default
|
||||||
|
RUN curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt
|
||||||
|
RUN jq '."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json && \
|
||||||
|
mv temp.json ./uBlock0.chromium/assets/assets.json
|
||||||
|
|
||||||
|
|
||||||
FROM linkding AS linkding-plus
|
FROM linkding AS linkding-plus
|
||||||
# install node, chromium and single-file
|
# install node, chromium
|
||||||
RUN apk update && apk add nodejs npm chromium && npm install -g single-file-cli
|
RUN apk update && apk add nodejs npm chromium
|
||||||
|
# install single-file from fork for now, which contains several hotfixes
|
||||||
|
RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6
|
||||||
|
# copy uBlock0
|
||||||
|
COPY --from=ublock-build /etc/linkding/uBlock0.chromium uBlock0.chromium/
|
||||||
|
# create chromium profile folder for user running background tasks
|
||||||
|
RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile
|
||||||
# enable snapshot support
|
# enable snapshot support
|
||||||
ENV LD_ENABLE_SNAPSHOTS=True
|
ENV LD_ENABLE_SNAPSHOTS=True
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ RUN pip install -U pip && pip install -r requirements.txt -r requirements.dev.tx
|
|||||||
COPY . .
|
COPY . .
|
||||||
COPY --from=node-build /etc/linkding .
|
COPY --from=node-build /etc/linkding .
|
||||||
# run Django part of the build
|
# run Django part of the build
|
||||||
RUN python manage.py compilescss && \
|
RUN mkdir data && \
|
||||||
|
python manage.py compilescss && \
|
||||||
python manage.py collectstatic --ignore=*.scss && \
|
python manage.py collectstatic --ignore=*.scss && \
|
||||||
python manage.py compilescss --delete-files
|
python manage.py compilescss --delete-files
|
||||||
|
|
||||||
@@ -95,8 +96,38 @@ CMD curl -f http://localhost:${LD_SERVER_PORT:-9090}/${LD_CONTEXT_PATH}health ||
|
|||||||
|
|
||||||
CMD ["./bootstrap.sh"]
|
CMD ["./bootstrap.sh"]
|
||||||
|
|
||||||
|
|
||||||
|
FROM node:18-alpine AS ublock-build
|
||||||
|
WORKDIR /etc/linkding
|
||||||
|
# Install necessary tools
|
||||||
|
RUN apk add --no-cache curl jq unzip
|
||||||
|
# Fetch the latest release tag
|
||||||
|
# Download the library
|
||||||
|
# Unzip the library
|
||||||
|
RUN TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name') && \
|
||||||
|
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip && \
|
||||||
|
curl -L -o uBlock0.zip $DOWNLOAD_URL && \
|
||||||
|
unzip uBlock0.zip
|
||||||
|
# Patch assets.json to enable easylist-cookies by default
|
||||||
|
RUN curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt
|
||||||
|
RUN jq '."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json && \
|
||||||
|
mv temp.json ./uBlock0.chromium/assets/assets.json
|
||||||
|
|
||||||
|
|
||||||
FROM linkding AS linkding-plus
|
FROM linkding AS linkding-plus
|
||||||
# install node, chromium and single-file
|
# install chromium
|
||||||
RUN apt-get update && apt-get -y install nodejs npm chromium && npm install -g single-file-cli
|
RUN apt-get update && apt-get -y install chromium
|
||||||
|
# install node
|
||||||
|
ENV NODE_MAJOR=20
|
||||||
|
RUN apt-get install -y gnupg2 apt-transport-https ca-certificates && \
|
||||||
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg && \
|
||||||
|
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
|
||||||
|
apt-get update && apt-get install -y nodejs
|
||||||
|
# install single-file from fork for now, which contains several hotfixes
|
||||||
|
RUN npm install -g https://github.com/sissbruecker/single-file-cli/tarball/4c54b3bc704cfb3e96cec2d24854caca3df0b3b6
|
||||||
|
# create chromium profile folder for user running background tasks
|
||||||
|
RUN mkdir -p chromium-profile && chown -R www-data:www-data chromium-profile
|
||||||
|
# copy uBlock0
|
||||||
|
COPY --from=ublock-build /etc/linkding/uBlock0.chromium uBlock0.chromium/
|
||||||
# enable snapshot support
|
# enable snapshot support
|
||||||
ENV LD_ENABLE_SNAPSHOTS=True
|
ENV LD_ENABLE_SNAPSHOTS=True
|
||||||
|
|||||||
@@ -118,6 +118,46 @@ The following options can be configured:
|
|||||||
- `OIDC_RP_CLIENT_SECRET` - The client secret of the application.
|
- `OIDC_RP_CLIENT_SECRET` - The client secret of the application.
|
||||||
- `OIDC_RP_SIGN_ALGO` - The algorithm the OIDC provider uses to sign ID tokens. Default is `RS256`.
|
- `OIDC_RP_SIGN_ALGO` - The algorithm the OIDC provider uses to sign ID tokens. Default is `RS256`.
|
||||||
- `OIDC_USE_PKCE` - Whether to use PKCE for the OIDC flow. Default is `True`.
|
- `OIDC_USE_PKCE` - Whether to use PKCE for the OIDC flow. Default is `True`.
|
||||||
|
- `OIDC_VERIFY_SSL` - Whether to verify the SSL certificate of the OIDC provider. Set to `False` if using self-signed certificates or custom certificate authority. Default is `True`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
<summary>Authelia Example</summary>
|
||||||
|
|
||||||
|
#### Linkding Configuration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
LD_ENABLE_OIDC=True
|
||||||
|
OIDC_OP_AUTHORIZATION_ENDPOINT=https://auth.example.com/api/oidc/authorization
|
||||||
|
OIDC_OP_TOKEN_ENDPOINT=https://auth.example.com/api/oidc/token
|
||||||
|
OIDC_OP_USER_ENDPOINT=https://auth.example.com/api/oidc/userinfo
|
||||||
|
OIDC_OP_JWKS_ENDPOINT=https://auth.example.com/jwks.json
|
||||||
|
OIDC_RP_CLIENT_ID=linkding
|
||||||
|
OIDC_RP_CLIENT_SECRET=myClientSecret
|
||||||
|
```
|
||||||
|
#### Authelia Configuration
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
identity_providers:
|
||||||
|
oidc:
|
||||||
|
# --- more OIDC provider configuration ---
|
||||||
|
|
||||||
|
clients:
|
||||||
|
- id: linkding
|
||||||
|
description: Linkding
|
||||||
|
# docker run --rm authelia/authelia:latest authelia crypto rand --length 64 --charset alphanumeric
|
||||||
|
secret: myClientSecret
|
||||||
|
public: false
|
||||||
|
token_endpoint_auth_method: client_secret_post
|
||||||
|
scopes:
|
||||||
|
- openid
|
||||||
|
- email
|
||||||
|
- profile
|
||||||
|
redirect_uris:
|
||||||
|
- https://linkding.example.com/oidc/callback/
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### `LD_CSRF_TRUSTED_ORIGINS`
|
### `LD_CSRF_TRUSTED_ORIGINS`
|
||||||
|
|
||||||
@@ -206,3 +246,20 @@ See the default URL for how to insert the placeholder to the favicon provider UR
|
|||||||
|
|
||||||
Alternative favicon providers:
|
Alternative favicon providers:
|
||||||
- DuckDuckGo: `https://icons.duckduckgo.com/ip3/{domain}.ico`
|
- DuckDuckGo: `https://icons.duckduckgo.com/ip3/{domain}.ico`
|
||||||
|
|
||||||
|
|
||||||
|
### `LD_SINGLEFILE_TIMEOUT_SEC`
|
||||||
|
|
||||||
|
Values: `Float` | Default = 60.0
|
||||||
|
|
||||||
|
When creating HTML archive snapshots, control the timeout for how long to wait for the snapshot to complete, in `seconds`.
|
||||||
|
Defaults to 60 seconds; on lower-powered hardware you may need to increase this value.
|
||||||
|
|
||||||
|
### `LD_SINGLEFILE_OPTIONS`
|
||||||
|
|
||||||
|
Values: `String` | Default = None
|
||||||
|
|
||||||
|
When creating HTML archive snapshots, pass additional options to the `single-file` application that is used to create snapshots.
|
||||||
|
See `single-file --help` for complete list of arguments, or browse source: https://github.com/gildas-lormeau/single-file-cli/blob/master/options.js
|
||||||
|
|
||||||
|
Example: `LD_SINGLEFILE_OPTIONS=--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"`
|
||||||
|
|||||||
@@ -4,24 +4,56 @@ Linkding stores all data in the application's data folder.
|
|||||||
The full path to that folder in the Docker container is `/etc/linkding/data`.
|
The full path to that folder in the Docker container is `/etc/linkding/data`.
|
||||||
As described in the installation docs, you should mount the `/etc/linkding/data` folder to a folder on your host system.
|
As described in the installation docs, you should mount the `/etc/linkding/data` folder to a folder on your host system.
|
||||||
|
|
||||||
The data folder contains the following contents:
|
The data folder contains the following contents that are relevant for backups:
|
||||||
- `db.sqlite3` - the SQLite database
|
- `db.sqlite3` - the SQLite database
|
||||||
|
- `assets` - folder that contains HTML snapshots of bookmarks
|
||||||
- `favicons` - folder that contains downloaded favicons
|
- `favicons` - folder that contains downloaded favicons
|
||||||
|
|
||||||
The following sections explain how to back up the individual contents.
|
The following sections explain how to back up the individual contents.
|
||||||
|
|
||||||
## Database
|
## Full backup
|
||||||
|
|
||||||
This section describes several methods on how to back up the contents of the SQLite database.
|
linkding provides a CLI command to create a full backup of the data folder. This creates a zip file that contains backups of the database, assets, and favicons.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This method assumes that you are using the default SQLite database.
|
||||||
|
> If you are using a different database, such as Postgres, you'll have to back up the database and other contents of the data folder manually.
|
||||||
|
|
||||||
|
To create a full backup, execute the following command:
|
||||||
|
```shell
|
||||||
|
docker exec -it linkding python manage.py full_backup /etc/linkding/data/backup.zip
|
||||||
|
```
|
||||||
|
This creates a `backup.zip` file in the Docker container under `/etc/linkding/data`.
|
||||||
|
|
||||||
|
To copy the backup file to your host system, execute the following command:
|
||||||
|
```shell
|
||||||
|
docker cp linkding:/etc/linkding/data/backup.zip backup.zip
|
||||||
|
```
|
||||||
|
This copies the backup file from the Docker container to the current folder on your host system.
|
||||||
|
Now you can move that file to your backup location.
|
||||||
|
|
||||||
|
To restore a backup:
|
||||||
|
- Extract the zip file in a folder of your new installation.
|
||||||
|
- Rename the extracted folder to `data`.
|
||||||
|
- When starting the Docker container, mount that folder to `/etc/linkding/data` as explained in the README.
|
||||||
|
- Then start the Docker container.
|
||||||
|
|
||||||
|
## Alternative backup methods
|
||||||
|
|
||||||
|
If you can't use the full backup method, this section describes alternatives how to back up the individual contents of the data folder.
|
||||||
|
|
||||||
|
### SQLite database backup
|
||||||
|
|
||||||
|
linkding includes a CLI command for creating a backup copy of the database.
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> While the SQLite database is just a single file, it is not recommended to just copy that file.
|
> While the SQLite database is just a single file, it is not recommended to just copy that file.
|
||||||
> This method is not transaction safe and may result in a [corrupted database](https://www.sqlite.org/howtocorrupt.html).
|
> This method is not transaction safe and may result in a [corrupted database](https://www.sqlite.org/howtocorrupt.html).
|
||||||
> Use one of the backup methods described below.
|
> Use one of the backup methods described below.
|
||||||
|
|
||||||
### Using the backup command
|
> [!WARNING]
|
||||||
|
> This method is deprecated and may be removed in the future.
|
||||||
linkding includes a CLI command for creating a backup copy of the database.
|
> Please use the full backup method described above.
|
||||||
|
|
||||||
To create a backup, execute the following command:
|
To create a backup, execute the following command:
|
||||||
```shell
|
```shell
|
||||||
@@ -38,12 +70,12 @@ Now you can move that file to your backup location.
|
|||||||
|
|
||||||
To restore the backup, just copy the backup file to the data folder of your new installation and rename it to `db.sqlite3`. Then start the Docker container.
|
To restore the backup, just copy the backup file to the data folder of your new installation and rename it to `db.sqlite3`. Then start the Docker container.
|
||||||
|
|
||||||
### Using the SQLite dump function
|
### SQLite database SQL dump
|
||||||
|
|
||||||
Requires [SQLite](https://www.sqlite.org/index.html) to be installed on your host system.
|
Requires [SQLite](https://www.sqlite.org/index.html) to be installed on your host system.
|
||||||
|
|
||||||
With this method you create a plain text file with the SQL statements to recreate the SQLite database.
|
With this method you create a plain text file with the SQL statements to recreate the SQLite database.
|
||||||
To create a backup, execute the following command in the data folder:
|
To create a backup, execute the following command in the data folder on your host system:
|
||||||
```shell
|
```shell
|
||||||
sqlite3 db.sqlite3 .dump > backup.sql
|
sqlite3 db.sqlite3 .dump > backup.sql
|
||||||
```
|
```
|
||||||
@@ -56,8 +88,8 @@ Using git, you can commit the changes, followed by a git push to a remote reposi
|
|||||||
This is the least technical option to back up bookmarks, but has several limitations:
|
This is the least technical option to back up bookmarks, but has several limitations:
|
||||||
- It does not export user profiles.
|
- It does not export user profiles.
|
||||||
- It only exports your own bookmarks, not those of other users.
|
- It only exports your own bookmarks, not those of other users.
|
||||||
- It does not export archived bookmarks.
|
|
||||||
- It does not export URLs of snapshots on the Internet Archive Wayback machine.
|
- It does not export URLs of snapshots on the Internet Archive Wayback machine.
|
||||||
|
- It does not export HTML snapshots of bookmarks. Even if you backup and restore the assets folder, the bookmarks will not be linked to the snapshots anymore.
|
||||||
- It does not export favicons.
|
- It does not export favicons.
|
||||||
|
|
||||||
Only use this method if you are fine with the above limitations.
|
Only use this method if you are fine with the above limitations.
|
||||||
@@ -70,7 +102,16 @@ To restore bookmarks, open the general settings on your new installation.
|
|||||||
In the Import section, click on the *Choose file* button to select the HTML file you downloaded before.
|
In the Import section, click on the *Choose file* button to select the HTML file you downloaded before.
|
||||||
Then click on the *Import* button to import the bookmarks.
|
Then click on the *Import* button to import the bookmarks.
|
||||||
|
|
||||||
## Favicons
|
### Assets
|
||||||
|
|
||||||
|
If you are using the HTML snapshots feature, you should also do backups of the `assets` folder.
|
||||||
|
It contains the HTML snapshots files of your bookmarks which are referenced from the database.
|
||||||
|
|
||||||
|
To back up the assets, then you have to copy the `assets` folder to your backup location.
|
||||||
|
|
||||||
|
To restore the assets, copy the `assets` folder back to the data folder of your new installation.
|
||||||
|
|
||||||
|
### Favicons
|
||||||
|
|
||||||
Doing a backup of the icons is optional, as they can be downloaded again.
|
Doing a backup of the icons is optional, as they can be downloaded again.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "linkding",
|
"name": "linkding",
|
||||||
"version": "1.27.0",
|
"version": "1.29.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -28,5 +28,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^3.0.2"
|
"prettier": "^3.0.2"
|
||||||
}
|
},
|
||||||
|
"web-types": "./web-types.json"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ Django
|
|||||||
django-registration
|
django-registration
|
||||||
django-sass-processor
|
django-sass-processor
|
||||||
django-widget-tweaks
|
django-widget-tweaks
|
||||||
django4-background-tasks
|
|
||||||
djangorestframework
|
djangorestframework
|
||||||
|
huey
|
||||||
Markdown
|
Markdown
|
||||||
mozilla-django-oidc
|
mozilla-django-oidc
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ django-sass-processor==1.4
|
|||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-widget-tweaks==1.5.0
|
django-widget-tweaks==1.5.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django4-background-tasks==1.2.9
|
|
||||||
# via -r requirements.in
|
|
||||||
djangorestframework==3.14.0
|
djangorestframework==3.14.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
idna==3.6
|
huey==2.5.0
|
||||||
|
# via -r requirements.in
|
||||||
|
idna==3.7
|
||||||
# via requests
|
# via requests
|
||||||
josepy==1.14.0
|
josepy==1.14.0
|
||||||
# via mozilla-django-oidc
|
# via mozilla-django-oidc
|
||||||
@@ -69,7 +69,6 @@ requests==2.31.0
|
|||||||
six==1.16.0
|
six==1.16.0
|
||||||
# via
|
# via
|
||||||
# bleach
|
# bleach
|
||||||
# django4-background-tasks
|
|
||||||
# python-dateutil
|
# python-dateutil
|
||||||
soupsieve==2.5
|
soupsieve==2.5
|
||||||
# via beautifulsoup4
|
# via beautifulsoup4
|
||||||
|
|||||||
13
scripts/setup-ublock.sh
Executable file
13
scripts/setup-ublock.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
rm -rf ublock0.chromium
|
||||||
|
|
||||||
|
TAG=$(curl -sL https://api.github.com/repos/gorhill/uBlock/releases/latest | jq -r '.tag_name')
|
||||||
|
DOWNLOAD_URL=https://github.com/gorhill/uBlock/releases/download/$TAG/uBlock0_$TAG.chromium.zip
|
||||||
|
curl -L -o uBlock0.zip $DOWNLOAD_URL
|
||||||
|
unzip uBlock0.zip
|
||||||
|
rm uBlock0.zip
|
||||||
|
|
||||||
|
curl -L -o ./uBlock0.chromium/assets/thirdparties/easylist/easylist-cookies.txt https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt
|
||||||
|
jq '."fanboy-cookiemonster" |= del(.off) | ."fanboy-cookiemonster".contentURL += ["assets/thirdparties/easylist/easylist-cookies.txt"]' ./uBlock0.chromium/assets/assets.json > temp.json
|
||||||
|
mv temp.json ./uBlock0.chromium/assets/assets.json
|
||||||
|
|
||||||
|
mkdir -p chromium-profile
|
||||||
@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
@@ -42,7 +43,7 @@ INSTALLED_APPS = [
|
|||||||
"widget_tweaks",
|
"widget_tweaks",
|
||||||
"rest_framework",
|
"rest_framework",
|
||||||
"rest_framework.authtoken",
|
"rest_framework.authtoken",
|
||||||
"background_task",
|
"huey.contrib.djhuey",
|
||||||
"mozilla_django_oidc",
|
"mozilla_django_oidc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -173,13 +174,27 @@ LD_DISABLE_BACKGROUND_TASKS = os.getenv("LD_DISABLE_BACKGROUND_TASKS", False) in
|
|||||||
"1",
|
"1",
|
||||||
)
|
)
|
||||||
|
|
||||||
# django-background-tasks
|
# Huey task queue
|
||||||
MAX_ATTEMPTS = 5
|
HUEY = {
|
||||||
# How many tasks will run in parallel
|
"huey_class": "huey.SqliteHuey",
|
||||||
# We want to keep this low to prevent SQLite lock errors and in general not to consume too much resources on smaller
|
"filename": os.path.join(BASE_DIR, "data", "tasks.sqlite3"),
|
||||||
# specced systems like Raspberries. Should be OK as tasks are not time critical.
|
"immediate": False,
|
||||||
BACKGROUND_TASK_RUN_ASYNC = True
|
"results": False,
|
||||||
BACKGROUND_TASK_ASYNC_THREADS = 2
|
"store_none": False,
|
||||||
|
"utc": True,
|
||||||
|
"consumer": {
|
||||||
|
"workers": 2,
|
||||||
|
"worker_type": "thread",
|
||||||
|
"initial_delay": 5,
|
||||||
|
"backoff": 1.15,
|
||||||
|
"max_delay": 10,
|
||||||
|
"scheduler_interval": 10,
|
||||||
|
"periodic": True,
|
||||||
|
"check_worker_health": True,
|
||||||
|
"health_check_interval": 10,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Enable OICD support if configured
|
# Enable OICD support if configured
|
||||||
LD_ENABLE_OIDC = os.getenv("LD_ENABLE_OIDC", False) in (True, "True", "1")
|
LD_ENABLE_OIDC = os.getenv("LD_ENABLE_OIDC", False) in (True, "True", "1")
|
||||||
@@ -198,6 +213,7 @@ if LD_ENABLE_OIDC:
|
|||||||
OIDC_RP_CLIENT_SECRET = os.getenv("OIDC_RP_CLIENT_SECRET")
|
OIDC_RP_CLIENT_SECRET = os.getenv("OIDC_RP_CLIENT_SECRET")
|
||||||
OIDC_RP_SIGN_ALGO = os.getenv("OIDC_RP_SIGN_ALGO", "RS256")
|
OIDC_RP_SIGN_ALGO = os.getenv("OIDC_RP_SIGN_ALGO", "RS256")
|
||||||
OIDC_USE_PKCE = os.getenv("OIDC_USE_PKCE", True) in (True, "True", "1")
|
OIDC_USE_PKCE = os.getenv("OIDC_USE_PKCE", True) in (True, "True", "1")
|
||||||
|
OIDC_VERIFY_SSL = os.getenv("OIDC_VERIFY_SSL", True) in (True, "True", "1")
|
||||||
|
|
||||||
# Enable authentication proxy support if configured
|
# Enable authentication proxy support if configured
|
||||||
LD_ENABLE_AUTH_PROXY = os.getenv("LD_ENABLE_AUTH_PROXY", False) in (True, "True", "1")
|
LD_ENABLE_AUTH_PROXY = os.getenv("LD_ENABLE_AUTH_PROXY", False) in (True, "True", "1")
|
||||||
@@ -279,7 +295,19 @@ LD_ENABLE_SNAPSHOTS = os.getenv("LD_ENABLE_SNAPSHOTS", False) in (
|
|||||||
"1",
|
"1",
|
||||||
)
|
)
|
||||||
LD_SINGLEFILE_PATH = os.getenv("LD_SINGLEFILE_PATH", "single-file")
|
LD_SINGLEFILE_PATH = os.getenv("LD_SINGLEFILE_PATH", "single-file")
|
||||||
|
LD_SINGLEFILE_UBLOCK_OPTIONS = os.getenv(
|
||||||
|
"LD_SINGLEFILE_UBLOCK_OPTIONS",
|
||||||
|
shlex.join(
|
||||||
|
[
|
||||||
|
'--browser-arg="--headless=new"',
|
||||||
|
'--browser-arg="--user-data-dir=./chromium-profile"',
|
||||||
|
'--browser-arg="--no-sandbox"',
|
||||||
|
'--browser-arg="--load-extension=uBlock0.chromium"',
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
LD_SINGLEFILE_OPTIONS = os.getenv("LD_SINGLEFILE_OPTIONS", "")
|
LD_SINGLEFILE_OPTIONS = os.getenv("LD_SINGLEFILE_OPTIONS", "")
|
||||||
|
LD_SINGLEFILE_TIMEOUT_SEC = float(os.getenv("LD_SINGLEFILE_TIMEOUT_SEC", 120))
|
||||||
|
|
||||||
# Monolith isn't used at the moment, as the local snapshot implementation
|
# Monolith isn't used at the moment, as the local snapshot implementation
|
||||||
# switched to single-file after the prototype. Keeping this around in case
|
# switched to single-file after the prototype. Keeping this around in case
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ LOGGING = {
|
|||||||
"handlers": ["console"],
|
"handlers": ["console"],
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
},
|
},
|
||||||
|
"huey": { # Huey
|
||||||
|
"level": "INFO",
|
||||||
|
"handlers": ["console"],
|
||||||
|
"propagate": False,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,12 @@ LOGGING = {
|
|||||||
"level": "INFO",
|
"level": "INFO",
|
||||||
"handlers": ["console"],
|
"handlers": ["console"],
|
||||||
"propagate": False,
|
"propagate": False,
|
||||||
}
|
},
|
||||||
|
"huey": {
|
||||||
|
"level": "INFO",
|
||||||
|
"handlers": ["console"],
|
||||||
|
"propagate": False,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,20 @@ loglevel=info
|
|||||||
|
|
||||||
[program:jobs]
|
[program:jobs]
|
||||||
user=www-data
|
user=www-data
|
||||||
command=sh background-tasks-wrapper.sh
|
# setup a temp home folder for the job, required by chromium
|
||||||
|
environment=HOME=/tmp/home
|
||||||
|
command=python manage.py run_huey -f
|
||||||
stdout_logfile=background_tasks.log
|
stdout_logfile=background_tasks.log
|
||||||
stdout_logfile_maxbytes=10MB
|
stdout_logfile_maxbytes=10MB
|
||||||
stdout_logfile_backups=5
|
stdout_logfile_backups=5
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
|
|
||||||
|
[unix_http_server]
|
||||||
|
file=/var/run/supervisor.sock
|
||||||
|
chmod=0700
|
||||||
|
|
||||||
|
[rpcinterface:supervisor]
|
||||||
|
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||||
|
|
||||||
|
[supervisorctl]
|
||||||
|
serverurl=unix:///var/run/supervisor.sock
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.27.0
|
1.29.0
|
||||||
|
|||||||
130
web-types.json
Normal file
130
web-types.json
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
|
||||||
|
"name": "linkding",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"contributions": {
|
||||||
|
"html": {
|
||||||
|
"attributes": [
|
||||||
|
{
|
||||||
|
"name": "ld-fetch",
|
||||||
|
"description": "Fetches the HTML content of the given URL and replaces the content of an element with it. Fires events afterwards to notify other behaviors.",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-on",
|
||||||
|
"description": "The event that triggers a fetch, such as `click` or a custom event name fired by another behavior",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-target",
|
||||||
|
"description": "The target element to replace the content of and the replacement strategy, for example `body|append`",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-select",
|
||||||
|
"description": "The content element(s) to select from the fetched content, for example `#main-content`",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-interval",
|
||||||
|
"description": "Automatically fetches the content of the given URL at the given interval, in seconds",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-fire",
|
||||||
|
"description": "Fires one or more events once a behavior, such as ld-fetch or ld-form, is finished",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-form",
|
||||||
|
"description": "Converts a form into a fetch request. Fires events afterwards to notify other behaviors.",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-auto-submit",
|
||||||
|
"description": "Automatically submits the nearest form when the value of the input changes",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-modal",
|
||||||
|
"description": "Adds Javascript behavior to a modal HTML component",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-dropdown",
|
||||||
|
"description": "Adds Javascript behavior to a dropdown HTML component",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-confirm-button",
|
||||||
|
"description": "Converts a button into a confirmation button that shows confirm / cancel buttons when clicked",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-confirm-icon",
|
||||||
|
"description": "Icon to show when the confirm button is clicked",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-confirm-question",
|
||||||
|
"description": "Question to show when the confirm button is clicked",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-bookmark-item",
|
||||||
|
"description": "Adds Javascript behavior to a bookmark list item",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-bulk-edit",
|
||||||
|
"description": "Adds Javascript behavior for bulk editing the bookmark list",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-global-shortcuts",
|
||||||
|
"description": "Adds Javascript behavior for global shortcuts",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ld-tag-autocomplete",
|
||||||
|
"description": "Adds Javascript behavior for converting a plain input into a tag autocomplete Svelte component",
|
||||||
|
"value": {
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user