Feat/disable flexible backend (#1673)

* wip: refacto and start creating custom resolver

* feat: findMany & findUnique of a custom entity

* feat: wip pagination

* feat: initial metadata migration

* feat: universal findAll with pagination

* fix: clean small stuff in pagination

* fix: test

* fix: miss file

* feat: rename custom into universal

* feat: enable/disable flexible backend from env

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
Jérémy M 2023-09-21 02:25:45 +02:00 committed by GitHub
parent b1171e22a3
commit fc820f47b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 3 deletions

View File

@ -24,4 +24,5 @@ SIGN_IN_PREFILLED=true
# SUPPORT_FRONT_CHAT_ID=replace_me_with_front_chat_id
# LOGGER_DRIVER=console
# SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx
# LOG_LEVEL=error,warn
# LOG_LEVEL=error,warn
# FLEXIBLE_BACKEND_ENABLED=false

View File

@ -44,6 +44,9 @@ export class ClientConfig {
@Field(() => Boolean)
debugMode: boolean;
@Field(() => Boolean)
flexibleBackendEnabled: boolean;
@Field(() => Support)
support: Support;
}

View File

@ -23,6 +23,8 @@ export class ClientConfigResolver {
},
signInPrefilled: this.environmentService.isSignInPrefilled(),
debugMode: this.environmentService.isDebugMode(),
flexibleBackendEnabled:
this.environmentService.isFlexibleBackendEnabled(),
support: {
supportDriver: this.environmentService.getSupportDriver(),
supportFrontChatId: this.environmentService.getSupportFrontChatId(),

View File

@ -29,6 +29,10 @@ export class EnvironmentService {
);
}
isFlexibleBackendEnabled(): boolean {
return this.configService.get<boolean>('FLEXIBLE_BACKEND_ENABLED') ?? false;
}
getPort(): number {
return this.configService.get<number>('PORT') ?? 3000;
}

View File

@ -46,6 +46,11 @@ export class EnvironmentVariables {
@IsBoolean()
TELEMETRY_ANONYMIZATION_ENABLED?: boolean;
@CastToBoolean()
@IsOptional()
@IsBoolean()
FLEXIBLE_BACKEND_ENABLED?: boolean;
@CastToPositiveNumber()
@IsNumber()
@IsOptional()

View File

@ -1,10 +1,11 @@
import { Args, Query, Resolver } from '@nestjs/graphql';
import { UseGuards } from '@nestjs/common';
import { ForbiddenException, UseGuards } from '@nestjs/common';
import { Workspace } from '@prisma/client';
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';
import { UniversalService } from './universal.service';
@ -16,13 +17,20 @@ import { UpdateOneCustomArgs } from './args/update-one-custom.args';
@UseGuards(JwtAuthGuard)
@Resolver(() => UniversalEntity)
export class UniversalResolver {
constructor(private readonly customService: UniversalService) {}
constructor(
private readonly customService: UniversalService,
private readonly environmentService: EnvironmentService,
) {}
@Query(() => PaginatedUniversalEntity)
findMany(
@Args() args: FindManyUniversalArgs,
@AuthWorkspace() workspace: Workspace,
): Promise<PaginatedUniversalEntity> {
if (!this.environmentService.isFlexibleBackendEnabled()) {
throw new ForbiddenException();
}
return this.customService.findManyUniversal(args, workspace);
}
@ -31,11 +39,19 @@ export class UniversalResolver {
@Args() args: FindUniqueUniversalArgs,
@AuthWorkspace() workspace: Workspace,
): Promise<UniversalEntity | undefined> {
if (!this.environmentService.isFlexibleBackendEnabled()) {
throw new ForbiddenException();
}
return this.customService.findUniqueUniversal(args, workspace);
}
@Query(() => UniversalEntity)
updateOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
if (!this.environmentService.isFlexibleBackendEnabled()) {
throw new ForbiddenException();
}
return {
id: 'exampleId',
data: {},
@ -46,6 +62,10 @@ export class UniversalResolver {
@Query(() => UniversalEntity)
deleteOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
if (!this.environmentService.isFlexibleBackendEnabled()) {
throw new ForbiddenException();
}
return {
id: 'exampleId',
data: {},

View File

@ -1,6 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DataSourceService } from 'src/tenant/metadata/data-source/data-source.service';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { UniversalService } from './universal.service';
@ -15,6 +16,10 @@ describe('UniversalService', () => {
provide: DataSourceService,
useValue: {},
},
{
provide: EnvironmentService,
useValue: {},
},
],
}).compile();