mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
Added API to get user groups for an app with view access
This commit is contained in:
parent
4b4cae5b83
commit
fc3669af74
11 changed files with 33 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ import { FeaturesConfig } from '../types';
|
|||
export const FEATURES: FeaturesConfig = {
|
||||
[MODULES.APP_PERMISSIONS]: {
|
||||
[FEATURE_KEY.FETCH_USERS]: {},
|
||||
[FEATURE_KEY.FETCH_USER_GROUPS]: {},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export enum FEATURE_KEY {
|
||||
FETCH_USERS = 'fetch_users',
|
||||
FETCH_USER_GROUPS = 'fetch_user_groups',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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[]>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue