mirror of
https://github.com/lingble/twenty.git
synced 2025-11-02 05:37:56 +00:00
* Add folder for api settings * Init create api key page * Update create api key page * Implement api call to create apiKey * Add create api key mutation * Get id when creating apiKey * Display created Api Key * Add delete api key button * Remove button from InputText * Update stuff * Add test for ApiDetail * Fix type * Use recoil instead of router state * Remane route paths * Remove online return * Move and test date util * Remove useless Component * Rename ApiKeys paths * Rename ApiKeys files * Add input text info testing * Rename hooks to webhooks * Remove console error * Add tests to reach minimum coverage
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import {
|
|
Injectable,
|
|
ExecutionContext,
|
|
NotFoundException,
|
|
} from '@nestjs/common';
|
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
|
|
import { subject } from '@casl/ability';
|
|
|
|
import { IAbilityHandler } from 'src/ability/interfaces/ability-handler.interface';
|
|
|
|
import { AppAbility } from 'src/ability/ability.factory';
|
|
import { relationAbilityChecker } from 'src/ability/ability.util';
|
|
import { PrismaService } from 'src/database/prisma.service';
|
|
import { AbilityAction } from 'src/ability/ability.action';
|
|
import { assert } from 'src/utils/assert';
|
|
|
|
@Injectable()
|
|
export class CreateWebHookAbilityHandler implements IAbilityHandler {
|
|
constructor(private readonly prismaService: PrismaService) {}
|
|
|
|
async handle(ability: AppAbility, context: ExecutionContext) {
|
|
const gqlContext = GqlExecutionContext.create(context);
|
|
const args = gqlContext.getArgs();
|
|
const allowed = await relationAbilityChecker(
|
|
'WebHook',
|
|
ability,
|
|
this.prismaService.client,
|
|
args,
|
|
);
|
|
if (!allowed) {
|
|
return false;
|
|
}
|
|
return ability.can(AbilityAction.Create, 'WebHook');
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class DeleteWebHookAbilityHandler implements IAbilityHandler {
|
|
constructor(private readonly prismaService: PrismaService) {}
|
|
async handle(ability: AppAbility, context: ExecutionContext) {
|
|
const gqlContext = GqlExecutionContext.create(context);
|
|
const args = gqlContext.getArgs();
|
|
const hook = await this.prismaService.client.webHook.findFirst({
|
|
where: args.where,
|
|
});
|
|
assert(hook, '', NotFoundException);
|
|
return ability.can(AbilityAction.Delete, subject('WebHook', hook));
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class ReadWebHookAbilityHandler implements IAbilityHandler {
|
|
async handle(ability: AppAbility) {
|
|
return ability.can(AbilityAction.Read, 'WebHook');
|
|
}
|
|
}
|