diff --git a/src-ui/src/app/components/common/permissions-dialog/permissions-dialog.component.ts b/src-ui/src/app/components/common/permissions-dialog/permissions-dialog.component.ts
index f00d5ebea..0d7b07c00 100644
--- a/src-ui/src/app/components/common/permissions-dialog/permissions-dialog.component.ts
+++ b/src-ui/src/app/components/common/permissions-dialog/permissions-dialog.component.ts
@@ -3,6 +3,7 @@ import { FormControl, FormGroup } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { PaperlessGroup } from 'src/app/data/paperless-group'
import { PaperlessUser } from 'src/app/data/paperless-user'
+import { UserService } from 'src/app/services/rest/user.service'
@Component({
selector: 'app-permissions-dialog',
@@ -10,7 +11,14 @@ import { PaperlessUser } from 'src/app/data/paperless-user'
styleUrls: ['./permissions-dialog.component.scss'],
})
export class PermissionsDialogComponent implements OnInit {
- constructor(public activeModal: NgbActiveModal) {}
+ users: PaperlessUser[]
+
+ constructor(
+ public activeModal: NgbActiveModal,
+ private userService: UserService
+ ) {
+ this.userService.listAll().subscribe((r) => (this.users = r.results))
+ }
@Output()
public confirmClicked = new EventEmitter()
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 ec9766d9f..0384e976c 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
@@ -181,18 +181,7 @@
Permissions
-
+
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 2fe42bc25..6be68e5d1 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
@@ -41,6 +41,7 @@ import {
PermissionType,
} from 'src/app/services/permissions.service'
import { PaperlessUser } from 'src/app/data/paperless-user'
+import { UserService } from 'src/app/services/rest/user.service'
@Component({
selector: 'app-document-detail',
@@ -64,6 +65,7 @@ export class DocumentDetailComponent
document: PaperlessDocument
metadata: PaperlessDocumentMetadata
suggestions: PaperlessDocumentSuggestions
+ users: PaperlessUser[]
title: string
titleSubject: Subject
= new Subject()
@@ -84,16 +86,7 @@ export class DocumentDetailComponent
storage_path: new FormControl(),
archive_serial_number: new FormControl(),
tags: new FormControl([]),
- set_permissions: new FormGroup({
- view: new FormGroup({
- users: new FormControl(null),
- groups: new FormControl(null),
- }),
- change: new FormGroup({
- users: new FormControl(null),
- groups: new FormControl(null),
- }),
- }),
+ permissions_form: new FormControl(null),
})
previewCurrentPage: number = 1
@@ -138,7 +131,8 @@ export class DocumentDetailComponent
private toastService: ToastService,
private settings: SettingsService,
private storagePathService: StoragePathService,
- private permissionsService: PermissionsService
+ private permissionsService: PermissionsService,
+ private userService: UserService
) {}
titleKeyUp(event) {
@@ -160,7 +154,13 @@ export class DocumentDetailComponent
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe(() => {
this.error = null
- Object.assign(this.document, this.documentForm.value)
+ const docValues = Object.assign({}, this.documentForm.value)
+ docValues['owner'] =
+ this.documentForm.get('permissions_form').value['owner']
+ docValues['set_permissions'] =
+ this.documentForm.get('permissions_form').value['set_permissions']
+ delete docValues['permissions_form']
+ Object.assign(this.document, docValues)
})
this.correspondentService
@@ -178,6 +178,11 @@ export class DocumentDetailComponent
.pipe(first())
.subscribe((result) => (this.storagePaths = result.results))
+ this.userService
+ .listAll()
+ .pipe(first())
+ .subscribe((result) => (this.users = result.results))
+
this.route.paramMap
.pipe(
takeUntil(this.unsubscribeNotifier),
@@ -241,7 +246,10 @@ export class DocumentDetailComponent
storage_path: doc.storage_path,
archive_serial_number: doc.archive_serial_number,
tags: [...doc.tags],
- set_permissions: doc.permissions,
+ permissions_form: {
+ owner: doc.owner,
+ set_permissions: doc.permissions,
+ },
})
this.isDirty$ = dirtyCheck(
@@ -296,8 +304,13 @@ export class DocumentDetailComponent
},
})
this.title = this.documentTitlePipe.transform(doc.title)
- doc['set_permissions'] = doc.permissions
- this.documentForm.patchValue(doc)
+ const docFormValues = Object.assign({}, doc)
+ docFormValues['permissions_form'] = {
+ owner: doc.owner,
+ set_permissions: doc.permissions,
+ }
+
+ this.documentForm.patchValue(docFormValues, { emitEvent: false })
if (!this.userCanEdit) this.documentForm.disable()
}
@@ -586,18 +599,25 @@ export class DocumentDetailComponent
}
get userIsOwner(): boolean {
- return (
- !this.document ||
- this.permissionsService.currentUserOwnsObject(this.document)
- )
+ let doc: PaperlessDocument = Object.assign({}, this.document)
+ // dont disable while editing
+ if (this.document && this.store?.value.owner) {
+ doc.owner = this.store?.value.owner
+ }
+ return !this.document || this.permissionsService.currentUserOwnsObject(doc)
}
get userCanEdit(): boolean {
+ let doc: PaperlessDocument = Object.assign({}, this.document)
+ // dont disable while editing
+ if (this.document && this.store?.value.owner) {
+ doc.owner = this.store?.value.owner
+ }
return (
!this.document ||
this.permissionsService.currentUserHasObjectPermissions(
PermissionAction.Change,
- this.document
+ doc
)
)
}
diff --git a/src/documents/permissions.py b/src/documents/permissions.py
index d4dad17de..c0e7ac345 100644
--- a/src/documents/permissions.py
+++ b/src/documents/permissions.py
@@ -56,7 +56,6 @@ def get_groups_with_only_permission(obj, codename):
def set_permissions_for_object(permissions, object):
- print(permissions, object)
for action in permissions:
permission = f"{action}_{object.__class__.__name__.lower()}"
# users
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index 715d09e98..4e585825e 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -117,9 +117,9 @@ class SetPermissionsMixin:
if set_permissions is not None:
for action in permissions_dict:
users = set_permissions[action]["users"]
- self._validate_user_ids(users)
+ permissions_dict[action]["users"] = self._validate_user_ids(users)
groups = set_permissions[action]["groups"]
- self._validate_group_ids(groups)
+ permissions_dict[action]["groups"] = self._validate_group_ids(groups)
return permissions_dict
def _set_permissions(self, permissions, object):