Auto-set user & user's groups in permissions when creating folder

This commit is contained in:
Martin Tan 2023-09-03 20:09:10 +08:00
parent a58c96a51e
commit e83a17524c

View File

@ -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<PaperlessStoragePath>
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()
}