From b6f1ced45508824df552cd8afd8c00b380009873 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:58:49 -0800 Subject: [PATCH] retain user / group permissions the UI doesnt use --- src-ui/src/app/services/rest/group.service.ts | 20 ++++++++++++++++++- src-ui/src/app/services/rest/user.service.ts | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/services/rest/group.service.ts b/src-ui/src/app/services/rest/group.service.ts index 7c913b92c..800c3c71b 100644 --- a/src-ui/src/app/services/rest/group.service.ts +++ b/src-ui/src/app/services/rest/group.service.ts @@ -1,13 +1,31 @@ import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' +import { Observable, switchMap } from 'rxjs' import { PaperlessGroup } from 'src/app/data/paperless-group' +import { PermissionsService } from '../permissions.service' import { AbstractNameFilterService } from './abstract-name-filter-service' @Injectable({ providedIn: 'root', }) export class GroupService extends AbstractNameFilterService { - constructor(http: HttpClient) { + constructor(http: HttpClient, private permissionService: PermissionsService) { super(http, 'groups') } + + update(o: PaperlessGroup): Observable { + return this.getCached(o.id).pipe( + switchMap((initialGroup) => { + initialGroup.permissions?.forEach((perm) => { + const { typeKey, actionKey } = + this.permissionService.getPermissionKeys(perm) + if (!typeKey || !actionKey) { + // dont lose permissions the UI doesnt use + o.permissions.push(perm) + } + }) + return super.update(o) + }) + ) + } } diff --git a/src-ui/src/app/services/rest/user.service.ts b/src-ui/src/app/services/rest/user.service.ts index e8466a2a2..125a35ce6 100644 --- a/src-ui/src/app/services/rest/user.service.ts +++ b/src-ui/src/app/services/rest/user.service.ts @@ -1,13 +1,31 @@ import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' +import { Observable, switchMap } from 'rxjs' import { PaperlessUser } from 'src/app/data/paperless-user' +import { PermissionsService } from '../permissions.service' import { AbstractNameFilterService } from './abstract-name-filter-service' @Injectable({ providedIn: 'root', }) export class UserService extends AbstractNameFilterService { - constructor(http: HttpClient) { + constructor(http: HttpClient, private permissionService: PermissionsService) { super(http, 'users') } + + update(o: PaperlessUser): Observable { + return this.getCached(o.id).pipe( + switchMap((initialUser) => { + initialUser.user_permissions?.forEach((perm) => { + const { typeKey, actionKey } = + this.permissionService.getPermissionKeys(perm) + if (!typeKey || !actionKey) { + // dont lose permissions the UI doesnt use + o.user_permissions.push(perm) + } + }) + return super.update(o) + }) + ) + } }