mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-24 00:59:35 -06:00
Compare commits
6 Commits
fix-celery
...
fix-max-pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0914a4b34d | ||
|
|
98298e37cd | ||
|
|
35be0850ec | ||
|
|
1bb4b9b473 | ||
|
|
f85094dc2b | ||
|
|
65ca78e9e7 |
@@ -1,5 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## paperless-ngx 2.20.8
|
||||||
|
|
||||||
## paperless-ngx 2.20.7
|
## paperless-ngx 2.20.7
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "paperless-ngx"
|
name = "paperless-ngx"
|
||||||
version = "2.20.7"
|
version = "2.20.8"
|
||||||
description = "A community-supported supercharged document management system: scan, index and archive all your physical documents"
|
description = "A community-supported supercharged document management system: scan, index and archive all your physical documents"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "paperless-ngx-ui",
|
"name": "paperless-ngx-ui",
|
||||||
"version": "2.20.7",
|
"version": "2.20.8",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const environment = {
|
|||||||
apiVersion: '9', // match src/paperless/settings.py
|
apiVersion: '9', // match src/paperless/settings.py
|
||||||
appTitle: 'Paperless-ngx',
|
appTitle: 'Paperless-ngx',
|
||||||
tag: 'prod',
|
tag: 'prod',
|
||||||
version: '2.20.7',
|
version: '2.20.8',
|
||||||
webSocketHost: window.location.host,
|
webSocketHost: window.location.host,
|
||||||
webSocketProtocol: window.location.protocol == 'https:' ? 'wss:' : 'ws:',
|
webSocketProtocol: window.location.protocol == 'https:' ? 'wss:' : 'ws:',
|
||||||
webSocketBaseUrl: base_url.pathname + 'ws/',
|
webSocketBaseUrl: base_url.pathname + 'ws/',
|
||||||
|
|||||||
@@ -151,50 +151,6 @@ class TestSystemStatus(APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data["tasks"]["celery_status"], "OK")
|
self.assertEqual(response.data["tasks"]["celery_status"], "OK")
|
||||||
|
|
||||||
@mock.patch("celery.app.control.Inspect.ping")
|
|
||||||
def test_system_status_celery_ping_none(self, mock_ping) -> None:
|
|
||||||
"""
|
|
||||||
GIVEN:
|
|
||||||
- Celery ping returns no worker responses
|
|
||||||
WHEN:
|
|
||||||
- The user requests the system status
|
|
||||||
THEN:
|
|
||||||
- The response contains an error celery status
|
|
||||||
"""
|
|
||||||
mock_ping.return_value = None
|
|
||||||
self.client.force_login(self.user)
|
|
||||||
response = self.client.get(self.ENDPOINT)
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
self.assertEqual(response.data["tasks"]["celery_status"], "WARNING")
|
|
||||||
self.assertEqual(
|
|
||||||
response.data["tasks"]["celery_error"],
|
|
||||||
"No celery workers responded to ping. This may be temporary.",
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch("documents.views.sleep")
|
|
||||||
@mock.patch("celery.app.control.Inspect.ping")
|
|
||||||
def test_system_status_celery_ping_retry_success(
|
|
||||||
self,
|
|
||||||
mock_ping,
|
|
||||||
mock_sleep,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
GIVEN:
|
|
||||||
- Celery ping fails once but succeeds on retry
|
|
||||||
WHEN:
|
|
||||||
- The user requests the system status
|
|
||||||
THEN:
|
|
||||||
- The response contains an OK celery status
|
|
||||||
"""
|
|
||||||
mock_ping.side_effect = [None, {"hostname": {"ok": "pong"}}]
|
|
||||||
self.client.force_login(self.user)
|
|
||||||
response = self.client.get(self.ENDPOINT)
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
self.assertEqual(response.data["tasks"]["celery_status"], "OK")
|
|
||||||
self.assertIsNone(response.data["tasks"]["celery_error"])
|
|
||||||
self.assertEqual(mock_ping.call_count, 2)
|
|
||||||
mock_sleep.assert_called_once_with(0.25)
|
|
||||||
|
|
||||||
@override_settings(INDEX_DIR=Path("/tmp/index"))
|
@override_settings(INDEX_DIR=Path("/tmp/index"))
|
||||||
@mock.patch("whoosh.index.FileIndex.last_modified")
|
@mock.patch("whoosh.index.FileIndex.last_modified")
|
||||||
def test_system_status_index_ok(self, mock_last_modified):
|
def test_system_status_index_ok(self, mock_last_modified):
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ from collections import deque
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import mktime
|
from time import mktime
|
||||||
from time import sleep
|
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
@@ -3036,29 +3035,11 @@ class SystemStatusView(PassUserMixin):
|
|||||||
celery_error = None
|
celery_error = None
|
||||||
celery_url = None
|
celery_url = None
|
||||||
try:
|
try:
|
||||||
celery_ping = None
|
celery_ping = celery_app.control.inspect().ping()
|
||||||
for ping_attempt in range(3):
|
celery_url = next(iter(celery_ping.keys()))
|
||||||
celery_ping = celery_app.control.inspect().ping()
|
first_worker_ping = celery_ping[celery_url]
|
||||||
if celery_ping:
|
if first_worker_ping["ok"] == "pong":
|
||||||
break
|
celery_active = "OK"
|
||||||
if ping_attempt < 2:
|
|
||||||
sleep(0.25)
|
|
||||||
|
|
||||||
if not celery_ping:
|
|
||||||
celery_active = "WARNING"
|
|
||||||
celery_error = (
|
|
||||||
"No celery workers responded to ping. This may be temporary."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
celery_url, first_worker_ping = next(iter(celery_ping.items()))
|
|
||||||
if (
|
|
||||||
isinstance(first_worker_ping, dict)
|
|
||||||
and first_worker_ping.get("ok") == "pong"
|
|
||||||
):
|
|
||||||
celery_active = "OK"
|
|
||||||
else:
|
|
||||||
celery_active = "WARNING"
|
|
||||||
celery_error = "Celery worker responded unexpectedly."
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
celery_active = "ERROR"
|
celery_active = "ERROR"
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2026-02-23 21:54
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("paperless", "0004_applicationconfiguration_barcode_asn_prefix_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="applicationconfiguration",
|
||||||
|
name="barcode_max_pages",
|
||||||
|
field=models.PositiveIntegerField(
|
||||||
|
null=True,
|
||||||
|
verbose_name="Sets the maximum pages for barcode",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -250,7 +250,6 @@ class ApplicationConfiguration(AbstractSingletonModel):
|
|||||||
barcode_max_pages = models.PositiveIntegerField(
|
barcode_max_pages = models.PositiveIntegerField(
|
||||||
verbose_name=_("Sets the maximum pages for barcode"),
|
verbose_name=_("Sets the maximum pages for barcode"),
|
||||||
null=True,
|
null=True,
|
||||||
validators=[MinValueValidator(1)],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# PAPERLESS_CONSUMER_ENABLE_TAG_BARCODE
|
# PAPERLESS_CONSUMER_ENABLE_TAG_BARCODE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
__version__: Final[tuple[int, int, int]] = (2, 20, 7)
|
__version__: Final[tuple[int, int, int]] = (2, 20, 8)
|
||||||
# Version string like X.Y.Z
|
# Version string like X.Y.Z
|
||||||
__full_version_str__: Final[str] = ".".join(map(str, __version__))
|
__full_version_str__: Final[str] = ".".join(map(str, __version__))
|
||||||
# Version string like X.Y
|
# Version string like X.Y
|
||||||
|
|||||||
@@ -272,6 +272,24 @@ class TestAPIMailAccounts(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data["success"], True)
|
self.assertEqual(response.data["success"], True)
|
||||||
|
|
||||||
|
def test_mail_account_test_existing_nonexistent_id_forbidden(self):
|
||||||
|
response = self.client.post(
|
||||||
|
f"{self.ENDPOINT}test/",
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"id": 999999,
|
||||||
|
"imap_server": "server.example.com",
|
||||||
|
"imap_port": 443,
|
||||||
|
"imap_security": MailAccount.ImapSecurity.SSL,
|
||||||
|
"username": "admin",
|
||||||
|
"password": "******",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
content_type="application/json",
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
self.assertEqual(response.content.decode(), "Insufficient permissions")
|
||||||
|
|
||||||
def test_get_mail_accounts_owner_aware(self):
|
def test_get_mail_accounts_owner_aware(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from datetime import timedelta
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import DatabaseError
|
from django.db import DatabaseError
|
||||||
@@ -1699,6 +1700,10 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
username="testuser",
|
username="testuser",
|
||||||
password="testpassword",
|
password="testpassword",
|
||||||
)
|
)
|
||||||
|
self.user.user_permissions.add(
|
||||||
|
*Permission.objects.filter(codename__in=["add_mailaccount"]),
|
||||||
|
)
|
||||||
|
self.user.save()
|
||||||
self.client.force_authenticate(user=self.user)
|
self.client.force_authenticate(user=self.user)
|
||||||
self.url = "/api/mail_accounts/test/"
|
self.url = "/api/mail_accounts/test/"
|
||||||
|
|
||||||
@@ -1815,6 +1820,54 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
expected_str = "Unable to refresh oauth token"
|
expected_str = "Unable to refresh oauth token"
|
||||||
self.assertIn(expected_str, error_str)
|
self.assertIn(expected_str, error_str)
|
||||||
|
|
||||||
|
def test_mail_account_test_view_existing_forbidden_for_other_owner(self):
|
||||||
|
other_user = User.objects.create_user(
|
||||||
|
username="otheruser",
|
||||||
|
password="testpassword",
|
||||||
|
)
|
||||||
|
existing_account = MailAccount.objects.create(
|
||||||
|
name="Owned account",
|
||||||
|
imap_server="imap.example.com",
|
||||||
|
imap_port=993,
|
||||||
|
imap_security=MailAccount.ImapSecurity.SSL,
|
||||||
|
username="admin",
|
||||||
|
password="secret",
|
||||||
|
owner=other_user,
|
||||||
|
)
|
||||||
|
data = {
|
||||||
|
"id": existing_account.id,
|
||||||
|
"imap_server": "imap.example.com",
|
||||||
|
"imap_port": 993,
|
||||||
|
"imap_security": MailAccount.ImapSecurity.SSL,
|
||||||
|
"username": "admin",
|
||||||
|
"password": "****",
|
||||||
|
"is_token": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(self.url, data, format="json")
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
self.assertEqual(response.content.decode(), "Insufficient permissions")
|
||||||
|
|
||||||
|
def test_mail_account_test_view_requires_add_permission_without_account_id(self):
|
||||||
|
self.user.user_permissions.remove(
|
||||||
|
*Permission.objects.filter(codename__in=["add_mailaccount"]),
|
||||||
|
)
|
||||||
|
self.user.save()
|
||||||
|
data = {
|
||||||
|
"imap_server": "imap.example.com",
|
||||||
|
"imap_port": 993,
|
||||||
|
"imap_security": MailAccount.ImapSecurity.SSL,
|
||||||
|
"username": "admin",
|
||||||
|
"password": "secret",
|
||||||
|
"is_token": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(self.url, data, format="json")
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
self.assertEqual(response.content.decode(), "Insufficient permissions")
|
||||||
|
|
||||||
|
|
||||||
class TestMailAccountProcess(APITestCase):
|
class TestMailAccountProcess(APITestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
@@ -86,13 +86,34 @@ class MailAccountViewSet(ModelViewSet, PassUserMixin):
|
|||||||
request.data["name"] = datetime.datetime.now().isoformat()
|
request.data["name"] = datetime.datetime.now().isoformat()
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
existing_account = None
|
||||||
|
account_id = request.data.get("id")
|
||||||
|
|
||||||
# account exists, use the password from there instead of *** and refresh_token / expiration
|
# testing a new connection requires add permission
|
||||||
|
if account_id is None and not request.user.has_perms(
|
||||||
|
["paperless_mail.add_mailaccount"],
|
||||||
|
):
|
||||||
|
return HttpResponseForbidden("Insufficient permissions")
|
||||||
|
|
||||||
|
# testing an existing account requires change permission on that account
|
||||||
|
if account_id is not None:
|
||||||
|
try:
|
||||||
|
existing_account = MailAccount.objects.get(pk=account_id)
|
||||||
|
except (TypeError, ValueError, MailAccount.DoesNotExist):
|
||||||
|
return HttpResponseForbidden("Insufficient permissions")
|
||||||
|
|
||||||
|
if not has_perms_owner_aware(
|
||||||
|
request.user,
|
||||||
|
"change_mailaccount",
|
||||||
|
existing_account,
|
||||||
|
):
|
||||||
|
return HttpResponseForbidden("Insufficient permissions")
|
||||||
|
|
||||||
|
# account exists, use the password from there instead of ***
|
||||||
if (
|
if (
|
||||||
len(serializer.validated_data.get("password").replace("*", "")) == 0
|
len(serializer.validated_data.get("password").replace("*", "")) == 0
|
||||||
and request.data["id"] is not None
|
and existing_account is not None
|
||||||
):
|
):
|
||||||
existing_account = MailAccount.objects.get(pk=request.data["id"])
|
|
||||||
serializer.validated_data["password"] = existing_account.password
|
serializer.validated_data["password"] = existing_account.password
|
||||||
serializer.validated_data["account_type"] = existing_account.account_type
|
serializer.validated_data["account_type"] = existing_account.account_type
|
||||||
serializer.validated_data["refresh_token"] = existing_account.refresh_token
|
serializer.validated_data["refresh_token"] = existing_account.refresh_token
|
||||||
@@ -106,7 +127,8 @@ class MailAccountViewSet(ModelViewSet, PassUserMixin):
|
|||||||
) as M:
|
) as M:
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
account.is_token
|
existing_account is not None
|
||||||
|
and account.is_token
|
||||||
and account.expiration is not None
|
and account.expiration is not None
|
||||||
and account.expiration < timezone.now()
|
and account.expiration < timezone.now()
|
||||||
):
|
):
|
||||||
@@ -248,6 +270,7 @@ class OauthCallbackView(GenericAPIView):
|
|||||||
imap_server=imap_server,
|
imap_server=imap_server,
|
||||||
refresh_token=refresh_token,
|
refresh_token=refresh_token,
|
||||||
expiration=timezone.now() + timedelta(seconds=expires_in),
|
expiration=timezone.now() + timedelta(seconds=expires_in),
|
||||||
|
owner=request.user,
|
||||||
defaults=defaults,
|
defaults=defaults,
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
|
|||||||
2
uv.lock
generated
2
uv.lock
generated
@@ -1991,7 +1991,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "paperless-ngx"
|
name = "paperless-ngx"
|
||||||
version = "2.20.7"
|
version = "2.20.8"
|
||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "babel", marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },
|
{ name = "babel", marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },
|
||||||
|
|||||||
Reference in New Issue
Block a user