Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

slack integration reinstall

Sheen Capadnganf509464947e4
diff --git a/backend/src/services/slack/slack-service.ts b/backend/src/services/slack/slack-service.ts
index d4a2dd81bd..aa72d0d826 100644
--- a/backend/src/services/slack/slack-service.ts
+++ b/backend/src/services/slack/slack-service.ts
@@ -21,7 +21,7 @@ import {
type TSlackServiceFactoryDep = {
slackIntegrationDAL: Pick<
TSlackIntegrationDALFactory,
- "create" | "findOne" | "findById" | "updateById" | "deleteById"
+ "create" | "findOne" | "findById" | "updateById" | "deleteById" | "transaction"
>;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
projectDAL: Pick<TProjectDALFactory, "findById">;
@@ -62,15 +62,43 @@ export const slackServiceFactory = ({
plainText: Buffer.from(botAccessToken, "utf8")
});
- await slackIntegrationDAL.create({
- projectId,
- teamId,
- teamName,
- slackUserId,
- slackAppId,
- slackBotId,
- slackBotUserId,
- encryptedBotAccessToken
+ await slackIntegrationDAL.transaction(async (tx) => {
+ const slackIntegration = await slackIntegrationDAL.findOne(
+ {
+ projectId
+ },
+ tx
+ );
+
+ if (slackIntegration) {
+ return slackIntegrationDAL.updateById(
+ slackIntegration.id,
+ {
+ teamId,
+ teamName,
+ slackUserId,
+ slackAppId,
+ slackBotId,
+ slackBotUserId,
+ encryptedBotAccessToken
+ },
+ tx
+ );
+ }
+
+ return slackIntegrationDAL.create(
+ {
+ projectId,
+ teamId,
+ teamName,
+ slackUserId,
+ slackAppId,
+ slackBotId,
+ slackBotUserId,
+ encryptedBotAccessToken
+ },
+ tx
+ );
});
};
diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/NotificationSection/NotificationTab.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/NotificationSection/NotificationTab.tsx
index 9f0dadaaf8..3a6ae45fdb 100644
--- a/frontend/src/views/Settings/ProjectSettingsPage/components/NotificationSection/NotificationTab.tsx
+++ b/frontend/src/views/Settings/ProjectSettingsPage/components/NotificationSection/NotificationTab.tsx
@@ -59,6 +59,7 @@ export const NotificationTab = () => {
const router = useRouter();
const [isConnectToSlackLoading, setIsConnectToSlackLoading] = useToggle(false);
+ const [isReinstallLoading, setIsReinstallLoading] = useToggle(false);
const secretRequestNotifState = watch("isSecretRequestNotificationEnabled");
const accessRequestNotifState = watch("isAccessRequestNotificationEnabled");
@@ -95,6 +96,13 @@ export const NotificationTab = () => {
});
};
+ const triggerSlackInstall = async () => {
+ const slackInstallUrl = await fetchSlackInstallUrl(currentWorkspace?.id);
+ if (slackInstallUrl) {
+ router.push(slackInstallUrl);
+ }
+ };
+
useEffect(() => {
if (slackIntegration) {
setValue(
@@ -131,10 +139,7 @@ export const NotificationTab = () => {
isLoading={isConnectToSlackLoading}
onClick={async () => {
setIsConnectToSlackLoading.on();
- const slackInstallUrl = await fetchSlackInstallUrl(currentWorkspace?.id);
- if (slackInstallUrl) {
- router.push(slackInstallUrl);
- }
+ await triggerSlackInstall();
}}
>
Connect to Slack
@@ -144,8 +149,16 @@ export const NotificationTab = () => {
<form onSubmit={handleSubmit(handleIntegrationSave)}>
<div>Connected Slack workspace: {slackIntegration.teamName}</div>
<div className="mt-2 mb-6">
- <Button colorSchema="secondary" size="xs">
- Reinstall integration
+ <Button
+ colorSchema="secondary"
+ size="xs"
+ isLoading={isReinstallLoading}
+ onClick={async () => {
+ setIsReinstallLoading.on();
+ await triggerSlackInstall();
+ }}
+ >
+ Reinstall
</Button>
<Button
colorSchema="secondary"
@@ -156,6 +169,7 @@ export const NotificationTab = () => {
Delete
</Button>
</div>
+ <h2 className="mb-2 flex-1 text-lg font-semibold text-mineshaft-100">Events</h2>
<Controller
control={control}
name="isSecretRequestNotificationEnabled"