mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Unify API perm endpoint to set_permissions
, initial frontend support for doc sharing
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
i18n-addTagText="Used for both types, correspondents, storage paths"
|
||||
[placeholder]="placeholder"
|
||||
[multiple]="multiple"
|
||||
bindLabel="name"
|
||||
[bindLabel]="bindLabel"
|
||||
bindValue="id"
|
||||
(change)="onChange(value)"
|
||||
(search)="onSearch($event)"
|
||||
|
@@ -47,6 +47,9 @@ export class SelectComponent extends AbstractInputComponent<number> {
|
||||
@Input()
|
||||
multiple: boolean = false
|
||||
|
||||
@Input()
|
||||
bindLabel: string = 'name'
|
||||
|
||||
@Output()
|
||||
createNew = new EventEmitter<string>()
|
||||
|
||||
|
@@ -170,12 +170,23 @@
|
||||
</div>
|
||||
</ng-template>
|
||||
</li>
|
||||
|
||||
<li [ngbNavItem]="5" *ngIf="commentsEnabled">
|
||||
<a ngbNavLink i18n>Comments</a>
|
||||
<ng-template ngbNavContent>
|
||||
<app-document-comments [documentId]="documentId"></app-document-comments>
|
||||
</ng-template>
|
||||
</li>
|
||||
|
||||
<li [ngbNavItem]="6">
|
||||
<a ngbNavLink i18n>Permissions</a>
|
||||
<ng-template ngbNavContent>
|
||||
<div formGroupName="set_permissions">
|
||||
<app-input-select i18n-title title="Users can view" [items]="users" [bindLabel]="'username'" multiple="true" formControlName="view"></app-input-select>
|
||||
<app-input-select i18n-title title="Users can edit" [items]="users" [bindLabel]="'username'" multiple="true" formControlName="change"></app-input-select>
|
||||
</div>
|
||||
</ng-template>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
||||
|
@@ -40,6 +40,8 @@ import {
|
||||
PermissionsService,
|
||||
PermissionType,
|
||||
} from 'src/app/services/permissions.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
|
||||
@Component({
|
||||
selector: 'app-document-detail',
|
||||
@@ -73,6 +75,7 @@ export class DocumentDetailComponent
|
||||
correspondents: PaperlessCorrespondent[]
|
||||
documentTypes: PaperlessDocumentType[]
|
||||
storagePaths: PaperlessStoragePath[]
|
||||
users: PaperlessUser[]
|
||||
|
||||
documentForm: FormGroup = new FormGroup({
|
||||
title: new FormControl(''),
|
||||
@@ -83,6 +86,10 @@ export class DocumentDetailComponent
|
||||
storage_path: new FormControl(),
|
||||
archive_serial_number: new FormControl(),
|
||||
tags: new FormControl([]),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormControl(null),
|
||||
change: new FormControl(null),
|
||||
}),
|
||||
})
|
||||
|
||||
previewCurrentPage: number = 1
|
||||
@@ -127,7 +134,8 @@ export class DocumentDetailComponent
|
||||
private toastService: ToastService,
|
||||
private settings: SettingsService,
|
||||
private storagePathService: StoragePathService,
|
||||
private permissionsService: PermissionsService
|
||||
private permissionsService: PermissionsService,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
titleKeyUp(event) {
|
||||
@@ -167,6 +175,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),
|
||||
@@ -230,6 +243,14 @@ export class DocumentDetailComponent
|
||||
storage_path: doc.storage_path,
|
||||
archive_serial_number: doc.archive_serial_number,
|
||||
tags: [...doc.tags],
|
||||
set_permissions: {
|
||||
view: doc.permissions
|
||||
.filter((p) => (p[1] as string).includes('view'))
|
||||
.map((p) => p[0]),
|
||||
change: doc.permissions
|
||||
.filter((p) => (p[1] as string).includes('change'))
|
||||
.map((p) => p[0]),
|
||||
},
|
||||
})
|
||||
|
||||
this.isDirty$ = dirtyCheck(
|
||||
@@ -284,6 +305,14 @@ export class DocumentDetailComponent
|
||||
},
|
||||
})
|
||||
this.title = this.documentTitlePipe.transform(doc.title)
|
||||
doc['set_permissions'] = {
|
||||
view: doc.permissions
|
||||
.filter((p) => (p[1] as string).includes('view'))
|
||||
.map((p) => p[0]),
|
||||
change: doc.permissions
|
||||
.filter((p) => (p[1] as string).includes('change'))
|
||||
.map((p) => p[0]),
|
||||
}
|
||||
this.documentForm.patchValue(doc)
|
||||
}
|
||||
|
||||
@@ -376,7 +405,7 @@ export class DocumentDetailComponent
|
||||
.update(this.document)
|
||||
.pipe(first())
|
||||
.subscribe({
|
||||
next: (result) => {
|
||||
next: () => {
|
||||
this.close()
|
||||
this.networkActive = false
|
||||
this.error = null
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { ObjectWithId } from './object-with-id'
|
||||
import { ObjectWithPermissions } from './object-with-permissions'
|
||||
|
||||
export const MATCH_ANY = 1
|
||||
export const MATCH_ALL = 2
|
||||
@@ -41,7 +41,7 @@ export const MATCHING_ALGORITHMS = [
|
||||
},
|
||||
]
|
||||
|
||||
export interface MatchingModel extends ObjectWithId {
|
||||
export interface MatchingModel extends ObjectWithPermissions {
|
||||
name?: string
|
||||
|
||||
slug?: string
|
||||
|
8
src-ui/src/app/data/object-with-permissions.ts
Normal file
8
src-ui/src/app/data/object-with-permissions.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ObjectWithId } from './object-with-id'
|
||||
import { PaperlessUser } from './paperless-user'
|
||||
|
||||
export interface ObjectWithPermissions extends ObjectWithId {
|
||||
user?: PaperlessUser
|
||||
|
||||
permissions?: Array<[number, string]>
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
import { PaperlessCorrespondent } from './paperless-correspondent'
|
||||
import { ObjectWithId } from './object-with-id'
|
||||
import { PaperlessTag } from './paperless-tag'
|
||||
import { PaperlessDocumentType } from './paperless-document-type'
|
||||
import { Observable } from 'rxjs'
|
||||
import { PaperlessStoragePath } from './paperless-storage-path'
|
||||
import { ObjectWithPermissions } from './object-with-permissions'
|
||||
|
||||
export interface SearchHit {
|
||||
score?: number
|
||||
@@ -12,7 +12,7 @@ export interface SearchHit {
|
||||
highlights?: string
|
||||
}
|
||||
|
||||
export interface PaperlessDocument extends ObjectWithId {
|
||||
export interface PaperlessDocument extends ObjectWithPermissions {
|
||||
correspondent$?: Observable<PaperlessCorrespondent>
|
||||
|
||||
correspondent?: number
|
||||
|
@@ -2,8 +2,10 @@ import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
import { map, publishReplay, refCount } from 'rxjs/operators'
|
||||
import { ObjectWithId } from 'src/app/data/object-with-id'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { Results } from 'src/app/data/results'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { PermissionAction, PermissionType } from '../permissions.service'
|
||||
|
||||
export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
protected baseUrl: string = environment.apiBaseUrl
|
||||
|
Reference in New Issue
Block a user