feat: slack integration deletion

This commit is contained in:
Sheen Capadngan
2024-09-02 20:34:13 +08:00
parent f6d3831d6d
commit 07fd489982
7 changed files with 276 additions and 135 deletions
@@ -126,6 +126,46 @@ export const registerSlackRouter = async (server: FastifyZodProvider) => {
}
});
server.route({
method: "DELETE",
url: "/:slackIntegrationId",
config: {
rateLimit: writeLimit
},
schema: {
security: [
{
bearerAuth: []
}
],
params: z.object({
slackIntegrationId: z.string()
}),
response: {
200: SlackIntegrationsSchema.pick({
id: true,
teamName: true,
isAccessRequestNotificationEnabled: true,
accessRequestChannels: true,
isSecretRequestNotificationEnabled: true,
secretRequestChannels: true
})
}
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
// TODO: add audit logs
return server.services.slack.deleteSlackIntegration({
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
id: req.params.slackIntegrationId
});
}
});
server.route({
method: "GET",
url: "/oauth_redirect",
+37 -6
View File
@@ -12,13 +12,17 @@ import { TProjectDALFactory } from "../project/project-dal";
import { TSlackIntegrationDALFactory } from "./slack-integration-dal";
import {
TCompleteSlackIntegrationDTO,
TDeleteSlackIntegrationDTO,
TGetSlackInstallUrlDTO,
TGetSlackIntegrationByProjectId,
TUpdateSlackIntegration
TGetSlackIntegrationByProjectIdDTO,
TUpdateSlackIntegrationDTO
} from "./slack-types";
type TSlackServiceFactoryDep = {
slackIntegrationDAL: Pick<TSlackIntegrationDALFactory, "create" | "findOne" | "findById" | "updateById">;
slackIntegrationDAL: Pick<
TSlackIntegrationDALFactory,
"create" | "findOne" | "findById" | "updateById" | "deleteById"
>;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
projectDAL: Pick<TProjectDALFactory, "findById">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
@@ -156,7 +160,7 @@ export const slackServiceFactory = ({
actorOrgId,
actorAuthMethod,
projectId
}: TGetSlackIntegrationByProjectId) => {
}: TGetSlackIntegrationByProjectIdDTO) => {
const { permission } = await permissionService.getProjectPermission(
actor,
actorId,
@@ -183,7 +187,7 @@ export const slackServiceFactory = ({
accessRequestChannels,
isSecretRequestNotificationEnabled,
secretRequestChannels
}: TUpdateSlackIntegration) => {
}: TUpdateSlackIntegrationDTO) => {
const slackIntegration = await slackIntegrationDAL.findById(id);
if (!slackIntegration) {
throw new NotFoundError({
@@ -208,11 +212,38 @@ export const slackServiceFactory = ({
});
};
const deleteSlackIntegration = async ({
actorId,
actor,
actorOrgId,
actorAuthMethod,
id
}: TDeleteSlackIntegrationDTO) => {
const slackIntegration = await slackIntegrationDAL.findById(id);
if (!slackIntegration) {
throw new NotFoundError({
message: "Slack integration not found"
});
}
const { permission } = await permissionService.getProjectPermission(
actor,
actorId,
slackIntegration.projectId,
actorAuthMethod,
actorOrgId
);
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.Settings);
return slackIntegrationDAL.deleteById(id);
};
return {
getInstallUrl,
getSlackIntegrationByProjectId,
completeSlackIntegration,
getSlackInstaller,
updateSlackIntegration
updateSlackIntegration,
deleteSlackIntegration
};
};
+6 -2
View File
@@ -2,9 +2,9 @@ import { TProjectPermission } from "@app/lib/types";
export type TGetSlackInstallUrlDTO = TProjectPermission;
export type TGetSlackIntegrationByProjectId = TProjectPermission;
export type TGetSlackIntegrationByProjectIdDTO = TProjectPermission;
export type TUpdateSlackIntegration = {
export type TUpdateSlackIntegrationDTO = {
id: string;
isAccessRequestNotificationEnabled?: boolean;
accessRequestChannels?: string;
@@ -12,6 +12,10 @@ export type TUpdateSlackIntegration = {
secretRequestChannels?: string;
} & Omit<TProjectPermission, "projectId">;
export type TDeleteSlackIntegrationDTO = {
id: string;
} & Omit<TProjectPermission, "projectId">;
export type TCompleteSlackIntegrationDTO = {
projectId: string;
teamId: string;