Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

chore(suggestions): trim comments in Carbon Slack forwarding

naveenkash4b2ef27a5adf
diff --git a/apps/erp/app/routes/x+/resources+/suggestions.new.tsx b/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
index 59e5b11140..93748b666a 100644
--- a/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
+++ b/apps/erp/app/routes/x+/resources+/suggestions.new.tsx
@@ -33,9 +33,7 @@ export async function action({ request }: ActionFunctionArgs) {
sendToCarbon
} = validation.data;
- // Never trust form-supplied identifiers: the userId field is only an
- // anonymous on/off signal (attribute the authenticated user or nobody), and
- // attachments must live in this company's suggestions folder.
+ // formUserId is only an anonymous on/off signal — attribute the session user or nobody
const suggestionUserId = formUserId ? userId : null;
const suggestionAttachmentPath =
attachmentPath && attachmentPath.startsWith(`${companyId}/suggestions/`)
diff --git a/apps/mes/app/routes/x+/suggestion.tsx b/apps/mes/app/routes/x+/suggestion.tsx
index 2454b6441f..4297cea760 100644
--- a/apps/mes/app/routes/x+/suggestion.tsx
+++ b/apps/mes/app/routes/x+/suggestion.tsx
@@ -32,9 +32,7 @@ export async function action({ request }: ActionFunctionArgs) {
sendToCarbon
} = validation.data;
- // Never trust form-supplied identifiers: the userId field is only an
- // anonymous on/off signal (attribute the authenticated user or nobody), and
- // attachments must live in this company's suggestions folder.
+ // formUserId is only an anonymous on/off signal — attribute the session user or nobody
const suggestionUserId = formUserId ? userId : null;
const suggestionAttachmentPath =
attachmentPath && attachmentPath.startsWith(`${companyId}/suggestions/`)
diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts
index 6e8c14deeb..aff8a305db 100644
--- a/packages/env/src/index.ts
+++ b/packages/env/src/index.ts
@@ -248,9 +248,7 @@ export const RESEND_DOMAIN =
export const SLACK_BOT_TOKEN = getEnv("SLACK_BOT_TOKEN", {
isRequired: false
});
-// Derived, non-secret flag telling the browser whether this deployment can
-// forward suggestions to Carbon's Slack — the token itself stays server-only.
-// Crosses the wire as "true" | "" (window.env values are all strings).
+// Derived from SLACK_BOT_TOKEN — the token itself never reaches the browser.
export const CARBON_SLACK_ENABLED = isBrowser
? window.env?.CARBON_SLACK_ENABLED === "true"
: Boolean(SLACK_BOT_TOKEN);
diff --git a/packages/lib/src/slack.server.ts b/packages/lib/src/slack.server.ts
index 26bdf7ba8a..5a3433c5ba 100644
--- a/packages/lib/src/slack.server.ts
+++ b/packages/lib/src/slack.server.ts
@@ -48,8 +48,7 @@ export function getSlackClient(
}
const SUGGESTION_CHANNEL = "#feedback";
-// Slack rejects section blocks over 3000 chars; stay under it and split long
-// text across blocks instead of truncating (50-block message ceiling).
+// Slack rejects section blocks over 3000 chars; long text is split, not truncated.
const SECTION_CHAR_LIMIT = 2900;
const MAX_TEXT_BLOCKS = 12;
@@ -60,10 +59,7 @@ function escapeSlackText(text: string): string {
.replace(/>/g, ">");
}
-// Operates on already-escaped text so SECTION_CHAR_LIMIT bounds the exact
-// length Slack receives. Escaped entities (& / < / >) contain no
-// whitespace, so only a hard cut can land inside one — back up to keep the
-// entity intact.
+// Input is already mrkdwn-escaped; a hard cut backs up so it can't split an entity.
function splitForSections(text: string): string[] {
const chunks: string[] = [];
let start = 0;
@@ -105,8 +101,6 @@ export async function postSuggestionToCarbonSlack(
attachmentPath?: string | null;
}
): Promise<void> {
- // Self-hosted deployments have no Carbon Slack token — nothing to post to,
- // even if a forged form submits sendToCarbon=true.
if (!(process.env.SLACK_BOT_TOKEN ?? SLACK_BOT_TOKEN)) {
return;
}
@@ -149,9 +143,7 @@ export async function postSuggestionToCarbonSlack(
});
}
- // This is awaited inside the user's submit request — the WebClient default
- // retry policy (ten retries over ~30 minutes on 5xx/429) would hang the
- // response during a Slack outage. One attempt, then give up.
+ // Awaited in the submit request — the default retry policy (~30 min) would hang it.
await getSlackClient(undefined, {
retryConfig: { retries: 0 }
}).sendMessage({