mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Fix/refactor: remove doc observables, fix username async (#8908)
This commit is contained in:
46
src-ui/src/app/pipes/object-name.pipe.ts
Normal file
46
src-ui/src/app/pipes/object-name.pipe.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { catchError, map, Observable, of } from 'rxjs'
|
||||
import { MatchingModel } from '../data/matching-model'
|
||||
import {
|
||||
PermissionAction,
|
||||
PermissionsService,
|
||||
PermissionType,
|
||||
} from '../services/permissions.service'
|
||||
import { AbstractNameFilterService } from '../services/rest/abstract-name-filter-service'
|
||||
|
||||
@Pipe({
|
||||
name: 'objectName',
|
||||
})
|
||||
export abstract class ObjectNamePipe implements PipeTransform {
|
||||
/*
|
||||
ObjectNamePipe is an abstract class to prevent instantiation,
|
||||
object-specific pipes extend this class and provide the
|
||||
correct permission type, and object service.
|
||||
*/
|
||||
protected objects: MatchingModel[]
|
||||
|
||||
constructor(
|
||||
protected permissionsService: PermissionsService,
|
||||
protected permissionType: PermissionType,
|
||||
protected objectService: AbstractNameFilterService<MatchingModel>
|
||||
) {}
|
||||
|
||||
transform(obejctId: number): Observable<string> {
|
||||
if (
|
||||
this.permissionsService.currentUserCan(
|
||||
PermissionAction.View,
|
||||
this.permissionType
|
||||
)
|
||||
) {
|
||||
return this.objectService.listAll().pipe(
|
||||
map((objects) => {
|
||||
this.objects = objects.results
|
||||
return this.objects.find((o) => o.id === obejctId)?.name || ''
|
||||
}),
|
||||
catchError(() => of(''))
|
||||
)
|
||||
} else {
|
||||
return of($localize`Private`)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user