Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Merge branch 'dev' into feature-permissions

Michael Shamoona4d96061de8f
diff --cc src-ui/cypress/support/e2e.ts
index 9ea46314d,1d17409c2..1a8ef1710
--- a/src-ui/cypress/support/e2e.ts
+++ b/src-ui/cypress/support/e2e.ts
@@@ -3,16 -3,8 +3,16 @@@
beforeEach(() => {
cy.intercept('http://localhost:8000/api/ui_settings/', {
fixture: 'ui_settings/settings.json',
- })
+ }).as('ui-settings')
+ cy.intercept('http://localhost:8000/api/users/*', {
+ fixture: 'users/users.json',
+ })
+
+ cy.intercept('http://localhost:8000/api/groups/*', {
+ fixture: 'groups/groups.json',
+ })
+
cy.intercept('http://localhost:8000/api/remote_version/', {
fixture: 'remote_version/remote_version.json',
})
diff --cc src-ui/src/app/app.module.ts
index 3592ff253,581d788d5..05ce2feee
--- a/src-ui/src/app/app.module.ts
+++ b/src-ui/src/app/app.module.ts
@@@ -79,16 -77,10 +79,17 @@@ import { StoragePathEditDialogComponen
import { SettingsService } from './services/settings.service'
import { TasksComponent } from './components/manage/tasks/tasks.component'
import { TourNgBootstrapModule } from 'ngx-ui-tour-ng-bootstrap'
+import { UserEditDialogComponent } from './components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
+import { GroupEditDialogComponent } from './components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component'
+import { PermissionsSelectComponent } from './components/common/permissions-select/permissions-select.component'
import { MailAccountEditDialogComponent } from './components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
import { MailRuleEditDialogComponent } from './components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component'
+import { PermissionsUserComponent } from './components/common/input/permissions/permissions-user/permissions-user.component'
+import { PermissionsGroupComponent } from './components/common/input/permissions/permissions-group/permissions-group.component'
+import { IfOwnerDirective } from './directives/if-owner.directive'
+import { IfObjectPermissionsDirective } from './directives/if-object-permissions.directive'
+ import localeAr from '@angular/common/locales/ar'
import localeBe from '@angular/common/locales/be'
import localeCs from '@angular/common/locales/cs'
import localeDa from '@angular/common/locales/da'
@@@ -108,9 -100,8 +109,10 @@@ import localeSr from '@angular/common/l
import localeSv from '@angular/common/locales/sv'
import localeTr from '@angular/common/locales/tr'
import localeZh from '@angular/common/locales/zh'
+import { PermissionsDialogComponent } from './components/common/permissions-dialog/permissions-dialog.component'
+import { PermissionsFormComponent } from './components/common/input/permissions/permissions-form/permissions-form.component'
+ registerLocaleData(localeAr)
registerLocaleData(localeBe)
registerLocaleData(localeCs)
registerLocaleData(localeDa)
diff --cc src-ui/src/app/components/document-detail/document-detail.component.html
index 38a8bf44a,19ae590a7..d1e74cb6d
--- a/src-ui/src/app/components/document-detail/document-detail.component.html
+++ b/src-ui/src/app/components/document-detail/document-detail.component.html
@@@ -190,11 -180,9 +190,11 @@@
<div [ngbNavOutlet]="nav" class="mt-2"></div>
- <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive || (isDirty$ | async) !== true">Discard</button>&nbsp;
- <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || (isDirty$ | async) !== true || error">Save & next</button>&nbsp;
- <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || (isDirty$ | async) !== true || error">Save</button>&nbsp;
+ <ng-container>
- <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) === false">Discard</button>&nbsp;
- <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) === false || error">Save & next</button>&nbsp;
- <button type="submit" class="btn btn-primary" *appIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Document }" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) === false || error">Save</button>&nbsp;
++ <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) !== true">Discard</button>&nbsp;
++ <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) !== true || error">Save & next</button>&nbsp;
++ <button type="submit" class="btn btn-primary" *appIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Document }" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) !== true || error">Save</button>&nbsp;
+ </ng-container>
</form>
</div>
diff --cc src-ui/src/app/data/paperless-document.ts
index 9899c60ac,cdee624af..8936e2b43
--- a/src-ui/src/app/data/paperless-document.ts
+++ b/src-ui/src/app/data/paperless-document.ts
@@@ -10,9 -10,10 +10,10 @@@ export interface SearchHit
rank?: number
highlights?: string
+ comment_highlights?: string
}
-export interface PaperlessDocument extends ObjectWithId {
+export interface PaperlessDocument extends ObjectWithPermissions {
correspondent$?: Observable<PaperlessCorrespondent>
correspondent?: number
diff --cc src/documents/index.py
index 5b8504383,7ba50a324..b60b33c14
--- a/src/documents/index.py
+++ b/src/documents/index.py
@@@ -5,8 -5,8 +5,9 @@@ from contextlib import contextmanage
from dateutil.parser import isoparse
from django.conf import settings
+ from documents.models import Comment
from documents.models import Document
+from guardian.shortcuts import get_users_with_perms
from whoosh import classify
from whoosh import highlight
from whoosh import query
@@@ -50,10 -50,7 +51,11 @@@ def get_schema()
path=TEXT(sortable=True),
path_id=NUMERIC(),
has_path=BOOLEAN(),
+ comments=TEXT(),
+ owner=TEXT(),
+ owner_id=NUMERIC(),
+ has_owner=BOOLEAN(),
+ viewer_id=KEYWORD(commas=True),
)
@@@ -95,11 -92,7 +97,12 @@@ def open_index_searcher()
def update_document(writer, doc):
tags = ",".join([t.name for t in doc.tags.all()])
tags_ids = ",".join([str(t.id) for t in doc.tags.all()])
+ comments = ",".join([str(c.comment) for c in Comment.objects.filter(document=doc)])
+ users_with_perms = get_users_with_perms(
+ doc,
+ only_with_perms_in=["view_document"],
+ )
+ viewer_ids = ",".join([str(u.id) for u in users_with_perms])
writer.update_document(
id=doc.pk,
title=doc.title,
@@@ -120,10 -113,7 +123,11 @@@
path=doc.storage_path.name if doc.storage_path else None,
path_id=doc.storage_path.id if doc.storage_path else None,
has_path=doc.storage_path is not None,
+ comments=comments,
+ owner=doc.owner.username if doc.owner else None,
+ owner_id=doc.owner.id if doc.owner else None,
+ has_owner=doc.owner is not None,
+ viewer_id=viewer_ids if viewer_ids else None,
)
diff --cc src/documents/views.py
index 734a2e8ac,c65b6f0b4..fd0949fc1
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@@ -491,9 -455,17 +491,17 @@@ class DocumentViewSet
)
-class SearchResultSerializer(DocumentSerializer):
+class SearchResultSerializer(DocumentSerializer, PassUserMixin):
def to_representation(self, instance):
doc = Document.objects.get(id=instance["id"])
+ commentTerm = instance.results.q.subqueries[0]
+ comments = ",".join(
+ [
+ str(c.comment)
+ for c in Comment.objects.filter(document=instance["id"])
+ if commentTerm.text in c.comment
+ ],
+ )
r = super().to_representation(doc)
r["__search_hit__"] = {
"score": instance.score,