2060 create a new api key (#2206)
* 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
This commit is contained in:
@ -7,7 +7,6 @@ import {
|
||||
ActivityTarget,
|
||||
Attachment,
|
||||
ApiKey,
|
||||
Hook,
|
||||
Comment,
|
||||
Company,
|
||||
Favorite,
|
||||
@ -22,6 +21,7 @@ import {
|
||||
ViewField,
|
||||
ViewFilter,
|
||||
ViewSort,
|
||||
WebHook,
|
||||
Workspace,
|
||||
WorkspaceMember,
|
||||
} from '@prisma/client';
|
||||
@ -36,7 +36,7 @@ type SubjectsAbility = Subjects<{
|
||||
Comment: Comment;
|
||||
Company: Company;
|
||||
Favorite: Favorite;
|
||||
Hook: Hook;
|
||||
WebHook: WebHook;
|
||||
Person: Person;
|
||||
Pipeline: Pipeline;
|
||||
PipelineProgress: PipelineProgress;
|
||||
@ -83,10 +83,10 @@ export class AbilityFactory {
|
||||
can(AbilityAction.Create, 'ApiKey');
|
||||
can(AbilityAction.Update, 'ApiKey', { workspaceId: workspace.id });
|
||||
|
||||
// Hook
|
||||
can(AbilityAction.Read, 'Hook', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Hook');
|
||||
can(AbilityAction.Delete, 'Hook', { workspaceId: workspace.id });
|
||||
// WebHook
|
||||
can(AbilityAction.Read, 'WebHook', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'WebHook');
|
||||
can(AbilityAction.Delete, 'WebHook', { workspaceId: workspace.id });
|
||||
|
||||
// Workspace
|
||||
can(AbilityAction.Read, 'Workspace');
|
||||
|
||||
@ -2,6 +2,11 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { AbilityFactory } from 'src/ability/ability.factory';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import {
|
||||
CreateWebHookAbilityHandler,
|
||||
DeleteWebHookAbilityHandler,
|
||||
ReadWebHookAbilityHandler,
|
||||
} from 'src/ability/handlers/web-hook.ability-handler';
|
||||
|
||||
import {
|
||||
CreateUserAbilityHandler,
|
||||
@ -129,11 +134,6 @@ import {
|
||||
ManageApiKeyAbilityHandler,
|
||||
ReadApiKeyAbilityHandler,
|
||||
} from './handlers/api-key.ability-handler';
|
||||
import {
|
||||
CreateHookAbilityHandler,
|
||||
DeleteHookAbilityHandler,
|
||||
ReadHookAbilityHandler,
|
||||
} from './handlers/hook.ability-handler';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
@ -247,9 +247,9 @@ import {
|
||||
CreateApiKeyAbilityHandler,
|
||||
UpdateApiKeyAbilityHandler,
|
||||
// Hook
|
||||
CreateHookAbilityHandler,
|
||||
DeleteHookAbilityHandler,
|
||||
ReadHookAbilityHandler,
|
||||
CreateWebHookAbilityHandler,
|
||||
DeleteWebHookAbilityHandler,
|
||||
ReadWebHookAbilityHandler,
|
||||
],
|
||||
exports: [
|
||||
AbilityFactory,
|
||||
@ -360,9 +360,9 @@ import {
|
||||
CreateApiKeyAbilityHandler,
|
||||
UpdateApiKeyAbilityHandler,
|
||||
// Hook
|
||||
CreateHookAbilityHandler,
|
||||
DeleteHookAbilityHandler,
|
||||
ReadHookAbilityHandler,
|
||||
CreateWebHookAbilityHandler,
|
||||
DeleteWebHookAbilityHandler,
|
||||
ReadWebHookAbilityHandler,
|
||||
],
|
||||
})
|
||||
export class AbilityModule {}
|
||||
|
||||
@ -16,14 +16,14 @@ import { AbilityAction } from 'src/ability/ability.action';
|
||||
import { assert } from 'src/utils/assert';
|
||||
|
||||
@Injectable()
|
||||
export class CreateHookAbilityHandler implements IAbilityHandler {
|
||||
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(
|
||||
'Hook',
|
||||
'WebHook',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
@ -31,27 +31,27 @@ export class CreateHookAbilityHandler implements IAbilityHandler {
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
return ability.can(AbilityAction.Create, 'Hook');
|
||||
return ability.can(AbilityAction.Create, 'WebHook');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteHookAbilityHandler implements IAbilityHandler {
|
||||
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.hook.findFirst({
|
||||
const hook = await this.prismaService.client.webHook.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(hook, '', NotFoundException);
|
||||
return ability.can(AbilityAction.Delete, subject('Hook', hook));
|
||||
return ability.can(AbilityAction.Delete, subject('WebHook', hook));
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ReadHookAbilityHandler implements IAbilityHandler {
|
||||
export class ReadWebHookAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility) {
|
||||
return ability.can(AbilityAction.Read, 'Hook');
|
||||
return ability.can(AbilityAction.Read, 'WebHook');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user