From 6f0ac7ae452ff2207a61a807b5f04028d72136e9 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 1 Apr 2022 01:47:21 -0700 Subject: [PATCH 01/12] Update bootstrap-icons.svg --- .../components/app-frame/app-frame.component.html | 12 ++++++------ src-ui/src/assets/bootstrap-icons.svg | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.html b/src-ui/src/app/components/app-frame/app-frame.component.html index 5889e0e24..aca66eb3a 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.html +++ b/src-ui/src/app/components/app-frame/app-frame.component.html @@ -12,7 +12,7 @@
- + diff --git a/src-ui/src/app/components/app-frame/app-frame.component.scss b/src-ui/src/app/components/app-frame/app-frame.component.scss index 95cb888e7..6fe4c1ed9 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.scss +++ b/src-ui/src/app/components/app-frame/app-frame.component.scss @@ -176,3 +176,22 @@ } } } + +.version-check { + animation: pulse 2s ease-in-out 0s 1; +} + +@keyframes pulse { + 0% { + opacity: 0; + } + 25% { + opacity: 100%; + } + 75% { + opacity: 0; + } + 100% { + opacity: 100%; + } +} diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index a038c9a31..a335aad1d 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -18,6 +18,10 @@ import { DocumentDetailComponent } from '../document-detail/document-detail.comp import { Meta } from '@angular/platform-browser' import { DocumentListViewService } from 'src/app/services/document-list-view.service' import { FILTER_FULLTEXT_QUERY } from 'src/app/data/filter-rule-type' +import { + RemoteVersionService, + AppRemoteVersion, +} from 'src/app/services/rest/remote-version.service' @Component({ selector: 'app-app-frame', @@ -32,10 +36,18 @@ export class AppFrameComponent { private searchService: SearchService, public savedViewService: SavedViewService, private list: DocumentListViewService, - private meta: Meta - ) {} + private meta: Meta, + private remoteVersionService: RemoteVersionService + ) { + this.remoteVersionService + .checkForUpdates() + .subscribe((appRemoteVersion: AppRemoteVersion) => { + this.appRemoteVersion = appRemoteVersion + }) + } versionString = `${environment.appTitle} ${environment.version}` + appRemoteVersion isMenuCollapsed: boolean = true diff --git a/src-ui/src/theme.scss b/src-ui/src/theme.scss index 916524e89..cb6ee859a 100644 --- a/src-ui/src/theme.scss +++ b/src-ui/src/theme.scss @@ -271,6 +271,7 @@ table.table { .popover-body { background-color: var(--ngx-bg-alt); border-color: var(--bs-border-color); + color: var(--bs-body-color); } } From 1019660f6a7896a1454c1b863955b32ccc02867b Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 1 Apr 2022 07:22:55 -0700 Subject: [PATCH 05/12] Add config variable for update check --- docs/configuration.rst | 10 ++++++++++ paperless.conf.example | 1 + src/documents/views.py | 35 ++++++++++++++++++++--------------- src/paperless/settings.py | 2 ++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 261eab7d5..cc9b9f5e9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -764,3 +764,13 @@ PAPERLESS_OCR_LANGUAGES= PAPERLESS_OCR_LANGUAGE=tur Defaults to none, which does not install any additional languages. + +PAPERLESS_ENABLE_UPDATE_CHECK= + Enabling this option enables the check for available updates, which works by + loading the version file of the public repository for this project on Github e.g. + https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/src/paperless/version.py + to determine whether a new version is available. Actual updating of the app must be done manually. + + No tracking data is collected by the app in any way. + + Defaults to true. diff --git a/paperless.conf.example b/paperless.conf.example index bfb4fac7e..539e33b0d 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -67,6 +67,7 @@ #PAPERLESS_FILENAME_PARSE_TRANSFORMS=[] #PAPERLESS_THUMBNAIL_FONT_NAME= #PAPERLESS_IGNORE_DATES= +#PAPERLESS_ENABLE_UPDATE_CHECK= # Tika settings diff --git a/src/documents/views.py b/src/documents/views.py index faca183c7..8ae34d454 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -674,22 +674,27 @@ class BulkDownloadView(GenericAPIView): class RemoteVersionView(GenericAPIView): def get(self, request, format=None): - try: - with urllib.request.urlopen( - "https://raw.githubusercontent.com/paperless-ngx/paperless-ngx" - + "/main/src/paperless/version.py", - ) as response: - remote = response.read().decode("utf-8") - match = re.search("(\\d+, \\d+, \\d+)", remote) - if match: - remote_version = ".".join(match[0].split(", ")) - except urllib.error.URLError: - remote_version = "0.0.0" + remote_version = "0.0.0" + is_greater = False + if settings.ENABLE_UPDATE_CHECK: + try: + with urllib.request.urlopen( + "https://raw.githubusercontent.com/paperless-ngx" + + "/paperless-ngx/main/src/paperless/version.py", + ) as response: + remote = response.read().decode("utf-8") + match = re.search("(\\d+, \\d+, \\d+)", remote) + if match: + remote_version = ".".join(match[0].split(", ")) + except urllib.error.URLError: + logger.debug("An error occured checking for available updates") - current_version = ".".join([str(_) for _ in version.__version__[:3]]) - is_greater = packaging_version.parse(remote_version) > packaging_version.parse( - current_version, - ) + current_version = ".".join([str(_) for _ in version.__version__[:3]]) + is_greater = packaging_version.parse( + remote_version, + ) > packaging_version.parse( + current_version, + ) return Response( { diff --git a/src/paperless/settings.py b/src/paperless/settings.py index d485c5a50..382a2a38b 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -566,3 +566,5 @@ if os.getenv("PAPERLESS_IGNORE_DATES", ""): d = dateparser.parse(s) if d: IGNORE_DATES.add(d.date()) + +ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK", "true") From 6dbebf4806380b4e01203a6c57dc72e4132fb2be Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:10:29 -0700 Subject: [PATCH 06/12] Fix version string regex --- src/documents/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/documents/views.py b/src/documents/views.py index 8ae34d454..09f18c9e6 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -683,7 +683,7 @@ class RemoteVersionView(GenericAPIView): + "/paperless-ngx/main/src/paperless/version.py", ) as response: remote = response.read().decode("utf-8") - match = re.search("(\\d+, \\d+, \\d+)", remote) + match = re.search(r"(\d+, \d+, \d+)", remote) if match: remote_version = ".".join(match[0].split(", ")) except urllib.error.URLError: From d02c7df75cfb1f38cf3c90ff03d98c0382a4df29 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:31:10 -0700 Subject: [PATCH 07/12] json parse version string --- src/documents/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/documents/views.py b/src/documents/views.py index 09f18c9e6..858a3bab6 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1,6 +1,6 @@ +import json import logging import os -import re import tempfile import urllib import uuid @@ -683,9 +683,11 @@ class RemoteVersionView(GenericAPIView): + "/paperless-ngx/main/src/paperless/version.py", ) as response: remote = response.read().decode("utf-8") - match = re.search(r"(\d+, \d+, \d+)", remote) - if match: - remote_version = ".".join(match[0].split(", ")) + try: + remote_json = json.loads(remote) + remote_version = remote_json["tag_name"].replace("ngx-", "") + except ValueError: + logger.debug("An error occured parsing remote version json") except urllib.error.URLError: logger.debug("An error occured checking for available updates") From b58550bb790b1c43eeee4a1ec738b6670cc59250 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 2 Apr 2022 01:32:11 -0700 Subject: [PATCH 08/12] refactor to update_available --- src-ui/src/app/components/app-frame/app-frame.component.html | 2 +- src-ui/src/app/services/rest/remote-version.service.ts | 2 +- src/documents/views.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.html b/src-ui/src/app/components/app-frame/app-frame.component.html index 208100af8..e201a7d6e 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.html +++ b/src-ui/src/app/components/app-frame/app-frame.component.html @@ -185,7 +185,7 @@ diff --git a/src-ui/src/app/services/rest/remote-version.service.ts b/src-ui/src/app/services/rest/remote-version.service.ts index 9b1def363..ab1b5a66b 100644 --- a/src-ui/src/app/services/rest/remote-version.service.ts +++ b/src-ui/src/app/services/rest/remote-version.service.ts @@ -6,6 +6,7 @@ import { environment } from 'src/environments/environment' export interface AppRemoteVersion { version: string update_available: boolean + feature_is_set: boolean } @Injectable({ diff --git a/src/documents/views.py b/src/documents/views.py index 5dc5667c3..ff269186c 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -675,8 +675,10 @@ class BulkDownloadView(GenericAPIView): class RemoteVersionView(GenericAPIView): def get(self, request, format=None): remote_version = "0.0.0" - is_greater = False - if settings.ENABLE_UPDATE_CHECK: + is_greater_than_current = False + # TODO: this can likely be removed when frontend settings are saved to DB + feature_is_set = settings.ENABLE_UPDATE_CHECK != "default" + if feature_is_set and settings.ENABLE_UPDATE_CHECK: try: with urllib.request.urlopen( "https://api.github.com/repos/" @@ -692,7 +694,7 @@ class RemoteVersionView(GenericAPIView): logger.debug("An error occured checking for available updates") current_version = ".".join([str(_) for _ in version.__version__[:3]]) - is_greater = packaging_version.parse( + is_greater_than_current = packaging_version.parse( remote_version, ) > packaging_version.parse( current_version, @@ -701,6 +703,7 @@ class RemoteVersionView(GenericAPIView): return Response( { "version": remote_version, - "update_available": is_greater, + "update_available": is_greater_than_current, + "feature_is_set": feature_is_set, }, ) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 382a2a38b..708be2d33 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -567,4 +567,6 @@ if os.getenv("PAPERLESS_IGNORE_DATES", ""): if d: IGNORE_DATES.add(d.date()) -ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK", "true") +ENABLE_UPDATE_CHECK = os.getenv("PAPERLESS_ENABLE_UPDATE_CHECK", "default") +if ENABLE_UPDATE_CHECK != "default": + ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK", "true") From 91165e80ba59fd1a4d0d8437e8b02465e07c6459 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 4 Apr 2022 07:05:00 -0700 Subject: [PATCH 12/12] Remove unused default --- src/paperless/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 708be2d33..60f6ef7dd 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -569,4 +569,4 @@ if os.getenv("PAPERLESS_IGNORE_DATES", ""): ENABLE_UPDATE_CHECK = os.getenv("PAPERLESS_ENABLE_UPDATE_CHECK", "default") if ENABLE_UPDATE_CHECK != "default": - ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK", "true") + ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK")