From e83a17524c4c93c441e21087284e66853c0bd3a9 Mon Sep 17 00:00:00 2001 From: Martin Tan Date: Sun, 3 Sep 2023 20:09:10 +0800 Subject: [PATCH] Auto-set user & user's groups in permissions when creating folder --- .../folder-create-dialog.component.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/common/create-dialog/folder-create-dialog/folder-create-dialog.component.ts b/src-ui/src/app/components/common/create-dialog/folder-create-dialog/folder-create-dialog.component.ts index cd6a60c4b..07d162931 100644 --- a/src-ui/src/app/components/common/create-dialog/folder-create-dialog/folder-create-dialog.component.ts +++ b/src-ui/src/app/components/common/create-dialog/folder-create-dialog/folder-create-dialog.component.ts @@ -1,12 +1,14 @@ -import { Component, OnInit } from '@angular/core' +import { AfterViewInit, Component, OnInit } from '@angular/core' import { FormControl, FormGroup } from '@angular/forms' import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { Subscription } from 'rxjs' import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model' import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path' +import { PermissionsService } from 'src/app/services/permissions.service' import { StoragePathService } from 'src/app/services/rest/storage-path.service' import { UserService } from 'src/app/services/rest/user.service' import { EditDialogComponent } from '../../edit-dialog/edit-dialog.component' +import { SettingsService } from 'src/app/services/settings.service' @Component({ selector: 'app-folder-create-dialog', @@ -15,13 +17,14 @@ import { EditDialogComponent } from '../../edit-dialog/edit-dialog.component' }) export class FolderCreateDialogComponent extends EditDialogComponent - implements OnInit { + implements OnInit, AfterViewInit { nameSub: Subscription constructor( service: StoragePathService, activeModal: NgbActiveModal, - userService: UserService + userService: UserService, + private settingsService: SettingsService ) { super(service, activeModal, userService) } @@ -37,8 +40,20 @@ export class FolderCreateDialogComponent }) } + ngAfterViewInit(): void { + this.objectForm.get('permissions_form').patchValue({ + owner: this.settingsService.currentUser.id, + set_permissions: { + view: { users: [], groups: [] }, + change: { users: [], groups: this.settingsService.currentUser.groups }, + }, + }) + } + submit(): void { this.nameSub.unsubscribe() + // This has to be done here, if we do it in the subscription, + // user's input will get constantly interrupted this.objectForm.get('name').patchValue(this.objectForm.get('path').value) this.save() }