Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix googleApisSetRequestExtraParams #6455

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export type Mutation = {
disablePostgresProxy: PostgresCredentials;
emailPasswordResetLink: EmailPasswordResetLink;
enablePostgresProxy: PostgresCredentials;
enableWorkflowTrigger: Scalars['Boolean'];
exchangeAuthorizationCode: ExchangeAuthCode;
generateApiKeyToken: ApiKeyToken;
generateJWT: AuthTokens;
Expand Down Expand Up @@ -377,6 +378,11 @@ export type MutationEmailPasswordResetLinkArgs = {
};


export type MutationEnableWorkflowTriggerArgs = {
workflowVersionId: Scalars['String'];
};


export type MutationExchangeAuthorizationCodeArgs = {
authorizationCode: Scalars['String'];
clientSecret?: InputMaybe<Scalars['String']>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataSource } from 'typeorm';

import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';

const tableName = 'featureFlag';

Expand All @@ -16,47 +16,47 @@ export const seedFeatureFlags = async (
.orIgnore()
.values([
{
key: FeatureFlagKeys.IsBlocklistEnabled,
key: FeatureFlagKey.IsBlocklistEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsAirtableIntegrationEnabled,
key: FeatureFlagKey.IsAirtableIntegrationEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsPostgreSQLIntegrationEnabled,
key: FeatureFlagKey.IsPostgreSQLIntegrationEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsEventObjectEnabled,
key: FeatureFlagKey.IsEventObjectEnabled,
workspaceId: workspaceId,
value: false,
},
{
key: FeatureFlagKeys.IsStripeIntegrationEnabled,
key: FeatureFlagKey.IsStripeIntegrationEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsMessagingAliasFetchingEnabled,
key: FeatureFlagKey.IsMessagingAliasFetchingEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsGoogleCalendarSyncV2Enabled,
key: FeatureFlagKey.IsGoogleCalendarSyncV2Enabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsFunctionSettingsEnabled,
key: FeatureFlagKey.IsFunctionSettingsEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsWorkflowEnabled,
key: FeatureFlagKey.IsWorkflowEnabled,
workspaceId: workspaceId,
value: false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Args, Query, Resolver, ArgsType, Field } from '@nestjs/graphql';
import { ForbiddenException, UseGuards } from '@nestjs/common';
import { Args, ArgsType, Field, Query, Resolver } from '@nestjs/graphql';
import { InjectRepository } from '@nestjs/typeorm';

import { Repository } from 'typeorm';

import { AISQLQueryService } from 'src/engine/core-modules/ai-sql-query/ai-sql-query.service';
import { AISQLQueryResult } from 'src/engine/core-modules/ai-sql-query/dtos/ai-sql-query-result.dto';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { User } from 'src/engine/core-modules/user/user.entity';
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { AuthUser } from 'src/engine/decorators/auth/auth-user.decorator';
import { AISQLQueryResult } from 'src/engine/core-modules/ai-sql-query/dtos/ai-sql-query-result.dto';
import { AISQLQueryService } from 'src/engine/core-modules/ai-sql-query/ai-sql-query.service';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';

@ArgsType()
class GetAISQLQueryArgs {
Expand All @@ -40,13 +38,13 @@ export class AISQLQueryResolver {
const isCopilotEnabledFeatureFlag =
await this.featureFlagRepository.findOneBy({
workspaceId,
key: FeatureFlagKeys.IsCopilotEnabled,
key: FeatureFlagKey.IsCopilotEnabled,
value: true,
});

if (!isCopilotEnabledFeatureFlag?.value) {
throw new ForbiddenException(
`${FeatureFlagKeys.IsCopilotEnabled} feature flag is disabled`,
`${FeatureFlagKey.IsCopilotEnabled} feature flag is disabled`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import {
GoogleAPIScopeConfig,
GoogleAPIsOauthExchangeCodeForTokenStrategy,
} from 'src/engine/core-modules/auth/strategies/google-apis-oauth-exchange-code-for-token.auth.strategy';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { setRequestExtraParams } from 'src/engine/core-modules/auth/utils/google-apis-set-request-extra-params.util';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';

@Injectable()
export class GoogleAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
Expand Down Expand Up @@ -52,7 +50,7 @@ export class GoogleAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
isMessagingAliasFetchingEnabled:
!!(await this.featureFlagRepository.findOneBy({
workspaceId,
key: FeatureFlagKeys.IsMessagingAliasFetchingEnabled,
key: FeatureFlagKey.IsMessagingAliasFetchingEnabled,
value: true,
})),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import { Repository } from 'typeorm';

import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
import { GoogleAPIScopeConfig } from 'src/engine/core-modules/auth/strategies/google-apis-oauth-exchange-code-for-token.auth.strategy';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { GoogleAPIsOauthRequestCodeStrategy } from 'src/engine/core-modules/auth/strategies/google-apis-oauth-request-code.auth.strategy';
import { setRequestExtraParams } from 'src/engine/core-modules/auth/utils/google-apis-set-request-extra-params.util';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';

@Injectable()
export class GoogleAPIsOauthRequestCodeGuard extends AuthGuard('google-apis') {
Expand Down Expand Up @@ -49,7 +47,7 @@ export class GoogleAPIsOauthRequestCodeGuard extends AuthGuard('google-apis') {
isMessagingAliasFetchingEnabled:
!!(await this.featureFlagRepository.findOneBy({
workspaceId,
key: FeatureFlagKeys.IsMessagingAliasFetchingEnabled,
key: FeatureFlagKey.IsMessagingAliasFetchingEnabled,
value: true,
})),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { InjectRepository } from '@nestjs/typeorm';

import { In, Repository } from 'typeorm';

import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import {
BillingSubscription,
SubscriptionStatus,
} from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';

@Injectable()
export class BillingService {
Expand Down Expand Up @@ -47,7 +45,7 @@ export class BillingService {

const freeAccessFeatureFlags = await this.featureFlagRepository.find({
where: {
key: FeatureFlagKeys.IsFreeAccessEnabled,
key: FeatureFlagKey.IsFreeAccessEnabled,
value: true,
},
select: ['workspaceId'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {
SubscriptionStatus,
} from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { StripeService } from 'src/engine/core-modules/billing/stripe/stripe.service';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service';
import { User } from 'src/engine/core-modules/user/user.entity';
import {
Expand Down Expand Up @@ -57,7 +55,7 @@ export class BillingWorkspaceService {
async isBillingEnabledForWorkspace(workspaceId: string) {
const isFreeAccessEnabled = await this.featureFlagRepository.findOneBy({
workspaceId,
key: FeatureFlagKeys.IsFreeAccessEnabled,
key: FeatureFlagKey.IsFreeAccessEnabled,
value: true,
});

Expand Down Expand Up @@ -330,7 +328,7 @@ export class BillingWorkspaceService {

await this.featureFlagRepository.delete({
workspaceId,
key: FeatureFlagKeys.IsFreeAccessEnabled,
key: FeatureFlagKey.IsFreeAccessEnabled,
});

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum FeatureFlagKey {
IsBlocklistEnabled = 'IS_BLOCKLIST_ENABLED',
IsEventObjectEnabled = 'IS_EVENT_OBJECT_ENABLED',
IsAirtableIntegrationEnabled = 'IS_AIRTABLE_INTEGRATION_ENABLED',
IsPostgreSQLIntegrationEnabled = 'IS_POSTGRESQL_INTEGRATION_ENABLED',
IsStripeIntegrationEnabled = 'IS_STRIPE_INTEGRATION_ENABLED',
IsCopilotEnabled = 'IS_COPILOT_ENABLED',
IsMessagingAliasFetchingEnabled = 'IS_MESSAGING_ALIAS_FETCHING_ENABLED',
IsGoogleCalendarSyncV2Enabled = 'IS_GOOGLE_CALENDAR_SYNC_V2_ENABLED',
IsFreeAccessEnabled = 'IS_FREE_ACCESS_ENABLED',
IsFunctionSettingsEnabled = 'IS_FUNCTION_SETTINGS_ENABLED',
IsWorkflowEnabled = 'IS_WORKFLOW_ENABLED',
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,9 @@ import {
} from 'typeorm';

import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';

export enum FeatureFlagKeys {
IsBlocklistEnabled = 'IS_BLOCKLIST_ENABLED',
IsEventObjectEnabled = 'IS_EVENT_OBJECT_ENABLED',
IsAirtableIntegrationEnabled = 'IS_AIRTABLE_INTEGRATION_ENABLED',
IsPostgreSQLIntegrationEnabled = 'IS_POSTGRESQL_INTEGRATION_ENABLED',
IsStripeIntegrationEnabled = 'IS_STRIPE_INTEGRATION_ENABLED',
IsCopilotEnabled = 'IS_COPILOT_ENABLED',
IsMessagingAliasFetchingEnabled = 'IS_MESSAGING_ALIAS_FETCHING_ENABLED',
IsGoogleCalendarSyncV2Enabled = 'IS_GOOGLE_CALENDAR_SYNC_V2_ENABLED',
IsFreeAccessEnabled = 'IS_FREE_ACCESS_ENABLED',
IsFunctionSettingsEnabled = 'IS_FUNCTION_SETTINGS_ENABLED',
IsWorkflowEnabled = 'IS_WORKFLOW_ENABLED',
}

@Entity({ name: 'featureFlag', schema: 'core' })
@ObjectType('FeatureFlag')
@Unique('IndexOnKeyAndWorkspaceIdUnique', ['key', 'workspaceId'])
Expand All @@ -37,9 +24,9 @@ export class FeatureFlagEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Field()
@Field(() => String)
@Column({ nullable: false, type: 'text' })
key: FeatureFlagKeys;
key: FeatureFlagKey;

@Field()
@Column({ nullable: false, type: 'uuid' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';

export type FeatureFlagMap = Record<`${FeatureFlagKeys}`, boolean>;
export type FeatureFlagMap = Record<`${FeatureFlagKey}`, boolean>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { InjectRepository } from '@nestjs/typeorm';

import { Repository } from 'typeorm';

import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';

@Injectable()
export class IsFeatureEnabledService {
Expand All @@ -16,7 +14,7 @@ export class IsFeatureEnabledService {
) {}

public async isFeatureEnabled(
key: FeatureFlagKeys,
key: FeatureFlagKey,
workspaceId: string,
): Promise<boolean> {
const featureFlag = await this.featureFlagRepository.findOneBy({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Repository } from 'typeorm';

import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { RemoteServerType } from 'src/engine/metadata-modules/remote-server/remote-server.entity';
import {
RemoteServerException,
Expand Down Expand Up @@ -36,9 +34,9 @@ export const validateRemoteServerType = async (
const getFeatureFlagKey = (remoteServerType: RemoteServerType) => {
switch (remoteServerType) {
case RemoteServerType.POSTGRES_FDW:
return FeatureFlagKeys.IsPostgreSQLIntegrationEnabled;
return FeatureFlagKey.IsPostgreSQLIntegrationEnabled;
case RemoteServerType.STRIPE_FDW:
return FeatureFlagKeys.IsStripeIntegrationEnabled;
return FeatureFlagKey.IsStripeIntegrationEnabled;
default:
throw new RemoteServerException(
`Type ${remoteServerType} is not supported.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ import { InjectRepository } from '@nestjs/typeorm';
import { FileUpload, GraphQLUpload } from 'graphql-upload';
import { Repository } from 'typeorm';

import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import { CreateServerlessFunctionFromFileInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function-from-file.input';
import { CreateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input';
import { DeleteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/delete-serverless-function.input';
import { ExecuteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/execute-serverless-function.input';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { ServerlessFunctionDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
import { ServerlessFunctionExecutionResultDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
import { serverlessFunctionGraphQLApiExceptionHandler } from 'src/engine/metadata-modules/serverless-function/utils/serverless-function-graphql-api-exception-handler.utils';
import { CreateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input';
import { CreateServerlessFunctionFromFileInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function-from-file.input';
import { ServerlessFunctionDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
import { UpdateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/update-serverless-function.input';
import { DeleteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/delete-serverless-function.input';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import {
ServerlessFunctionException,
ServerlessFunctionExceptionCode,
} from 'src/engine/metadata-modules/serverless-function/serverless-function.exception';
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import { serverlessFunctionGraphQLApiExceptionHandler } from 'src/engine/metadata-modules/serverless-function/utils/serverless-function-graphql-api-exception-handler.utils';

@UseGuards(JwtAuthGuard)
@Resolver()
Expand All @@ -39,7 +37,7 @@ export class ServerlessFunctionResolver {
const isFunctionSettingsEnabled =
await this.featureFlagRepository.findOneBy({
workspaceId,
key: FeatureFlagKeys.IsFunctionSettingsEnabled,
key: FeatureFlagKey.IsFunctionSettingsEnabled,
value: true,
});

Expand Down
Loading
Loading