Add ability to set owner per object

This commit is contained in:
Michael Shamoon
2022-12-09 10:04:39 -08:00
parent df2540320c
commit 360a2258e1
28 changed files with 293 additions and 220 deletions

View File

@@ -0,0 +1,53 @@
<h5 i18n>Permissions</h5>
<div [formGroup]="form">
<div class="row">
<div class="col-lg-3">
<label class="form-label d-block my-2" i18n>Owner:</label>
</div>
<div class="col-lg-9">
<app-input-select [items]="users" bindLabel="username" formControlName="owner" [allowNull]="true"></app-input-select>
</div>
</div>
<small class="form-text text-muted text-end d-block mt-n2" i18n>Objects without an owner can be viewed and edited by all users</small>
<div formGroupName="set_permissions">
<h6 class="mt-3" i18n>View</h6>
<div formGroupName="view" class="mb-2">
<div class="row mb-1">
<div class="col-lg-3">
<label class="form-label d-block my-2" i18n>Users:</label>
</div>
<div class="col-lg-9">
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<label class="form-label d-block my-2" i18n>Groups:</label>
</div>
<div class="col-lg-9">
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
</div>
</div>
</div>
<h6 class="mt-4" i18n>Edit</h6>
<div formGroupName="change">
<div class="row mb-1">
<div class="col-lg-3">
<label class="form-label d-block my-2" i18n>Users:</label>
</div>
<div class="col-lg-9">
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<label class="form-label d-block my-2" i18n>Groups:</label>
</div>
<div class="col-lg-9">
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
</div>
</div>
<small class="form-text text-muted text-end d-block" i18n>Edit permissions also grant viewing permissions</small>
</div>
</div>
</div>

View File

@@ -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<PermissionsFormObject>
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 })
}
}

View File

@@ -1,15 +1,13 @@
<div class="mb-3 paperless-input-select">
<label class="form-label" [for]="inputId">{{title}}</label>
<div>
<ng-select name="inputId" [(ngModel)]="value"
[disabled]="disabled"
clearable="true"
[items]="groups"
multiple="true"
bindLabel="name"
bindValue="id"
(change)="onChange(value)">
</ng-select>
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
</div>
<div class="paperless-input-select">
<div>
<ng-select name="inputId" [(ngModel)]="value"
[disabled]="disabled"
clearable="true"
[items]="groups"
multiple="true"
bindLabel="name"
bindValue="id"
(change)="onChange(value)">
</ng-select>
</div>
</div>

View File

@@ -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<PaperlessGroup>
implements OnInit
{
export class PermissionsGroupComponent extends AbstractInputComponent<PaperlessGroup> {
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()
}
}

View File

@@ -1,15 +1,13 @@
<div class="mb-3 paperless-input-select">
<label class="form-label" [for]="inputId">{{title}}</label>
<div>
<ng-select name="inputId" [(ngModel)]="value"
[disabled]="disabled"
clearable="true"
[items]="users"
multiple="true"
bindLabel="username"
bindValue="id"
(change)="onChange(value)">
</ng-select>
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
<div class="paperless-input-select">
<div>
<ng-select name="inputId" [(ngModel)]="value"
[disabled]="disabled"
clearable="true"
[items]="users"
multiple="true"
bindLabel="username"
bindValue="id"
(change)="onChange(value)">
</ng-select>
</div>
</div>

View File

@@ -18,15 +18,11 @@ import { AbstractInputComponent } from '../abstract-input'
templateUrl: './permissions-user.component.html',
styleUrls: ['./permissions-user.component.scss'],
})
export class PermissionsUserComponent
extends AbstractInputComponent<PaperlessUser>
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()
}
}

View File

@@ -1,5 +1,5 @@
<div class="mb-3 paperless-input-select">
<label class="form-label" [for]="inputId">{{title}}</label>
<label *ngIf="title" class="form-label" [for]="inputId">{{title}}</label>
<div [class.input-group]="allowCreateNew">
<ng-select name="inputId" [(ngModel)]="value"
[disabled]="disabled"