mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-15 06:29:21 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e1c9a7add6 | ||
![]() |
82b4268a26 | ||
![]() |
5287eb3f8b | ||
![]() |
d298260122 | ||
![]() |
12e5810aee | ||
![]() |
1dabd0266b | ||
![]() |
7390fc3f4f | ||
![]() |
5e003ede92 | ||
![]() |
984eef92e2 | ||
![]() |
eae6ca6e07 | ||
![]() |
a6bfaa7c78 |
@@ -8,6 +8,7 @@
|
|||||||
/static
|
/static
|
||||||
/build
|
/build
|
||||||
/out
|
/out
|
||||||
|
/.git
|
||||||
|
|
||||||
/.dockerignore
|
/.dockerignore
|
||||||
/.gitignore
|
/.gitignore
|
||||||
|
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.8.4 (16/10/2021)
|
||||||
|
- [**enhancement**] Allow non-admin users to change their password [#166](https://github.com/sissbruecker/linkding/issues/166)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v1.8.3 (03/10/2021)
|
||||||
|
- [**enhancement**] Enhancement: let user configure to open links in same tab instead on a new window/tab [#27](https://github.com/sissbruecker/linkding/issues/27)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## v1.8.2 (02/10/2021)
|
## v1.8.2 (02/10/2021)
|
||||||
- [**bug**] Fix jumping search box [#163](https://github.com/sissbruecker/linkding/pull/163)
|
- [**bug**] Fix jumping search box [#163](https://github.com/sissbruecker/linkding/pull/163)
|
||||||
---
|
---
|
||||||
|
@@ -58,6 +58,8 @@ class AdminTag(admin.ModelAdmin):
|
|||||||
|
|
||||||
def bookmarks_count(self, obj):
|
def bookmarks_count(self, obj):
|
||||||
return obj.bookmarks_count
|
return obj.bookmarks_count
|
||||||
|
|
||||||
|
bookmarks_count.admin_order_field = 'bookmarks_count'
|
||||||
|
|
||||||
def delete_unused_tags(self, request, queryset: QuerySet):
|
def delete_unused_tags(self, request, queryset: QuerySet):
|
||||||
unused_tags = queryset.filter(bookmark__isnull=True)
|
unused_tags = queryset.filter(bookmark__isnull=True)
|
||||||
|
@@ -41,14 +41,14 @@ class BookmarkSerializer(serializers.ModelSerializer):
|
|||||||
bookmark.url = validated_data['url']
|
bookmark.url = validated_data['url']
|
||||||
bookmark.title = validated_data['title']
|
bookmark.title = validated_data['title']
|
||||||
bookmark.description = validated_data['description']
|
bookmark.description = validated_data['description']
|
||||||
tag_string = build_tag_string(validated_data['tag_names'], ' ')
|
tag_string = build_tag_string(validated_data['tag_names'])
|
||||||
return create_bookmark(bookmark, tag_string, self.context['user'])
|
return create_bookmark(bookmark, tag_string, self.context['user'])
|
||||||
|
|
||||||
def update(self, instance: Bookmark, validated_data):
|
def update(self, instance: Bookmark, validated_data):
|
||||||
instance.url = validated_data['url']
|
instance.url = validated_data['url']
|
||||||
instance.title = validated_data['title']
|
instance.title = validated_data['title']
|
||||||
instance.description = validated_data['description']
|
instance.description = validated_data['description']
|
||||||
tag_string = build_tag_string(validated_data['tag_names'], ' ')
|
tag_string = build_tag_string(validated_data['tag_names'])
|
||||||
return update_bookmark(instance, tag_string, self.context['user'])
|
return update_bookmark(instance, tag_string, self.context['user'])
|
||||||
|
|
||||||
|
|
||||||
|
@@ -20,11 +20,19 @@ class Tag(models.Model):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize_tag_name(tag_name: str):
|
||||||
|
# strip leading/trailing spaces
|
||||||
|
# replace inner spaces with replacement char
|
||||||
|
return tag_name.strip().replace(' ', '-')
|
||||||
|
|
||||||
|
|
||||||
def parse_tag_string(tag_string: str, delimiter: str = ','):
|
def parse_tag_string(tag_string: str, delimiter: str = ','):
|
||||||
if not tag_string:
|
if not tag_string:
|
||||||
return []
|
return []
|
||||||
names = tag_string.strip().split(delimiter)
|
names = tag_string.strip().split(delimiter)
|
||||||
names = [name.strip() for name in names if name]
|
# remove empty names, sanitize remaining names
|
||||||
|
names = [sanitize_tag_name(name) for name in names if name]
|
||||||
|
# remove duplicates
|
||||||
names = unique(names, str.lower)
|
names = unique(names, str.lower)
|
||||||
names.sort(key=str.lower)
|
names.sort(key=str.lower)
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ def delete_bookmarks(bookmark_ids: [Union[int, str]], current_user: User):
|
|||||||
def tag_bookmarks(bookmark_ids: [Union[int, str]], tag_string: str, current_user: User):
|
def tag_bookmarks(bookmark_ids: [Union[int, str]], tag_string: str, current_user: User):
|
||||||
sanitized_bookmark_ids = _sanitize_id_list(bookmark_ids)
|
sanitized_bookmark_ids = _sanitize_id_list(bookmark_ids)
|
||||||
bookmarks = Bookmark.objects.filter(owner=current_user, id__in=sanitized_bookmark_ids)
|
bookmarks = Bookmark.objects.filter(owner=current_user, id__in=sanitized_bookmark_ids)
|
||||||
tag_names = parse_tag_string(tag_string, ' ')
|
tag_names = parse_tag_string(tag_string)
|
||||||
tags = get_or_create_tags(tag_names, current_user)
|
tags = get_or_create_tags(tag_names, current_user)
|
||||||
|
|
||||||
for bookmark in bookmarks:
|
for bookmark in bookmarks:
|
||||||
@@ -103,7 +103,7 @@ def tag_bookmarks(bookmark_ids: [Union[int, str]], tag_string: str, current_user
|
|||||||
def untag_bookmarks(bookmark_ids: [Union[int, str]], tag_string: str, current_user: User):
|
def untag_bookmarks(bookmark_ids: [Union[int, str]], tag_string: str, current_user: User):
|
||||||
sanitized_bookmark_ids = _sanitize_id_list(bookmark_ids)
|
sanitized_bookmark_ids = _sanitize_id_list(bookmark_ids)
|
||||||
bookmarks = Bookmark.objects.filter(owner=current_user, id__in=sanitized_bookmark_ids)
|
bookmarks = Bookmark.objects.filter(owner=current_user, id__in=sanitized_bookmark_ids)
|
||||||
tag_names = parse_tag_string(tag_string, ' ')
|
tag_names = parse_tag_string(tag_string)
|
||||||
tags = get_or_create_tags(tag_names, current_user)
|
tags = get_or_create_tags(tag_names, current_user)
|
||||||
|
|
||||||
for bookmark in bookmarks:
|
for bookmark in bookmarks:
|
||||||
@@ -125,7 +125,7 @@ def _update_website_metadata(bookmark: Bookmark):
|
|||||||
|
|
||||||
|
|
||||||
def _update_bookmark_tags(bookmark: Bookmark, tag_string: str, user: User):
|
def _update_bookmark_tags(bookmark: Bookmark, tag_string: str, user: User):
|
||||||
tag_names = parse_tag_string(tag_string, ' ')
|
tag_names = parse_tag_string(tag_string)
|
||||||
tags = get_or_create_tags(tag_names, user)
|
tags = get_or_create_tags(tag_names, user)
|
||||||
bookmark.tags.set(tags)
|
bookmark.tags.set(tags)
|
||||||
|
|
||||||
|
21
bookmarks/templates/registration/password_change_done.html
Normal file
21
bookmarks/templates/registration/password_change_done.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'bookmarks/layout.html' %}
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
|
||||||
|
{% block title %}Password changed{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="auth-page">
|
||||||
|
<div class="columns">
|
||||||
|
<section class="content-area column col-5 col-md-12">
|
||||||
|
<div class="content-area-header">
|
||||||
|
<h2>Password Changed</h2>
|
||||||
|
</div>
|
||||||
|
<p class="text-success">
|
||||||
|
Your password was changed successfully.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
55
bookmarks/templates/registration/password_change_form.html
Normal file
55
bookmarks/templates/registration/password_change_form.html
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{% extends 'bookmarks/layout.html' %}
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
|
||||||
|
{% block title %}Change Password{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="auth-page">
|
||||||
|
<div class="columns">
|
||||||
|
<section class="content-area column col-5 col-md-12">
|
||||||
|
<div class="content-area-header">
|
||||||
|
<h2>Change Password</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{% url 'change_password' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="form-group {% if form.old_password.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.old_password.id_for_label }}">Old password</label>
|
||||||
|
{{ form.old_password|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.old_password.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.old_password.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="form-group {% if form.new_password1.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.new_password1.id_for_label }}">New password</label>
|
||||||
|
{{ form.new_password1|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.new_password1.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.new_password1.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="form-group {% if form.new_password2.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.new_password2.id_for_label }}">Confirm new password</label>
|
||||||
|
{{ form.new_password2|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.new_password2.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.new_password2.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column col-3">
|
||||||
|
<input type="submit" value="Change Password" class="btn btn-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
@@ -1,25 +0,0 @@
|
|||||||
{% extends "bookmarks/layout.html" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="settings-page">
|
|
||||||
|
|
||||||
{% include 'settings/nav.html' %}
|
|
||||||
|
|
||||||
<section class="content-area">
|
|
||||||
<h2>API Token</h2>
|
|
||||||
<p>The following token can be used to authenticate 3rd-party applications against the REST API:</p>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="columns">
|
|
||||||
<div class="column col-6 col-md-12">
|
|
||||||
<input class="form-input" value="{{ api_token }}" disabled>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p><strong>Please treat this token as you would any other credential.</strong> Any party with access to this
|
|
||||||
token can access and manage all your bookmarks.</p>
|
|
||||||
<p>If you think that a token was compromised you can revoke (delete) it in the <a href="{% url 'admin:authtoken_tokenproxy_changelist' %}">admin panel</a>. After deleting the token, a new one will be generated when you reload this settings page.</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@@ -9,6 +9,9 @@
|
|||||||
{# Profile section #}
|
{# Profile section #}
|
||||||
<section class="content-area">
|
<section class="content-area">
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'change_password' %}">Change password</a>
|
||||||
|
</p>
|
||||||
<form action="{% url 'bookmarks:settings.general' %}" method="post" novalidate>
|
<form action="{% url 'bookmarks:settings.general' %}" method="post" novalidate>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
{% include 'settings/nav.html' %}
|
{% include 'settings/nav.html' %}
|
||||||
|
|
||||||
{# Integrations section #}
|
|
||||||
<section class="content-area">
|
<section class="content-area">
|
||||||
<h2>Browser Extension</h2>
|
<h2>Browser Extension</h2>
|
||||||
<p>The browser extension allows you to quickly add new bookmarks without leaving the page that you are on. The extension is available in the official extension stores for:</p>
|
<p>The browser extension allows you to quickly add new bookmarks without leaving the page that you are on. The extension is available in the official extension stores for:</p>
|
||||||
@@ -29,5 +28,19 @@
|
|||||||
class="btn btn-primary">📎 Add bookmark</a>
|
class="btn btn-primary">📎 Add bookmark</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="content-area">
|
||||||
|
<h2>REST API</h2>
|
||||||
|
<p>The following token can be used to authenticate 3rd-party applications against the REST API:</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column col-6 col-md-12">
|
||||||
|
<input class="form-input" value="{{ api_token }}" readonly>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><strong>Please treat this token as you would any other credential.</strong> Any party with access to this
|
||||||
|
token can access and manage all your bookmarks.</p>
|
||||||
|
<p>If you think that a token was compromised you can revoke (delete) it in the <a href="{% url 'admin:authtoken_tokenproxy_changelist' %}">admin panel</a>. After deleting the token, a new one will be generated when you reload this settings page.</p>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
{% url 'bookmarks:settings.index' as index_url %}
|
{% url 'bookmarks:settings.index' as index_url %}
|
||||||
{% url 'bookmarks:settings.general' as general_url %}
|
{% url 'bookmarks:settings.general' as general_url %}
|
||||||
{% url 'bookmarks:settings.integrations' as integrations_url %}
|
{% url 'bookmarks:settings.integrations' as integrations_url %}
|
||||||
{% url 'bookmarks:settings.api' as api_url %}
|
|
||||||
|
|
||||||
<ul class="tab tab-block">
|
<ul class="tab tab-block">
|
||||||
<li class="tab-item {% if request.get_full_path == index_url or request.get_full_path == general_url%}active{% endif %}">
|
<li class="tab-item {% if request.get_full_path == index_url or request.get_full_path == general_url%}active{% endif %}">
|
||||||
@@ -10,9 +9,6 @@
|
|||||||
<li class="tab-item {% if request.get_full_path == integrations_url %}active{% endif %}">
|
<li class="tab-item {% if request.get_full_path == integrations_url %}active{% endif %}">
|
||||||
<a href="{% url 'bookmarks:settings.integrations' %}">Integrations</a>
|
<a href="{% url 'bookmarks:settings.integrations' %}">Integrations</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="tab-item {% if request.get_full_path == api_url %}active{% endif %}">
|
|
||||||
<a href="{% url 'bookmarks:settings.api' %}">API</a>
|
|
||||||
</li>
|
|
||||||
<li class="tab-item tooltip tooltip-bottom" data-tooltip="The admin panel provides additional features 
 such as user management and bulk operations.">
|
<li class="tab-item tooltip tooltip-bottom" data-tooltip="The admin panel provides additional features 
 such as user management and bulk operations.">
|
||||||
<a href="{% url 'admin:index' %}" target="_blank">
|
<a href="{% url 'admin:index' %}" target="_blank">
|
||||||
<span>Admin</span>
|
<span>Admin</span>
|
||||||
|
@@ -60,6 +60,18 @@ class BookmarksApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
|
|||||||
self.assertEqual(bookmark.tags.filter(name=data['tag_names'][0]).count(), 1)
|
self.assertEqual(bookmark.tags.filter(name=data['tag_names'][0]).count(), 1)
|
||||||
self.assertEqual(bookmark.tags.filter(name=data['tag_names'][1]).count(), 1)
|
self.assertEqual(bookmark.tags.filter(name=data['tag_names'][1]).count(), 1)
|
||||||
|
|
||||||
|
def test_create_bookmark_replaces_whitespace_in_tag_names(self):
|
||||||
|
data = {
|
||||||
|
'url': 'https://example.com/',
|
||||||
|
'title': 'Test title',
|
||||||
|
'description': 'Test description',
|
||||||
|
'tag_names': ['tag 1', 'tag 2']
|
||||||
|
}
|
||||||
|
self.post(reverse('bookmarks:bookmark-list'), data, status.HTTP_201_CREATED)
|
||||||
|
bookmark = Bookmark.objects.get(url=data['url'])
|
||||||
|
tag_names = [tag.name for tag in bookmark.tags.all()]
|
||||||
|
self.assertListEqual(tag_names, ['tag-1', 'tag-2'])
|
||||||
|
|
||||||
def test_create_bookmark_minimal_payload(self):
|
def test_create_bookmark_minimal_payload(self):
|
||||||
data = {'url': 'https://example.com/'}
|
data = {'url': 'https://example.com/'}
|
||||||
self.post(reverse('bookmarks:bookmark-list'), data, status.HTTP_201_CREATED)
|
self.post(reverse('bookmarks:bookmark-list'), data, status.HTTP_201_CREATED)
|
||||||
|
@@ -21,7 +21,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
def test_create_should_create_web_archive_snapshot(self):
|
def test_create_should_create_web_archive_snapshot(self):
|
||||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||||
bookmark_data = Bookmark(url='https://example.com')
|
bookmark_data = Bookmark(url='https://example.com')
|
||||||
bookmark = create_bookmark(bookmark_data, 'tag1 tag2', self.user)
|
bookmark = create_bookmark(bookmark_data, 'tag1,tag2', self.user)
|
||||||
|
|
||||||
mock_create_web_archive_snapshot.assert_called_once_with(bookmark.id, False)
|
mock_create_web_archive_snapshot.assert_called_once_with(bookmark.id, False)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
bookmark.url = 'https://example.com/updated'
|
bookmark.url = 'https://example.com/updated'
|
||||||
update_bookmark(bookmark, 'tag1 tag2', self.user)
|
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||||
|
|
||||||
mock_create_web_archive_snapshot.assert_called_once_with(bookmark.id, True)
|
mock_create_web_archive_snapshot.assert_called_once_with(bookmark.id, True)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
bookmark.title = 'updated title'
|
bookmark.title = 'updated title'
|
||||||
update_bookmark(bookmark, 'tag1 tag2', self.user)
|
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||||
|
|
||||||
mock_create_web_archive_snapshot.assert_not_called()
|
mock_create_web_archive_snapshot.assert_not_called()
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
tag1 = self.setup_tag()
|
tag1 = self.setup_tag()
|
||||||
tag2 = self.setup_tag()
|
tag2 = self.setup_tag()
|
||||||
|
|
||||||
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name} {tag2.name}',
|
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
@@ -232,7 +232,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark2 = self.setup_bookmark()
|
bookmark2 = self.setup_bookmark()
|
||||||
bookmark3 = self.setup_bookmark()
|
bookmark3 = self.setup_bookmark()
|
||||||
|
|
||||||
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], 'tag1 tag2', self.get_or_create_test_user())
|
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], 'tag1,tag2', self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
bookmark2.refresh_from_db()
|
bookmark2.refresh_from_db()
|
||||||
@@ -257,7 +257,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
tag1 = self.setup_tag()
|
tag1 = self.setup_tag()
|
||||||
tag2 = self.setup_tag()
|
tag2 = self.setup_tag()
|
||||||
|
|
||||||
tag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name} {tag2.name}', self.get_or_create_test_user())
|
tag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name},{tag2.name}', self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
bookmark2.refresh_from_db()
|
bookmark2.refresh_from_db()
|
||||||
@@ -275,7 +275,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
tag1 = self.setup_tag()
|
tag1 = self.setup_tag()
|
||||||
tag2 = self.setup_tag()
|
tag2 = self.setup_tag()
|
||||||
|
|
||||||
tag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name} {tag2.name}',
|
tag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
@@ -293,7 +293,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
tag1 = self.setup_tag()
|
tag1 = self.setup_tag()
|
||||||
tag2 = self.setup_tag()
|
tag2 = self.setup_tag()
|
||||||
|
|
||||||
tag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name} {tag2.name}',
|
tag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2])
|
self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2])
|
||||||
@@ -307,7 +307,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
|
|
||||||
untag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name} {tag2.name}',
|
untag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
@@ -325,7 +325,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
|
|
||||||
untag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name} {tag2.name}', self.get_or_create_test_user())
|
untag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name},{tag2.name}', self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
bookmark2.refresh_from_db()
|
bookmark2.refresh_from_db()
|
||||||
@@ -343,7 +343,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
inaccessible_bookmark = self.setup_bookmark(user=other_user, tags=[tag1, tag2])
|
inaccessible_bookmark = self.setup_bookmark(user=other_user, tags=[tag1, tag2])
|
||||||
|
|
||||||
untag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name} {tag2.name}',
|
untag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
bookmark1.refresh_from_db()
|
bookmark1.refresh_from_db()
|
||||||
@@ -361,7 +361,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||||
|
|
||||||
untag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name} {tag2.name}',
|
untag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name},{tag2.name}',
|
||||||
self.get_or_create_test_user())
|
self.get_or_create_test_user())
|
||||||
|
|
||||||
self.assertCountEqual(bookmark1.tags.all(), [])
|
self.assertCountEqual(bookmark1.tags.all(), [])
|
||||||
|
@@ -2,6 +2,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from bookmarks.models import Tag
|
||||||
from bookmarks.services import tasks
|
from bookmarks.services import tasks
|
||||||
from bookmarks.services.importer import import_netscape_html
|
from bookmarks.services.importer import import_netscape_html
|
||||||
from bookmarks.tests.helpers import BookmarkFactoryMixin, disable_logging
|
from bookmarks.tests.helpers import BookmarkFactoryMixin, disable_logging
|
||||||
@@ -20,6 +21,18 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
</DL><p>
|
</DL><p>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def test_replace_whitespace_in_tag_names(self):
|
||||||
|
test_html = self.create_import_html(f'''
|
||||||
|
<DT><A HREF="https://example.com" ADD_DATE="1616337559" PRIVATE="0" TOREAD="0" TAGS="tag 1, tag 2, tag 3">Example.com</A>
|
||||||
|
<DD>Example.com
|
||||||
|
''')
|
||||||
|
import_netscape_html(test_html, self.get_or_create_test_user())
|
||||||
|
|
||||||
|
tags = Tag.objects.all()
|
||||||
|
tag_names = [tag.name for tag in tags]
|
||||||
|
|
||||||
|
self.assertListEqual(tag_names, ['tag-1', 'tag-2', 'tag-3'])
|
||||||
|
|
||||||
@disable_logging
|
@disable_logging
|
||||||
def test_validate_empty_or_missing_bookmark_url(self):
|
def test_validate_empty_or_missing_bookmark_url(self):
|
||||||
test_html = self.create_import_html(f'''
|
test_html = self.create_import_html(f'''
|
||||||
|
55
bookmarks/tests/test_password_change_view.py
Normal file
55
bookmarks/tests/test_password_change_view.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||||
|
|
||||||
|
|
||||||
|
class PasswordChangeViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.user = User.objects.create_user('testuser', 'test@example.com', 'initial_password')
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
def test_change_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertRedirects(response, reverse('password_change_done'))
|
||||||
|
|
||||||
|
def test_change_password_done(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data, follow=True)
|
||||||
|
|
||||||
|
self.assertContains(response, 'Your password was changed successfully')
|
||||||
|
|
||||||
|
def test_should_return_error_for_invalid_old_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'wrong_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertIn('old_password', response.context_data['form'].errors)
|
||||||
|
|
||||||
|
def test_should_return_error_for_mismatching_new_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'wrong_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertIn('new_password2', response.context_data['form'].errors)
|
@@ -1,40 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.authtoken.models import Token
|
|
||||||
|
|
||||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsApiViewTestCase(TestCase, BookmarkFactoryMixin):
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
|
||||||
user = self.get_or_create_test_user()
|
|
||||||
self.client.force_login(user)
|
|
||||||
|
|
||||||
def test_should_render_successfully(self):
|
|
||||||
response = self.client.get(reverse('bookmarks:settings.api'))
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_should_check_authentication(self):
|
|
||||||
self.client.logout()
|
|
||||||
response = self.client.get(reverse('bookmarks:settings.api'), follow=True)
|
|
||||||
|
|
||||||
self.assertRedirects(response, reverse('login') + '?next=' + reverse('bookmarks:settings.api'))
|
|
||||||
|
|
||||||
def test_should_generate_api_token_if_not_exists(self):
|
|
||||||
self.assertEqual(Token.objects.count(), 0)
|
|
||||||
|
|
||||||
self.client.get(reverse('bookmarks:settings.api'))
|
|
||||||
|
|
||||||
self.assertEqual(Token.objects.count(), 1)
|
|
||||||
token = Token.objects.first()
|
|
||||||
self.assertEqual(token.user, self.user)
|
|
||||||
|
|
||||||
def test_should_not_generate_api_token_if_exists(self):
|
|
||||||
Token.objects.get_or_create(user=self.user)
|
|
||||||
self.assertEqual(Token.objects.count(), 1)
|
|
||||||
|
|
||||||
self.client.get(reverse('bookmarks:settings.api'))
|
|
||||||
|
|
||||||
self.assertEqual(Token.objects.count(), 1)
|
|
@@ -1,5 +1,6 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||||
|
|
||||||
@@ -20,3 +21,20 @@ class SettingsIntegrationsViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
response = self.client.get(reverse('bookmarks:settings.integrations'), follow=True)
|
response = self.client.get(reverse('bookmarks:settings.integrations'), follow=True)
|
||||||
|
|
||||||
self.assertRedirects(response, reverse('login') + '?next=' + reverse('bookmarks:settings.integrations'))
|
self.assertRedirects(response, reverse('login') + '?next=' + reverse('bookmarks:settings.integrations'))
|
||||||
|
|
||||||
|
def test_should_generate_api_token_if_not_exists(self):
|
||||||
|
self.assertEqual(Token.objects.count(), 0)
|
||||||
|
|
||||||
|
self.client.get(reverse('bookmarks:settings.integrations'))
|
||||||
|
|
||||||
|
self.assertEqual(Token.objects.count(), 1)
|
||||||
|
token = Token.objects.first()
|
||||||
|
self.assertEqual(token.user, self.user)
|
||||||
|
|
||||||
|
def test_should_not_generate_api_token_if_exists(self):
|
||||||
|
Token.objects.get_or_create(user=self.user)
|
||||||
|
self.assertEqual(Token.objects.count(), 1)
|
||||||
|
|
||||||
|
self.client.get(reverse('bookmarks:settings.integrations'))
|
||||||
|
|
||||||
|
self.assertEqual(Token.objects.count(), 1)
|
||||||
|
@@ -25,3 +25,9 @@ class TagTestCase(TestCase):
|
|||||||
def test_parse_tag_string_deduplicates_tag_names(self):
|
def test_parse_tag_string_deduplicates_tag_names(self):
|
||||||
self.assertEqual(len(parse_tag_string('book,book,Book,BOOK')), 1)
|
self.assertEqual(len(parse_tag_string('book,book,Book,BOOK')), 1)
|
||||||
|
|
||||||
|
def test_parse_tag_string_handles_duplicate_separators(self):
|
||||||
|
self.assertCountEqual(parse_tag_string('book,,movie,,,album'), ['album', 'book', 'movie'])
|
||||||
|
|
||||||
|
def test_parse_tag_string_replaces_whitespace_within_names(self):
|
||||||
|
self.assertCountEqual(parse_tag_string('travel guide, book recommendations'),
|
||||||
|
['travel-guide', 'book-recommendations'])
|
||||||
|
@@ -23,7 +23,6 @@ urlpatterns = [
|
|||||||
path('settings', views.settings.general, name='settings.index'),
|
path('settings', views.settings.general, name='settings.index'),
|
||||||
path('settings/general', views.settings.general, name='settings.general'),
|
path('settings/general', views.settings.general, name='settings.general'),
|
||||||
path('settings/integrations', views.settings.integrations, name='settings.integrations'),
|
path('settings/integrations', views.settings.integrations, name='settings.integrations'),
|
||||||
path('settings/api', views.settings.api, name='settings.api'),
|
|
||||||
path('settings/import', views.settings.bookmark_import, name='settings.import'),
|
path('settings/import', views.settings.bookmark_import, name='settings.import'),
|
||||||
path('settings/export', views.settings.bookmark_export, name='settings.export'),
|
path('settings/export', views.settings.bookmark_export, name='settings.export'),
|
||||||
# API
|
# API
|
||||||
|
@@ -68,6 +68,12 @@ def generate_return_url(base_url, page, query_string):
|
|||||||
return urllib.parse.quote_plus(return_url)
|
return urllib.parse.quote_plus(return_url)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_tag_string(tag_string: str):
|
||||||
|
# Tag strings coming from inputs are space-separated, however services.bookmarks functions expect comma-separated
|
||||||
|
# strings
|
||||||
|
return tag_string.replace(' ', ',')
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def new(request):
|
def new(request):
|
||||||
initial_url = request.GET.get('url')
|
initial_url = request.GET.get('url')
|
||||||
@@ -78,7 +84,8 @@ def new(request):
|
|||||||
auto_close = form.data['auto_close']
|
auto_close = form.data['auto_close']
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
current_user = request.user
|
current_user = request.user
|
||||||
create_bookmark(form.save(commit=False), form.data['tag_string'], current_user)
|
tag_string = convert_tag_string(form.data['tag_string'])
|
||||||
|
create_bookmark(form.save(commit=False), tag_string, current_user)
|
||||||
if auto_close:
|
if auto_close:
|
||||||
return HttpResponseRedirect(reverse('bookmarks:close'))
|
return HttpResponseRedirect(reverse('bookmarks:close'))
|
||||||
else:
|
else:
|
||||||
@@ -107,7 +114,8 @@ def edit(request, bookmark_id: int):
|
|||||||
form = BookmarkForm(request.POST, instance=bookmark)
|
form = BookmarkForm(request.POST, instance=bookmark)
|
||||||
return_url = form.data['return_url']
|
return_url = form.data['return_url']
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
update_bookmark(form.save(commit=False), form.data['tag_string'], request.user)
|
tag_string = convert_tag_string(form.data['tag_string'])
|
||||||
|
update_bookmark(form.save(commit=False), tag_string, request.user)
|
||||||
return HttpResponseRedirect(return_url)
|
return HttpResponseRedirect(return_url)
|
||||||
else:
|
else:
|
||||||
return_url = request.GET.get('return_url')
|
return_url = request.GET.get('return_url')
|
||||||
@@ -166,10 +174,10 @@ def bulk_edit(request):
|
|||||||
if 'bulk_delete' in request.POST:
|
if 'bulk_delete' in request.POST:
|
||||||
delete_bookmarks(bookmark_ids, request.user)
|
delete_bookmarks(bookmark_ids, request.user)
|
||||||
if 'bulk_tag' in request.POST:
|
if 'bulk_tag' in request.POST:
|
||||||
tag_string = request.POST['bulk_tag_string']
|
tag_string = convert_tag_string(request.POST['bulk_tag_string'])
|
||||||
tag_bookmarks(bookmark_ids, tag_string, request.user)
|
tag_bookmarks(bookmark_ids, tag_string, request.user)
|
||||||
if 'bulk_untag' in request.POST:
|
if 'bulk_untag' in request.POST:
|
||||||
tag_string = request.POST['bulk_tag_string']
|
tag_string = convert_tag_string(request.POST['bulk_tag_string'])
|
||||||
untag_bookmarks(bookmark_ids, tag_string, request.user)
|
untag_bookmarks(bookmark_ids, tag_string, request.user)
|
||||||
|
|
||||||
return_url = request.GET.get('return_url')
|
return_url = request.GET.get('return_url')
|
||||||
|
@@ -43,15 +43,9 @@ def general(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def integrations(request):
|
def integrations(request):
|
||||||
application_url = request.build_absolute_uri("/bookmarks/new")
|
application_url = request.build_absolute_uri("/bookmarks/new")
|
||||||
|
api_token = Token.objects.get_or_create(user=request.user)[0]
|
||||||
return render(request, 'settings/integrations.html', {
|
return render(request, 'settings/integrations.html', {
|
||||||
'application_url': application_url,
|
'application_url': application_url,
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def api(request):
|
|
||||||
api_token = Token.objects.get_or_create(user=request.user)[0]
|
|
||||||
return render(request, 'settings/api.html', {
|
|
||||||
'api_token': api_token.key
|
'api_token': api_token.key
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -8,4 +8,6 @@ services:
|
|||||||
- "${LD_HOST_PORT:-9090}:9090"
|
- "${LD_HOST_PORT:-9090}:9090"
|
||||||
volumes:
|
volumes:
|
||||||
- "${LD_HOST_DATA_DIR:-./data}:/etc/linkding/data"
|
- "${LD_HOST_DATA_DIR:-./data}:/etc/linkding/data"
|
||||||
restart: unless-stopped
|
env_file:
|
||||||
|
- .env
|
||||||
|
restart: unless-stopped
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "linkding",
|
"name": "linkding",
|
||||||
"version": "1.8.3",
|
"version": "1.8.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@@ -25,11 +25,14 @@ urlpatterns = [
|
|||||||
extra_context=dict(allow_registration=ALLOW_REGISTRATION)),
|
extra_context=dict(allow_registration=ALLOW_REGISTRATION)),
|
||||||
name='login'),
|
name='login'),
|
||||||
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
|
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
|
||||||
|
path('change-password/', auth_views.PasswordChangeView.as_view(), name='change_password'),
|
||||||
|
path('password-change-done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),
|
||||||
path('', include('bookmarks.urls')),
|
path('', include('bookmarks.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
import debug_toolbar
|
import debug_toolbar
|
||||||
|
|
||||||
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
||||||
|
|
||||||
if ALLOW_REGISTRATION:
|
if ALLOW_REGISTRATION:
|
||||||
|
@@ -1 +1 @@
|
|||||||
1.8.3
|
1.8.5
|
||||||
|
Reference in New Issue
Block a user