mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Dont perform permissions queries by default
This commit is contained in:
@@ -122,7 +122,8 @@ export abstract class ManagementListComponent<T extends ObjectWithId>
|
||||
null,
|
||||
this.sortField,
|
||||
this.sortReverse,
|
||||
this._nameFilter
|
||||
this._nameFilter,
|
||||
true
|
||||
)
|
||||
.subscribe((c) => {
|
||||
this.data = c.results
|
||||
|
@@ -16,4 +16,6 @@ export interface ObjectWithPermissions extends ObjectWithId {
|
||||
owner?: number
|
||||
|
||||
permissions?: PermissionsObject
|
||||
|
||||
user_can_change?: boolean
|
||||
}
|
||||
|
@@ -58,17 +58,24 @@ export class PermissionsService {
|
||||
action: string,
|
||||
object: ObjectWithPermissions
|
||||
): boolean {
|
||||
let actionObject = null
|
||||
if (action === PermissionAction.View) actionObject = object.permissions.view
|
||||
else if (action === PermissionAction.Change)
|
||||
actionObject = object.permissions.change
|
||||
if (!actionObject) return false
|
||||
return (
|
||||
this.currentUserOwnsObject(object) ||
|
||||
actionObject.users.includes(this.currentUser.id) ||
|
||||
actionObject.groups.filter((g) => this.currentUser.groups.includes(g))
|
||||
.length > 0
|
||||
)
|
||||
if (action === PermissionAction.View) {
|
||||
return (
|
||||
this.currentUserOwnsObject(object) ||
|
||||
object.permissions?.view.users.includes(this.currentUser.id) ||
|
||||
object.permissions?.view.groups.filter((g) =>
|
||||
this.currentUser.groups.includes(g)
|
||||
).length > 0
|
||||
)
|
||||
} else if (action === PermissionAction.Change) {
|
||||
return (
|
||||
this.currentUserOwnsObject(object) ||
|
||||
object.user_can_change ||
|
||||
object.permissions?.change.users.includes(this.currentUser.id) ||
|
||||
object.permissions?.change.groups.filter((g) =>
|
||||
this.currentUser.groups.includes(g)
|
||||
).length > 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public getPermissionCode(
|
||||
|
@@ -9,11 +9,15 @@ export abstract class AbstractNameFilterService<
|
||||
pageSize?: number,
|
||||
sortField?: string,
|
||||
sortReverse?: boolean,
|
||||
nameFilter?: string
|
||||
nameFilter?: string,
|
||||
fullPerms?: boolean
|
||||
) {
|
||||
let params = {}
|
||||
if (nameFilter) {
|
||||
params = { name__icontains: nameFilter }
|
||||
params['name__icontains'] = nameFilter
|
||||
}
|
||||
if (fullPerms) {
|
||||
params['full_perms'] = true
|
||||
}
|
||||
return this.list(page, pageSize, sortField, sortReverse, params)
|
||||
}
|
||||
|
@@ -113,6 +113,14 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
}).pipe(map((response) => response.results.map((doc) => doc.id)))
|
||||
}
|
||||
|
||||
get(id: number): Observable<PaperlessDocument> {
|
||||
return this.http.get<PaperlessDocument>(this.getResourceUrl(id), {
|
||||
params: {
|
||||
full_perms: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
getPreviewUrl(id: number, original: boolean = false): string {
|
||||
let url = this.getResourceUrl(id, 'preview')
|
||||
if (this._searchQuery) url += `#search="${this._searchQuery}"`
|
||||
|
Reference in New Issue
Block a user