mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-03 09:48:41 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b2b635090 | ||
|
|
9a6b0b092f | ||
|
|
3f5d14bf05 | ||
|
|
aa44ff75e1 | ||
|
|
b783d5e895 |
No files matched your search
@@ -104,7 +104,7 @@ jobs:
|
||||
with:
|
||||
python-version: "${{ matrix.python-version }}"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: true
|
||||
@@ -174,7 +174,7 @@ jobs:
|
||||
with:
|
||||
python-version: "${{ env.DEFAULT_PYTHON }}"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: true
|
||||
|
||||
@@ -109,7 +109,7 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
@@ -139,8 +139,6 @@ jobs:
|
||||
file: ./Dockerfile
|
||||
platforms: ${{ matrix.platform }}
|
||||
labels: ${{ steps.docker-meta.outputs.labels }}
|
||||
sbom: true
|
||||
provenance: mode=max
|
||||
build-args: |
|
||||
PNGX_TAG_VERSION=${{ steps.docker-meta.outputs.version }}
|
||||
outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.repo.outputs.name }},push-by-digest=true,name-canonical=true,push=${{ steps.check-push.outputs.should-push }}
|
||||
@@ -173,7 +171,6 @@ jobs:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
||||
@@ -188,20 +185,20 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Login to Docker Hub
|
||||
if: needs.build-arch.outputs.push-external == 'true'
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Login to Quay.io
|
||||
if: needs.build-arch.outputs.push-external == 'true'
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
|
||||
with:
|
||||
registry: quay.io
|
||||
username: ${{ secrets.QUAY_USERNAME }}
|
||||
@@ -261,25 +258,3 @@ jobs:
|
||||
echo "Copying ${tag} to ${quay_tag}"
|
||||
skopeo copy --all "docker://${tag}" "docker://${quay_tag}"
|
||||
done
|
||||
- name: Install cosign
|
||||
uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4.1.4
|
||||
- name: Sign images (keyless)
|
||||
env:
|
||||
FIRST_TAG: ${{ fromJSON(steps.docker-meta.outputs.json).tags[0] }}
|
||||
GHCR_REPO: ${{ env.REGISTRY }}/${{ needs.build-arch.outputs.repository }}
|
||||
PUSH_EXTERNAL: ${{ needs.build-arch.outputs.push-external }}
|
||||
run: |
|
||||
digest=$(docker buildx imagetools inspect "${FIRST_TAG}" --format '{{json .Manifest}}' | jq -r '.digest')
|
||||
echo "Signing manifest list ${digest}"
|
||||
|
||||
repos=("${GHCR_REPO}")
|
||||
if [ "${PUSH_EXTERNAL}" == "true" ]; then
|
||||
repos+=("docker.io/paperlessngx/paperless-ngx" "quay.io/paperlessngx/paperless-ngx")
|
||||
fi
|
||||
|
||||
for repo in "${repos[@]}"; do
|
||||
echo "Verifying digest in ${repo}"
|
||||
docker buildx imagetools inspect "${repo}@${digest}" > /dev/null
|
||||
echo "Signing ${repo}@${digest}"
|
||||
cosign sign --yes "${repo}@${digest}"
|
||||
done
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: true
|
||||
|
||||
@@ -83,7 +83,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
@@ -115,7 +115,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
@@ -154,7 +154,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
@@ -203,7 +203,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
@@ -218,7 +218,7 @@ jobs:
|
||||
with:
|
||||
python-version: '3.12'
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: '0.13.x'
|
||||
enable-cache: false
|
||||
@@ -258,7 +258,7 @@ jobs:
|
||||
fetch-depth: 2
|
||||
persist-credentials: false
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
|
||||
@@ -26,4 +26,4 @@ jobs:
|
||||
with:
|
||||
python-version: "3.14"
|
||||
- name: Run prek
|
||||
uses: j178/prek-action@44924fe9ef4a6f88253c4b6b1bf11c689d3ce53d # v3.1.0
|
||||
uses: j178/prek-action@7b101f8338a08d2bd6fdb3625e4e7692428763a3 # v3.1.1
|
||||
@@ -40,7 +40,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
# ---- Frontend Build ----
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: false
|
||||
@@ -172,7 +172,7 @@ jobs:
|
||||
fi
|
||||
- name: Create release and changelog
|
||||
id: create-release
|
||||
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
|
||||
uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0
|
||||
with:
|
||||
name: Paperless-ngx ${{ steps.get-version.outputs.version }}
|
||||
tag: ${{ steps.get-version.outputs.version }}
|
||||
@@ -213,7 +213,7 @@ jobs:
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: false
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Run zizmor
|
||||
uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0
|
||||
uses: zizmorcore/zizmor-action@1b4550e929643b8b26a62303c6bd64814271a4f1 # v0.9.2
|
||||
semgrep:
|
||||
name: Semgrep CE
|
||||
runs-on: ubuntu-26.04
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
- name: Run Semgrep
|
||||
run: semgrep scan --config auto --sarif-output results.sarif
|
||||
- name: Upload results to GitHub code scanning
|
||||
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||
uses: github/codeql-action/upload-sarif@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
|
||||
if: always()
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -47,4 +47,4 @@ jobs:
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
token: ${{ secrets.PNGX_BOT_PAT }}
|
||||
persist-credentials: false
|
||||
- name: crowdin action
|
||||
uses: crowdin/github-action@959dc74ac104447731cba99a016f85d0ae719788 # v3.5.0
|
||||
uses: crowdin/github-action@d651c77756acbe11a31d77a6fb79d8a239e1e05a # v3.6.0
|
||||
with:
|
||||
upload_translations: false
|
||||
download_translations: true
|
||||
|
||||
@@ -19,6 +19,6 @@ jobs:
|
||||
if: github.event_name == 'pull_request_target' && (github.event.action == 'opened' || github.event.action == 'reopened') && github.event.pull_request.user.login != 'dependabot'
|
||||
steps:
|
||||
- name: Label PR with release-drafter
|
||||
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
|
||||
uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -30,7 +30,7 @@ jobs:
|
||||
with:
|
||||
packages: gettext
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
||||
with:
|
||||
version: ${{ env.DEFAULT_UV_VERSION }}
|
||||
enable-cache: true
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
PAPERLESS_SECRET_KEY: "ci-translate-not-a-real-secret"
|
||||
run: cd src/ && uv run manage.py makemessages -l en_US -i "samples*"
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
||||
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
||||
with:
|
||||
package_json_file: src-ui/package.json
|
||||
- name: Use Node.js 24
|
||||
|
||||
@@ -38,7 +38,7 @@ repos:
|
||||
- json
|
||||
# See https://github.com/prettier/prettier/issues/15742 for the fork reason
|
||||
- repo: https://github.com/rbubley/mirrors-prettier
|
||||
rev: 'v3.9.10'
|
||||
rev: 'v3.10.1'
|
||||
hooks:
|
||||
- id: prettier
|
||||
types_or:
|
||||
@@ -46,7 +46,7 @@ repos:
|
||||
- ts
|
||||
- markdown
|
||||
additional_dependencies:
|
||||
- prettier@3.9.10
|
||||
- prettier@3.10.1
|
||||
- 'prettier-plugin-organize-imports@4.3.0'
|
||||
# Python hooks
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
@@ -55,7 +55,7 @@ repos:
|
||||
- id: ruff-check
|
||||
- id: ruff-format
|
||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||
rev: "v2.30.3"
|
||||
rev: "v2.31.2"
|
||||
hooks:
|
||||
- id: pyproject-fmt
|
||||
additional_dependencies: [tomli]
|
||||
|
||||
+8
-8
@@ -19,7 +19,7 @@ classifiers = [
|
||||
dependencies = [
|
||||
"azure-ai-documentintelligence>=1.0.2",
|
||||
"babel>=2.17",
|
||||
"celery[redis]~=5.6.2",
|
||||
"celery[redis]~=5.7.0",
|
||||
"channels~=4.2",
|
||||
"channels-redis~=4.2",
|
||||
"concurrent-log-handler~=0.9.25",
|
||||
@@ -27,7 +27,7 @@ dependencies = [
|
||||
"dateparser~=1.4",
|
||||
# WARNING: django does not use semver.
|
||||
# Only patch versions are guaranteed to not introduce breaking changes.
|
||||
"django~=5.2.18",
|
||||
"django~=5.2.19",
|
||||
"django-allauth[mfa,socialaccount]~=65.21.1",
|
||||
"django-auditlog~=3.4.1",
|
||||
"django-cachalot~=2.9.0",
|
||||
@@ -49,7 +49,7 @@ dependencies = [
|
||||
"httpx-oauth~=0.17",
|
||||
"humanize>=4.15",
|
||||
"ijson>=3.5.1",
|
||||
"imap-tools>=1.14,<1.16",
|
||||
"imap-tools>=1.14,<1.17",
|
||||
"jinja2~=3.1.6",
|
||||
"langdetect~=1.0.9",
|
||||
"llama-index-core>=0.14.23",
|
||||
@@ -79,8 +79,8 @@ dependencies = [
|
||||
"sqlite-vec==0.1.10+paperless.3",
|
||||
"tantivy~=0.26.0",
|
||||
"tika-client[httpx]~=1.0",
|
||||
"torch>=2.13,<2.15",
|
||||
"turbohtml~=1.15.3",
|
||||
"torch>=2.13,<2.16",
|
||||
"turbohtml~=1.16.0",
|
||||
"watchfiles>=1.2",
|
||||
"whitenoise~=6.11",
|
||||
"whoosh-compat[tantivy]==0.3",
|
||||
@@ -116,15 +116,15 @@ lint = [
|
||||
testing = [
|
||||
"daphne",
|
||||
"factory-boy~=3.3.1",
|
||||
"faker>=40.36,<40.44",
|
||||
"faker>=40.36,<40.64",
|
||||
"imagehash",
|
||||
"pytest~=9.1.1",
|
||||
"pytest~=9.2.0",
|
||||
"pytest-cov~=7.1.0",
|
||||
"pytest-django>=4.12,<4.15",
|
||||
"pytest-env~=1.8.1",
|
||||
"pytest-httpx",
|
||||
"pytest-mock~=3.17.0",
|
||||
"pytest-randomly~=5.0.0",
|
||||
"pytest-randomly~=5.1.0",
|
||||
"pytest-rerunfailures~=16.4",
|
||||
"pytest-sugar",
|
||||
"pytest-xdist~=3.8.0",
|
||||
|
||||
@@ -73,9 +73,10 @@ def get_suggestion_cache(document_id: int) -> SuggestionCacheData | None:
|
||||
|
||||
doc_key = get_suggestion_cache_key(document_id)
|
||||
cache_hits = cache.get_many([CLASSIFIER_VERSION_KEY, CLASSIFIER_HASH_KEY, doc_key])
|
||||
# The document suggestions are in the cache
|
||||
if doc_key in cache_hits:
|
||||
doc_suggestions: SuggestionCacheData = cache_hits[doc_key]
|
||||
# The document suggestions are in the cache. get_many keeps an entry the cache
|
||||
# serializer rejected as None, rather than leaving the key out.
|
||||
doc_suggestions: SuggestionCacheData | None = cache_hits.get(doc_key)
|
||||
if doc_suggestions is not None:
|
||||
# The classifier format is the same
|
||||
# The classifier hash is the same
|
||||
# Then the suggestions can be used
|
||||
|
||||
@@ -19,7 +19,7 @@ from documents.models import StoragePath
|
||||
from documents.models import Tag
|
||||
from documents.models import Workflow
|
||||
from documents.models import WorkflowTrigger
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.permissions import permitted_object_ids
|
||||
from documents.regex import safe_regex_search
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -55,10 +55,8 @@ def match_correspondents(document: Document, classifier: DocumentClassifier, use
|
||||
user = document.owner
|
||||
|
||||
if user is not None:
|
||||
correspondents = restrict_queryset_to_visible(
|
||||
Correspondent.objects.all(),
|
||||
user,
|
||||
"view_correspondent",
|
||||
correspondents = Correspondent.objects.filter(
|
||||
id__in=permitted_object_ids(user, Correspondent, "view_correspondent"),
|
||||
)
|
||||
else:
|
||||
correspondents = Correspondent.objects.all()
|
||||
@@ -86,10 +84,8 @@ def match_document_types(document: Document, classifier: DocumentClassifier, use
|
||||
user = document.owner
|
||||
|
||||
if user is not None:
|
||||
document_types = restrict_queryset_to_visible(
|
||||
DocumentType.objects.all(),
|
||||
user,
|
||||
"view_documenttype",
|
||||
document_types = DocumentType.objects.filter(
|
||||
id__in=permitted_object_ids(user, DocumentType, "view_documenttype"),
|
||||
)
|
||||
else:
|
||||
document_types = DocumentType.objects.all()
|
||||
@@ -116,10 +112,8 @@ def match_tags(document: Document, classifier: DocumentClassifier, user=None):
|
||||
user = document.owner
|
||||
|
||||
if user is not None:
|
||||
tags = restrict_queryset_to_visible(
|
||||
Tag.objects.all(),
|
||||
user,
|
||||
"view_tag",
|
||||
tags = Tag.objects.filter(
|
||||
id__in=permitted_object_ids(user, Tag, "view_tag"),
|
||||
)
|
||||
else:
|
||||
tags = Tag.objects.all()
|
||||
@@ -149,10 +143,8 @@ def match_storage_paths(document: Document, classifier: DocumentClassifier, user
|
||||
user = document.owner
|
||||
|
||||
if user is not None:
|
||||
storage_paths = restrict_queryset_to_visible(
|
||||
StoragePath.objects.all(),
|
||||
user,
|
||||
"view_storagepath",
|
||||
storage_paths = StoragePath.objects.filter(
|
||||
id__in=permitted_object_ids(user, StoragePath, "view_storagepath"),
|
||||
)
|
||||
else:
|
||||
storage_paths = StoragePath.objects.all()
|
||||
|
||||
@@ -435,33 +435,31 @@ def annotate_authorizing_fields(
|
||||
)
|
||||
|
||||
|
||||
def user_is_active_superuser(user: User | None) -> bool:
|
||||
def user_is_unrestricted(user: User | None) -> bool:
|
||||
"""
|
||||
True only for an active, authenticated superuser. ``None`` is not one.
|
||||
True when ``user`` means "no restriction at all" (an absent user, or an
|
||||
*active* superuser) without needing a database check to know it.
|
||||
|
||||
``permitted_object_ids(None, ...)`` itself means the much narrower "only
|
||||
unowned rows", which is NOT the same thing as "no user filtering
|
||||
requested", so callers must special-case this before ever calling it.
|
||||
A deactivated superuser is deliberately NOT unrestricted here, matching
|
||||
permitted_object_ids's own is_active-before-is_superuser ordering.
|
||||
|
||||
Callers that can avoid a database round trip entirely when this is true
|
||||
(e.g. checking a single already-loaded object's visibility rather than
|
||||
filtering a queryset) should do so via this function directly, rather
|
||||
than through restrict_queryset_to_visible() below.
|
||||
"""
|
||||
if user is None:
|
||||
return True
|
||||
return (
|
||||
user is not None
|
||||
and getattr(user, "is_authenticated", False)
|
||||
getattr(user, "is_authenticated", False)
|
||||
and getattr(user, "is_active", False)
|
||||
and getattr(user, "is_superuser", False)
|
||||
)
|
||||
|
||||
|
||||
def user_is_unrestricted(user: User | None) -> bool:
|
||||
"""
|
||||
True when ``user`` means "no restriction at all": an absent user, or an
|
||||
active superuser.
|
||||
|
||||
This is for callers that treat "no user" as "do not filter", such as a
|
||||
system-triggered code path. It is NOT how ``permitted_object_ids`` and
|
||||
``restrict_queryset_to_visible`` read ``None``: they take it to mean "no
|
||||
identity", which sees only unowned rows. A deactivated superuser is not
|
||||
unrestricted, matching ``permitted_object_ids``'s is_active-before-
|
||||
is_superuser ordering.
|
||||
"""
|
||||
return user is None or user_is_active_superuser(user)
|
||||
|
||||
|
||||
def restrict_queryset_to_visible(
|
||||
queryset: QuerySet[ModelT],
|
||||
user: User | None,
|
||||
@@ -470,14 +468,38 @@ def restrict_queryset_to_visible(
|
||||
"""
|
||||
Restrict ``queryset`` to the rows ``user`` may see with ``perm``.
|
||||
|
||||
``user=None`` means no identity and sees only unowned rows, exactly as in
|
||||
``permitted_object_ids``. A caller that wants "no restriction" when there
|
||||
is no user has to say so itself rather than rely on ``None``.
|
||||
Delegates the visibility check to the database as a
|
||||
``WHERE id IN (subquery)`` rather than materializing the full
|
||||
permitted-id set into a Python collection first: a caller that only
|
||||
needs to check a small handful of rows (a resolved-id list, a few
|
||||
RAG-neighbour candidate ids) never pays for scanning or holding the
|
||||
installation's entire taxonomy in memory to do it.
|
||||
|
||||
The check is a ``WHERE id IN (subquery)`` rather than a materialized id
|
||||
set, so a caller that only checks a handful of rows never scans or holds
|
||||
the installation's whole taxonomy. An active superuser skips the subquery
|
||||
entirely and gets ``queryset`` back unchanged.
|
||||
Returns ``queryset`` unchanged for user_is_unrestricted(user); every
|
||||
other case is delegated to ``permitted_object_ids`` rather than
|
||||
re-deciding the ordering here.
|
||||
"""
|
||||
if user_is_unrestricted(user):
|
||||
return queryset
|
||||
return queryset.filter(pk__in=permitted_object_ids(user, queryset.model, perm))
|
||||
|
||||
|
||||
def user_is_active_superuser(user: User | None) -> bool:
|
||||
"""
|
||||
True only for an active, authenticated superuser.
|
||||
"""
|
||||
return user is not None and user_is_unrestricted(user)
|
||||
|
||||
|
||||
def restrict_queryset_to_owner_visible(
|
||||
queryset: QuerySet[ModelT],
|
||||
user: User | None,
|
||||
perm: str,
|
||||
) -> QuerySet[ModelT]:
|
||||
"""
|
||||
Like ``restrict_queryset_to_visible``, but ``user=None`` sees only unowned
|
||||
rows (``permitted_object_ids(None, ...)`` semantics) instead of every row.
|
||||
See ``user_is_active_superuser``.
|
||||
"""
|
||||
if user_is_active_superuser(user):
|
||||
return queryset
|
||||
|
||||
@@ -86,6 +86,7 @@ from documents.permissions import get_document_count_filter_for_user
|
||||
from documents.permissions import get_permission_grantees
|
||||
from documents.permissions import has_perms_owner_aware
|
||||
from documents.permissions import permitted_document_ids
|
||||
from documents.permissions import permitted_object_ids
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.permissions import set_permissions_for_objects
|
||||
from documents.regex import validate_regex_pattern
|
||||
@@ -596,9 +597,7 @@ class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer):
|
||||
.annotate(document_count=Count("documents", filter=filter_q))
|
||||
)
|
||||
user = getattr(request, "user", None) if request else self.user
|
||||
# No user at all (no request, no serializer user) means no restriction
|
||||
if user is not None:
|
||||
children = restrict_queryset_to_visible(children, user, "view_tag")
|
||||
children = restrict_queryset_to_visible(children, user, "view_tag")
|
||||
|
||||
view = self.context.get("view")
|
||||
ordering = (
|
||||
@@ -1797,10 +1796,8 @@ class RunZoneOcrSerializer(serializers.Serializer[Any]):
|
||||
serializers.PrimaryKeyRelatedField,
|
||||
): # pragma: no cover
|
||||
return
|
||||
template_field.queryset = restrict_queryset_to_visible(
|
||||
OcrTemplate.objects.all(),
|
||||
user,
|
||||
"view_ocrtemplate",
|
||||
template_field.queryset = OcrTemplate.objects.filter(
|
||||
id__in=permitted_object_ids(user, OcrTemplate, "view_ocrtemplate"),
|
||||
).prefetch_related("zones", "zones__custom_field")
|
||||
|
||||
|
||||
|
||||
@@ -85,14 +85,11 @@ DRF_DATETIME_FIELD = serializers.DateTimeField()
|
||||
|
||||
|
||||
def add_inbox_tags(sender, document: Document, logging_group=None, **kwargs) -> None:
|
||||
inbox_tags = Tag.objects.filter(is_inbox_tag=True)
|
||||
# An unowned document gets every inbox tag, not just the unowned ones
|
||||
if document.owner is not None:
|
||||
inbox_tags = restrict_queryset_to_visible(
|
||||
inbox_tags,
|
||||
document.owner,
|
||||
"view_tag",
|
||||
)
|
||||
inbox_tags = restrict_queryset_to_visible(
|
||||
Tag.objects.filter(is_inbox_tag=True),
|
||||
document.owner,
|
||||
"view_tag",
|
||||
)
|
||||
document.add_nested_tags(inbox_tags)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from documents.caching import CLASSIFIER_VERSION_KEY
|
||||
from documents.caching import get_suggestion_cache
|
||||
from documents.caching import get_suggestion_cache_key
|
||||
from documents.classifier import DocumentClassifier
|
||||
|
||||
|
||||
class TestGetSuggestionCache:
|
||||
def test_rejected_entry_is_a_cache_miss(self, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A document suggestion entry the cache serializer rejected, which
|
||||
get_many reports as None
|
||||
- A classifier version entry matching the current format
|
||||
WHEN:
|
||||
- The suggestion cache is read
|
||||
THEN:
|
||||
- It is treated as a cache miss
|
||||
"""
|
||||
doc_key = get_suggestion_cache_key(1)
|
||||
mocker.patch(
|
||||
"documents.caching.cache.get_many",
|
||||
return_value={
|
||||
CLASSIFIER_VERSION_KEY: DocumentClassifier.FORMAT_VERSION,
|
||||
doc_key: None,
|
||||
},
|
||||
)
|
||||
|
||||
assert get_suggestion_cache(1) is None
|
||||
@@ -24,9 +24,7 @@ from documents.permissions import has_perms_owner_aware
|
||||
from documents.permissions import permitted_document_ids
|
||||
from documents.permissions import permitted_object_ids
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.serialisers import TagSerializer
|
||||
from documents.serialisers import _get_viewable_duplicates
|
||||
from documents.signals.handlers import add_inbox_tags
|
||||
from paperless_testing.factories import CorrespondentFactory
|
||||
from paperless_testing.factories import DocumentFactory
|
||||
from paperless_testing.factories import DocumentTypeFactory
|
||||
@@ -1287,34 +1285,25 @@ class TestBulkEditObjectsTagDescendantPartialPermission:
|
||||
@pytest.mark.django_db
|
||||
class TestRestrictQuerysetToVisible:
|
||||
"""restrict_queryset_to_visible() returns its queryset argument
|
||||
unchanged only for an active superuser, so the cases that may do that
|
||||
have to be kept narrow."""
|
||||
unchanged only for "no restriction at all", so the cases that may do
|
||||
that have to be kept narrow."""
|
||||
|
||||
def test_no_user_sees_only_unowned_rows(self) -> None:
|
||||
def test_no_user_means_no_restriction(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- No user at all (a system-triggered call)
|
||||
- One owned and one unowned tag
|
||||
WHEN:
|
||||
- restrict_queryset_to_visible() is called
|
||||
THEN:
|
||||
- Only the unowned tag is visible, matching permitted_object_ids
|
||||
for None, never the whole queryset
|
||||
- The queryset is returned unfiltered, rather than
|
||||
permitted_object_ids(None, ...)'s narrower "unowned rows only"
|
||||
"""
|
||||
owner = UserFactory(username="vis_none_owner")
|
||||
owned = TagFactory(owner=owner)
|
||||
unowned = TagFactory(owner=None)
|
||||
tag = TagFactory(owner=owner)
|
||||
|
||||
visible_ids = set(
|
||||
restrict_queryset_to_visible(
|
||||
Tag.objects.all(),
|
||||
None,
|
||||
"view_tag",
|
||||
).values_list("pk", flat=True),
|
||||
)
|
||||
visible = restrict_queryset_to_visible(Tag.objects.all(), None, "view_tag")
|
||||
|
||||
assert unowned.pk in visible_ids
|
||||
assert owned.pk not in visible_ids
|
||||
assert tag.pk in visible.values_list("pk", flat=True)
|
||||
|
||||
def test_active_superuser_means_no_restriction(self) -> None:
|
||||
"""
|
||||
@@ -1483,89 +1472,3 @@ class TestGetPermissionGrantees:
|
||||
"change": {"users": [], "groups": []},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestAddInboxTagsVisibility:
|
||||
def test_unowned_document_gets_every_inbox_tag(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An unowned document
|
||||
- An inbox tag owned by a user and an unowned inbox tag
|
||||
WHEN:
|
||||
- add_inbox_tags() runs for the document
|
||||
THEN:
|
||||
- Both inbox tags are added, since an unowned document is not
|
||||
restricted to unowned tags
|
||||
"""
|
||||
owner = UserFactory(username="inbox_owner")
|
||||
owned = TagFactory(owner=owner, is_inbox_tag=True)
|
||||
unowned = TagFactory(owner=None, is_inbox_tag=True)
|
||||
doc = DocumentFactory(owner=None)
|
||||
|
||||
add_inbox_tags(sender=None, document=doc)
|
||||
|
||||
assert set(doc.tags.values_list("pk", flat=True)) == {owned.pk, unowned.pk}
|
||||
|
||||
def test_owned_document_only_gets_inbox_tags_its_owner_can_view(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A document owned by one user
|
||||
- An inbox tag owned by the same user, one owned by someone else,
|
||||
and one unowned
|
||||
WHEN:
|
||||
- add_inbox_tags() runs for the document
|
||||
THEN:
|
||||
- Only the owner's tag and the unowned tag are added
|
||||
"""
|
||||
owner = UserFactory(username="inbox_doc_owner")
|
||||
other = UserFactory(username="inbox_other")
|
||||
own = TagFactory(owner=owner, is_inbox_tag=True)
|
||||
hidden = TagFactory(owner=other, is_inbox_tag=True)
|
||||
unowned = TagFactory(owner=None, is_inbox_tag=True)
|
||||
doc = DocumentFactory(owner=owner)
|
||||
|
||||
add_inbox_tags(sender=None, document=doc)
|
||||
|
||||
added = set(doc.tags.values_list("pk", flat=True))
|
||||
assert added == {own.pk, unowned.pk}
|
||||
assert hidden.pk not in added
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestTagSerializerChildrenVisibility:
|
||||
def test_no_user_and_no_request_shows_every_child(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A tag with a child owned by another user
|
||||
- A TagSerializer with neither a request nor a user
|
||||
WHEN:
|
||||
- The children are serialized
|
||||
THEN:
|
||||
- The child is listed, since no user at all means no restriction
|
||||
here, unlike restrict_queryset_to_visible(None)
|
||||
"""
|
||||
parent = TagFactory(owner=None)
|
||||
child = TagFactory(owner=UserFactory(), tn_parent=parent)
|
||||
|
||||
serializer = TagSerializer(parent, context={})
|
||||
|
||||
assert {entry["id"] for entry in serializer.data["children"]} == {child.pk}
|
||||
|
||||
def test_serializer_user_without_request_hides_unviewable_child(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A tag with a child owned by another user
|
||||
- A TagSerializer given a regular user but no request
|
||||
WHEN:
|
||||
- The children are serialized
|
||||
THEN:
|
||||
- The child is not listed, the user having no view permission on it
|
||||
"""
|
||||
parent = TagFactory(owner=None)
|
||||
TagFactory(owner=UserFactory(), tn_parent=parent)
|
||||
viewer = UserFactory()
|
||||
|
||||
serializer = TagSerializer(parent, user=viewer, context={})
|
||||
|
||||
assert serializer.data["children"] == []
|
||||
+7
-11
@@ -662,13 +662,11 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet[Tag]):
|
||||
user = getattr(getattr(self, "request", None), "user", None)
|
||||
children_source = list(
|
||||
annotate_document_count_for_related_queryset(
|
||||
restrict_queryset_to_visible(
|
||||
Tag.objects.filter(
|
||||
pk__in=descendant_pks | {t.pk for t in all_tags},
|
||||
),
|
||||
user,
|
||||
"view_tag",
|
||||
).select_related("owner"),
|
||||
Tag.objects.filter(
|
||||
pk__in=descendant_pks | {t.pk for t in all_tags},
|
||||
)
|
||||
.filter(pk__in=permitted_object_ids(user, Tag, "view_tag"))
|
||||
.select_related("owner"),
|
||||
through_model=self.document_count_through,
|
||||
related_object_field=self._get_document_count_source_field(),
|
||||
user=user,
|
||||
@@ -5333,10 +5331,8 @@ class BulkEditObjectsView(PassUserMixin):
|
||||
"document_types": DocumentTypeFilterSet,
|
||||
"storage_paths": StoragePathFilterSet,
|
||||
}[object_type]
|
||||
user_permitted_objects = restrict_queryset_to_visible(
|
||||
object_class.objects.all(),
|
||||
user,
|
||||
perm_codename,
|
||||
user_permitted_objects = object_class.objects.filter(
|
||||
id__in=permitted_object_ids(user, object_class, perm_codename),
|
||||
)
|
||||
objs = filterset_class(
|
||||
data=filters,
|
||||
|
||||
@@ -44,7 +44,7 @@ from documents.models import OcrTemplate
|
||||
from documents.models import OcrTemplateZone
|
||||
from documents.parsers import ParseError
|
||||
from documents.parsers import rasterize_pdf_page_to_png
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.permissions import permitted_object_ids
|
||||
from documents.regex import safe_regex_fullmatch
|
||||
from documents.validators import monetary_validator
|
||||
from documents.versioning import get_root_document
|
||||
@@ -261,12 +261,12 @@ def _visible_templates(
|
||||
"""The enabled templates both the owner and the requester can view, if given."""
|
||||
templates = OcrTemplate.objects.filter(enabled=True)
|
||||
if owner is not None:
|
||||
templates = restrict_queryset_to_visible(templates, owner, "view_ocrtemplate")
|
||||
templates = templates.filter(
|
||||
id__in=permitted_object_ids(owner, OcrTemplate, "view_ocrtemplate"),
|
||||
)
|
||||
if requester is not None:
|
||||
templates = restrict_queryset_to_visible(
|
||||
templates,
|
||||
requester,
|
||||
"view_ocrtemplate",
|
||||
templates = templates.filter(
|
||||
id__in=permitted_object_ids(requester, OcrTemplate, "view_ocrtemplate"),
|
||||
)
|
||||
return templates.order_by("name", "pk").prefetch_related(
|
||||
"zones",
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from paperless.signed_pickle import SignedPickleError
|
||||
from paperless.signed_pickle import signed_pickle_dumps
|
||||
from paperless.signed_pickle import signed_pickle_loads
|
||||
|
||||
logger = logging.getLogger("paperless.cache")
|
||||
|
||||
|
||||
class SignedRedisSerializer:
|
||||
"""
|
||||
Cache serializer for Django's RedisCache which HMAC-signs every pickled value.
|
||||
|
||||
Django's default serializer unpickles whatever it finds under a key, so anything
|
||||
able to write to the Redis instance could get code run in the web server, for
|
||||
example through a session entry. Values are signed with SECRET_KEY on write and
|
||||
verified before unpickling on read, the same protection the Celery messages on
|
||||
the same broker have.
|
||||
|
||||
An entry that fails verification is dropped and reported as a cache miss.
|
||||
"""
|
||||
|
||||
def dumps(self, obj: Any) -> bytes | int:
|
||||
# Like Django's own serializer, keep plain integers unpickled so incr() and
|
||||
# decr() stay atomic. Using type() rather than isinstance() excludes bool.
|
||||
if type(obj) is int:
|
||||
return obj
|
||||
return signed_pickle_dumps(obj)
|
||||
|
||||
def loads(self, data: bytes) -> Any:
|
||||
try:
|
||||
return int(data)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
return signed_pickle_loads(data)
|
||||
except SignedPickleError:
|
||||
logger.warning("Ignoring cache entry with an invalid signature")
|
||||
return None
|
||||
@@ -807,17 +807,23 @@ _CACHE_BACKEND = os.environ.get(
|
||||
)
|
||||
|
||||
|
||||
# Entries are HMAC-signed so values planted in Redis are never unpickled
|
||||
_CACHE_OPTIONS = {"serializer": "paperless.cache.SignedRedisSerializer"}
|
||||
|
||||
|
||||
def _parse_caches():
|
||||
return {
|
||||
"default": {
|
||||
"BACKEND": _CACHE_BACKEND,
|
||||
"LOCATION": _CHANNELS_REDIS_URL,
|
||||
"KEY_PREFIX": _REDIS_KEY_PREFIX,
|
||||
"OPTIONS": _CACHE_OPTIONS,
|
||||
},
|
||||
"read-cache": {
|
||||
"BACKEND": _CACHE_BACKEND,
|
||||
"LOCATION": cachalot_settings["CACHALOT_REDIS_URL"],
|
||||
"KEY_PREFIX": _REDIS_KEY_PREFIX,
|
||||
"OPTIONS": _CACHE_OPTIONS,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import pickle
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
|
||||
from paperless.cache import SignedRedisSerializer
|
||||
from paperless.signed_pickle import compute_signature
|
||||
|
||||
|
||||
class _Evil:
|
||||
def __init__(self, marker: Path) -> None:
|
||||
self.marker = marker
|
||||
|
||||
def __reduce__(self) -> tuple[Any, tuple[str]]:
|
||||
return (self.marker.write_text, ("pwned",))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def serializer() -> SignedRedisSerializer:
|
||||
return SignedRedisSerializer()
|
||||
|
||||
|
||||
class TestSignedRedisSerializer:
|
||||
def test_round_trip(self, serializer: SignedRedisSerializer) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A nested value
|
||||
WHEN:
|
||||
- It is serialized and then deserialized
|
||||
THEN:
|
||||
- The original value is returned
|
||||
"""
|
||||
value = {"a": [1, 2, 3], "b": ("x", None)}
|
||||
|
||||
assert serializer.loads(serializer.dumps(value)) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "stored_type"),
|
||||
[
|
||||
pytest.param(7, int, id="int"),
|
||||
pytest.param(True, bytes, id="bool"),
|
||||
],
|
||||
)
|
||||
def test_only_plain_integers_are_stored_raw(
|
||||
self,
|
||||
serializer: SignedRedisSerializer,
|
||||
value: object,
|
||||
stored_type: type,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A plain integer or a bool
|
||||
WHEN:
|
||||
- The value is serialized
|
||||
THEN:
|
||||
- Only the integer is stored unpickled, so incr/decr stay atomic
|
||||
"""
|
||||
assert type(serializer.dumps(value)) is stored_type
|
||||
|
||||
def test_raw_integer_is_loaded(self, serializer: SignedRedisSerializer) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An integer as stored by Redis incr/decr
|
||||
WHEN:
|
||||
- It is deserialized
|
||||
THEN:
|
||||
- The integer is returned without signature verification
|
||||
"""
|
||||
assert serializer.loads(b"7") == 7
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"forge",
|
||||
[
|
||||
pytest.param(lambda data: data, id="unsigned"),
|
||||
pytest.param(
|
||||
lambda data: compute_signature(b"other data") + data,
|
||||
id="signature-for-other-data",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_forged_pickle_is_not_loaded(
|
||||
self,
|
||||
serializer: SignedRedisSerializer,
|
||||
tmp_path: Path,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
forge: Callable[[bytes], bytes],
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A malicious pickle without a valid signature
|
||||
WHEN:
|
||||
- It is deserialized
|
||||
THEN:
|
||||
- It is treated as a cache miss, never executed, and a warning is logged
|
||||
"""
|
||||
marker = tmp_path / "marker"
|
||||
payload = forge(pickle.dumps(_Evil(marker)))
|
||||
|
||||
assert serializer.loads(payload) is None
|
||||
assert not marker.exists()
|
||||
assert "invalid signature" in caplog.text
|
||||
|
||||
|
||||
class TestCacheSettings:
|
||||
@pytest.mark.parametrize(
|
||||
"alias",
|
||||
[
|
||||
pytest.param("default", id="default"),
|
||||
pytest.param("read-cache", id="read-cache"),
|
||||
],
|
||||
)
|
||||
def test_caches_use_signed_serializer(self, alias: str) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The configured cache aliases
|
||||
WHEN:
|
||||
- Their options are inspected
|
||||
THEN:
|
||||
- Each uses the signed serializer
|
||||
"""
|
||||
options = settings.CACHES[alias]["OPTIONS"]
|
||||
|
||||
assert options["serializer"] == "paperless.cache.SignedRedisSerializer"
|
||||
@@ -11,7 +11,8 @@ from documents.models import Correspondent
|
||||
from documents.models import DocumentType
|
||||
from documents.models import StoragePath
|
||||
from documents.models import Tag
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.permissions import permitted_object_ids
|
||||
from documents.permissions import restrict_queryset_to_owner_visible
|
||||
|
||||
MATCH_THRESHOLD = 0.8
|
||||
|
||||
@@ -33,7 +34,7 @@ def _resolve_visible_ids(
|
||||
"""
|
||||
if not ids:
|
||||
return []
|
||||
queryset = restrict_queryset_to_visible(
|
||||
queryset = restrict_queryset_to_owner_visible(
|
||||
model.objects.filter(pk__in=ids),
|
||||
user,
|
||||
perm,
|
||||
@@ -66,9 +67,11 @@ def _match_by_name(
|
||||
model: type[ModelT],
|
||||
perm: str,
|
||||
) -> list[ModelT]:
|
||||
# A workflow may have no user. In that case only unowned objects are visible,
|
||||
# which avoids another user's private taxonomy.
|
||||
queryset = restrict_queryset_to_visible(model.objects.all(), user, perm)
|
||||
# A workflow may have no user. In that case permitted_object_ids limits
|
||||
# matching to unowned objects, avoiding another user's private taxonomy.
|
||||
queryset = model.objects.filter(
|
||||
pk__in=permitted_object_ids(user, model, perm),
|
||||
)
|
||||
return _match_names_to_queryset(names, queryset)
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import StoragePath
|
||||
from documents.models import Tag
|
||||
from documents.permissions import restrict_queryset_to_visible
|
||||
from documents.permissions import restrict_queryset_to_owner_visible
|
||||
from paperless_ai.prompts.context import TaxonomyBlockPromptContext
|
||||
from paperless_ai.prompts.render import render_prompt
|
||||
|
||||
@@ -97,7 +97,7 @@ def _visible_ranked_candidates(
|
||||
"""
|
||||
if not weighted_ids:
|
||||
return []
|
||||
visible_queryset = restrict_queryset_to_visible(
|
||||
visible_queryset = restrict_queryset_to_owner_visible(
|
||||
model.objects.filter(pk__in=weighted_ids),
|
||||
user,
|
||||
perm,
|
||||
|
||||
Reference in new issue
Block a user