diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index c6b0c1484..46121a54f 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -109,6 +109,7 @@ 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-form/permissions-form.component' registerLocaleData(localeBe) registerLocaleData(localeCs) @@ -205,6 +206,7 @@ function initializeApp(settings: SettingsService) { IfOwnerDirective, IfObjectPermissionsDirective, PermissionsDialogComponent, + PermissionsFormComponent, ], imports: [ BrowserModule, diff --git a/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html b/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html index 3867146a3..f1a3ee59d 100644 --- a/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html +++ b/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html @@ -12,19 +12,7 @@
-
Permissions
-
-
View
-
- - -
-
Edit
-
- - -
-
+
diff --git a/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.ts index 5320def27..2ac7f2d99 100644 --- a/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.ts @@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit- import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent' import { CorrespondentService } from 'src/app/services/rest/correspondent.service' +import { UserService } from 'src/app/services/rest/user.service' @Component({ selector: 'app-correspondent-edit-dialog', @@ -12,8 +13,12 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic styleUrls: ['./correspondent-edit-dialog.component.scss'], }) export class CorrespondentEditDialogComponent extends EditDialogComponent { - constructor(service: CorrespondentService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: CorrespondentService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } getCreateTitle() { @@ -30,16 +35,7 @@ export class CorrespondentEditDialogComponent extends EditDialogComponent diff --git a/src-ui/src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.ts index 81854df34..a1d3e4fc4 100644 --- a/src-ui/src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.ts @@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit- import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' import { PaperlessDocumentType } from 'src/app/data/paperless-document-type' import { DocumentTypeService } from 'src/app/services/rest/document-type.service' +import { UserService } from 'src/app/services/rest/user.service' @Component({ selector: 'app-document-type-edit-dialog', @@ -12,8 +13,12 @@ import { DocumentTypeService } from 'src/app/services/rest/document-type.service styleUrls: ['./document-type-edit-dialog.component.scss'], }) export class DocumentTypeEditDialogComponent extends EditDialogComponent { - constructor(service: DocumentTypeService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: DocumentTypeService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } getCreateTitle() { @@ -30,16 +35,7 @@ export class DocumentTypeEditDialogComponent extends EditDialogComponent, - private activeModal: NgbActiveModal + private activeModal: NgbActiveModal, + private userService: UserService ) {} + users: PaperlessUser[] + @Input() dialogMode: string = 'create' @@ -41,6 +47,12 @@ export abstract class EditDialogComponent< if (this.object['permissions']) { this.object['set_permissions'] = this.object['permissions'] } + console.log(this.object) + + this.object['permissions_form'] = { + owner: (this.object as ObjectWithPermissions).owner, + set_permissions: (this.object as ObjectWithPermissions).permissions, + } this.objectForm.patchValue(this.object) } @@ -48,6 +60,8 @@ export abstract class EditDialogComponent< setTimeout(() => { this.closeEnabled = true }) + + this.userService.listAll().subscribe((r) => (this.users = r.results)) } getCreateTitle() { @@ -82,10 +96,16 @@ export abstract class EditDialogComponent< } save() { - var newObject = Object.assign( - Object.assign({}, this.object), - this.objectForm.value - ) + const formValues = Object.assign({}, this.objectForm.value) + const permissionsObject: PermissionsFormObject = + this.objectForm.get('permissions_form').value + if (permissionsObject) { + formValues.owner = permissionsObject.owner + formValues.set_permissions = permissionsObject.set_permissions + delete formValues.permissions_form + } + + var newObject = Object.assign(Object.assign({}, this.object), formValues) var serverResponse: Observable switch (this.dialogMode) { case 'create': diff --git a/src-ui/src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.ts index db58b3930..785d6c20d 100644 --- a/src-ui/src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.ts @@ -4,6 +4,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component' import { PaperlessGroup } from 'src/app/data/paperless-group' import { GroupService } from 'src/app/services/rest/group.service' +import { UserService } from 'src/app/services/rest/user.service' @Component({ selector: 'app-group-edit-dialog', @@ -11,8 +12,12 @@ import { GroupService } from 'src/app/services/rest/group.service' styleUrls: ['./group-edit-dialog.component.scss'], }) export class GroupEditDialogComponent extends EditDialogComponent { - constructor(service: GroupService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: GroupService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } getCreateTitle() { diff --git a/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.ts index b2edb9219..1c42ffeb0 100644 --- a/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.ts @@ -7,6 +7,7 @@ import { PaperlessMailAccount, } from 'src/app/data/paperless-mail-account' import { MailAccountService } from 'src/app/services/rest/mail-account.service' +import { UserService } from 'src/app/services/rest/user.service' const IMAP_SECURITY_OPTIONS = [ { id: IMAPSecurity.None, name: $localize`No encryption` }, @@ -20,8 +21,12 @@ const IMAP_SECURITY_OPTIONS = [ styleUrls: ['./mail-account-edit-dialog.component.scss'], }) export class MailAccountEditDialogComponent extends EditDialogComponent { - constructor(service: MailAccountService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: MailAccountService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } getCreateTitle() { diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts index 126c4968f..bfc83d829 100644 --- a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts @@ -17,6 +17,7 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic import { DocumentTypeService } from 'src/app/services/rest/document-type.service' import { MailAccountService } from 'src/app/services/rest/mail-account.service' import { MailRuleService } from 'src/app/services/rest/mail-rule.service' +import { UserService } from 'src/app/services/rest/user.service' const ATTACHMENT_TYPE_OPTIONS = [ { @@ -97,9 +98,10 @@ export class MailRuleEditDialogComponent extends EditDialogComponent
-
Permissions
-
-
View
-
- - -
-
Edit
-
- - -
-
+
diff --git a/src-ui/src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.ts index 42d533c96..edb144a59 100644 --- a/src-ui/src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.ts @@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit- import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path' import { StoragePathService } from 'src/app/services/rest/storage-path.service' +import { UserService } from 'src/app/services/rest/user.service' @Component({ selector: 'app-storage-path-edit-dialog', @@ -12,8 +13,12 @@ import { StoragePathService } from 'src/app/services/rest/storage-path.service' styleUrls: ['./storage-path-edit-dialog.component.scss'], }) export class StoragePathEditDialogComponent extends EditDialogComponent { - constructor(service: StoragePathService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: StoragePathService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } get pathHint() { @@ -41,16 +46,7 @@ export class StoragePathEditDialogComponent extends EditDialogComponent
-
Permissions
-
-
View
-
- - -
-
Edit
-
- - -
-
+
diff --git a/src-ui/src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.ts index 8b79d36bc..a0d0dd17d 100644 --- a/src-ui/src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.ts @@ -6,6 +6,7 @@ import { PaperlessTag } from 'src/app/data/paperless-tag' import { TagService } from 'src/app/services/rest/tag.service' import { randomColor } from 'src/app/utils/color' import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' +import { UserService } from 'src/app/services/rest/user.service' @Component({ selector: 'app-tag-edit-dialog', @@ -13,8 +14,12 @@ import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' styleUrls: ['./tag-edit-dialog.component.scss'], }) export class TagEditDialogComponent extends EditDialogComponent { - constructor(service: TagService, activeModal: NgbActiveModal) { - super(service, activeModal) + constructor( + service: TagService, + activeModal: NgbActiveModal, + userService: UserService + ) { + super(service, activeModal, userService) } getCreateTitle() { @@ -33,16 +38,7 @@ export class TagEditDialogComponent extends EditDialogComponent { matching_algorithm: new FormControl(DEFAULT_MATCHING_ALGORITHM), match: new FormControl(''), is_insensitive: new FormControl(true), - 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), }) } } diff --git a/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts index 0a87e33aa..70dcd42af 100644 --- a/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts @@ -24,7 +24,7 @@ export class UserEditDialogComponent activeModal: NgbActiveModal, groupsService: GroupService ) { - super(service, activeModal) + super(service, activeModal, service) groupsService .listAll() diff --git a/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.html b/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.html new file mode 100644 index 000000000..56c9e4dfa --- /dev/null +++ b/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.html @@ -0,0 +1,53 @@ +
Permissions
+
+
+
+ +
+
+ +
+
+ Objects without an owner can be viewed and edited by all users +
+
View
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
Edit
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ Edit permissions also grant viewing permissions +
+
+
diff --git a/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.scss b/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.ts b/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.ts new file mode 100644 index 000000000..1c1df164c --- /dev/null +++ b/src-ui/src/app/components/common/input/permissions-form/permissions-form.component.ts @@ -0,0 +1,66 @@ +import { Component, forwardRef, Input, OnInit } from '@angular/core' +import { FormControl, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms' +import { PaperlessUser } from 'src/app/data/paperless-user' +import { AbstractInputComponent } from '../abstract-input' + +export interface PermissionsFormObject { + owner?: number + set_permissions?: { + view?: { + users?: number[] + groups?: number[] + } + change?: { + users?: number[] + groups?: number[] + } + } +} + +@Component({ + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => PermissionsFormComponent), + multi: true, + }, + ], + selector: 'app-permissions-form', + templateUrl: './permissions-form.component.html', + styleUrls: ['./permissions-form.component.scss'], +}) +export class PermissionsFormComponent + extends AbstractInputComponent + implements OnInit +{ + @Input() + users: PaperlessUser[] + + form = new FormGroup({ + owner: new FormControl(null), + set_permissions: new FormGroup({ + view: new FormGroup({ + users: new FormControl([]), + groups: new FormControl([]), + }), + change: new FormGroup({ + users: new FormControl([]), + groups: new FormControl([]), + }), + }), + }) + + constructor() { + super() + } + + ngOnInit(): void { + this.form.valueChanges.subscribe((value) => { + this.onChange(value) + }) + } + + writeValue(newValue: any): void { + this.form.patchValue(newValue, { emitEvent: false }) + } +} diff --git a/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.html b/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.html index 1b74b1eb4..5ff0fa894 100644 --- a/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.html +++ b/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.html @@ -1,15 +1,13 @@ -
- -
- - -
- {{hint}} -
+
+
+ + +
+
diff --git a/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.ts b/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.ts index bef172747..ee2dfdf18 100644 --- a/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.ts +++ b/src-ui/src/app/components/common/input/permissions-group/permissions-group.component.ts @@ -3,7 +3,6 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms' import { first } from 'rxjs/operators' import { PaperlessGroup } from 'src/app/data/paperless-group' import { GroupService } from 'src/app/services/rest/group.service' -import { SettingsService } from 'src/app/services/settings.service' import { AbstractInputComponent } from '../abstract-input' @Component({ @@ -18,31 +17,14 @@ import { AbstractInputComponent } from '../abstract-input' templateUrl: './permissions-group.component.html', styleUrls: ['./permissions-group.component.scss'], }) -export class PermissionsGroupComponent - extends AbstractInputComponent - implements OnInit -{ +export class PermissionsGroupComponent extends AbstractInputComponent { groups: PaperlessGroup[] - @Input() - type: string - - constructor(groupService: GroupService, settings: SettingsService) { + constructor(groupService: GroupService) { super() groupService .listAll() .pipe(first()) .subscribe((result) => (this.groups = result.results)) } - - ngOnInit(): void { - if (this.type == 'view') { - this.title = $localize`Groups can view` - } else if (this.type == 'change') { - this.title = $localize`Groups can edit` - this.hint = $localize`Edit permissions also grant viewing permissions` - } - - super.ngOnInit() - } } diff --git a/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.html b/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.html index 9022b1a99..fdb832cf1 100644 --- a/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.html +++ b/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.html @@ -1,15 +1,13 @@ -
- -
- - -
- {{hint}} +
+
+ +
+
diff --git a/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.ts b/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.ts index 87ce08f08..2e0ba82f8 100644 --- a/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.ts +++ b/src-ui/src/app/components/common/input/permissions-user/permissions-user.component.ts @@ -18,15 +18,11 @@ import { AbstractInputComponent } from '../abstract-input' templateUrl: './permissions-user.component.html', styleUrls: ['./permissions-user.component.scss'], }) -export class PermissionsUserComponent - extends AbstractInputComponent - implements OnInit -{ +export class PermissionsUserComponent extends AbstractInputComponent< + PaperlessUser[] +> { users: PaperlessUser[] - @Input() - type: string - constructor(userService: UserService, settings: SettingsService) { super() userService @@ -39,15 +35,4 @@ export class PermissionsUserComponent )) ) } - - ngOnInit(): void { - if (this.type == 'view') { - this.title = $localize`Users can view` - } else if (this.type == 'change') { - this.title = $localize`Users can edit` - this.hint = $localize`Edit permissions also grant viewing permissions` - } - - super.ngOnInit() - } } diff --git a/src-ui/src/app/components/common/input/select/select.component.html b/src-ui/src/app/components/common/input/select/select.component.html index 6bb5f5036..fbe1e1018 100644 --- a/src-ui/src/app/components/common/input/select/select.component.html +++ b/src-ui/src/app/components/common/input/select/select.component.html @@ -1,5 +1,5 @@
- +
+ + Objects without an owner can be viewed and edited by all users
View
Edit
+ Edit permissions also grant viewing permissions
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 -
    -
    View
    -
    - - -
    -
    Edit
    -
    - - -
    -
    +
  • 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):