mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-01 09:00:25 +00:00
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aad30b134 | ||
|
|
8464a91b4c | ||
|
|
2d28fc216c | ||
|
|
e399937109 | ||
|
|
9c8fd02bf8 | ||
|
|
ec82da6d9a | ||
|
|
00a73a24d2 | ||
|
|
9d8903b32d | ||
|
|
637d190332 | ||
|
|
8b34780d3e | ||
|
|
bb3604624b | ||
|
|
8591e71a4e | ||
|
|
5f6617ff29 | ||
|
|
56a77ed914 | ||
|
|
970aab73ea | ||
|
|
d1251aaef6 | ||
|
|
fca95bc821 | ||
|
|
f684baaea8 | ||
|
|
e7ead755d3 | ||
|
|
be4c4cdbfe | ||
|
|
3e6e1e6efd |
No files matched your search
@@ -1,8 +1,6 @@
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
version: 2
|
||||
# Required for uv support for now
|
||||
enable-beta-ecosystems: true
|
||||
updates:
|
||||
# Enable version updates for pnpm
|
||||
- package-ecosystem: "npm"
|
||||
|
||||
@@ -193,7 +193,7 @@ jobs:
|
||||
runs-on: ubuntu-26.04
|
||||
permissions:
|
||||
contents: read
|
||||
container: mcr.microsoft.com/playwright:v1.64.1-resolute
|
||||
container: mcr.microsoft.com/playwright:v1.65.1-resolute
|
||||
env:
|
||||
PLAYWRIGHT_BROWSERS_PATH: /ms-playwright
|
||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||
|
||||
+35
-35
@@ -5,14 +5,14 @@
|
||||
<trans-unit id="ngb.alert.close" datatype="html">
|
||||
<source>Close</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/alert/alert.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/alert/alert.ts</context>
|
||||
<context context-type="linenumber">38,39</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.carousel.slide-number" datatype="html">
|
||||
<source> Slide <x id="INTERPOLATION" equiv-text="source?: NgbSli"/> of <x id="INTERPOLATION_1" equiv-text="s._cycleToSelec"/> </source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="linenumber">386,393</context>
|
||||
</context-group>
|
||||
<note priority="1" from="description">Currently selected slide number read by screen reader</note>
|
||||
@@ -20,219 +20,219 @@
|
||||
<trans-unit id="ngb.carousel.previous" datatype="html">
|
||||
<source>Previous</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="linenumber">425,426</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.carousel.next" datatype="html">
|
||||
<source>Next</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/carousel/carousel.ts</context>
|
||||
<context context-type="linenumber">452,453</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.datepicker.select-month" datatype="html">
|
||||
<source>Select month</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="linenumber">52</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="linenumber">52</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.datepicker.select-year" datatype="html">
|
||||
<source>Select year</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="linenumber">52</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation-select.ts</context>
|
||||
<context context-type="linenumber">52</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.datepicker.previous-month" datatype="html">
|
||||
<source>Previous month</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="linenumber">73,76</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="linenumber">73,76</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.datepicker.next-month" datatype="html">
|
||||
<source>Next month</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="linenumber">73,74</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/datepicker/datepicker-navigation.ts</context>
|
||||
<context context-type="linenumber">73,74</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.first" datatype="html">
|
||||
<source>««</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.previous" datatype="html">
|
||||
<source>«</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.next" datatype="html">
|
||||
<source>»</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.last" datatype="html">
|
||||
<source>»»</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.first-aria" datatype="html">
|
||||
<source>First</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.previous-aria" datatype="html">
|
||||
<source>Previous</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.next-aria" datatype="html">
|
||||
<source>Next</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.pagination.last-aria" datatype="html">
|
||||
<source>Last</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/pagination/pagination.ts</context>
|
||||
<context context-type="linenumber">277,278</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.progressbar.value" datatype="html">
|
||||
<source><x id="INTERPOLATION"/></source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/progressbar/progressbar.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/progressbar/progressbar.ts</context>
|
||||
<context context-type="linenumber">39,40</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.HH" datatype="html">
|
||||
<source>HH</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.hours" datatype="html">
|
||||
<source>Hours</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.MM" datatype="html">
|
||||
<source>MM</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.minutes" datatype="html">
|
||||
<source>Minutes</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.increment-hours" datatype="html">
|
||||
<source>Increment hours</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.decrement-hours" datatype="html">
|
||||
<source>Decrement hours</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.increment-minutes" datatype="html">
|
||||
<source>Increment minutes</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.decrement-minutes" datatype="html">
|
||||
<source>Decrement minutes</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.SS" datatype="html">
|
||||
<source>SS</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.seconds" datatype="html">
|
||||
<source>Seconds</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.increment-seconds" datatype="html">
|
||||
<source>Increment seconds</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.decrement-seconds" datatype="html">
|
||||
<source>Decrement seconds</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.timepicker.PM" datatype="html">
|
||||
<source><x id="INTERPOLATION"/></source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/timepicker/timepicker.ts</context>
|
||||
<context context-type="linenumber">442</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="ngb.toast.close-aria" datatype="html">
|
||||
<source>Close</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.2.3_@angular+core@22.2.3_@angular+_2a970977f09c8afdd1f9933e219c8db5/node_modules/src/toast/toast.ts</context>
|
||||
<context context-type="sourcefile">node_modules/.pnpm/@ng-bootstrap+ng-bootstrap@21.0.0_@angular+common@22.3.0_@angular+core@22.3.0_@angular+_a7f2e22ebef7f277c3d304e2c62cd610/node_modules/src/toast/toast.ts</context>
|
||||
<context context-type="linenumber">80</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
|
||||
+30
-30
@@ -15,60 +15,60 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/cdk": "^22.2.4",
|
||||
"@angular/common": "~22.2.3",
|
||||
"@angular/compiler": "~22.2.3",
|
||||
"@angular/core": "~22.2.3",
|
||||
"@angular/forms": "~22.2.3",
|
||||
"@angular/localize": "~22.2.3",
|
||||
"@angular/platform-browser": "~22.2.3",
|
||||
"@angular/router": "~22.2.3",
|
||||
"@angular/cdk": "^22.3.0",
|
||||
"@angular/common": "~22.3.0",
|
||||
"@angular/compiler": "~22.3.0",
|
||||
"@angular/core": "~22.3.0",
|
||||
"@angular/forms": "~22.3.0",
|
||||
"@angular/localize": "~22.3.0",
|
||||
"@angular/platform-browser": "~22.3.0",
|
||||
"@angular/router": "~22.3.0",
|
||||
"@ng-bootstrap/ng-bootstrap": "^21.0.0",
|
||||
"@ng-select/ng-select": "~24.2.1",
|
||||
"@ngneat/dirty-check-forms": "^3.0.3",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"bootstrap": "^5.3.8",
|
||||
"bootstrap": "^5.3.9",
|
||||
"bootstrap-icons": "^1.13.2",
|
||||
"file-saver": "^2.0.5",
|
||||
"lodash-es": "^4.18.1",
|
||||
"marked": "~18.1.1",
|
||||
"marked": "~18.2.1",
|
||||
"mime-names": "^1.0.0",
|
||||
"ngx-color": "^10.1.0",
|
||||
"ngx-cookie-service": "^22.0.0",
|
||||
"ngx-cookie-service": "^22.2.0",
|
||||
"ngx-device-detector": "^12.0.0",
|
||||
"ngx-ui-tour-ng-bootstrap": "^19.0.0",
|
||||
"normalize-diacritics": "^5.0.0",
|
||||
"pdfjs-dist": "^6.4.299",
|
||||
"pdfjs-dist": "^6.5.438",
|
||||
"rxjs": "^7.8.2",
|
||||
"tslib": "^2.8.1",
|
||||
"tslib": "^2.9.1",
|
||||
"utif": "^3.1.0",
|
||||
"uuid": "^14.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-builders/jest": "^22.0.1",
|
||||
"@angular-devkit/core": "^22.2.4",
|
||||
"@angular-devkit/schematics": "^22.2.4",
|
||||
"@angular-eslint/builder": "22.6.0",
|
||||
"@angular-eslint/eslint-plugin": "22.6.0",
|
||||
"@angular-eslint/eslint-plugin-template": "22.6.0",
|
||||
"@angular-eslint/schematics": "22.6.0",
|
||||
"@angular-eslint/template-parser": "22.6.0",
|
||||
"@angular/build": "22.2.4",
|
||||
"@angular/cli": "22.2.4",
|
||||
"@angular/compiler-cli": "~22.2.3",
|
||||
"@playwright/test": "^1.64.1",
|
||||
"@angular-devkit/core": "^22.3.0",
|
||||
"@angular-devkit/schematics": "^22.3.0",
|
||||
"@angular-eslint/builder": "22.8.0",
|
||||
"@angular-eslint/eslint-plugin": "22.8.0",
|
||||
"@angular-eslint/eslint-plugin-template": "22.8.0",
|
||||
"@angular-eslint/schematics": "22.8.0",
|
||||
"@angular-eslint/template-parser": "22.8.0",
|
||||
"@angular/build": "22.3.0",
|
||||
"@angular/cli": "22.3.0",
|
||||
"@angular/compiler-cli": "~22.3.0",
|
||||
"@playwright/test": "^1.65.1",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^26.6.5",
|
||||
"@typescript-eslint/eslint-plugin": "^8.72.0",
|
||||
"@typescript-eslint/parser": "^8.72.0",
|
||||
"@typescript-eslint/utils": "^8.72.0",
|
||||
"eslint": "^10.13.0",
|
||||
"@types/node": "^26.6.6",
|
||||
"@typescript-eslint/eslint-plugin": "^8.74.0",
|
||||
"@typescript-eslint/parser": "^8.74.0",
|
||||
"@typescript-eslint/utils": "^8.74.0",
|
||||
"eslint": "^10.15.0",
|
||||
"jest": "30.5.2",
|
||||
"jest-environment-jsdom": "^30.5.2",
|
||||
"jest-junit": "^17.0.0",
|
||||
"jest-preset-angular": "^17.0.3",
|
||||
"jest-websocket-mock": "^2.5.0",
|
||||
"prettier": "^3.9.10",
|
||||
"prettier": "^3.10.1",
|
||||
"prettier-plugin-organize-imports": "^4.3.0",
|
||||
"ts-node": "~10.9.2",
|
||||
"typescript": "^6.0.3"
|
||||
|
||||
Generated
+1670
-1235
File diff suppressed because it is too large.
Load diff
+24
-172
@@ -6,17 +6,13 @@ import json
|
||||
import logging
|
||||
import operator
|
||||
from contextlib import contextmanager
|
||||
from datetime import UTC
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
from decimal import InvalidOperation
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.db.models import Case
|
||||
from django.db.models import CharField
|
||||
from django.db.models import Count
|
||||
@@ -33,7 +29,6 @@ from django.db.models.functions import NullIf
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_filters import DateFilter
|
||||
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS
|
||||
from django_filters.rest_framework import BooleanFilter
|
||||
from django_filters.rest_framework import CharFilter
|
||||
from django_filters.rest_framework import DateTimeFilter
|
||||
@@ -66,7 +61,6 @@ from documents.versioning import annotate_effective_content
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Iterable
|
||||
from datetime import datetime
|
||||
|
||||
CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"]
|
||||
@@ -101,110 +95,7 @@ CUSTOM_FIELD_QUERY_MAX_ATOMS = 20
|
||||
logger = logging.getLogger("paperless.api")
|
||||
|
||||
|
||||
# The smallest and largest values a 64 bit integer column can hold. Nothing outside can
|
||||
# match a row, and handing it to the database raises an error on some backends.
|
||||
INT64_MIN = -(2**63)
|
||||
INT64_MAX = 2**63 - 1
|
||||
# Real UTC offsets run from -12:00 to +14:00, databases reject anything much larger.
|
||||
MAX_UTC_OFFSET = timedelta(hours=14)
|
||||
DATE_PART_BOUNDS = {"year": (1, 9999), "month": (1, 12), "day": (1, 31)}
|
||||
|
||||
|
||||
def in_id_range(value: int) -> bool:
|
||||
return INT64_MIN <= value <= INT64_MAX
|
||||
|
||||
|
||||
def in_range_ids(ids: Iterable[int]) -> list[int]:
|
||||
"""
|
||||
The ids a row could have. Any other id cannot match, and some databases raise an
|
||||
error instead of finding nothing when asked for one.
|
||||
"""
|
||||
return [i for i in ids if in_id_range(i)]
|
||||
|
||||
|
||||
class BoundedDecimalField(forms.DecimalField):
|
||||
"""
|
||||
django-filter only bounds numbers at 1e50, which is far past any integer column
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
kwargs.setdefault("min_value", INT64_MIN)
|
||||
kwargs.setdefault("max_value", INT64_MAX)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
class BoundedNumberFilter(NumberFilter):
|
||||
field_class = BoundedDecimalField
|
||||
|
||||
|
||||
class BoundedIntegerField(forms.IntegerField):
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
kwargs.setdefault("min_value", INT64_MIN)
|
||||
kwargs.setdefault("max_value", INT64_MAX)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
class BoundedDateTimeField(forms.DateTimeField):
|
||||
def clean(self, value: Any) -> Any:
|
||||
value = super().clean(value)
|
||||
if value is not None and timezone.is_aware(value):
|
||||
offset = value.utcoffset()
|
||||
if offset is not None and abs(offset) > MAX_UTC_OFFSET:
|
||||
raise forms.ValidationError(
|
||||
_("Enter a valid UTC offset."),
|
||||
code="invalid",
|
||||
)
|
||||
try:
|
||||
value.astimezone(UTC)
|
||||
except OverflowError:
|
||||
raise forms.ValidationError(
|
||||
_("Enter a valid date and time."),
|
||||
code="invalid",
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
class BoundedDateTimeFilter(DateTimeFilter):
|
||||
field_class = BoundedDateTimeField
|
||||
|
||||
|
||||
class BoundedFilterSet(FilterSet):
|
||||
"""
|
||||
A FilterSet whose generated number and datetime filters reject values the database
|
||||
cannot hold, as a 400, instead of failing later as a server error
|
||||
"""
|
||||
|
||||
FILTER_DEFAULTS = {
|
||||
**FILTER_FOR_DBFIELD_DEFAULTS,
|
||||
**{
|
||||
field: {"filter_class": BoundedNumberFilter}
|
||||
for field in (
|
||||
models.AutoField,
|
||||
models.BigAutoField,
|
||||
models.SmallAutoField,
|
||||
models.IntegerField,
|
||||
models.BigIntegerField,
|
||||
models.SmallIntegerField,
|
||||
models.PositiveIntegerField,
|
||||
models.PositiveSmallIntegerField,
|
||||
models.PositiveBigIntegerField,
|
||||
)
|
||||
},
|
||||
models.DateTimeField: {"filter_class": BoundedDateTimeFilter},
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def filter_for_field(cls, field, field_name, lookup_expr=None):
|
||||
filter_ = super().filter_for_field(field, field_name, lookup_expr)
|
||||
# The lookup resolves to a plain integer field, so only here is it known to be
|
||||
# a year, month or day
|
||||
bounds = DATE_PART_BOUNDS.get(lookup_expr)
|
||||
if bounds is not None and isinstance(filter_, NumberFilter):
|
||||
filter_.extra["min_value"], filter_.extra["max_value"] = bounds
|
||||
return filter_
|
||||
|
||||
|
||||
class CorrespondentFilterSet(BoundedFilterSet):
|
||||
class CorrespondentFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = Correspondent
|
||||
fields = {
|
||||
@@ -213,7 +104,7 @@ class CorrespondentFilterSet(BoundedFilterSet):
|
||||
}
|
||||
|
||||
|
||||
class TagFilterSet(BoundedFilterSet):
|
||||
class TagFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = Tag
|
||||
fields = {
|
||||
@@ -228,7 +119,7 @@ class TagFilterSet(BoundedFilterSet):
|
||||
)
|
||||
|
||||
|
||||
class DocumentTypeFilterSet(BoundedFilterSet):
|
||||
class DocumentTypeFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = DocumentType
|
||||
fields = {
|
||||
@@ -237,7 +128,7 @@ class DocumentTypeFilterSet(BoundedFilterSet):
|
||||
}
|
||||
|
||||
|
||||
class StoragePathFilterSet(BoundedFilterSet):
|
||||
class StoragePathFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = StoragePath
|
||||
fields = {
|
||||
@@ -264,21 +155,9 @@ class ObjectFilter(Filter):
|
||||
return qs
|
||||
|
||||
if self.in_list:
|
||||
qs = qs.filter(
|
||||
**{
|
||||
f"{self.field_name}__id__in": [
|
||||
obj_id for obj_id in object_ids if in_id_range(obj_id)
|
||||
],
|
||||
},
|
||||
).distinct()
|
||||
qs = qs.filter(**{f"{self.field_name}__id__in": object_ids}).distinct()
|
||||
else:
|
||||
for obj_id in object_ids:
|
||||
if not in_id_range(obj_id):
|
||||
# No row has this id: excluding it changes nothing, requiring it
|
||||
# matches nothing
|
||||
if self.exclude:
|
||||
continue
|
||||
return qs.none()
|
||||
if self.exclude:
|
||||
qs = qs.exclude(**{f"{self.field_name}__id": obj_id})
|
||||
else:
|
||||
@@ -327,14 +206,8 @@ class EffectiveContentFilter(Filter):
|
||||
)
|
||||
|
||||
|
||||
@extend_schema_field(serializers.IntegerField)
|
||||
@extend_schema_field(serializers.BooleanField)
|
||||
class SharedByUser(Filter):
|
||||
"""
|
||||
Documents owned by the given user id that are shared with someone
|
||||
"""
|
||||
|
||||
field_class = BoundedIntegerField
|
||||
|
||||
def filter(self, qs, value):
|
||||
ctype = ContentType.objects.get_for_model(self.model)
|
||||
UserObjectPermission = get_user_obj_perms_model()
|
||||
@@ -369,7 +242,7 @@ class SharedByUser(Filter):
|
||||
)
|
||||
|
||||
|
||||
class CustomFieldFilterSet(BoundedFilterSet):
|
||||
class CustomFieldFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = CustomField
|
||||
fields = {
|
||||
@@ -378,8 +251,8 @@ class CustomFieldFilterSet(BoundedFilterSet):
|
||||
}
|
||||
|
||||
|
||||
class WorkflowFilterSet(BoundedFilterSet):
|
||||
trigger_type = BoundedNumberFilter(field_name="triggers__type", distinct=True)
|
||||
class WorkflowFilterSet(FilterSet):
|
||||
trigger_type = NumberFilter(field_name="triggers__type", distinct=True)
|
||||
|
||||
class Meta:
|
||||
model = Workflow
|
||||
@@ -403,25 +276,9 @@ class CustomFieldsFilter(Filter):
|
||||
option_ids = []
|
||||
if fields_with_matching_selects.count() > 0:
|
||||
for field in fields_with_matching_selects:
|
||||
# Extra data saved by older versions may not be an object
|
||||
options = (
|
||||
field.extra_data.get("select_options")
|
||||
if isinstance(field.extra_data, dict)
|
||||
else None
|
||||
)
|
||||
if not isinstance(options, list):
|
||||
options = []
|
||||
for option in options:
|
||||
label = (
|
||||
option.get("label") if isinstance(option, dict) else None
|
||||
)
|
||||
if (
|
||||
isinstance(label, str)
|
||||
and label.lower().find(
|
||||
value.lower(),
|
||||
)
|
||||
!= -1
|
||||
):
|
||||
options = field.extra_data.get("select_options", [])
|
||||
for _, option in enumerate(options):
|
||||
if option.get("label").lower().find(value.lower()) != -1:
|
||||
option_ids.extend([option.get("id")])
|
||||
# A document with multiple custom field instances can match more
|
||||
# than one of these OR-ed branches (or the same branch via
|
||||
@@ -995,7 +852,7 @@ class CustomFieldQueryFilter(Filter):
|
||||
return qs.filter(pk__in=matching_ids)
|
||||
|
||||
|
||||
class DocumentFilterSet(BoundedFilterSet):
|
||||
class DocumentFilterSet(FilterSet):
|
||||
has_duplicates = BooleanFilter(method="filter_has_duplicates")
|
||||
|
||||
def __init__(self, *args: Any, user: Any = None, **kwargs: Any) -> None:
|
||||
@@ -1127,7 +984,7 @@ class DocumentFilterSet(BoundedFilterSet):
|
||||
}
|
||||
|
||||
|
||||
class ShareLinkFilterSet(BoundedFilterSet):
|
||||
class ShareLinkFilterSet(FilterSet):
|
||||
class Meta:
|
||||
model = ShareLink
|
||||
fields = {
|
||||
@@ -1136,7 +993,7 @@ class ShareLinkFilterSet(BoundedFilterSet):
|
||||
}
|
||||
|
||||
|
||||
class ShareLinkBundleFilterSet(BoundedFilterSet):
|
||||
class ShareLinkBundleFilterSet(FilterSet):
|
||||
documents = Filter(method="filter_documents")
|
||||
|
||||
class Meta:
|
||||
@@ -1156,13 +1013,10 @@ class ShareLinkBundleFilterSet(BoundedFilterSet):
|
||||
return queryset.none()
|
||||
if not ids:
|
||||
return queryset
|
||||
ids = [item for item in ids if in_id_range(item)]
|
||||
if not ids:
|
||||
return queryset.none()
|
||||
return queryset.filter(documents__in=ids).distinct()
|
||||
|
||||
|
||||
class PaperlessTaskFilterSet(BoundedFilterSet):
|
||||
class PaperlessTaskFilterSet(FilterSet):
|
||||
name = CharFilter(
|
||||
method="filter_name",
|
||||
label="Name",
|
||||
@@ -1198,13 +1052,13 @@ class PaperlessTaskFilterSet(BoundedFilterSet):
|
||||
field_name="acknowledged",
|
||||
)
|
||||
|
||||
date_created_after = BoundedDateTimeFilter(
|
||||
date_created_after = DateTimeFilter(
|
||||
field_name="date_created",
|
||||
lookup_expr="gte",
|
||||
label="Created After",
|
||||
)
|
||||
|
||||
date_created_before = BoundedDateTimeFilter(
|
||||
date_created_before = DateTimeFilter(
|
||||
field_name="date_created",
|
||||
lookup_expr="lte",
|
||||
label="Created Before",
|
||||
@@ -1256,10 +1110,9 @@ class PaperlessTaskFilterSet(BoundedFilterSet):
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
else:
|
||||
if in_id_range(numeric_value):
|
||||
query |= Q(result_data__document_id=numeric_value) | Q(
|
||||
result_data__duplicate_of=numeric_value,
|
||||
)
|
||||
query |= Q(result_data__document_id=numeric_value) | Q(
|
||||
result_data__duplicate_of=numeric_value,
|
||||
)
|
||||
|
||||
if "duplicate" in value.lower():
|
||||
query |= Q(result_data__duplicate_of__isnull=False)
|
||||
@@ -1331,13 +1184,12 @@ class DocumentsOrderingFilter(OrderingFilter):
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
param = request.query_params.get("ordering")
|
||||
if param and self.prefix in param:
|
||||
custom_field_suffix = param.split(self.prefix)[1]
|
||||
custom_field_id = int(param.split(self.prefix)[1])
|
||||
try:
|
||||
custom_field_id = int(custom_field_suffix)
|
||||
field = CustomField.objects.get(pk=custom_field_id)
|
||||
except (ValueError, CustomField.DoesNotExist):
|
||||
except CustomField.DoesNotExist:
|
||||
raise serializers.ValidationError(
|
||||
{self.prefix + custom_field_suffix: [_("Custom field not found")]},
|
||||
{self.prefix + str(custom_field_id): [_("Custom field not found")]},
|
||||
)
|
||||
|
||||
annotation = None
|
||||
|
||||
+44
-162
@@ -53,7 +53,6 @@ if settings.AUDIT_LOG_ENABLED:
|
||||
from documents import bulk_edit
|
||||
from documents.data_models import DocumentSource
|
||||
from documents.filters import CustomFieldQueryParser
|
||||
from documents.filters import in_range_ids
|
||||
from documents.models import Correspondent
|
||||
from documents.models import CustomField
|
||||
from documents.models import CustomFieldInstance
|
||||
@@ -231,7 +230,7 @@ class SetPermissionsMixin:
|
||||
def _validate_user_ids(self, user_ids):
|
||||
users = User.objects.none()
|
||||
if user_ids is not None:
|
||||
users = User.objects.filter(id__in=in_range_ids(user_ids))
|
||||
users = User.objects.filter(id__in=user_ids)
|
||||
if not users.count() == len(user_ids):
|
||||
raise serializers.ValidationError(
|
||||
"Some users in don't exist or were specified twice.",
|
||||
@@ -241,7 +240,7 @@ class SetPermissionsMixin:
|
||||
def _validate_group_ids(self, group_ids):
|
||||
groups = Group.objects.none()
|
||||
if group_ids is not None:
|
||||
groups = Group.objects.filter(id__in=in_range_ids(group_ids))
|
||||
groups = Group.objects.filter(id__in=group_ids)
|
||||
if not groups.count() == len(group_ids):
|
||||
raise serializers.ValidationError(
|
||||
"Some groups in don't exist or were specified twice.",
|
||||
@@ -726,15 +725,6 @@ class CustomFieldSerializer(serializers.ModelSerializer[CustomField]):
|
||||
]
|
||||
|
||||
def validate(self, attrs):
|
||||
# Extra data is read as an object everywhere, any other JSON would be stored
|
||||
# to fail on the next read
|
||||
if attrs.get("extra_data") is not None and not isinstance(
|
||||
attrs["extra_data"],
|
||||
dict,
|
||||
):
|
||||
raise serializers.ValidationError(
|
||||
{"extra_data": "Must be an object"},
|
||||
)
|
||||
# TODO: remove pending https://github.com/encode/django-rest-framework/issues/7173
|
||||
name = attrs.get(
|
||||
"name",
|
||||
@@ -760,19 +750,14 @@ class CustomFieldSerializer(serializers.ModelSerializer[CustomField]):
|
||||
self.instance
|
||||
and self.instance.data_type == CustomField.FieldDataType.SELECT
|
||||
):
|
||||
select_options = (
|
||||
attrs["extra_data"].get("select_options")
|
||||
if isinstance(attrs.get("extra_data"), dict)
|
||||
else None
|
||||
)
|
||||
if (
|
||||
not isinstance(select_options, list)
|
||||
or len(select_options) == 0
|
||||
"extra_data" not in attrs
|
||||
or "select_options" not in attrs["extra_data"]
|
||||
or not isinstance(attrs["extra_data"]["select_options"], list)
|
||||
or len(attrs["extra_data"]["select_options"]) == 0
|
||||
or not all(
|
||||
isinstance(option, dict)
|
||||
and isinstance(option.get("label", ""), str)
|
||||
and len(option.get("label", "")) > 0
|
||||
for option in select_options
|
||||
len(option.get("label", "")) > 0
|
||||
for option in attrs["extra_data"]["select_options"]
|
||||
)
|
||||
):
|
||||
raise serializers.ValidationError(
|
||||
@@ -785,7 +770,7 @@ class CustomFieldSerializer(serializers.ModelSerializer[CustomField]):
|
||||
elif (
|
||||
"data_type" in attrs
|
||||
and attrs["data_type"] == CustomField.FieldDataType.MONETARY
|
||||
and isinstance(attrs.get("extra_data"), dict)
|
||||
and "extra_data" in attrs
|
||||
and "default_currency" in attrs["extra_data"]
|
||||
and attrs["extra_data"]["default_currency"] is not None
|
||||
and (
|
||||
@@ -817,7 +802,7 @@ class ReadWriteSerializerMethodField(serializers.SerializerMethodField):
|
||||
|
||||
|
||||
def validate_documentlink_targets(user, doc_ids):
|
||||
if Document.objects.filter(id__in=in_range_ids(doc_ids)).count() != len(doc_ids):
|
||||
if Document.objects.filter(id__in=doc_ids).count() != len(doc_ids):
|
||||
raise serializers.ValidationError(
|
||||
"Some documents in value don't exist or were specified twice.",
|
||||
)
|
||||
@@ -1485,29 +1470,16 @@ class SavedViewSerializer(OwnedObjectSerializer):
|
||||
def validate(self, attrs):
|
||||
attrs = super().validate(attrs)
|
||||
if "display_fields" in attrs and attrs["display_fields"] is not None:
|
||||
if not isinstance(attrs["display_fields"], list):
|
||||
raise serializers.ValidationError(
|
||||
{"display_fields": "Must be a list"},
|
||||
)
|
||||
for field in attrs["display_fields"]:
|
||||
if not isinstance(field, str):
|
||||
raise serializers.ValidationError(
|
||||
f"Invalid field: {field}",
|
||||
)
|
||||
custom_field = re.fullmatch(
|
||||
rf"{re.escape(SavedView.DisplayFields.CUSTOM_FIELD[:-2])}(\d+)",
|
||||
field,
|
||||
) # i.e. 'custom_field_' followed by an id
|
||||
if custom_field:
|
||||
field_id = int(custom_field[1])
|
||||
if (
|
||||
SavedView.DisplayFields.CUSTOM_FIELD[:-2] in field
|
||||
): # i.e. check for 'custom_field_' prefix
|
||||
field_id = int(re.search(r"\d+", field)[0])
|
||||
if not CustomField.objects.filter(id=field_id).exists():
|
||||
raise serializers.ValidationError(
|
||||
f"Invalid field: {field}",
|
||||
)
|
||||
elif (
|
||||
field == SavedView.DisplayFields.CUSTOM_FIELD
|
||||
or field not in SavedView.DisplayFields.values
|
||||
): # the bare 'custom_field_%d' template names no custom field
|
||||
elif field not in SavedView.DisplayFields.values:
|
||||
raise serializers.ValidationError(
|
||||
f"Invalid field: {field}",
|
||||
)
|
||||
@@ -1581,9 +1553,7 @@ class DocumentListSerializer(serializers.Serializer[dict[str, list[int]]]):
|
||||
raise serializers.ValidationError(f"{name} must be a list")
|
||||
if not all(isinstance(i, int) for i in documents):
|
||||
raise serializers.ValidationError(f"{name} must be a list of integers")
|
||||
# An id beyond what a database column holds can't exist, and some backends raise
|
||||
# an error instead of finding nothing
|
||||
count = Document.objects.filter(id__in=in_range_ids(documents)).count()
|
||||
count = Document.objects.filter(id__in=documents).count()
|
||||
if not count == len(documents):
|
||||
raise serializers.ValidationError(
|
||||
f"Some documents in {name} don't exist or were specified twice.",
|
||||
@@ -1756,10 +1726,6 @@ class EditPdfDocumentsSerializer(DocumentListSerializer, SourceModeValidationMix
|
||||
raise serializers.ValidationError(
|
||||
"Edit PDF method only supports one document",
|
||||
)
|
||||
if len(documents) == 0:
|
||||
raise serializers.ValidationError(
|
||||
"Edit PDF method requires a document",
|
||||
)
|
||||
|
||||
operations = attrs["operations"]
|
||||
|
||||
@@ -1911,7 +1877,7 @@ class BulkEditSerializer(
|
||||
raise serializers.ValidationError(f"{name} must be a list")
|
||||
if not all(isinstance(i, int) for i in tags):
|
||||
raise serializers.ValidationError(f"{name} must be a list of integers")
|
||||
count = Tag.objects.filter(id__in=in_range_ids(tags)).count()
|
||||
count = Tag.objects.filter(id__in=tags).count()
|
||||
if not count == len(tags):
|
||||
raise serializers.ValidationError(
|
||||
f"Some tags in {name} don't exist or were specified twice.",
|
||||
@@ -1937,7 +1903,7 @@ class BulkEditSerializer(
|
||||
raise serializers.ValidationError(
|
||||
f"{name} must be a list of integers or a dict of id:value pairs",
|
||||
)
|
||||
count = CustomField.objects.filter(id__in=in_range_ids(ids)).count()
|
||||
count = CustomField.objects.filter(id__in=ids).count()
|
||||
if not count == len(ids):
|
||||
raise serializers.ValidationError(
|
||||
f"Some custom fields in {name} don't exist or were specified twice.",
|
||||
@@ -2303,20 +2269,12 @@ class BulkEditSerializer(
|
||||
raise serializers.ValidationError(
|
||||
"Split method only supports one document",
|
||||
)
|
||||
if len(attrs["documents"]) == 0:
|
||||
raise serializers.ValidationError(
|
||||
"Split method requires a document",
|
||||
)
|
||||
self._validate_parameters_split(parameters, attrs["documents"][0])
|
||||
elif method == bulk_edit.delete_pages:
|
||||
if len(attrs["documents"]) > 1:
|
||||
raise serializers.ValidationError(
|
||||
"Delete pages method only supports one document",
|
||||
)
|
||||
if len(attrs["documents"]) == 0:
|
||||
raise serializers.ValidationError(
|
||||
"Delete pages method requires a document",
|
||||
)
|
||||
self._validate_parameters_delete_pages(parameters)
|
||||
elif method == bulk_edit.merge:
|
||||
self._validate_parameters_merge(parameters)
|
||||
@@ -2325,10 +2283,6 @@ class BulkEditSerializer(
|
||||
raise serializers.ValidationError(
|
||||
"Edit PDF method only supports one document",
|
||||
)
|
||||
if len(attrs["documents"]) == 0:
|
||||
raise serializers.ValidationError(
|
||||
"Edit PDF method requires a document",
|
||||
)
|
||||
self._validate_parameters_edit_pdf(parameters, attrs["documents"][0])
|
||||
elif method == bulk_edit.remove_password:
|
||||
self.validate_parameters_remove_password(parameters)
|
||||
@@ -2499,9 +2453,7 @@ class PostDocumentSerializer(serializers.Serializer[dict[str, Any]]):
|
||||
"Custom fields must be a list of integers or an object mapping ids to values.",
|
||||
),
|
||||
)
|
||||
if CustomField.objects.filter(id__in=in_range_ids(ids)).count() != len(
|
||||
set(ids),
|
||||
):
|
||||
if CustomField.objects.filter(id__in=ids).count() != len(set(ids)):
|
||||
raise serializers.ValidationError(
|
||||
_("Some custom fields don't exist or were specified twice."),
|
||||
)
|
||||
@@ -2681,17 +2633,12 @@ class UiSettingsViewSerializer(serializers.ModelSerializer[UiSettings]):
|
||||
]
|
||||
|
||||
def validate_settings(self, settings):
|
||||
if settings is None:
|
||||
return settings
|
||||
if not isinstance(settings, dict):
|
||||
raise serializers.ValidationError("Settings must be an object")
|
||||
# we never save update checking backend setting
|
||||
if "update_checking" in settings:
|
||||
if not isinstance(settings["update_checking"], dict):
|
||||
raise serializers.ValidationError(
|
||||
{"update_checking": "Must be an object"},
|
||||
)
|
||||
settings["update_checking"].pop("backend_setting", None)
|
||||
try:
|
||||
settings["update_checking"].pop("backend_setting")
|
||||
except KeyError:
|
||||
pass
|
||||
return settings
|
||||
|
||||
def create(self, validated_data):
|
||||
@@ -2908,7 +2855,7 @@ class AcknowledgeTasksViewSerializer(serializers.Serializer[dict[str, Any]]):
|
||||
if not all(isinstance(i, int) for i in tasks):
|
||||
raise serializers.ValidationError(f"{name} must be a list of integers")
|
||||
queryset = self.context.get("queryset", PaperlessTask.objects.all())
|
||||
count = queryset.filter(id__in=in_range_ids(tasks)).count()
|
||||
count = queryset.filter(id__in=tasks).count()
|
||||
if not count == len(tasks):
|
||||
raise serializers.ValidationError(
|
||||
f"Some tasks in {name} don't exist or were specified twice.",
|
||||
@@ -2951,8 +2898,6 @@ class ShareLinkSerializer(OwnedObjectSerializer):
|
||||
"document_title",
|
||||
"file_version",
|
||||
)
|
||||
# The model field is blank=True but not nullable, so it would be optional
|
||||
extra_kwargs = {"document": {"required": True}}
|
||||
|
||||
def create(self, validated_data):
|
||||
validated_data["slug"] = get_random_string(50)
|
||||
@@ -3044,7 +2989,7 @@ class ShareLinkBundleSerializer(OwnedObjectSerializer):
|
||||
share_link_bundle = super().create(validated_data)
|
||||
|
||||
documents = list(
|
||||
Document.objects.filter(pk__in=in_range_ids(document_ids)).only(
|
||||
Document.objects.filter(pk__in=document_ids).only(
|
||||
"pk",
|
||||
),
|
||||
)
|
||||
@@ -3150,7 +3095,7 @@ class BulkEditObjectsSerializer(SerializerWithPerms, SetPermissionsMixin):
|
||||
if not all(isinstance(i, int) for i in objects):
|
||||
raise serializers.ValidationError("objects must be a list of integers")
|
||||
object_class = self.get_object_class(object_type)
|
||||
count = object_class.objects.filter(id__in=in_range_ids(objects)).count()
|
||||
count = object_class.objects.filter(id__in=objects).count()
|
||||
if not count == len(objects):
|
||||
raise serializers.ValidationError(
|
||||
"Some ids in objects don't exist or were specified twice.",
|
||||
@@ -3389,42 +3334,6 @@ class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]):
|
||||
"ai_overwrite_existing",
|
||||
]
|
||||
|
||||
def _save_nested(self, instance, email_data, webhook_data) -> None:
|
||||
# Never trust an id from the payload here, it could name another action's row
|
||||
created = False
|
||||
for data, model, attribute in (
|
||||
(email_data, WorkflowActionEmail, "email"),
|
||||
(webhook_data, WorkflowActionWebhook, "webhook"),
|
||||
):
|
||||
if data is None:
|
||||
continue
|
||||
values = {key: value for key, value in data.items() if key != "id"}
|
||||
existing = getattr(instance, attribute)
|
||||
if existing is not None:
|
||||
# Change the loaded row, the response is built from it
|
||||
for key, value in values.items():
|
||||
setattr(existing, key, value)
|
||||
existing.save()
|
||||
else:
|
||||
setattr(instance, attribute, model.objects.create(**values))
|
||||
created = True
|
||||
if created:
|
||||
instance.save()
|
||||
|
||||
def create(self, validated_data):
|
||||
email_data = validated_data.pop("email", None)
|
||||
webhook_data = validated_data.pop("webhook", None)
|
||||
instance = super().create(validated_data)
|
||||
self._save_nested(instance, email_data, webhook_data)
|
||||
return instance
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
email_data = validated_data.pop("email", None)
|
||||
webhook_data = validated_data.pop("webhook", None)
|
||||
instance = super().update(instance, validated_data)
|
||||
self._save_nested(instance, email_data, webhook_data)
|
||||
return instance
|
||||
|
||||
def validate(self, attrs):
|
||||
if "assign_title" in attrs and attrs["assign_title"] is not None:
|
||||
if len(attrs["assign_title"]) == 0:
|
||||
@@ -3438,48 +3347,30 @@ class WorkflowActionSerializer(serializers.ModelSerializer[WorkflowAction]):
|
||||
{"assign_title": f"{e.args[0]}"},
|
||||
)
|
||||
|
||||
if attrs.get("assign_custom_fields_values") is not None:
|
||||
if not isinstance(attrs["assign_custom_fields_values"], dict):
|
||||
raise serializers.ValidationError(
|
||||
{"assign_custom_fields_values": "Must be an object"},
|
||||
)
|
||||
if attrs.get("assign_custom_fields_values"):
|
||||
# Empty strings treated as None to avoid unexpected behavior
|
||||
attrs["assign_custom_fields_values"] = {
|
||||
field_id: (None if value == "" else value)
|
||||
for field_id, value in attrs["assign_custom_fields_values"].items()
|
||||
}
|
||||
|
||||
action_type = attrs.get("type", self.instance.type if self.instance else None)
|
||||
for attribute, nested_type, serializer_class, label in (
|
||||
(
|
||||
"email",
|
||||
WorkflowAction.WorkflowActionType.EMAIL,
|
||||
WorkflowActionEmailSerializer,
|
||||
"Email",
|
||||
),
|
||||
(
|
||||
"webhook",
|
||||
WorkflowAction.WorkflowActionType.WEBHOOK,
|
||||
WorkflowActionWebhookSerializer,
|
||||
"Webhook",
|
||||
),
|
||||
if (
|
||||
"type" in attrs
|
||||
and attrs["type"] == WorkflowAction.WorkflowActionType.EMAIL
|
||||
and "email" not in attrs
|
||||
):
|
||||
if action_type != nested_type or not (
|
||||
"type" in attrs or attribute in attrs
|
||||
):
|
||||
continue
|
||||
if self.instance is not None and getattr(self.instance, attribute):
|
||||
# An existing row can be updated partially
|
||||
continue
|
||||
data = attrs.get(attribute)
|
||||
if not isinstance(data, dict):
|
||||
raise serializers.ValidationError(
|
||||
f"{label} data is required for {attribute} actions",
|
||||
)
|
||||
# A partial update skipped the required fields of this new row
|
||||
nested = serializer_class(data=data, context=self.context)
|
||||
if not nested.is_valid():
|
||||
raise serializers.ValidationError({attribute: nested.errors})
|
||||
raise serializers.ValidationError(
|
||||
"Email data is required for email actions",
|
||||
)
|
||||
|
||||
if (
|
||||
"type" in attrs
|
||||
and attrs["type"] == WorkflowAction.WorkflowActionType.WEBHOOK
|
||||
and "webhook" not in attrs
|
||||
):
|
||||
raise serializers.ValidationError(
|
||||
"Webhook data is required for webhook actions",
|
||||
)
|
||||
|
||||
if (
|
||||
"type" in attrs
|
||||
@@ -3820,22 +3711,13 @@ class TrashSerializer(SerializerWithPerms):
|
||||
)
|
||||
|
||||
def validate_documents(self, documents: list[int]) -> list[int]:
|
||||
count = Document.deleted_objects.filter(
|
||||
id__in=in_range_ids(documents),
|
||||
).count()
|
||||
count = Document.deleted_objects.filter(id__in=documents).count()
|
||||
if not count == len(documents):
|
||||
raise serializers.ValidationError(
|
||||
"Some documents in the list have not yet been deleted.",
|
||||
)
|
||||
return documents
|
||||
|
||||
def validate(self, attrs):
|
||||
if attrs.get("action") == "restore" and "documents" not in attrs:
|
||||
raise serializers.ValidationError(
|
||||
{"documents": "This field is required to restore documents."},
|
||||
)
|
||||
return attrs
|
||||
|
||||
|
||||
class StoragePathTestSerializer(SerializerWithPerms):
|
||||
path = serializers.CharField(
|
||||
|
||||
@@ -786,15 +786,15 @@ def cleanup_user_deletion(sender, instance: User | Group, **kwargs) -> None:
|
||||
if instance.pk in permissions.get("default_view_users", []):
|
||||
permissions["default_view_users"].remove(instance.pk)
|
||||
updated = True
|
||||
if instance.pk in permissions.get("default_change_users", []):
|
||||
permissions["default_change_users"].remove(instance.pk)
|
||||
if instance.pk in permissions.get("default_edit_users", []):
|
||||
permissions["default_edit_users"].remove(instance.pk)
|
||||
updated = True
|
||||
elif isinstance(instance, Group):
|
||||
if instance.pk in permissions.get("default_view_groups", []):
|
||||
permissions["default_view_groups"].remove(instance.pk)
|
||||
updated = True
|
||||
if instance.pk in permissions.get("default_change_groups", []):
|
||||
permissions["default_change_groups"].remove(instance.pk)
|
||||
if instance.pk in permissions.get("default_edit_groups", []):
|
||||
permissions["default_edit_groups"].remove(instance.pk)
|
||||
updated = True
|
||||
if updated:
|
||||
ui_settings.settings["permissions"] = permissions
|
||||
|
||||
@@ -75,17 +75,3 @@ def searchable_document(_search_index: None) -> "Document":
|
||||
def mock_zone_ocr_run(mocker: "MockerFixture") -> "MagicMock":
|
||||
"""Patch the subprocess runner used by zone OCR (tesseract and pdftoppm)."""
|
||||
return mocker.patch("documents.zone_ocr.subprocess.run")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_id(db: None) -> int:
|
||||
"""
|
||||
The id of the application configuration row. A migration creates it, but a test
|
||||
that flushes the database in the same worker removes it, so make sure it exists.
|
||||
"""
|
||||
from paperless.models import ApplicationConfiguration
|
||||
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
if config is None:
|
||||
config = ApplicationConfiguration.objects.create()
|
||||
return config.pk
|
||||
@@ -1,114 +0,0 @@
|
||||
import pytest
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from documents.models import CustomField
|
||||
from paperless_testing.http import send_json
|
||||
|
||||
|
||||
class TestCustomFieldExtraData:
|
||||
@pytest.mark.parametrize("extra_data", [[1], "text", 5, True])
|
||||
def test_extra_data_that_is_not_an_object_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
extra_data: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A custom field is created with extra data that is not an object
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/custom_fields/",
|
||||
{"name": "field", "data_type": "string", "extra_data": extra_data},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert "extra_data" in response.data
|
||||
|
||||
@pytest.mark.parametrize("extra_data", [None, {}])
|
||||
def test_null_or_empty_extra_data_is_accepted(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
extra_data: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A string custom field has null or empty extra data
|
||||
THEN:
|
||||
- It is created
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/custom_fields/",
|
||||
{"name": "field", "data_type": "string", "extra_data": extra_data},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extra_data", "term"),
|
||||
[
|
||||
pytest.param([1], "1", id="list"),
|
||||
pytest.param(
|
||||
{"select_options": [1, "x"]},
|
||||
"select",
|
||||
id="options-not-objects",
|
||||
),
|
||||
pytest.param(
|
||||
{"select_options": None, "note": "zzz"},
|
||||
"zzz",
|
||||
id="options-null",
|
||||
),
|
||||
pytest.param(
|
||||
{"select_options": 5, "note": "zzz"},
|
||||
"zzz",
|
||||
id="options-a-number",
|
||||
),
|
||||
pytest.param(
|
||||
{"select_options": [{"label": None, "id": "zzz"}]},
|
||||
"zzz",
|
||||
id="label-missing",
|
||||
),
|
||||
pytest.param(
|
||||
{"select_options": [{"label": 5, "id": "zzz"}]},
|
||||
"zzz",
|
||||
id="label-not-a-string",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_the_deprecated_custom_fields_filter_survives_odd_stored_data(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
db: None,
|
||||
extra_data: object,
|
||||
term: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A custom field whose stored extra data an older version allowed
|
||||
WHEN:
|
||||
- Documents are filtered with the deprecated custom_fields__icontains
|
||||
THEN:
|
||||
- The request succeeds
|
||||
"""
|
||||
CustomField.objects.create(
|
||||
name="legacy",
|
||||
data_type=CustomField.FieldDataType.SELECT,
|
||||
extra_data=extra_data,
|
||||
)
|
||||
|
||||
response = admin_client.get(
|
||||
"/api/documents/",
|
||||
{"custom_fields__icontains": term},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
@@ -1,842 +0,0 @@
|
||||
import pytest
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from documents.models import UiSettings
|
||||
from documents.models import WorkflowAction
|
||||
from documents.models import WorkflowActionEmail
|
||||
from paperless_testing.http import send_json
|
||||
|
||||
EMAIL = {
|
||||
"subject": "Subject",
|
||||
"body": "Body",
|
||||
"to": "someone@example.com",
|
||||
"include_document": False,
|
||||
}
|
||||
|
||||
|
||||
class TestObjectJsonBody:
|
||||
@pytest.mark.parametrize("body", [[], [1, 2], True, 1, 1.5, None, "text"])
|
||||
@pytest.mark.parametrize(
|
||||
("method", "path"),
|
||||
[
|
||||
pytest.param("PATCH", "/api/workflow_triggers/1/", id="trigger-patch"),
|
||||
pytest.param("PATCH", "/api/workflow_actions/1/", id="action-patch"),
|
||||
pytest.param("POST", "/api/documents/bulk_edit/", id="bulk-edit"),
|
||||
pytest.param(
|
||||
"POST",
|
||||
"/api/processed_mail/bulk_delete/",
|
||||
id="processed-mail-bulk-delete",
|
||||
),
|
||||
pytest.param("POST", "/api/tags/", id="tags-create"),
|
||||
],
|
||||
)
|
||||
def test_body_that_is_not_an_object_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
method: str,
|
||||
path: str,
|
||||
body: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A JSON body that is a list or a scalar is sent
|
||||
THEN:
|
||||
- The response is a 400, never a server error
|
||||
"""
|
||||
response = send_json(admin_client, method, path, body)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
|
||||
class TestNullAndWrongTypeFields:
|
||||
@pytest.mark.parametrize("password", [["x"], 5, {"a": 1}, True])
|
||||
def test_password_that_is_not_a_string_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
admin_user: User,
|
||||
password: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A user
|
||||
WHEN:
|
||||
- The password is sent as something other than a string
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"PATCH",
|
||||
f"/api/users/{admin_user.pk}/",
|
||||
{"password": password},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert "password" in response.data
|
||||
|
||||
@pytest.mark.parametrize("ui_settings", [None, {}])
|
||||
def test_ui_settings_that_are_null_or_empty_are_accepted_and_readable(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
ui_settings: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- UI settings are saved as null or with an unexpected update_checking
|
||||
THEN:
|
||||
- The request does not fail with a server error
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/ui_settings/",
|
||||
{"settings": ui_settings},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
# What was saved must also be readable, null used to break the GET afterwards
|
||||
assert admin_client.get("/api/ui_settings/").status_code == status.HTTP_200_OK
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ui_settings",
|
||||
[[1], "text", 5, {"update_checking": [1]}, {"update_checking": "x"}],
|
||||
)
|
||||
def test_ui_settings_of_the_wrong_shape_are_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
ui_settings: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- UI settings are saved that are not an object, or have a mistyped
|
||||
update_checking
|
||||
THEN:
|
||||
- The response is a 400, not stored to break the next read
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/ui_settings/",
|
||||
{"settings": ui_settings},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"stored",
|
||||
[None, [1], "text", {"update_checking": "x"}, {"update_checking": [1]}],
|
||||
)
|
||||
def test_reading_ui_settings_saved_in_an_unexpected_shape_still_works(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
admin_user: User,
|
||||
stored: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- UI settings stored in a shape the API no longer accepts, as older
|
||||
versions allowed it
|
||||
WHEN:
|
||||
- The settings are read
|
||||
THEN:
|
||||
- The request succeeds
|
||||
"""
|
||||
UiSettings.objects.update_or_create(
|
||||
user=admin_user,
|
||||
defaults={"settings": stored},
|
||||
)
|
||||
|
||||
response = admin_client.get("/api/ui_settings/")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"field",
|
||||
["llm_api_key", "llm_embedding_api_key", "remote_ocr_api_key"],
|
||||
)
|
||||
@pytest.mark.parametrize("value", [5, ["a"], {"a": 1}, True])
|
||||
def test_config_api_key_that_is_not_a_string_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
config_id: int,
|
||||
field: str,
|
||||
value: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The application configuration
|
||||
WHEN:
|
||||
- An obfuscated key field is sent as something other than a string
|
||||
THEN:
|
||||
- The response is a 400, not a server error
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"PATCH",
|
||||
f"/api/config/{config_id}/",
|
||||
{field: value},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert field in response.data
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"display_fields",
|
||||
[
|
||||
["custom_field_abc"],
|
||||
["custom_field_"],
|
||||
["xcustom_field_1"],
|
||||
["custom_field_%d"],
|
||||
],
|
||||
)
|
||||
def test_saved_view_custom_field_name_must_be_well_formed(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
display_fields: list,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A saved view lists a custom field display name without a numeric id
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/saved_views/",
|
||||
{
|
||||
"name": "view",
|
||||
"show_on_dashboard": False,
|
||||
"show_in_sidebar": False,
|
||||
"sort_field": "created",
|
||||
"filter_rules": [],
|
||||
"display_fields": display_fields,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize("display_fields", [5, True, {"a": 1}, "text"])
|
||||
def test_saved_view_display_fields_must_be_a_list(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
display_fields: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A saved view is created with display fields that are not a list
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/saved_views/",
|
||||
{
|
||||
"name": "view",
|
||||
"show_on_dashboard": False,
|
||||
"show_in_sidebar": False,
|
||||
"sort_field": "created",
|
||||
"filter_rules": [],
|
||||
"display_fields": display_fields,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize("display_fields", [[None], [5], [["x"]]])
|
||||
def test_saved_view_display_field_that_is_not_a_string_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
display_fields: list,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A saved view is created with display fields that are not strings
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/saved_views/",
|
||||
{
|
||||
"name": "view",
|
||||
"show_on_dashboard": False,
|
||||
"show_in_sidebar": False,
|
||||
"sort_field": "created",
|
||||
"filter_rules": [],
|
||||
"display_fields": display_fields,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"extra_data",
|
||||
[None, {}, {"select_options": None}, {"select_options": [1, 2]}, [1]],
|
||||
)
|
||||
def test_select_custom_field_without_valid_options_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
extra_data: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A select custom field is created without usable options
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/custom_fields/",
|
||||
{"name": "select", "data_type": "select", "extra_data": extra_data},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
def test_monetary_custom_field_with_null_extra_data_is_accepted(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A monetary custom field is created with null extra data
|
||||
THEN:
|
||||
- It is created
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/custom_fields/",
|
||||
{"name": "money", "data_type": "monetary", "extra_data": None},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
|
||||
@pytest.mark.parametrize("values", [[1], "text", 5])
|
||||
def test_workflow_custom_field_values_must_be_an_object(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
values: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A workflow action carries custom field values that are not an object
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflows/",
|
||||
{
|
||||
"name": "workflow",
|
||||
"order": 0,
|
||||
"enabled": True,
|
||||
"triggers": [{"type": 2, "sources": [1], "matching_algorithm": 0}],
|
||||
"actions": [{"type": 1, "assign_custom_fields_values": values}],
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
|
||||
class TestRequiredFields:
|
||||
def test_share_link_requires_a_document(self, admin_client: APIClient) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A share link is created without a document
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(admin_client, "POST", "/api/share_links/", {})
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert "document" in response.data
|
||||
|
||||
def test_restoring_from_the_trash_requires_documents(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- The trash is asked to restore without saying which documents
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(admin_client, "POST", "/api/trash/", {"action": "restore"})
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert "documents" in response.data
|
||||
|
||||
@pytest.mark.parametrize("action", ["restore", "empty"])
|
||||
def test_trash_document_id_beyond_the_database_range_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
action: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- The trash is given a document id no row can have
|
||||
THEN:
|
||||
- The response is a 400, as for any document that is not in the trash
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/trash/",
|
||||
{"action": action, "documents": [2**70]},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize("method", ["split", "delete_pages", "edit_pdf"])
|
||||
def test_single_document_bulk_methods_reject_an_empty_selection(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
method: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A method that works on exactly one document gets none
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/documents/bulk_edit/",
|
||||
{
|
||||
"documents": [],
|
||||
"method": method,
|
||||
"parameters": {
|
||||
"pages": "1",
|
||||
"operations": [{"page": 1}],
|
||||
"split_pages": [[1]],
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
def test_edit_pdf_endpoint_rejects_an_empty_selection(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- The edit_pdf endpoint gets no documents
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/documents/edit_pdf/",
|
||||
{"documents": [], "operations": [{"page": 1}]},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
|
||||
class TestSharedByFilter:
|
||||
@pytest.mark.parametrize("value", ["false", "abc", "1.5", str(2**63)])
|
||||
def test_non_integer_user_id_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
value: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- shared_by__id is not an integer user id
|
||||
THEN:
|
||||
- The response is a 400
|
||||
"""
|
||||
response = admin_client.get("/api/documents/", {"shared_by__id": value})
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize("value", ["", "1"])
|
||||
def test_empty_or_valid_user_id_works(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
value: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- shared_by__id is empty or a user id
|
||||
THEN:
|
||||
- The request succeeds
|
||||
"""
|
||||
response = admin_client.get("/api/documents/", {"shared_by__id": value})
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
|
||||
class TestStandaloneWorkflowActions:
|
||||
def test_create_with_nested_email(self, admin_client: APIClient) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- An email action is created through the standalone endpoint
|
||||
THEN:
|
||||
- The action and its email are both stored
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{"type": WorkflowAction.WorkflowActionType.EMAIL, "email": EMAIL},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
action = WorkflowAction.objects.get(pk=response.data["id"])
|
||||
assert action.email is not None
|
||||
assert action.email.subject == "Subject"
|
||||
|
||||
def test_update_changes_the_existing_email_row(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An email action
|
||||
WHEN:
|
||||
- Its email is changed through the standalone endpoint
|
||||
THEN:
|
||||
- The existing email row is updated, no new row is made
|
||||
"""
|
||||
created = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{"type": WorkflowAction.WorkflowActionType.EMAIL, "email": EMAIL},
|
||||
)
|
||||
action = WorkflowAction.objects.get(pk=created.data["id"])
|
||||
email_id = action.email_id
|
||||
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"PATCH",
|
||||
f"/api/workflow_actions/{action.pk}/",
|
||||
{"email": {**EMAIL, "subject": "Changed"}},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
# The response must show the saved value, not the row loaded before the update
|
||||
assert response.data["email"]["subject"] == "Changed"
|
||||
action.refresh_from_db()
|
||||
assert action.email_id == email_id
|
||||
assert WorkflowActionEmail.objects.get(pk=email_id).subject == "Changed"
|
||||
assert WorkflowActionEmail.objects.count() == 1
|
||||
|
||||
def test_null_email_leaves_the_existing_email_alone(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An email action
|
||||
WHEN:
|
||||
- It is patched with a null email
|
||||
THEN:
|
||||
- The email is kept, null is a no-op as in the nested workflow serializer
|
||||
"""
|
||||
created = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{"type": WorkflowAction.WorkflowActionType.EMAIL, "email": EMAIL},
|
||||
)
|
||||
action = WorkflowAction.objects.get(pk=created.data["id"])
|
||||
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"PATCH",
|
||||
f"/api/workflow_actions/{action.pk}/",
|
||||
{"email": None},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
action.refresh_from_db()
|
||||
assert action.email is not None
|
||||
assert action.email.subject == "Subject"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("action_type", "nested", "payload"),
|
||||
[
|
||||
pytest.param(
|
||||
WorkflowAction.WorkflowActionType.EMAIL,
|
||||
"email",
|
||||
{"email": {}},
|
||||
id="email-empty",
|
||||
),
|
||||
pytest.param(
|
||||
WorkflowAction.WorkflowActionType.EMAIL,
|
||||
"email",
|
||||
{"email": None},
|
||||
id="email-null",
|
||||
),
|
||||
pytest.param(
|
||||
WorkflowAction.WorkflowActionType.EMAIL,
|
||||
"email",
|
||||
{"email": {"subject": "Only a subject"}},
|
||||
id="email-incomplete",
|
||||
),
|
||||
pytest.param(
|
||||
WorkflowAction.WorkflowActionType.WEBHOOK,
|
||||
"webhook",
|
||||
{"webhook": {}},
|
||||
id="webhook-empty",
|
||||
),
|
||||
pytest.param(
|
||||
WorkflowAction.WorkflowActionType.WEBHOOK,
|
||||
"webhook",
|
||||
{"webhook": None},
|
||||
id="webhook-null",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_patch_cannot_make_an_incomplete_nested_row(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
action_type: int,
|
||||
nested: str,
|
||||
payload: dict,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An action that has no email or webhook
|
||||
WHEN:
|
||||
- It is patched to an email or webhook action with no, or incomplete,
|
||||
email or webhook data
|
||||
THEN:
|
||||
- The response is a 400 and nothing is stored, a partial update only
|
||||
applies to a row that already exists
|
||||
"""
|
||||
action = WorkflowAction.objects.create(
|
||||
type=WorkflowAction.WorkflowActionType.ASSIGNMENT,
|
||||
)
|
||||
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"PATCH",
|
||||
f"/api/workflow_actions/{action.pk}/",
|
||||
{"type": action_type, **payload},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
action.refresh_from_db()
|
||||
assert getattr(action, nested) is None
|
||||
assert action.type == WorkflowAction.WorkflowActionType.ASSIGNMENT
|
||||
|
||||
@pytest.mark.parametrize("value", [[], "", 0, False, "text", 5])
|
||||
def test_custom_field_values_must_be_an_object(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
value: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- An action is created with custom field values that are not an object,
|
||||
including values that are falsy
|
||||
THEN:
|
||||
- The response is a 400 and nothing is stored
|
||||
"""
|
||||
response = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{
|
||||
"type": WorkflowAction.WorkflowActionType.ASSIGNMENT,
|
||||
"assign_custom_fields_values": value,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert WorkflowAction.objects.count() == 0
|
||||
|
||||
def test_an_id_in_the_payload_cannot_reach_another_actions_email(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An email action
|
||||
WHEN:
|
||||
- A second action is created with the first action's email id in its payload
|
||||
THEN:
|
||||
- The first email is untouched and the second action gets its own row
|
||||
"""
|
||||
first = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{"type": WorkflowAction.WorkflowActionType.EMAIL, "email": EMAIL},
|
||||
)
|
||||
first_email = WorkflowAction.objects.get(pk=first.data["id"]).email
|
||||
|
||||
second = send_json(
|
||||
admin_client,
|
||||
"POST",
|
||||
"/api/workflow_actions/",
|
||||
{
|
||||
"type": WorkflowAction.WorkflowActionType.EMAIL,
|
||||
"email": {**EMAIL, "id": first_email.pk, "subject": "Hijacked"},
|
||||
},
|
||||
)
|
||||
|
||||
assert second.status_code == status.HTTP_201_CREATED
|
||||
first_email.refresh_from_db()
|
||||
assert first_email.subject == "Subject"
|
||||
assert WorkflowAction.objects.get(pk=second.data["id"]).email_id != (
|
||||
first_email.pk
|
||||
)
|
||||
|
||||
|
||||
BEYOND_THE_DATABASE = 2**70
|
||||
|
||||
|
||||
class TestIdListsBeyondTheDatabaseRange:
|
||||
@pytest.mark.parametrize(
|
||||
("path", "body"),
|
||||
[
|
||||
pytest.param(
|
||||
"/api/documents/bulk_edit/",
|
||||
{"documents": [BEYOND_THE_DATABASE], "method": "delete"},
|
||||
id="bulk-edit-documents",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/bulk_edit/",
|
||||
{
|
||||
"documents": [],
|
||||
"method": "modify_tags",
|
||||
"parameters": {"add_tags": [BEYOND_THE_DATABASE]},
|
||||
},
|
||||
id="bulk-edit-tags",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/bulk_edit/",
|
||||
{
|
||||
"documents": [],
|
||||
"method": "modify_custom_fields",
|
||||
"parameters": {
|
||||
"add_custom_fields": [BEYOND_THE_DATABASE],
|
||||
"remove_custom_fields": [],
|
||||
},
|
||||
},
|
||||
id="bulk-edit-custom-fields",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/delete/",
|
||||
{"documents": [BEYOND_THE_DATABASE]},
|
||||
id="delete",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/reprocess/",
|
||||
{"documents": [BEYOND_THE_DATABASE]},
|
||||
id="reprocess",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/rotate/",
|
||||
{"documents": [BEYOND_THE_DATABASE], "degrees": 90},
|
||||
id="rotate",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/merge/",
|
||||
{"documents": [BEYOND_THE_DATABASE, BEYOND_THE_DATABASE + 1]},
|
||||
id="merge",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/bulk_download/",
|
||||
{"documents": [BEYOND_THE_DATABASE], "content": "both"},
|
||||
id="bulk-download",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/selection_data/",
|
||||
{"documents": [BEYOND_THE_DATABASE]},
|
||||
id="selection-data",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/share_link_bundles/",
|
||||
{"document_ids": [BEYOND_THE_DATABASE], "file_version": "archive"},
|
||||
id="share-link-bundle",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/bulk_edit_objects/",
|
||||
{
|
||||
"objects": [BEYOND_THE_DATABASE],
|
||||
"object_type": "tags",
|
||||
"operation": "delete",
|
||||
},
|
||||
id="bulk-edit-objects",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/tasks/acknowledge/",
|
||||
{"tasks": [BEYOND_THE_DATABASE]},
|
||||
id="acknowledge-tasks",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/trash/",
|
||||
{"action": "restore", "documents": [BEYOND_THE_DATABASE]},
|
||||
id="trash",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_id_no_row_can_have_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
path: str,
|
||||
body: dict,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A list of ids includes one larger than a database column can hold
|
||||
THEN:
|
||||
- The response is a 400 like any id that does not exist, not a server
|
||||
error
|
||||
"""
|
||||
response = send_json(admin_client, "POST", path, body)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
@@ -671,8 +671,8 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
content="things i paid for in august",
|
||||
pk=2,
|
||||
checksum="B",
|
||||
# 1 month, 1 day ago
|
||||
added=timezone.now() - relativedelta(months=1, days=1),
|
||||
# More than 1 month ago, in the search timezone
|
||||
added=timezone.localtime() - relativedelta(months=1, days=7),
|
||||
)
|
||||
d3 = Document.objects.create(
|
||||
title="bank statement 3",
|
||||
@@ -706,6 +706,10 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
@override_settings(
|
||||
TIME_ZONE="America/Denver",
|
||||
)
|
||||
@time_machine.travel(
|
||||
datetime.datetime(2026, 12, 1, 0, 1, tzinfo=datetime.UTC),
|
||||
tick=False,
|
||||
)
|
||||
def test_search_added_in_last_month_timezone_behind(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
@@ -729,8 +733,8 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
content="things i paid for in august",
|
||||
pk=2,
|
||||
checksum="B",
|
||||
# 1 month, 1 day ago
|
||||
added=timezone.now() - relativedelta(months=1, days=1),
|
||||
# More than 1 month ago, in the search timezone
|
||||
added=timezone.localtime() - relativedelta(months=1, days=7),
|
||||
)
|
||||
d3 = Document.objects.create(
|
||||
title="bank statement 3",
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
import pytest
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from paperless_testing.factories import DocumentFactory
|
||||
from paperless_testing.factories import TagFactory
|
||||
|
||||
HUGE = 2**63 # one above the largest signed 64 bit integer
|
||||
|
||||
|
||||
class TestFilterInputBounds:
|
||||
@pytest.mark.parametrize(
|
||||
("path", "query"),
|
||||
[
|
||||
pytest.param("/api/tags/", f"id__in={HUGE}", id="tags-id-in"),
|
||||
pytest.param("/api/tags/", f"id={HUGE}", id="tags-id-exact"),
|
||||
pytest.param("/api/tags/", f"id__in=1,{HUGE}", id="tags-id-in-mixed"),
|
||||
pytest.param("/api/documents/", f"id__in={HUGE}", id="documents-id-in"),
|
||||
pytest.param("/api/documents/", "created__year=0", id="year-zero"),
|
||||
pytest.param("/api/documents/", "created__year=10000", id="year-too-big"),
|
||||
pytest.param("/api/documents/", "created__month=13", id="month-13"),
|
||||
pytest.param("/api/documents/", "created__day=0", id="day-zero"),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"created__year=-10000000000000000",
|
||||
id="year-hugely-negative",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"added__gt=2024-01-01T00:00:00%2B16:29",
|
||||
id="offset-too-large",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"added__gt=0001-01-01T00:00:00%2B05:00",
|
||||
id="utc-conversion-overflows",
|
||||
),
|
||||
pytest.param("/api/share_links/", "created__year=0", id="share-links-year"),
|
||||
pytest.param(
|
||||
"/api/share_links/",
|
||||
f"expiration__day={HUGE}",
|
||||
id="share-links-day",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/share_link_bundles/",
|
||||
"expiration__year=100000000000000000",
|
||||
id="bundles-year",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/tasks/",
|
||||
"date_created_after=2024-01-01T00:00:00%2B16:29",
|
||||
id="tasks-offset",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"ordering=custom_field_abc",
|
||||
id="ordering-not-a-number",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
f"ordering=custom_field_{HUGE}",
|
||||
id="ordering-out-of-range",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_out_of_range_value_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
path: str,
|
||||
query: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- A filter or ordering value outside what the database can hold is sent
|
||||
THEN:
|
||||
- The response is a 400, not a server error
|
||||
"""
|
||||
response = admin_client.get(f"{path}?{query}")
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("path", "query"),
|
||||
[
|
||||
pytest.param("/api/documents/", f"tags__id__all={HUGE}", id="tags-all"),
|
||||
pytest.param("/api/documents/", f"tags__id__in={HUGE}", id="tags-in"),
|
||||
pytest.param(
|
||||
"/api/share_link_bundles/",
|
||||
f"documents={HUGE}",
|
||||
id="bundle-documents",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_id_list_with_an_impossible_id_matches_nothing(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
path: str,
|
||||
query: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A document that has a tag
|
||||
WHEN:
|
||||
- An id list filter includes an id that no row can have
|
||||
THEN:
|
||||
- The request succeeds and nothing matches
|
||||
"""
|
||||
document = DocumentFactory.create()
|
||||
document.tags.add(TagFactory.create())
|
||||
|
||||
response = admin_client.get(f"{path}?{query}")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data["count"] == 0
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("path", "query"),
|
||||
[
|
||||
pytest.param("/api/tags/", "id__in=1,2", id="id-in"),
|
||||
pytest.param("/api/documents/", "created__year=2024", id="year"),
|
||||
pytest.param("/api/documents/", "created__year=9999", id="year-max"),
|
||||
pytest.param("/api/documents/", "created__month=12", id="month"),
|
||||
pytest.param("/api/documents/", "created__day=31", id="day"),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"added__gt=2024-01-01T00:00:00%2B14:00",
|
||||
id="offset-at-the-limit",
|
||||
),
|
||||
pytest.param(
|
||||
"/api/documents/",
|
||||
"added__gt=2024-01-01T00:00:00-12:00",
|
||||
id="negative-offset",
|
||||
),
|
||||
pytest.param("/api/tasks/", "date_created_after=2024-01-01", id="tasks"),
|
||||
],
|
||||
)
|
||||
def test_in_range_values_still_work(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
path: str,
|
||||
query: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- Filters with ordinary values are sent
|
||||
THEN:
|
||||
- The request succeeds
|
||||
"""
|
||||
response = admin_client.get(f"{path}?{query}")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
|
||||
class TestSetPermissionsIdBounds:
|
||||
@pytest.mark.parametrize("grantee", ["users", "groups"])
|
||||
@pytest.mark.parametrize("bad_id", [HUGE, -HUGE, "abc", None])
|
||||
def test_impossible_grantee_id_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
grantee: str,
|
||||
bad_id: object,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A tag
|
||||
WHEN:
|
||||
- Permissions are set with a user or group id that cannot exist
|
||||
THEN:
|
||||
- The response is a 400, not a server error
|
||||
"""
|
||||
tag = TagFactory.create()
|
||||
|
||||
response = admin_client.put(
|
||||
f"/api/tags/{tag.pk}/",
|
||||
{"name": tag.name, "set_permissions": {"view": {grantee: [bad_id]}}},
|
||||
format="json",
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
+12
-26
@@ -3,7 +3,6 @@ import logging
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
from collections import Counter
|
||||
@@ -150,7 +149,6 @@ from documents.filters import StoragePathFilterSet
|
||||
from documents.filters import TagFilterSet
|
||||
from documents.filters import TitleContentFilter
|
||||
from documents.filters import WorkflowFilterSet
|
||||
from documents.filters import in_range_ids
|
||||
from documents.mail import EmailAttachment
|
||||
from documents.mail import send_email
|
||||
from documents.matching import match_correspondents
|
||||
@@ -266,7 +264,6 @@ from documents.versioning import resolve_effective_document
|
||||
from documents.versioning import resolve_requested_version_for_root
|
||||
from documents.versioning import versions_newest_first
|
||||
from paperless import version
|
||||
from paperless.api_parsers import ObjectJSONParser
|
||||
from paperless.celery import app as celery_app
|
||||
from paperless.config import AIConfig
|
||||
from paperless.config import GeneralConfig
|
||||
@@ -2942,14 +2939,12 @@ LOG_FILES = {
|
||||
class LogViewSet(ViewSet):
|
||||
permission_classes = (IsAuthenticated, PaperlessAdminPermissions)
|
||||
|
||||
ALLOWED_LOG_FILES = LOG_FILES
|
||||
|
||||
def get_log_file(self, log_key: str) -> Path:
|
||||
return Path(settings.LOGGING_DIR) / self.ALLOWED_LOG_FILES[log_key]
|
||||
return Path(settings.LOGGING_DIR) / LOG_FILES[log_key]
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
log_key = kwargs.get("pk")
|
||||
if log_key not in self.ALLOWED_LOG_FILES:
|
||||
if log_key not in LOG_FILES:
|
||||
raise Http404
|
||||
|
||||
log_file = self.get_log_file(log_key)
|
||||
@@ -2965,8 +2960,6 @@ class LogViewSet(ViewSet):
|
||||
raise ValidationError({"limit": "Must be a positive integer"})
|
||||
if limit < 1:
|
||||
raise ValidationError({"limit": "Must be a positive integer"})
|
||||
# A limit past what a deque can hold is the same as no limit at all
|
||||
limit = min(limit, sys.maxsize)
|
||||
else:
|
||||
limit = None
|
||||
|
||||
@@ -2980,9 +2973,7 @@ class LogViewSet(ViewSet):
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
existing_logs = [
|
||||
log_key
|
||||
for log_key in self.ALLOWED_LOG_FILES
|
||||
if self.get_log_file(log_key).is_file()
|
||||
log_key for log_key in LOG_FILES if self.get_log_file(log_key).is_file()
|
||||
]
|
||||
return Response(existing_logs)
|
||||
|
||||
@@ -3137,7 +3128,7 @@ def queue_bulk_operation(
|
||||
|
||||
class DocumentOperationPermissionMixin(PassUserMixin, DocumentSelectionMixin):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
parser_classes = (ObjectJSONParser,)
|
||||
parser_classes = (parsers.JSONParser,)
|
||||
|
||||
def _queue_bulk_operation(self, method, documents, parameters, from_webui):
|
||||
return queue_bulk_operation(
|
||||
@@ -3639,7 +3630,7 @@ class PostDocumentView(GenericAPIView[Any]):
|
||||
class SelectionDataView(DocumentSelectionMixin, GenericAPIView[Any]):
|
||||
permission_classes = (IsAuthenticated, ViewDocumentsPermissions)
|
||||
serializer_class = DocumentSelectionSerializer
|
||||
parser_classes = (parsers.MultiPartParser, ObjectJSONParser)
|
||||
parser_classes = (parsers.MultiPartParser, parsers.JSONParser)
|
||||
|
||||
def post(self, request, format=None):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
@@ -3824,9 +3815,6 @@ class GlobalSearchView(PassUserMixin):
|
||||
return HttpResponseBadRequest(
|
||||
f"Query must be at most {_MAX_QUERY_LENGTH} characters",
|
||||
)
|
||||
if "\x00" in query:
|
||||
# Postgres cannot store or compare text containing a null byte
|
||||
return HttpResponseBadRequest("Query must not contain null characters")
|
||||
|
||||
db_only = request.query_params.get("db_only", False)
|
||||
|
||||
@@ -4180,7 +4168,7 @@ class StatisticsView(GenericAPIView[Any]):
|
||||
class BulkDownloadView(DocumentSelectionMixin, GenericAPIView[Any]):
|
||||
permission_classes = (IsAuthenticated, ViewDocumentsPermissions)
|
||||
serializer_class = BulkDownloadSerializer
|
||||
parser_classes = (ObjectJSONParser,)
|
||||
parser_classes = (parsers.JSONParser,)
|
||||
|
||||
def post(self, request, format=None):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
@@ -4330,10 +4318,8 @@ class UiSettingsView(GenericAPIView[Any]):
|
||||
user = User.objects.select_related("ui_settings").get(pk=request.user.id)
|
||||
ui_settings = {}
|
||||
if hasattr(user, "ui_settings"):
|
||||
# Saved as null or, before it was validated, as something else
|
||||
stored = user.ui_settings.settings
|
||||
ui_settings = stored if isinstance(stored, dict) else {}
|
||||
if isinstance(ui_settings.get("update_checking"), dict):
|
||||
ui_settings = user.ui_settings.settings
|
||||
if "update_checking" in ui_settings:
|
||||
ui_settings["update_checking"]["backend_setting"] = (
|
||||
settings.ENABLE_UPDATE_CHECK
|
||||
)
|
||||
@@ -5063,9 +5049,9 @@ class ShareLinkBundleViewSet(PassUserMixin, ModelViewSet[ShareLinkBundle]):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
document_ids = serializer.validated_data["document_ids"]
|
||||
documents_qs = Document.objects.filter(
|
||||
pk__in=in_range_ids(document_ids),
|
||||
).select_related("owner")
|
||||
documents_qs = Document.objects.filter(pk__in=document_ids).select_related(
|
||||
"owner",
|
||||
)
|
||||
found_ids = set(documents_qs.values_list("pk", flat=True))
|
||||
missing = sorted(set(document_ids) - found_ids)
|
||||
if missing:
|
||||
@@ -5317,7 +5303,7 @@ def serve_file(
|
||||
class BulkEditObjectsView(PassUserMixin):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
serializer_class = BulkEditObjectsSerializer
|
||||
parser_classes = (ObjectJSONParser,)
|
||||
parser_classes = (parsers.JSONParser,)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
|
||||
@@ -2,7 +2,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: paperless-ngx\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-28 23:01+0000\n"
|
||||
"POT-Creation-Date: 2026-11-30 18:39+0000\n"
|
||||
"PO-Revision-Date: 2022-02-17 04:17\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: English\n"
|
||||
@@ -1881,7 +1881,7 @@ msgstr ""
|
||||
|
||||
#: documents/serialisers.py:495 documents/serialisers.py:819
|
||||
#: documents/serialisers.py:2918 documents/views.py:372 documents/views.py:638
|
||||
#: documents/views.py:2870 paperless_mail/serialisers.py:145
|
||||
#: documents/views.py:2878 paperless_mail/serialisers.py:145
|
||||
msgid "Insufficient permissions."
|
||||
msgstr ""
|
||||
|
||||
@@ -1921,7 +1921,7 @@ msgstr ""
|
||||
msgid "Duplicate document identifiers are not allowed."
|
||||
msgstr ""
|
||||
|
||||
#: documents/serialisers.py:3004 documents/views.py:5008
|
||||
#: documents/serialisers.py:3004 documents/views.py:5061
|
||||
#, python-format
|
||||
msgid "Documents not found: %(ids)s"
|
||||
msgstr ""
|
||||
@@ -2192,36 +2192,36 @@ msgstr ""
|
||||
msgid "Specify only one of text, title_search, query, or more_like_id."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:365 documents/views.py:2867
|
||||
#: documents/views.py:365 documents/views.py:2875
|
||||
msgid "Invalid more_like_id"
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:1697
|
||||
#: documents/views.py:1705
|
||||
msgid "Invalid AI configuration."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:1708
|
||||
#: documents/views.py:1716
|
||||
msgid "AI backend request timed out."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:1720
|
||||
#: documents/views.py:1728
|
||||
msgid "AI backend rejected the request. Check logs for details."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:5024
|
||||
#: documents/views.py:5077
|
||||
#, python-format
|
||||
msgid "Insufficient permissions to share document %(id)s."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:5071
|
||||
#: documents/views.py:5124
|
||||
msgid "Bundle is already being processed."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:5137
|
||||
#: documents/views.py:5190
|
||||
msgid "The share link bundle is still being prepared. Please try again later."
|
||||
msgstr ""
|
||||
|
||||
#: documents/views.py:5151
|
||||
#: documents/views.py:5204
|
||||
msgid "The share link bundle is unavailable."
|
||||
msgstr ""
|
||||
|
||||
@@ -2661,7 +2661,7 @@ msgstr ""
|
||||
msgid "Chinese Traditional"
|
||||
msgstr ""
|
||||
|
||||
#: paperless/urls.py:452
|
||||
#: paperless/urls.py:455
|
||||
msgid "Paperless-ngx administration"
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.parsers import JSONParser
|
||||
|
||||
|
||||
class ObjectJSONParser(JSONParser):
|
||||
"""
|
||||
DRF accepts any JSON document as a request body. The views and serializers here
|
||||
read the body as a mapping, so a top level list or scalar (or null) would end in
|
||||
a server error. Reject it as the malformed request it is.
|
||||
"""
|
||||
|
||||
def parse(self, stream, media_type=None, parser_context=None):
|
||||
data = super().parse(stream, media_type, parser_context)
|
||||
if not isinstance(data, dict):
|
||||
raise ParseError("The request body must be a JSON object.")
|
||||
return data
|
||||
@@ -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
|
||||
@@ -20,6 +20,4 @@ class ObfuscatedPasswordField(serializers.CharField):
|
||||
return OBFUSCATED_PASSWORD_MASK
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if not isinstance(data, str):
|
||||
self.fail("invalid")
|
||||
return data
|
||||
@@ -374,15 +374,19 @@ class TikaDocumentParser:
|
||||
|
||||
try:
|
||||
parsed = self._tika_client.metadata.from_file(document_path, mime_type)
|
||||
return [
|
||||
{
|
||||
"namespace": "",
|
||||
"prefix": "",
|
||||
"key": key,
|
||||
"value": parsed.data[key],
|
||||
}
|
||||
for key in parsed.data
|
||||
]
|
||||
metadata: list[MetadataEntry] = []
|
||||
for key, value in parsed.data.items():
|
||||
if isinstance(value, list):
|
||||
value = " ".join(str(item) for item in value)
|
||||
metadata.append(
|
||||
{
|
||||
"namespace": "",
|
||||
"prefix": "",
|
||||
"key": key,
|
||||
"value": str(value),
|
||||
},
|
||||
)
|
||||
return metadata
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Error while fetching document metadata for %s: %s",
|
||||
|
||||
@@ -77,21 +77,9 @@ class PaperlessAuthTokenSerializer(AuthTokenSerializer):
|
||||
return attrs
|
||||
|
||||
|
||||
class CodenameRelatedField(serializers.SlugRelatedField):
|
||||
"""
|
||||
Looks a permission up by its codename. A codename with a null byte cannot exist, and
|
||||
Postgres raises an error, instead of finding nothing, if asked for one.
|
||||
"""
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if isinstance(data, str) and "\x00" in data:
|
||||
self.fail("does_not_exist", slug_name=self.slug_field, value=repr(data))
|
||||
return super().to_internal_value(data)
|
||||
|
||||
|
||||
class UserSerializer(PasswordValidationMixin, serializers.ModelSerializer[User]):
|
||||
password = ObfuscatedPasswordField(required=False)
|
||||
user_permissions = CodenameRelatedField(
|
||||
user_permissions = serializers.SlugRelatedField(
|
||||
many=True,
|
||||
queryset=Permission.objects.exclude(content_type__app_label="admin"),
|
||||
slug_field="codename",
|
||||
@@ -158,7 +146,7 @@ class UserSerializer(PasswordValidationMixin, serializers.ModelSerializer[User])
|
||||
|
||||
|
||||
class GroupSerializer(serializers.ModelSerializer[Group]):
|
||||
permissions = CodenameRelatedField(
|
||||
permissions = serializers.SlugRelatedField(
|
||||
many=True,
|
||||
queryset=Permission.objects.exclude(content_type__app_label="admin"),
|
||||
slug_field="codename",
|
||||
@@ -294,8 +282,7 @@ class ApplicationConfigurationSerializer(
|
||||
if "llm_output_language" in data and data["llm_output_language"] == "":
|
||||
data["llm_output_language"] = None
|
||||
for field in self.OBFUSCATED_FIELDS:
|
||||
# Anything that is not a string is left for the field to reject
|
||||
if field in data and isinstance(data[field], str):
|
||||
if field in data and data[field] is not None:
|
||||
if data[field] == "":
|
||||
data[field] = None
|
||||
# Not a real value, don't overwrite the stored one
|
||||
|
||||
@@ -169,11 +169,6 @@ REST_FRAMEWORK = {
|
||||
"rest_framework.authentication.TokenAuthentication",
|
||||
"rest_framework.authentication.SessionAuthentication",
|
||||
],
|
||||
"DEFAULT_PARSER_CLASSES": [
|
||||
"paperless.api_parsers.ObjectJSONParser",
|
||||
"rest_framework.parsers.FormParser",
|
||||
"rest_framework.parsers.MultiPartParser",
|
||||
],
|
||||
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.AcceptHeaderVersioning",
|
||||
"DEFAULT_VERSION": "10", # match src-ui/src/environments/environment.prod.ts
|
||||
# Make sure these are ordered and that the most recent version appears
|
||||
@@ -812,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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -131,8 +131,10 @@ class TestTikaParser:
|
||||
httpx_mock.add_response(
|
||||
json={
|
||||
"Content-Type": "application/vnd.oasis.opendocument.text",
|
||||
"X-TIKA:Parsed-By": [],
|
||||
"X-TIKA:Parsed-By": ["ParserA", "ParserB"],
|
||||
"X-TIKA:Parsed-By-Full-Set": [],
|
||||
"Some-key": "value",
|
||||
"meta:page-count": 2,
|
||||
"dcterms:created": "2020-11-21T00:00:00",
|
||||
},
|
||||
)
|
||||
@@ -144,6 +146,11 @@ class TestTikaParser:
|
||||
|
||||
assert "dcterms:created" in [m["key"] for m in metadata]
|
||||
assert "Some-key" in [m["key"] for m in metadata]
|
||||
values = {entry["key"]: entry["value"] for entry in metadata}
|
||||
assert values["X-TIKA:Parsed-By"] == "ParserA ParserB"
|
||||
assert values["X-TIKA:Parsed-By-Full-Set"] == ""
|
||||
assert values["meta:page-count"] == "2"
|
||||
assert all(isinstance(value, str) for value in values.values())
|
||||
|
||||
def test_convert_failure(
|
||||
self,
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pytest_django.fixtures import DjangoAssertNumQueries
|
||||
from pytest_django.fixtures import Settings
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from paperless.serialisers import GroupSerializer
|
||||
from paperless.serialisers import UserSerializer
|
||||
|
||||
|
||||
class TestNullByteInput:
|
||||
@pytest.mark.parametrize("db_only", ["true", "false"])
|
||||
def test_global_search_rejects_null_byte(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
db_only: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- The global search query contains a null byte
|
||||
THEN:
|
||||
- The response is a 400, the query never reaches the database
|
||||
"""
|
||||
response = admin_client.get(
|
||||
"/api/search/",
|
||||
{"query": "invoice\x00number", "db_only": db_only},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("serializer", "field"),
|
||||
[
|
||||
pytest.param(GroupSerializer, "permissions", id="group"),
|
||||
pytest.param(UserSerializer, "user_permissions", id="user"),
|
||||
],
|
||||
)
|
||||
def test_codename_with_null_byte_is_rejected_without_a_query(
|
||||
self,
|
||||
db: None,
|
||||
django_assert_num_queries: DjangoAssertNumQueries,
|
||||
serializer: type,
|
||||
field: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A permission codename field
|
||||
WHEN:
|
||||
- A value containing a null byte is validated
|
||||
THEN:
|
||||
- It is rejected without querying, Postgres raises an error for it
|
||||
where SQLite does not
|
||||
"""
|
||||
codename_field = serializer().fields[field].child_relation
|
||||
|
||||
with django_assert_num_queries(0), pytest.raises(ValidationError):
|
||||
codename_field.to_internal_value("view_document\x00")
|
||||
|
||||
|
||||
class TestLogLimit:
|
||||
def test_limit_larger_than_any_file_returns_everything(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
settings: Settings,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A log file
|
||||
WHEN:
|
||||
- The limit is larger than a platform integer can hold
|
||||
THEN:
|
||||
- The whole file is returned, as for any limit above its length
|
||||
"""
|
||||
settings.LOGGING_DIR = tmp_path
|
||||
(tmp_path / "paperless.log").write_text("one\ntwo\nthree\n")
|
||||
|
||||
response = admin_client.get("/api/logs/paperless/", {"limit": 2**70})
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data == ["one", "two", "three"]
|
||||
|
||||
|
||||
class TestTotpView:
|
||||
def test_options_does_not_fail(self, admin_client: APIClient) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- OPTIONS is sent to the TOTP endpoint
|
||||
THEN:
|
||||
- The request succeeds, DRF's metadata needs a serializer on the view
|
||||
"""
|
||||
response = admin_client.options("/api/profile/totp/")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"body",
|
||||
[{}, {"secret": "abc"}, {"code": "123456"}, {"secret": None, "code": None}],
|
||||
)
|
||||
def test_activation_with_missing_fields_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
body: dict,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- TOTP is activated without both the secret and the code
|
||||
THEN:
|
||||
- The response is a 400, not a server error
|
||||
"""
|
||||
response = admin_client.post("/api/profile/totp/", body, format="json")
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
@@ -0,0 +1,39 @@
|
||||
import pytest
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
|
||||
class TestTotpView:
|
||||
def test_options_does_not_fail(self, admin_client: APIClient) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- OPTIONS is sent to the TOTP endpoint
|
||||
THEN:
|
||||
- The request succeeds, DRF's metadata needs a serializer on the view
|
||||
"""
|
||||
response = admin_client.options("/api/profile/totp/")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"body",
|
||||
[{}, {"secret": "abc"}, {"code": "123456"}, {"secret": None, "code": None}],
|
||||
)
|
||||
def test_activation_with_missing_fields_is_a_400(
|
||||
self,
|
||||
admin_client: APIClient,
|
||||
body: dict[str, str | None],
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- An authenticated client
|
||||
WHEN:
|
||||
- TOTP is activated without both the secret and the code
|
||||
THEN:
|
||||
- The response is a 400, not a server error
|
||||
"""
|
||||
response = admin_client.post("/api/profile/totp/", body, format="json")
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
@@ -0,0 +1,66 @@
|
||||
import pickle
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from django.core.cache.backends.redis import RedisCache
|
||||
|
||||
from paperless.cache import SignedRedisSerializer
|
||||
from paperless.signed_pickle import compute_signature
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def serializer() -> SignedRedisSerializer:
|
||||
return SignedRedisSerializer()
|
||||
|
||||
|
||||
class TestSignedRedisSerializer:
|
||||
def test_round_trip(self, serializer: SignedRedisSerializer) -> None:
|
||||
value = {"a": [1, 2, 3], "b": ("x", None)}
|
||||
assert serializer.loads(serializer.dumps(value)) == value
|
||||
|
||||
def test_integers_are_stored_raw(self, serializer: SignedRedisSerializer) -> None:
|
||||
# incr/decr operate on the raw value in Redis
|
||||
assert serializer.dumps(7) == 7
|
||||
assert serializer.loads(b"7") == 7
|
||||
flag = bool(1)
|
||||
assert isinstance(serializer.dumps(flag), bytes)
|
||||
|
||||
def test_unsigned_pickle_is_not_loaded(
|
||||
self,
|
||||
serializer: SignedRedisSerializer,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
marker = tmp_path / "marker"
|
||||
|
||||
class Evil:
|
||||
def __reduce__(self):
|
||||
return (marker.write_text, ("pwned",))
|
||||
|
||||
assert serializer.loads(pickle.dumps(Evil())) is None
|
||||
assert not marker.exists()
|
||||
|
||||
def test_pickle_signed_with_other_key_is_not_loaded(
|
||||
self,
|
||||
serializer: SignedRedisSerializer,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
marker = tmp_path / "marker"
|
||||
|
||||
class Evil:
|
||||
def __reduce__(self):
|
||||
return (marker.write_text, ("pwned",))
|
||||
|
||||
data = pickle.dumps(Evil())
|
||||
forged = compute_signature(b"not the real data") + data
|
||||
assert serializer.loads(forged) is None
|
||||
assert not marker.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("alias", ["default", "read-cache"])
|
||||
def test_redis_caches_use_signed_serializer(alias: str) -> None:
|
||||
# The test settings use LocMemCache, so check the configuration is wired up
|
||||
# and that RedisCache honours it
|
||||
options = settings.CACHES[alias]["OPTIONS"]
|
||||
assert options["serializer"] == "paperless.cache.SignedRedisSerializer"
|
||||
cache = RedisCache("redis://localhost:6379", {"OPTIONS": options})
|
||||
assert isinstance(cache._cache._serializer, SignedRedisSerializer)
|
||||
@@ -658,9 +658,9 @@ class TestUserGroupDeletionCleanup(TestCase):
|
||||
"permissions": {
|
||||
"default_owner": user2.id,
|
||||
"default_view_users": [user2.id],
|
||||
"default_change_users": [user2.id],
|
||||
"default_edit_users": [user2.id],
|
||||
"default_view_groups": [group.id],
|
||||
"default_change_groups": [group.id],
|
||||
"default_edit_groups": [group.id],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -670,13 +670,13 @@ class TestUserGroupDeletionCleanup(TestCase):
|
||||
permissions = ui_settings.settings.get("permissions", {})
|
||||
self.assertIsNone(permissions.get("default_owner"))
|
||||
self.assertEqual(permissions.get("default_view_users"), [])
|
||||
self.assertEqual(permissions.get("default_change_users"), [])
|
||||
self.assertEqual(permissions.get("default_edit_users"), [])
|
||||
|
||||
group.delete()
|
||||
ui_settings.refresh_from_db()
|
||||
permissions = ui_settings.settings.get("permissions", {})
|
||||
self.assertEqual(permissions.get("default_view_groups"), [])
|
||||
self.assertEqual(permissions.get("default_change_groups"), [])
|
||||
self.assertEqual(permissions.get("default_edit_groups"), [])
|
||||
|
||||
def test_user_group_deletion_error_handling(self) -> None:
|
||||
"""
|
||||
|
||||
+37
-46
@@ -894,8 +894,6 @@ class MailAccountHandler(LoggingMixin):
|
||||
def _handle_message(self, message, rule: MailRule) -> int:
|
||||
message = self._preprocess_message(message)
|
||||
|
||||
processed_elements = 0
|
||||
|
||||
# Skip Message handling when only attachments are to be processed but
|
||||
# message doesn't have any.
|
||||
if (
|
||||
@@ -903,7 +901,7 @@ class MailAccountHandler(LoggingMixin):
|
||||
and rule.consumption_scope == MailRule.ConsumptionScope.ATTACHMENTS_ONLY
|
||||
):
|
||||
self._record_processed_without_consumption(message, rule)
|
||||
return processed_elements
|
||||
return 0
|
||||
|
||||
self.log.debug(
|
||||
f"Rule {rule}: "
|
||||
@@ -914,29 +912,47 @@ class MailAccountHandler(LoggingMixin):
|
||||
tag_ids: list[int] = [tag.id for tag in rule.assign_tags.all()]
|
||||
doc_type = rule.assign_document_type
|
||||
|
||||
consume_tasks: list[Signature] = []
|
||||
|
||||
if (
|
||||
rule.consumption_scope == MailRule.ConsumptionScope.EML_ONLY
|
||||
or rule.consumption_scope == MailRule.ConsumptionScope.EVERYTHING
|
||||
):
|
||||
processed_elements += self._process_eml(
|
||||
message,
|
||||
rule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
consume_tasks.append(
|
||||
self._build_eml_task(
|
||||
message,
|
||||
rule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
),
|
||||
)
|
||||
|
||||
if (
|
||||
rule.consumption_scope == MailRule.ConsumptionScope.ATTACHMENTS_ONLY
|
||||
or rule.consumption_scope == MailRule.ConsumptionScope.EVERYTHING
|
||||
):
|
||||
processed_elements += self._process_attachments(
|
||||
message,
|
||||
rule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
consume_tasks.extend(
|
||||
self._build_attachment_tasks(
|
||||
message,
|
||||
rule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
),
|
||||
)
|
||||
|
||||
return processed_elements
|
||||
# One chord per message, so the mail action and the ProcessedMail row
|
||||
# are written once, after every part of the message has been consumed
|
||||
if consume_tasks:
|
||||
queue_consumption_tasks(
|
||||
consume_tasks=consume_tasks,
|
||||
rule=rule,
|
||||
message=message,
|
||||
uid_validity=self._current_uid_validity,
|
||||
)
|
||||
else:
|
||||
self._record_processed_without_consumption(message, rule)
|
||||
|
||||
return len(consume_tasks)
|
||||
|
||||
def _record_processed_without_consumption(
|
||||
self,
|
||||
@@ -995,16 +1011,14 @@ class MailAccountHandler(LoggingMixin):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _process_attachments(
|
||||
def _build_attachment_tasks(
|
||||
self,
|
||||
message: MailMessage,
|
||||
rule: MailRule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
):
|
||||
processed_attachments = 0
|
||||
|
||||
consume_tasks = []
|
||||
) -> list[Signature]:
|
||||
consume_tasks: list[Signature] = []
|
||||
|
||||
for att in message.attachments:
|
||||
if (
|
||||
@@ -1105,8 +1119,6 @@ class MailAccountHandler(LoggingMixin):
|
||||
)
|
||||
|
||||
consume_tasks.append(consume_task)
|
||||
|
||||
processed_attachments += 1
|
||||
else:
|
||||
self.log.debug(
|
||||
f"Rule {rule}: "
|
||||
@@ -1115,26 +1127,15 @@ class MailAccountHandler(LoggingMixin):
|
||||
f"by paperless",
|
||||
)
|
||||
|
||||
if len(consume_tasks) > 0:
|
||||
queue_consumption_tasks(
|
||||
consume_tasks=consume_tasks,
|
||||
rule=rule,
|
||||
message=message,
|
||||
uid_validity=self._current_uid_validity,
|
||||
)
|
||||
else:
|
||||
# No files to consume, just mark as processed if it wasn't by .eml processing
|
||||
self._record_processed_without_consumption(message, rule)
|
||||
return consume_tasks
|
||||
|
||||
return processed_attachments
|
||||
|
||||
def _process_eml(
|
||||
def _build_eml_task(
|
||||
self,
|
||||
message: MailMessage,
|
||||
rule: MailRule,
|
||||
tag_ids,
|
||||
doc_type,
|
||||
):
|
||||
) -> Signature:
|
||||
settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True)
|
||||
fd, temp_filename = tempfile.mkstemp(
|
||||
prefix="paperless-mail-",
|
||||
@@ -1192,17 +1193,7 @@ class MailAccountHandler(LoggingMixin):
|
||||
owner_id=rule.owner.id if rule.owner else None,
|
||||
)
|
||||
|
||||
consume_task = consume_file.s(
|
||||
return consume_file.s(
|
||||
input_doc=input_doc,
|
||||
overrides=doc_overrides,
|
||||
).set(headers={"trigger_source": PaperlessTask.TriggerSource.EMAIL_CONSUME})
|
||||
|
||||
queue_consumption_tasks(
|
||||
consume_tasks=[consume_task],
|
||||
rule=rule,
|
||||
message=message,
|
||||
uid_validity=self._current_uid_validity,
|
||||
)
|
||||
|
||||
processed_elements = 1
|
||||
return processed_elements
|
||||
@@ -416,6 +416,44 @@ class TestMail(
|
||||
1,
|
||||
)
|
||||
|
||||
def test_handle_message_everything_scope_single_row(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A rule consuming the eml and attachments, and a mail with or
|
||||
without attachments
|
||||
WHEN:
|
||||
- The mail is handled and its queued mail action is applied
|
||||
THEN:
|
||||
- The eml and attachments are queued together in one call
|
||||
- Exactly one ProcessedMail row exists and it is not
|
||||
PROCESSED_WO_CONSUMPTION
|
||||
"""
|
||||
rule = MailRule.objects.create(
|
||||
account=MailAccount.objects.create(
|
||||
name="test",
|
||||
imap_server="",
|
||||
username="admin",
|
||||
password="secret",
|
||||
),
|
||||
consumption_scope=MailRule.ConsumptionScope.EVERYTHING,
|
||||
)
|
||||
|
||||
for attachments in (0, 2):
|
||||
with self.subTest(attachments=attachments):
|
||||
self.mailMocker._queue_consumption_tasks_mock.reset_mock()
|
||||
message = self.mailMocker.messageBuilder.create_message(
|
||||
subject=f"{attachments} attachments",
|
||||
attachments=attachments,
|
||||
)
|
||||
|
||||
result = self.mail_account_handler._handle_message(message, rule)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(result, 1 + attachments)
|
||||
self.mailMocker._queue_consumption_tasks_mock.assert_called_once()
|
||||
processed = ProcessedMail.objects.get(rule=rule, uid=message.uid)
|
||||
self.assertEqual(processed.status, "SUCCESS")
|
||||
|
||||
def test_handle_empty_message_long_subject(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
|
||||
@@ -272,8 +272,6 @@ class TestMailMessageGpgDecryptor(TestMail):
|
||||
"override_title": message.subject,
|
||||
"override_filename": f"{message.subject}.eml",
|
||||
},
|
||||
],
|
||||
[
|
||||
{"override_title": "file_0", "override_filename": "file_0.pdf"},
|
||||
{"override_title": "file_1", "override_filename": "file_1.pdf"},
|
||||
],
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpResponse
|
||||
from django.http import StreamingHttpResponse
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
|
||||
def read_streaming_response(response: StreamingHttpResponse) -> bytes:
|
||||
@@ -14,13 +11,3 @@ def read_streaming_response(response: StreamingHttpResponse) -> bytes:
|
||||
content = b"".join(response.streaming_content)
|
||||
response.close()
|
||||
return content
|
||||
|
||||
|
||||
def send_json(client: APIClient, method: str, path: str, body: object) -> HttpResponse:
|
||||
"""Send a request with a JSON body, any method, whatever the body is."""
|
||||
return client.generic(
|
||||
method,
|
||||
path,
|
||||
data=json.dumps(body),
|
||||
content_type="application/json",
|
||||
)
|
||||
Reference in new issue
Block a user