paperless-ngx/src-ui/src/app/components/common/permissions-dialog/permissions-dialog.component.ts

89 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-12-17 20:09:29 -08:00
import { Component, EventEmitter, Input, Output } from '@angular/core'
2022-12-08 02:03:50 -08:00
import { FormControl, FormGroup } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { ObjectWithPermissions } from 'src/app/data/object-with-permissions'
2023-12-19 22:36:35 -08:00
import { User } from 'src/app/data/user'
2022-12-09 10:04:39 -08:00
import { UserService } from 'src/app/services/rest/user.service'
2022-12-08 02:03:50 -08:00
@Component({
2023-09-14 14:03:28 -07:00
selector: 'pngx-permissions-dialog',
2022-12-08 02:03:50 -08:00
templateUrl: './permissions-dialog.component.html',
styleUrls: ['./permissions-dialog.component.scss'],
})
2022-12-17 20:09:29 -08:00
export class PermissionsDialogComponent {
2023-12-19 22:36:35 -08:00
users: User[]
private o: ObjectWithPermissions = undefined
2022-12-09 10:04:39 -08:00
constructor(
public activeModal: NgbActiveModal,
private userService: UserService
) {
this.userService.listAll().subscribe((r) => (this.users = r.results))
}
2022-12-08 02:03:50 -08:00
@Output()
2022-12-08 02:03:50 -08:00
public confirmClicked = new EventEmitter()
@Input()
title = $localize`Set permissions`
@Input()
set object(o: ObjectWithPermissions) {
this.o = o
this.title = $localize`Edit permissions for ` + o['name']
this.form.patchValue({
merge: true,
permissions_form: {
owner: o.owner,
set_permissions: o.permissions,
},
})
}
get object(): ObjectWithPermissions {
return this.o
}
2022-12-08 02:03:50 -08:00
public form = new FormGroup({
2022-12-09 17:51:01 -08:00
permissions_form: new FormControl(),
merge: new FormControl(true),
2022-12-08 02:03:50 -08:00
})
buttonsEnabled: boolean = true
2022-12-08 02:03:50 -08:00
get permissions() {
2022-12-09 17:51:01 -08:00
return {
owner: this.form.get('permissions_form').value?.owner ?? null,
set_permissions: this.form.get('permissions_form').value
?.set_permissions ?? {
view: {
users: [],
groups: [],
},
change: {
users: [],
groups: [],
},
},
2022-12-09 17:51:01 -08:00
}
2022-12-08 02:03:50 -08:00
}
get hint(): string {
if (this.object) return null
return this.form.get('merge').value
? $localize`Existing owner, user and group permissions will be merged with these settings.`
: $localize`Any and all existing owner, user and group permissions will be replaced.`
}
2022-12-08 02:03:50 -08:00
cancelClicked() {
this.activeModal.close()
}
confirm() {
this.confirmClicked.emit({
permissions: this.permissions,
merge: this.form.get('merge').value,
})
}
2022-12-08 02:03:50 -08:00
}