From 6fa32c36e92be0ae626e41ccd83b282189520011 Mon Sep 17 00:00:00 2001
From: Michael Shamoon <4887959+shamoon@users.noreply.github.com>
Date: Sun, 7 Aug 2022 15:05:58 -0700
Subject: [PATCH] Use frontend settings instead of env variable
---
.../document-detail.component.html | 2 +-
.../document-detail.component.ts | 16 +--
.../manage/settings/settings.component.html | 8 ++
.../manage/settings/settings.component.ts | 6 ++
src-ui/src/app/data/paperless-environment.ts | 3 -
src-ui/src/app/data/paperless-uisettings.ts | 6 ++
.../services/rest/environment.service.spec.ts | 16 ---
.../app/services/rest/environment.service.ts | 22 -----
src/documents/views.py | 99 +++++++------------
src/paperless/settings.py | 9 --
src/paperless/urls.py | 2 -
11 files changed, 63 insertions(+), 126 deletions(-)
delete mode 100644 src-ui/src/app/data/paperless-environment.ts
delete mode 100644 src-ui/src/app/services/rest/environment.service.spec.ts
delete mode 100644 src-ui/src/app/services/rest/environment.service.ts
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html
index ebf286895..211f93d50 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.html
+++ b/src-ui/src/app/components/document-detail/document-detail.component.html
@@ -169,7 +169,7 @@
-
+
Comments
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts
index d0f4ecded..06fddd41b 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.ts
@@ -35,7 +35,6 @@ import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
-import { EnvironmentService } from 'src/app/services/rest/environment.service'
@Component({
selector: 'app-document-detail',
@@ -84,8 +83,6 @@ export class DocumentDetailComponent
previewCurrentPage: number = 1
previewNumPages: number = 1
- isCommentsEnabled:boolean = false
-
store: BehaviorSubject
isDirty$: Observable
unsubscribeNotifier: Subject = new Subject()
@@ -121,8 +118,7 @@ export class DocumentDetailComponent
private documentTitlePipe: DocumentTitlePipe,
private toastService: ToastService,
private settings: SettingsService,
- private storagePathService: StoragePathService,
- private environment: EnvironmentService
+ private storagePathService: StoragePathService
) {}
titleKeyUp(event) {
@@ -278,12 +274,6 @@ export class DocumentDetailComponent
this.suggestions = null
},
})
-
- this.environment.get("PAPERLESS_COMMENTS_ENABLED").subscribe(result => {
- this.isCommentsEnabled = (result.value.toString().toLowerCase() === "true"?true:false);
- }, error => {
- this.isCommentsEnabled = false;
- })
this.title = this.documentTitlePipe.transform(doc.title)
this.documentForm.patchValue(doc)
@@ -562,4 +552,8 @@ export class DocumentDetailComponent
this.password = (event.target as HTMLInputElement).value
}
}
+
+ get commentsEnabled(): boolean {
+ return this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED)
+ }
}
diff --git a/src-ui/src/app/components/manage/settings/settings.component.html b/src-ui/src/app/components/manage/settings/settings.component.html
index 002cc4eed..f72587139 100644
--- a/src-ui/src/app/components/manage/settings/settings.component.html
+++ b/src-ui/src/app/components/manage/settings/settings.component.html
@@ -125,6 +125,14 @@
+ Comments
+
+
+
diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts
index 22ecfe9bb..bb7244663 100644
--- a/src-ui/src/app/components/manage/settings/settings.component.ts
+++ b/src-ui/src/app/components/manage/settings/settings.component.ts
@@ -44,6 +44,7 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
notificationsConsumerSuccess: new FormControl(null),
notificationsConsumerFailed: new FormControl(null),
notificationsConsumerSuppressOnDashboard: new FormControl(null),
+ commentsEnabled: new FormControl(null),
})
savedViews: PaperlessSavedView[]
@@ -116,6 +117,7 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
notificationsConsumerSuppressOnDashboard: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD
),
+ commentsEnabled: this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED),
}
for (let view of this.savedViews) {
@@ -234,6 +236,10 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD,
this.settingsForm.value.notificationsConsumerSuppressOnDashboard
)
+ this.settings.set(
+ SETTINGS_KEYS.COMMENTS_ENABLED,
+ this.settingsForm.value.commentsEnabled
+ )
this.settings.setLanguage(this.settingsForm.value.displayLanguage)
this.settings
.storeSettings()
diff --git a/src-ui/src/app/data/paperless-environment.ts b/src-ui/src/app/data/paperless-environment.ts
deleted file mode 100644
index 27dda6427..000000000
--- a/src-ui/src/app/data/paperless-environment.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface PaperlessEnvironment {
- value?: string;
-}
\ No newline at end of file
diff --git a/src-ui/src/app/data/paperless-uisettings.ts b/src-ui/src/app/data/paperless-uisettings.ts
index 75aec2a51..e3d977687 100644
--- a/src-ui/src/app/data/paperless-uisettings.ts
+++ b/src-ui/src/app/data/paperless-uisettings.ts
@@ -36,6 +36,7 @@ export const SETTINGS_KEYS = {
'general-settings:notifications:consumer-failed',
NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD:
'general-settings:notifications:consumer-suppress-on-dashboard',
+ COMMENTS_ENABLED: 'general-settings:comments-enabled',
}
export const SETTINGS: PaperlessUiSetting[] = [
@@ -114,4 +115,9 @@ export const SETTINGS: PaperlessUiSetting[] = [
type: 'boolean',
default: true,
},
+ {
+ key: SETTINGS_KEYS.COMMENTS_ENABLED,
+ type: 'boolean',
+ default: true,
+ },
]
diff --git a/src-ui/src/app/services/rest/environment.service.spec.ts b/src-ui/src/app/services/rest/environment.service.spec.ts
deleted file mode 100644
index 941a180b9..000000000
--- a/src-ui/src/app/services/rest/environment.service.spec.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { TestBed } from '@angular/core/testing';
-
-import { EnvironmentService } from './environment.service';
-
-describe('EnvironmentService', () => {
- let service: EnvironmentService;
-
- beforeEach(() => {
- TestBed.configureTestingModule({});
- service = TestBed.inject(EnvironmentService);
- });
-
- it('should be created', () => {
- expect(service).toBeTruthy();
- });
-});
\ No newline at end of file
diff --git a/src-ui/src/app/services/rest/environment.service.ts b/src-ui/src/app/services/rest/environment.service.ts
deleted file mode 100644
index 86ac146ea..000000000
--- a/src-ui/src/app/services/rest/environment.service.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { HttpClient, HttpParams } from '@angular/common/http';
-import { Injectable } from '@angular/core';
-import { Observable } from 'rxjs';
-import { PaperlessEnvironment } from 'src/app/data/paperless-environment';
-import { environment } from 'src/environments/environment'
-
-@Injectable({
- providedIn: 'root'
-})
-export class EnvironmentService {
-
- protected baseUrl: string = environment.apiBaseUrl
-
- constructor(protected http: HttpClient) { }
-
- get(environment: string): Observable {
- let httpParams = new HttpParams();
- httpParams = httpParams.set('name', environment);
-
- return this.http.get(`${this.baseUrl}environment/`, {params: httpParams})
- }
-}
\ No newline at end of file
diff --git a/src/documents/views.py b/src/documents/views.py
index 4633642e6..9713e5d95 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -22,7 +22,6 @@ from django.http import Http404
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.http import HttpResponseNotAllowed
-from django.http import HttpResponseNotFound
from django.utils.decorators import method_decorator
from django.utils.translation import get_language
from django.views.decorators.cache import cache_control
@@ -385,21 +384,22 @@ class DocumentViewSet(
def getComments(self, doc):
return [
{
- "id":c.id,
- "comment":c.comment,
- "created":c.created,
- "user":{
- "id":c.user.id,
+ "id": c.id,
+ "comment": c.comment,
+ "created": c.created,
+ "user": {
+ "id": c.user.id,
"username": c.user.username,
- "firstname":c.user.first_name,
- "lastname":c.user.last_name
- }
- } for c in Comment.objects.filter(document=doc).order_by('-created')
- ];
+ "firstname": c.user.first_name,
+ "lastname": c.user.last_name,
+ },
+ }
+ for c in Comment.objects.filter(document=doc).order_by("-created")
+ ]
- @action(methods=['get', 'post', 'delete'], detail=True)
+ @action(methods=["get", "post", "delete"], detail=True)
def comments(self, request, pk=None):
- if settings.PAPERLESS_COMMENTS_ENABLED != True:
+ if settings.PAPERLESS_COMMENTS_ENABLED is not True:
return HttpResponseNotAllowed("comment function is disabled")
try:
@@ -407,35 +407,39 @@ class DocumentViewSet(
except Document.DoesNotExist:
raise Http404()
- currentUser = request.user;
+ currentUser = request.user
- if request.method == 'GET':
+ if request.method == "GET":
try:
- return Response(self.getComments(doc));
+ return Response(self.getComments(doc))
except Exception as e:
- return Response({"error": str(e)});
- elif request.method == 'POST':
+ return Response({"error": str(e)})
+ elif request.method == "POST":
try:
c = Comment.objects.create(
- document = doc,
+ document=doc,
comment=request.data["payload"],
- user=currentUser
- );
- c.save();
+ user=currentUser,
+ )
+ c.save()
- return Response(self.getComments(doc));
+ return Response(self.getComments(doc))
except Exception as e:
- return Response({
- "error": str(e)
- });
- elif request.method == 'DELETE':
- comment = Comment.objects.get(id=int(request.GET.get("commentId")));
- comment.delete();
- return Response(self.getComments(doc));
+ return Response(
+ {
+ "error": str(e),
+ },
+ )
+ elif request.method == "DELETE":
+ comment = Comment.objects.get(id=int(request.GET.get("commentId")))
+ comment.delete()
+ return Response(self.getComments(doc))
- return Response({
- "error": "error"
- });
+ return Response(
+ {
+ "error": "error",
+ },
+ )
class SearchResultSerializer(DocumentSerializer):
@@ -893,32 +897,3 @@ class AcknowledgeTasksView(GenericAPIView):
return Response({"result": result})
except Exception:
return HttpResponseBadRequest()
-
-class EnvironmentView(APIView):
-
- permission_classes = (IsAuthenticated,)
-
- def get(self, request, format=None):
- if 'name' in request.query_params:
- name = request.query_params['name']
- else:
- return HttpResponseBadRequest("name required")
-
- if(name not in settings.PAPERLESS_FRONTEND_ALLOWED_ENVIRONMENTS and settings.PAPERLESS_DISABLED_FRONTEND_ENVIRONMENT_CHECK == False):
- return HttpResponseNotAllowed("environment not allowed to request")
-
- value = None
- try:
- value = getattr(settings, name)
- except:
- try:
- value = os.getenv(name)
- except:
- value = None
-
- if value == None:
- return HttpResponseNotFound("environment not found")
-
- return Response({
- "value": str(value)
- });
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
index e42cf4359..bfa498359 100644
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -566,15 +566,6 @@ CONVERT_MEMORY_LIMIT = os.getenv("PAPERLESS_CONVERT_MEMORY_LIMIT")
GS_BINARY = os.getenv("PAPERLESS_GS_BINARY", "gs")
-# Comment settings
-PAPERLESS_COMMENTS_ENABLED = __get_boolean("PAPERLESS_COMMENTS_ENABLED", "NO")
-
-# allowed environments for frontend
-PAPERLESS_DISABLED_FRONTEND_ENVIRONMENT_CHECK = __get_boolean("PAPERLESS_DISABLED_FRONTEND_ENVIRONMENT_CHECK", "NO")
-PAPERLESS_FRONTEND_ALLOWED_ENVIRONMENTS = [
- "PAPERLESS_COMMENTS_ENABLED"
-]
-
# Pre-2.x versions of Paperless stored your documents locally with GPG
# encryption, but that is no longer the default. This behaviour is still
# available, but it must be explicitly enabled by setting
diff --git a/src/paperless/urls.py b/src/paperless/urls.py
index 6ba1ee263..46309e1e6 100644
--- a/src/paperless/urls.py
+++ b/src/paperless/urls.py
@@ -8,7 +8,6 @@ from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import RedirectView
from documents.views import AcknowledgeTasksView
-from documents.views import EnvironmentView
from documents.views import BulkDownloadView
from documents.views import BulkEditView
from documents.views import CorrespondentViewSet
@@ -95,7 +94,6 @@ urlpatterns = [
AcknowledgeTasksView.as_view(),
name="acknowledge_tasks",
),
- re_path(r"^environment/", EnvironmentView.as_view()),
path("token/", views.obtain_auth_token),
]
+ api_router.urls,