diff --git a/server/src/modules/auth/guards/external-api-security.guard.ts b/server/src/modules/auth/guards/external-api-security.guard.ts index 19b0d197a4..f6aced14d5 100644 --- a/server/src/modules/auth/guards/external-api-security.guard.ts +++ b/server/src/modules/auth/guards/external-api-security.guard.ts @@ -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('ENABLE_EXTERNAL_API') === 'true'; if (!isExternalApiEnabled) { throw new ForbiddenException('External API is disabled'); diff --git a/server/src/modules/organizations/module.ts b/server/src/modules/organizations/module.ts index e430ae78e5..e533607557 100644 --- a/server/src/modules/organizations/module.ts +++ b/server/src/modules/organizations/module.ts @@ -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 { @@ -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], }; } diff --git a/server/src/modules/roles/service.ts b/server/src/modules/roles/service.ts index d67c7f9923..981f0e6f57 100644 --- a/server/src/modules/roles/service.ts +++ b/server/src/modules/roles/service.ts @@ -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); + }); } } diff --git a/server/src/modules/roles/util.service.ts b/server/src/modules/roles/util.service.ts index 6c596480f9..26733f07a1 100644 --- a/server/src/modules/roles/util.service.ts +++ b/server/src/modules/roles/util.service.ts @@ -57,8 +57,18 @@ export class RolesUtilService implements IRolesUtilService { editRoleDto: EditUserRoleDto, manager?: EntityManager ): Promise { - 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); - }); - } }