mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
util-service
This commit is contained in:
parent
3d697f08b1
commit
592447dc83
4 changed files with 28 additions and 31 deletions
|
|
@ -8,7 +8,7 @@ export class ExternalApiSecurityGuard implements CanActivate {
|
|||
canActivate(context: ExecutionContext): boolean {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
|
||||
// // Check if external API is enabled
|
||||
// Check if external API is enabled
|
||||
const isExternalApiEnabled = this.configService.get<string>('ENABLE_EXTERNAL_API') === 'true';
|
||||
if (!isExternalApiEnabled) {
|
||||
throw new ForbiddenException('External API is disabled');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { DynamicModule } from '@nestjs/common';
|
|||
import { getImportPath } from '@modules/app/constants';
|
||||
import { InstanceSettingsModule } from '@modules/instance-settings/module';
|
||||
import { OrganizationRepository } from './repository';
|
||||
import { AppEnvironmentsModule } from '@modules/app-environments/module';
|
||||
|
||||
export class OrganizationsModule {
|
||||
static async register(configs?: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
|
||||
|
|
@ -9,20 +10,13 @@ export class OrganizationsModule {
|
|||
const { OrganizationsService } = await import(`${importPath}/organizations/service`);
|
||||
const { OrganizationsController } = await import(`${importPath}/organizations/controller`);
|
||||
const { FeatureAbilityFactory } = await import(`${importPath}/organizations/ability`);
|
||||
const { AppEnvironmentUtilService } = await import(`${importPath}/app-environments/util.service`);
|
||||
const { OrganizationsUtilService } = await import(`${importPath}/organizations/util.service`);
|
||||
|
||||
return {
|
||||
module: OrganizationsModule,
|
||||
imports: [await InstanceSettingsModule.register(configs)],
|
||||
imports: [await InstanceSettingsModule.register(configs), await AppEnvironmentsModule.register(configs)],
|
||||
controllers: [OrganizationsController],
|
||||
providers: [
|
||||
OrganizationsService,
|
||||
OrganizationRepository,
|
||||
FeatureAbilityFactory,
|
||||
AppEnvironmentUtilService,
|
||||
OrganizationsUtilService,
|
||||
],
|
||||
providers: [OrganizationsService, OrganizationRepository, FeatureAbilityFactory, OrganizationsUtilService],
|
||||
exports: [OrganizationsUtilService],
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,23 @@ import { EditUserRoleDto } from './dto';
|
|||
import { RolesUtilService } from './util.service';
|
||||
import { RolesRepository } from './repository';
|
||||
import { IRolesService } from './interfaces/IService';
|
||||
import { EntityManager } from 'typeorm';
|
||||
import { dbTransactionWrap } from '@helpers/database.helper';
|
||||
import { LicenseUserService } from '@modules/licensing/services/user.service';
|
||||
|
||||
@Injectable()
|
||||
export class RolesService implements IRolesService {
|
||||
constructor(protected rolesUtilService: RolesUtilService, protected roleRepository: RolesRepository) {}
|
||||
constructor(
|
||||
protected rolesUtilService: RolesUtilService,
|
||||
protected roleRepository: RolesRepository,
|
||||
protected licenseUserService: LicenseUserService
|
||||
) {}
|
||||
|
||||
async updateUserRole(organizationId: string, editRoleDto: EditUserRoleDto) {
|
||||
await this.rolesUtilService.updateUserRole(organizationId, editRoleDto);
|
||||
await dbTransactionWrap(async (manager: EntityManager) => {
|
||||
await this.rolesUtilService.editDefaultGroupUserRole(organizationId, editRoleDto, manager);
|
||||
|
||||
await this.licenseUserService.validateUser(manager);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,8 +57,18 @@ export class RolesUtilService implements IRolesUtilService {
|
|||
editRoleDto: EditUserRoleDto,
|
||||
manager?: EntityManager
|
||||
): Promise<void> {
|
||||
const { newRole, userId, updatingUserId: updatedAdmin, currentRole: userRole } = editRoleDto;
|
||||
const { newRole, userId, updatingUserId: updatedAdmin } = editRoleDto;
|
||||
return await dbTransactionWrap(async (manager: EntityManager) => {
|
||||
const userRole = await this.roleRepository.getUserRole(userId, organizationId, manager);
|
||||
if (_.isEmpty(userRole)) {
|
||||
throw new BadRequestException(ERROR_HANDLER.ADD_GROUP_USER_NON_EXISTING_USER);
|
||||
}
|
||||
|
||||
if (userRole.name == newRole) {
|
||||
throw new BadRequestException(ERROR_HANDLER.DEFAULT_GROUP_ADD_USER_ROLE_EXIST(newRole));
|
||||
}
|
||||
editRoleDto.currentRole = userRole;
|
||||
|
||||
// Removing an admin
|
||||
if (userRole.name == USER_ROLE.ADMIN) {
|
||||
const groupUsers = await this.groupPermissionsRepository.getUsersInGroup(
|
||||
|
|
@ -196,22 +206,4 @@ export class RolesUtilService implements IRolesUtilService {
|
|||
return isBuilderLevelAppsPermission || isBuilderLevelDataSourcePermissions;
|
||||
}, manager);
|
||||
}
|
||||
|
||||
async updateUserRole(organizationId: string, editRoleDto: EditUserRoleDto) {
|
||||
const { userId, newRole } = editRoleDto;
|
||||
await dbTransactionWrap(async (manager: EntityManager) => {
|
||||
const userRole = await this.roleRepository.getUserRole(userId, organizationId, manager);
|
||||
if (_.isEmpty(userRole)) {
|
||||
throw new BadRequestException(ERROR_HANDLER.ADD_GROUP_USER_NON_EXISTING_USER);
|
||||
}
|
||||
|
||||
if (userRole.name == newRole) {
|
||||
throw new BadRequestException(ERROR_HANDLER.DEFAULT_GROUP_ADD_USER_ROLE_EXIST(newRole));
|
||||
}
|
||||
editRoleDto.currentRole = userRole;
|
||||
await this.editDefaultGroupUserRole(organizationId, editRoleDto, manager);
|
||||
|
||||
await this.licenseUserService.validateUser(manager);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue