Added API to get user groups for an app with view access

This commit is contained in:
devanshu052000 2025-04-17 03:38:31 +05:30
parent 4b4cae5b83
commit fc3669af74
11 changed files with 33 additions and 1 deletions

View file

@ -30,6 +30,7 @@ export class FeatureAbilityFactory extends AbilityFactory<FEATURE_KEY, Subjects>
if (isAdmin || superAdmin) {
// Admin or super admin and do all operations
can([FEATURE_KEY.FETCH_USERS], App);
can([FEATURE_KEY.FETCH_USER_GROUPS], App);
return;
}
@ -38,6 +39,7 @@ export class FeatureAbilityFactory extends AbilityFactory<FEATURE_KEY, Subjects>
(userAppPermissions?.editableAppsId?.length && appId && userAppPermissions.editableAppsId.includes(appId))
) {
can([FEATURE_KEY.FETCH_USERS], App);
can([FEATURE_KEY.FETCH_USER_GROUPS], App);
}
}
}

View file

@ -5,5 +5,6 @@ import { FeaturesConfig } from '../types';
export const FEATURES: FeaturesConfig = {
[MODULES.APP_PERMISSIONS]: {
[FEATURE_KEY.FETCH_USERS]: {},
[FEATURE_KEY.FETCH_USER_GROUPS]: {},
},
};

View file

@ -1,3 +1,4 @@
export enum FEATURE_KEY {
FETCH_USERS = 'fetch_users',
FETCH_USER_GROUPS = 'fetch_user_groups',
}

View file

@ -24,4 +24,14 @@ export class AppPermissionsController implements IAppPermissionsController {
): Promise<any> {
throw new NotFoundException();
}
@InitFeature(FEATURE_KEY.FETCH_USER_GROUPS)
@Get(':appId/pages/user-groups')
async fetchUserGroups(
@User() user,
@Param('appId') appId: string,
@Res({ passthrough: true }) response: Response
): Promise<any> {
throw new NotFoundException();
}
}

View file

@ -3,4 +3,6 @@ import { Response } from 'express';
export interface IAppPermissionsController {
fetchUsers(user: User, appId: string, response: Response): Promise<any>;
fetchUserGroups(user: User, appId: string, response: Response): Promise<any>;
}

View file

@ -2,4 +2,6 @@ import { User } from '@entities/user.entity';
export interface IAppPermissionsService {
fetchUsers(appId: string, user: User): Promise<any>;
fetchUserGroups(appId: string, user: User): Promise<any>;
}

View file

@ -1,5 +1,8 @@
import { User } from '@entities/user.entity';
import { GroupPermissions } from '@entities/group_permissions.entity';
export interface IUtilService {
getUsersWithViewAccess(appId: string, organizationId: string, endUserIds: string[]): Promise<User[]>;
getUserGroupsWithViewAccess(appId: string, organizationId: string): Promise<GroupPermissions[]>;
}

View file

@ -2,6 +2,7 @@ import { getImportPath } from '@modules/app/constants';
import { DynamicModule } from '@nestjs/common';
import { FeatureAbilityFactory } from './ability';
import { TypeOrmModule } from '@nestjs/typeorm';
import { GroupPermissions } from '@entities/group_permissions.entity';
import { User } from '@entities/user.entity';
import { RolesRepository } from '@modules/roles/repository';
@ -14,7 +15,7 @@ export class AppPermissionsModule {
return {
module: AppPermissionsModule,
imports: [TypeOrmModule.forFeature([User])],
imports: [TypeOrmModule.forFeature([GroupPermissions, User])],
controllers: [AppPermissionsController],
providers: [AppPermissionsService, AppPermissionsUtilService, RolesRepository, FeatureAbilityFactory],
exports: [AppPermissionsUtilService],

View file

@ -8,4 +8,8 @@ export class AppPermissionsService implements IAppPermissionsService {
async fetchUsers(appId, user) {
throw new Error('Method not implemented.');
}
async fetchUserGroups(appId, user) {
throw new Error('Method not implemented.');
}
}

View file

@ -4,6 +4,7 @@ import { MODULES } from '@modules/app/constants/modules';
interface Features {
[FEATURE_KEY.FETCH_USERS]: FeatureConfig;
[FEATURE_KEY.FETCH_USER_GROUPS]: FeatureConfig;
}
export interface FeaturesConfig {

View file

@ -1,11 +1,16 @@
import { User } from '@entities/user.entity';
import { IUtilService } from './interfaces/IUtilService';
import { Injectable } from '@nestjs/common';
import { GroupPermissions } from '@entities/group_permissions.entity';
@Injectable()
export class AppPermissionsUtilService implements IUtilService {
constructor() {}
async getUserGroupsWithViewAccess(appId: string, organizationId: string): Promise<GroupPermissions[]> {
throw new Error('Method not implemented.');
}
async getUsersWithViewAccess(appId: string, organizationId: string, endUserIds: string[]): Promise<User[]> {
throw new Error('Method not implemented.');
}