Skip to content

Commit

Permalink
QA blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul K R committed Jan 30, 2024
1 parent c975475 commit fb3696f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/app/core/constants/permissionsConstant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const permissions = {
MANAGE_USER: 'mentor_listing',
MANAGE_USER: 'manage_user',
MANAGE_SESSION: 'manage_session',
};
export const actions = {
Expand All @@ -16,7 +16,7 @@ export const manageSessionAction = {
};
export const manageUserAction = {
USER_ACTIONS: [
actions.GET,
actions.POST,
actions.DELETE
],
};
53 changes: 18 additions & 35 deletions src/app/core/services/permission/permission.service.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import { Injectable } from '@angular/core';
import { LocalStorageService } from '../localstorage.service';
import { localKeys } from '../../constants/localStorage.keys';
import { CommonRoutes } from 'src/global.routes';
import { manageSessionAction, manageUserAction, permissions } from '../../constants/permissionsConstant';

@Injectable({
providedIn: 'root',
})
export class PermissionService {

public userPermissions:any[] = [
{
title: 'MANAGE_USER',
url: CommonRoutes.ADMIN + '/' + CommonRoutes.MANAGE_USER,
icon: 'people-outline',
module: permissions.MANAGE_USER,
request_type: manageUserAction.USER_ACTIONS,
},
{
title: 'MANAGE_SESSION',
url: CommonRoutes.ADMIN + '/' + CommonRoutes.MANAGE_SESSION,
icon: 'people-outline',
module: permissions.MANAGE_SESSION,
request_type: manageSessionAction.SESSION_ACTIONS,
},
];
userPermissions:any = [];

constructor(private localStorage: LocalStorageService){}

async hasPermission(permissions: any): Promise <boolean> {
// if(!this.userPermissions.length){
// await this.fetchPermissions().then((res) =>{
// this.userPermissions = res;
// })
// }
if(!this.userPermissions.length){
await this.fetchPermissions().then((res) =>{
this.userPermissions = res;
})
}
for (let userPermission of this.userPermissions) {
if (permissions && userPermission.request_type.length && permissions.module === userPermission.module) {
if (permissions.action.every((value: any) => userPermission.request_type.includes(value))) {
Expand All @@ -45,17 +28,17 @@ public userPermissions:any[] = [
}
}

// async fetchPermissions():Promise<any []> {
// return new Promise((resolve, reject) => {
// try {
// this.localStorage.getLocalData(localKeys.USER_DETAILS)
// .then(async (data) => {
// if(data) {
// resolve(data?.permissions);
// }
// })
// } catch (error) {}
// });
async fetchPermissions():Promise<any []> {
return new Promise((resolve, reject) => {
try {
this.localStorage.getLocalData(localKeys.USER_DETAILS)
.then(async (data) => {
if(data) {
resolve(data?.permissions);
}
})
} catch (error) {}
});

// }
}
}

0 comments on commit fb3696f

Please sign in to comment.