From db06c079fc82d35ab7fd1d9c3991ebf9aeb974b1 Mon Sep 17 00:00:00 2001 From: Maxwell Mwandigha Date: Thu, 19 Sep 2024 12:20:33 +0300 Subject: [PATCH 1/2] Fix for permission rights disappearing after refresh --- .../choose-collection.component.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/mobile-mzima-client/src/app/shared/components/choose-collection/choose-collection.component.ts b/apps/mobile-mzima-client/src/app/shared/components/choose-collection/choose-collection.component.ts index e6f9f4e47..18bf0de84 100644 --- a/apps/mobile-mzima-client/src/app/shared/components/choose-collection/choose-collection.component.ts +++ b/apps/mobile-mzima-client/src/app/shared/components/choose-collection/choose-collection.component.ts @@ -118,7 +118,6 @@ export class ChooseCollectionComponent { }); this.userData$ = this.sessionService.currentUserData$.pipe(untilDestroyed(this)); - this.userData$.subscribe((userData) => { this.userRole = userData.role!; this.currentUserId = userData.userId; @@ -126,19 +125,18 @@ export class ChooseCollectionComponent { ? userData.permissions.join(',') : userData.permissions!; - this.canManageCollections = this.checkManageCollections(userData); + if (this.userRole && this.userPermissions) { + this.canManageCollections = this.checkManageCollections(userData); + } else { + console.log('Cannot retrieve userRole and permissions'); + } this.initRoles(); }); } - private checkManageCollections(userData: UserInterface): boolean { - if (Array.isArray(userData.permissions!)) { - const hasPermission = userData.permissions!.includes('Manage Collections and Saved Searches'); - return hasPermission; - } else { - console.log('User doesnt have the collection management rights'); - return false; - } + private checkManageCollections(userData: UserInterface) { + const hasPermission = userData.permissions!.includes('Manage Collections and Saved Searches'); + return hasPermission; } async ionViewWillEnter() { From 7c71b821a729e7b0019f7823a0303bcbe37cf227 Mon Sep 17 00:00:00 2001 From: Maxwell Mwandigha Date: Fri, 20 Sep 2024 21:46:10 +0300 Subject: [PATCH 2/2] Fixed collections for non admin users with permissions --- .../components/collection-item/collection-item.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/mobile-mzima-client/src/app/shared/components/collection-item/collection-item.component.ts b/apps/mobile-mzima-client/src/app/shared/components/collection-item/collection-item.component.ts index 06946e754..5f04975ad 100644 --- a/apps/mobile-mzima-client/src/app/shared/components/collection-item/collection-item.component.ts +++ b/apps/mobile-mzima-client/src/app/shared/components/collection-item/collection-item.component.ts @@ -19,7 +19,9 @@ export class CollectionItemComponent { if (this.userRole === 'admin') { return true; } - return this.canManageCollections && this.collection.user_id === this.currentUserId; + return ( + this.canManageCollections && String(this.collection.user_id) === String(this.currentUserId) + ); } public editClickHandle(event: Event): void {