b7f5445926
## Problem The ESLint rule `graphql-resolvers-should-be-guarded` introduced in #15392 was failing on main because the guard `SettingsPermissionsGuard` had inconsistent naming. ## Root Cause The guard was named `SettingsPermissionsGuard` (with an 's') which was inconsistent with other permission guards: - ✅ `CustomPermissionGuard` - ✅ `NoPermissionGuard` - ✅ `ImpersonatePermissionGuard` - ❌ `SettingsPermissionsGuard` (inconsistent!) The ESLint rule checks if guard names end with `PermissionGuard`, but `SettingsPermissionsGuard` ends with `sGuard`, so it wasn't recognized as a permission guard. ## Solution Renamed the guard to be consistent with the naming convention: 1. ✅ Renamed file: `settings-permissions.guard.ts` → `settings-permission.guard.ts` 2. ✅ Renamed export: `SettingsPermissionsGuard` → `SettingsPermissionGuard` 3. ✅ Renamed internal class: `SettingsPermissionsMixin` → `SettingsPermissionMixin` 4. ✅ Updated all 122 references across 44 files in the codebase 5. ✅ Renamed test file: `settings-permissions.guard.spec.ts` → `settings-permission.guard.spec.ts` ## Testing - ✅ `npx nx run twenty-server:lint` passes - ✅ `npx nx run twenty-server:typecheck` passes - ✅ No references to the old name remain in the codebase - ✅ All previously failing resolver files now pass ESLint validation ## Related Fixes issues introduced in #15392
184 lines
7.1 KiB
TypeScript
184 lines
7.1 KiB
TypeScript
import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
|
|
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import graphqlTypeJson from 'graphql-type-json';
|
|
import { Repository } from 'typeorm';
|
|
|
|
import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
|
|
import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
|
|
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
|
import { FeatureFlagGuard } from 'src/engine/guards/feature-flag.guard';
|
|
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
|
|
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
|
import { PermissionFlagType } from 'src/engine/metadata-modules/permissions/constants/permission-flag-type.constants';
|
|
import { CreateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input';
|
|
import { ExecuteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/execute-serverless-function.input';
|
|
import { GetServerlessFunctionSourceCodeInput } from 'src/engine/metadata-modules/serverless-function/dtos/get-serverless-function-source-code.input';
|
|
import { PublishServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/publish-serverless-function.input';
|
|
import { ServerlessFunctionExecutionResultDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
|
|
import { ServerlessFunctionIdInput } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-id.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 { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
|
|
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(WorkspaceAuthGuard, FeatureFlagGuard)
|
|
@Resolver()
|
|
@UsePipes(ResolverValidationPipe)
|
|
@UseFilters(PreventNestToAutoLogGraphqlErrorsFilter)
|
|
export class ServerlessFunctionResolver {
|
|
constructor(
|
|
private readonly serverlessFunctionService: ServerlessFunctionService,
|
|
@InjectRepository(ServerlessFunctionEntity)
|
|
private readonly serverlessFunctionRepository: Repository<ServerlessFunctionEntity>,
|
|
) {}
|
|
|
|
@Query(() => ServerlessFunctionDTO)
|
|
async findOneServerlessFunction(
|
|
@Args('input') { id }: ServerlessFunctionIdInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionRepository.findOneOrFail({
|
|
where: {
|
|
id,
|
|
workspaceId,
|
|
},
|
|
relations: ['cronTriggers', 'databaseEventTriggers', 'routeTriggers'],
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => [ServerlessFunctionDTO])
|
|
async findManyServerlessFunctions(
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return this.serverlessFunctionRepository.find({
|
|
where: { workspaceId },
|
|
relations: ['cronTriggers', 'databaseEventTriggers', 'routeTriggers'],
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => graphqlTypeJson)
|
|
async getAvailablePackages(@Args('input') { id }: ServerlessFunctionIdInput) {
|
|
try {
|
|
return await this.serverlessFunctionService.getAvailablePackages(id);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => graphqlTypeJson, { nullable: true })
|
|
async getServerlessFunctionSourceCode(
|
|
@Args('input') input: GetServerlessFunctionSourceCodeInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.getServerlessFunctionSourceCode(
|
|
workspaceId,
|
|
input.id,
|
|
input.version,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
@UseGuards(SettingsPermissionGuard(PermissionFlagType.WORKFLOWS))
|
|
async deleteOneServerlessFunction(
|
|
@Args('input') input: ServerlessFunctionIdInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.deleteOneServerlessFunction({
|
|
id: input.id,
|
|
workspaceId,
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
@UseGuards(SettingsPermissionGuard(PermissionFlagType.WORKFLOWS))
|
|
async updateOneServerlessFunction(
|
|
@Args('input')
|
|
input: UpdateServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.updateOneServerlessFunction(
|
|
input,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
@UseGuards(SettingsPermissionGuard(PermissionFlagType.WORKFLOWS))
|
|
async createOneServerlessFunction(
|
|
@Args('input')
|
|
input: CreateServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.createOneServerlessFunction(
|
|
input,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionExecutionResultDTO)
|
|
@UseGuards(SettingsPermissionGuard(PermissionFlagType.WORKFLOWS))
|
|
async executeOneServerlessFunction(
|
|
@Args('input') input: ExecuteServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
const { id, payload, version } = input;
|
|
|
|
return await this.serverlessFunctionService.executeOneServerlessFunction(
|
|
id,
|
|
workspaceId,
|
|
payload,
|
|
version,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
@UseGuards(SettingsPermissionGuard(PermissionFlagType.WORKFLOWS))
|
|
async publishServerlessFunction(
|
|
@Args('input') input: PublishServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
|
) {
|
|
try {
|
|
const { id } = input;
|
|
|
|
return await this.serverlessFunctionService.publishOneServerlessFunctionOrFail(
|
|
id,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
}
|