* Auto-add user to a working group when they join its Slack channel * This enables "join channel = join group" for all committee types * * For private committees, we only auto-add if the Slack channel is also private, * since Slack already enforces access control for private channels.
(
channelId: string,
workosUserId: string,
slackMapping: { slack_email?: string | null; slack_real_name?: string | null; slack_display_name?: string | null },
isPrivateSlackChannel: boolean
)
| 385 | * since Slack already enforces access control for private channels. |
| 386 | */ |
| 387 | async function autoAddToWorkingGroup( |
| 388 | channelId: string, |
| 389 | workosUserId: string, |
| 390 | slackMapping: { slack_email?: string | null; slack_real_name?: string | null; slack_display_name?: string | null }, |
| 391 | isPrivateSlackChannel: boolean |
| 392 | ): Promise<void> { |
| 393 | try { |
| 394 | // Check if this channel is linked to a working group |
| 395 | const workingGroup = await workingGroupDb.getWorkingGroupBySlackChannelId(channelId); |
| 396 | |
| 397 | if (!workingGroup) { |
| 398 | // Channel not linked to any working group |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | // Skip auto-add for private committees unless the Slack channel is also private |
| 403 | // (private Slack channels already enforce access control) |
| 404 | if (workingGroup.is_private && !isPrivateSlackChannel) { |
| 405 | logger.debug( |
| 406 | { workingGroupId: workingGroup.id, name: workingGroup.name }, |
| 407 | 'Skipping auto-add: committee is private but Slack channel is public' |
| 408 | ); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | // Check if already a member |
| 413 | const isMember = await workingGroupDb.isMember(workingGroup.id, workosUserId); |
| 414 | if (isMember) { |
| 415 | logger.debug( |
| 416 | { workingGroupId: workingGroup.id, userId: workosUserId }, |
| 417 | 'User already a member of working group' |
| 418 | ); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | // Set interest level for industry gatherings (other committee types don't track interest) |
| 423 | const interestLevel = workingGroup.committee_type === 'industry_gathering' ? 'interested' : undefined; |
| 424 | const interestSource = 'slack_join'; |
| 425 | |
| 426 | await workingGroupDb.addMembershipWithInterest({ |
| 427 | working_group_id: workingGroup.id, |
| 428 | workos_user_id: workosUserId, |
| 429 | user_email: slackMapping.slack_email || undefined, |
| 430 | user_name: slackMapping.slack_real_name || slackMapping.slack_display_name || undefined, |
| 431 | interest_level: interestLevel, |
| 432 | interest_source: interestSource, |
| 433 | }); |
| 434 | invalidateWebAdminStatusCache(workosUserId); |
| 435 | |
| 436 | logger.info( |
| 437 | { |
| 438 | workingGroupId: workingGroup.id, |
| 439 | workingGroupName: workingGroup.name, |
| 440 | userId: workosUserId, |
| 441 | type: workingGroup.committee_type, |
| 442 | }, |
| 443 | 'Auto-added user to working group via Slack channel join' |
| 444 | ); |
no test coverage detected