Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: team channels (#2150)

Will Hutchinsona4f2d01965c6
diff --git a/js/app/packages/core/component/EntityIcon.tsx b/js/app/packages/core/component/EntityIcon.tsx
index a90a2fea59..1d2dffe0e4 100644
--- a/js/app/packages/core/component/EntityIcon.tsx
+++ b/js/app/packages/core/component/EntityIcon.tsx
@@ -124,6 +124,12 @@ export const ENTITY_ICON_CONFIGS: Record<EntityWithValidIcon, IconConfig> = {
background: 'bg-default-bg',
prettyName: 'Direct Message',
},
+ team: {
+ icon: Users,
+ foreground: 'text-default',
+ background: 'bg-default-bg',
+ prettyName: 'Team Channel',
+ },
email: {
icon: Email,
foreground: 'text-email',
@@ -267,6 +273,7 @@ export const WIDE_ICONS: Record<EntityWithValidIcon, Component> = {
organization: Building,
private: WideChannel,
direct_message: WideChat,
+ team: WideChannel,
email: WideEmail,
code: WideFileCode,
csv: WideCsv,
diff --git a/js/app/packages/entity/src/types/entity.ts b/js/app/packages/entity/src/types/entity.ts
index 90877b43e6..9351180c34 100644
--- a/js/app/packages/entity/src/types/entity.ts
+++ b/js/app/packages/entity/src/types/entity.ts
@@ -19,7 +19,12 @@ export type EntityBase = {
export type ChannelEntity = EntityBase & {
type: 'channel';
- channelType: 'direct_message' | 'private' | 'organization' | 'public';
+ channelType:
+ | 'direct_message'
+ | 'private'
+ | 'organization'
+ | 'public'
+ | 'team';
interactedAt?: DateValue | null;
participantIds?: string[];
latestMessage?: {
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/teamMember.ts b/js/app/packages/service-clients/service-auth/generated/schemas/teamMember.ts
index 9dc94fa1e2..3debcd991d 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/teamMember.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/teamMember.ts
@@ -12,6 +12,8 @@ import type { TeamRole } from './teamRole';
export interface TeamMember {
/** The role of the team member */
role: TeamRole;
+ /** The id of the team */
+ team_id: string;
/** The user id of the team member */
user_id: string;
}
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index 35fe53b84b..3641f3f8bc 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -3550,12 +3550,17 @@
"TeamMember": {
"type": "object",
"description": "The team member struct",
- "required": ["user_id", "role"],
+ "required": ["team_id", "user_id", "role"],
"properties": {
"role": {
"$ref": "#/components/schemas/TeamRole",
"description": "The role of the team member"
},
+ "team_id": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The id of the team"
+ },
"user_id": {
"type": "string",
"description": "The user id of the team member"
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/channelType.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/channelType.ts
index 3601c55f5d..d92153770f 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/channelType.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/channelType.ts
@@ -13,4 +13,5 @@ export const ChannelType = {
organization: 'organization',
private: 'private',
direct_message: 'direct_message',
+ team: 'team',
} as const;
diff --git a/js/app/packages/service-clients/service-cognition/openapi.json b/js/app/packages/service-clients/service-cognition/openapi.json
index 0ee3739a17..15c3ac25e6 100644
--- a/js/app/packages/service-clients/service-cognition/openapi.json
+++ b/js/app/packages/service-clients/service-cognition/openapi.json
@@ -989,7 +989,7 @@
},
"ChannelType": {
"type": "string",
- "enum": ["public", "organization", "private", "direct_message"]
+ "enum": ["public", "organization", "private", "direct_message", "team"]
},
"Chat": {
"type": "object",
diff --git a/js/app/packages/service-clients/service-comms/generated/client.ts b/js/app/packages/service-clients/service-comms/generated/client.ts
index d714ef3fff..6430a5c380 100644
--- a/js/app/packages/service-clients/service-comms/generated/client.ts
+++ b/js/app/packages/service-clients/service-comms/generated/client.ts
@@ -291,6 +291,11 @@ export type createChannelResponse401 = {
status: 401;
};
+export type createChannelResponse403 = {
+ data: string;
+ status: 403;
+};
+
export type createChannelResponse404 = {
data: string;
status: 404;
@@ -307,6 +312,7 @@ export type createChannelResponseSuccess = createChannelResponse201 & {
export type createChannelResponseError = (
| createChannelResponse400
| createChannelResponse401
+ | createChannelResponse403
| createChannelResponse404
| createChannelResponse500
) & {
diff --git a/js/app/packages/service-clients/service-comms/generated/models/channelType.ts b/js/app/packages/service-clients/service-comms/generated/models/channelType.ts
index 82eed3972f..975ad3077b 100644
--- a/js/app/packages/service-clients/service-comms/generated/models/channelType.ts
+++ b/js/app/packages/service-clients/service-comms/generated/models/channelType.ts
@@ -13,4 +13,5 @@ export const ChannelType = {
organization: 'organization',
private: 'private',
direct_message: 'direct_message',
+ team: 'team',
} as const;
diff --git a/js/app/packages/service-clients/service-comms/generated/models/createChannelRequest.ts b/js/app/packages/service-clients/service-comms/generated/models/createChannelRequest.ts
index f6cd73b5cc..acca4b2d79 100644
--- a/js/app/packages/service-clients/service-comms/generated/models/createChannelRequest.ts
+++ b/js/app/packages/service-clients/service-comms/generated/models/createChannelRequest.ts
@@ -6,6 +6,7 @@
*/
import type { ChannelType } from './channelType';
import type { CreateChannelRequestName } from './createChannelRequestName';
+import type { CreateChannelRequestTeamId } from './createChannelRequestTeamId';
export interface CreateChannelRequest {
/** The type of channel */
@@ -14,4 +15,6 @@ export interface CreateChannelRequest {
name?: CreateChannelRequestName;
/** list of participants not including the owner */
participants: string[];
+ /** If the channel_type is team, provide the id of the team you are creating the channel for */
+ team_id?: CreateChannelRequestTeamId;
}
diff --git a/js/app/packages/service-clients/service-comms/generated/models/createChannelRequestTeamId.ts b/js/app/packages/service-clients/service-comms/generated/models/createChannelRequestTeamId.ts
new file mode 100644
index 0000000000..969797d0d2
--- /dev/null
+++ b/js/app/packages/service-clients/service-comms/generated/models/createChannelRequestTeamId.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * comms_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * If the channel_type is team, provide the id of the team you are creating the channel for
+ */
+export type CreateChannelRequestTeamId = string | null;
diff --git a/js/app/packages/service-clients/service-comms/generated/models/index.ts b/js/app/packages/service-clients/service-comms/generated/models/index.ts
index 3c94e2b932..4417daa988 100644
--- a/js/app/packages/service-clients/service-comms/generated/models/index.ts
+++ b/js/app/packages/service-clients/service-comms/generated/models/index.ts
@@ -50,6 +50,7 @@ export * from './communicationServiceApiVersion';
export * from './countedReaction';
export * from './createChannelRequest';
export * from './createChannelRequestName';
+export * from './createChannelRequestTeamId';
export * from './createChannelResponse';
export * from './createEntityMentionRequest';
export * from './createEntityMentionResponse';
diff --git a/js/app/packages/service-clients/service-comms/openapi.json b/js/app/packages/service-clients/service-comms/openapi.json
index 601b65c688..24d5c26d9d 100644
--- a/js/app/packages/service-clients/service-comms/openapi.json
+++ b/js/app/packages/service-clients/service-comms/openapi.json
@@ -283,6 +283,16 @@
}
}
},
+ "403": {
+ "description": "",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
"404": {
"description": "",
"content": {
@@ -1882,7 +1892,7 @@
},
"ChannelType": {
"type": "string",
- "enum": ["public", "organization", "private", "direct_message"]
+ "enum": ["public", "organization", "private", "direct_message", "team"]
},
"ChannelWithParticipants": {
"allOf": [
@@ -1940,6 +1950,11 @@
"type": "string"
},
"description": "list of participants not including the owner"
+ },
+ "team_id": {
+ "type": ["string", "null"],
+ "format": "uuid",
+ "description": "If the channel_type is team, provide the id of the team you are creating the channel for"
}
}
},
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/channelType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/channelType.ts
index 022c206fef..92de0d1c08 100644
--- a/js/app/packages/service-clients/service-notification/generated/schemas/channelType.ts
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/channelType.ts
@@ -13,4 +13,5 @@ export const ChannelType = {
organization: 'organization',
private: 'private',
directMessage: 'directMessage',
+ team: 'team',
} as const;
diff --git a/js/app/packages/service-clients/service-notification/openapi.json b/js/app/packages/service-clients/service-notification/openapi.json
index aebf0cfcea..fbfc54f4aa 100644
--- a/js/app/packages/service-clients/service-notification/openapi.json
+++ b/js/app/packages/service-clients/service-notification/openapi.json
@@ -1080,7 +1080,7 @@
},
"ChannelType": {
"type": "string",
- "enum": ["public", "organization", "private", "directMessage"]
+ "enum": ["public", "organization", "private", "directMessage", "team"]
},
"CommonChannelMetadata": {
"type": "object",
diff --git a/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts b/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts
index 274829c732..55f4f7a21a 100644
--- a/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts
+++ b/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts
@@ -6,6 +6,7 @@
*/
import type { ChannelFiltersImportance } from './channelFiltersImportance';
import type { ChannelFiltersOrgId } from './channelFiltersOrgId';
+import type { ChannelFiltersTeamId } from './channelFiltersTeamId';
import type { NotificationFilters } from './notificationFilters';
/**
@@ -26,6 +27,8 @@ export interface ChannelFilters {
org_id?: ChannelFiltersOrgId;
/** Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders. */
sender_ids?: string[];
+ /** Channel team ID to search within. Empty to ignore team filtering. */
+ team_id?: ChannelFiltersTeamId;
/** Channel thread IDs to search within. Examples: ['thread123']. Empty to search all threads. */
thread_ids?: string[];
}
diff --git a/js/app/packages/service-clients/service-search/generated/models/channelFiltersTeamId.ts b/js/app/packages/service-clients/service-search/generated/models/channelFiltersTeamId.ts
new file mode 100644
index 0000000000..009636175f
--- /dev/null
+++ b/js/app/packages/service-clients/service-search/generated/models/channelFiltersTeamId.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * search_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Channel team ID to search within. Empty to ignore team filtering.
+ */
+export type ChannelFiltersTeamId = string | null;
diff --git a/js/app/packages/service-clients/service-search/generated/models/index.ts b/js/app/packages/service-clients/service-search/generated/models/index.ts
index 0d3db333c2..188b804750 100644
--- a/js/app/packages/service-clients/service-search/generated/models/index.ts
+++ b/js/app/packages/service-clients/service-search/generated/models/index.ts
@@ -8,6 +8,7 @@
export * from './channelFilters';
export * from './channelFiltersImportance';
export * from './channelFiltersOrgId';
+export * from './channelFiltersTeamId';
export * from './channelMetadata';
export * from './channelMetadataInteractedAt';
export * from './channelMetadataViewedAt';
diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.json
index 2eb4fb53cb..1f84d2c289 100644
--- a/js/app/packages/service-clients/service-search/openapi.json
+++ b/js/app/packages/service-clients/service-search/openapi.json
@@ -218,6 +218,10 @@
},
"description": "Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders."
},
+ "team_id": {
+ "type": ["string", "null"],
+ "description": "Channel team ID to search within. Empty to ignore team filtering."
+ },
"thread_ids": {
"type": "array",
"items": {
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channel.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channel.ts
index 8277f9f7f9..da4985f2e8 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/channel.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channel.ts
@@ -7,6 +7,7 @@
import type { ChannelName } from './channelName';
import type { ChannelOrgId } from './channelOrgId';
+import type { ChannelTeamId } from './channelTeamId';
import type { ChannelType } from './channelType';
export interface Channel {
@@ -17,5 +18,6 @@ export interface Channel {
/** @minimum 0 */
org_id?: ChannelOrgId;
owner_id: string;
+ team_id?: ChannelTeamId;
updated_at: string;
}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts
index 7bbb6112f5..1681cdc554 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts
@@ -6,6 +6,7 @@
*/
import type { ChannelFiltersImportance } from './channelFiltersImportance';
import type { ChannelFiltersOrgId } from './channelFiltersOrgId';
+import type { ChannelFiltersTeamId } from './channelFiltersTeamId';
import type { NotificationFilters } from './notificationFilters';
/**
@@ -26,6 +27,8 @@ export interface ChannelFilters {
org_id?: ChannelFiltersOrgId;
/** Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders. */
sender_ids?: string[];
+ /** Channel team ID to search within. Empty to ignore team filtering. */
+ team_id?: ChannelFiltersTeamId;
/** Channel thread IDs to search within. Examples: ['thread123']. Empty to search all threads. */
thread_ids?: string[];
}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersTeamId.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersTeamId.ts
new file mode 100644
index 0000000000..69f43ec5c3
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersTeamId.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Channel team ID to search within. Empty to ignore team filtering.
+ */
+export type ChannelFiltersTeamId = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelTeamId.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelTeamId.ts
new file mode 100644
index 0000000000..a9c9a6e525
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelTeamId.ts
@@ -0,0 +1,8 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export type ChannelTeamId = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelType.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelType.ts
index 6efd3289ae..1c3dd79d68 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/channelType.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelType.ts
@@ -13,4 +13,5 @@ export const ChannelType = {
organization: 'organization',
private: 'private',
direct_message: 'direct_message',
+ team: 'team',
} as const;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index d15a215b93..adcc1c84ab 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -80,6 +80,7 @@ export * from './channel';
export * from './channelFilters';
export * from './channelFiltersImportance';
export * from './channelFiltersOrgId';
+export * from './channelFiltersTeamId';
export * from './channelMessage';
export * from './channelMessageDeletedAt';
export * from './channelMessageThreadId';
@@ -88,6 +89,7 @@ export * from './channelOrgId';
export * from './channelParticipant';
export * from './channelParticipantLeftAt';
export * from './channelSharePermission';
+export * from './channelTeamId';
export * from './channelType';
export * from './channelWithParticipants';
export * from './chat';
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index edca7774e7..7903b6e788 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -3999,6 +3999,7 @@ export const getItemsSoupResponse = zod.object({
'organization',
'private',
'direct_message',
+ 'team',
]),
created_at: zod.string().datetime({}),
id: zod.string().uuid(),
@@ -4008,6 +4009,7 @@ export const getItemsSoupResponse = zod.object({
.min(getItemsSoupResponseItemsItemDataChannelOrgIdMin)
.nullish(),
owner_id: zod.string(),
+ team_id: zod.string().uuid().nullish(),
updated_at: zod.string().datetime({}),
}),
participants: zod.array(
@@ -4148,6 +4150,12 @@ export const postItemsSoupBody = zod
.describe(
"Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders."
),
+ team_id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Channel team ID to search within. Empty to ignore team filtering.'
+ ),
thread_ids: zod
.array(zod.string())
.optional()
@@ -5597,6 +5605,7 @@ export const postItemsSoupResponse = zod.object({
'organization',
'private',
'direct_message',
+ 'team',
]),
created_at: zod.string().datetime({}),
id: zod.string().uuid(),
@@ -5606,6 +5615,7 @@ export const postItemsSoupResponse = zod.object({
.min(postItemsSoupResponseItemsItemDataChannelOrgIdMin)
.nullish(),
owner_id: zod.string(),
+ team_id: zod.string().uuid().nullish(),
updated_at: zod.string().datetime({}),
}),
participants: zod.array(
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 509b6ab4ec..c6a3bed8e1 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -5476,6 +5476,10 @@
"owner_id": {
"type": "string"
},
+ "team_id": {
+ "type": ["string", "null"],
+ "format": "uuid"
+ },
"updated_at": {
"type": "string",
"format": "date-time"
@@ -5527,6 +5531,10 @@
},
"description": "Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders."
},
+ "team_id": {
+ "type": ["string", "null"],
+ "description": "Channel team ID to search within. Empty to ignore team filtering."
+ },
"thread_ids": {
"type": "array",
"items": {
@@ -5623,7 +5631,7 @@
},
"ChannelType": {
"type": "string",
- "enum": ["public", "organization", "private", "direct_message"]
+ "enum": ["public", "organization", "private", "direct_message", "team"]
},
"ChannelWithParticipants": {
"type": "object",
diff --git a/rust/cloud-storage/authentication_service/src/api/context.rs b/rust/cloud-storage/authentication_service/src/api/context.rs
index 3395fa10f0..8020c92bbd 100644
--- a/rust/cloud-storage/authentication_service/src/api/context.rs
+++ b/rust/cloud-storage/authentication_service/src/api/context.rs
@@ -34,6 +34,7 @@ pub(crate) type NotificationIngressType = SqsNotificationIngress<SqsIngressQueue
pub(crate) type TeamsServiceType = teams::domain::team_service::TeamServiceImpl<
teams::outbound::team_repo::TeamRepositoryImpl,
teams::outbound::customer_repo::CustomerRepositoryImpl,
+ teams::outbound::team_channels_repo::TeamChannelsRepositoryImpl,
UserRolesAndPermissionsServiceImpl<MacroDB, MacroDB>,
NotificationIngressType,
>;
diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs
index 6f3518056d..8293890437 100644
--- a/rust/cloud-storage/authentication_service/src/main.rs
+++ b/rust/cloud-storage/authentication_service/src/main.rs
@@ -29,7 +29,10 @@ use secretsmanager_client::SecretManager;
use sqlx::postgres::PgPoolOptions;
use teams::{
domain::team_service::TeamServiceImpl,
- outbound::{customer_repo::CustomerRepositoryImpl, team_repo::TeamRepositoryImpl},
+ outbound::{
+ customer_repo::CustomerRepositoryImpl, team_channels_repo::TeamChannelsRepositoryImpl,
+ team_repo::TeamRepositoryImpl,
+ },
};
use referral::{
@@ -226,12 +229,14 @@ async fn main() -> anyhow::Result<()> {
stripe_client.clone(),
&config.stripe_price_ids.stripe_price_id_haiku,
);
+ let team_channels_repo_impl = TeamChannelsRepositoryImpl::new(db.clone());
let notification_ingress_service = Arc::new(notification_ingress_service);
let teams_service_impl = TeamServiceImpl::new(
teams_repo_impl,
customer_repo_impl,
+ team_channels_repo_impl,
user_roles_and_permissions_service.clone(),
notification_ingress_service.clone(),
);
diff --git a/rust/cloud-storage/comms/.sqlx/query-23a3f847d9d017fb9e5faf9e8b7b0ed6fc3621a443b76867e7b193453cfae7eb.json b/rust/cloud-storage/comms/.sqlx/query-45064c055927af781bc06e3a602a9efbefbd111110b9f0fab5cf029e70208c1e.json
similarity index 77%
rename from rust/cloud-storage/comms/.sqlx/query-23a3f847d9d017fb9e5faf9e8b7b0ed6fc3621a443b76867e7b193453cfae7eb.json
rename to rust/cloud-storage/comms/.sqlx/query-45064c055927af781bc06e3a602a9efbefbd111110b9f0fab5cf029e70208c1e.json
index a709876b83..ddaefc32ef 100644
--- a/rust/cloud-storage/comms/.sqlx/query-23a3f847d9d017fb9e5faf9e8b7b0ed6fc3621a443b76867e7b193453cfae7eb.json
+++ b/rust/cloud-storage/comms/.sqlx/query-45064c055927af781bc06e3a602a9efbefbd111110b9f0fab5cf029e70208c1e.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH user_channels AS (\n SELECT DISTINCT c.*\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n ),\n channel_participants_json AS (\n SELECT \n uc.id as channel_id,\n ARRAY_AGG(\n json_build_object(\n 'channel_id', cp.channel_id,\n 'user_id', cp.user_id,\n 'role', cp.role,\n 'joined_at', cp.joined_at,\n 'left_at', cp.left_at\n )\n ) as participants\n FROM user_channels uc\n JOIN comms_channel_participants cp ON cp.channel_id = uc.id\n WHERE cp.left_at IS NULL\n GROUP BY uc.id\n )\n SELECT \n uc.id as \"id!\",\n uc.name as \"name\",\n uc.channel_type as \"channel_type!: ChannelType\",\n uc.org_id,\n uc.created_at as \"created_at!\",\n uc.updated_at as \"updated_at!\",\n uc.owner_id as \"owner_id!\",\n cpj.participants as \"participants_json?\"\n FROM user_channels uc\n LEFT JOIN channel_participants_json cpj ON cpj.channel_id = uc.id\n ORDER BY uc.created_at DESC\n ",
+ "query": "\n WITH user_channels AS (\n SELECT DISTINCT c.*\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n ),\n channel_participants_json AS (\n SELECT \n uc.id as channel_id,\n ARRAY_AGG(\n json_build_object(\n 'channel_id', cp.channel_id,\n 'user_id', cp.user_id,\n 'role', cp.role,\n 'joined_at', cp.joined_at,\n 'left_at', cp.left_at\n )\n ) as participants\n FROM user_channels uc\n JOIN comms_channel_participants cp ON cp.channel_id = uc.id\n WHERE cp.left_at IS NULL\n GROUP BY uc.id\n )\n SELECT \n uc.id as \"id!\",\n uc.name as \"name\",\n uc.channel_type as \"channel_type!: ChannelType\",\n uc.team_id,\n uc.org_id,\n uc.created_at as \"created_at!\",\n uc.updated_at as \"updated_at!\",\n uc.owner_id as \"owner_id!\",\n cpj.participants as \"participants_json?\"\n FROM user_channels uc\n LEFT JOIN channel_participants_json cpj ON cpj.channel_id = uc.id\n ORDER BY uc.created_at DESC\n ",
"describe": {
"columns": [
{
@@ -24,7 +24,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
@@ -32,26 +33,31 @@
},
{
"ordinal": 3,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 4,
"name": "org_id",
"type_info": "Int8"
},
{
- "ordinal": 4,
+ "ordinal": 5,
"name": "created_at!",
"type_info": "Timestamptz"
},
{
- "ordinal": 5,
+ "ordinal": 6,
"name": "updated_at!",
"type_info": "Timestamptz"
},
{
- "ordinal": 6,
+ "ordinal": 7,
"name": "owner_id!",
"type_info": "Text"
},
{
- "ordinal": 7,
+ "ordinal": 8,
"name": "participants_json?",
"type_info": "JsonArray"
}
@@ -66,11 +72,12 @@
true,
false,
true,
+ true,
false,
false,
false,
null
]
},
- "hash": "23a3f847d9d017fb9e5faf9e8b7b0ed6fc3621a443b76867e7b193453cfae7eb"
+ "hash": "45064c055927af781bc06e3a602a9efbefbd111110b9f0fab5cf029e70208c1e"
}
diff --git a/rust/cloud-storage/comms/Cargo.toml b/rust/cloud-storage/comms/Cargo.toml
index 3c08d41b91..e4b3145456 100644
--- a/rust/cloud-storage/comms/Cargo.toml
+++ b/rust/cloud-storage/comms/Cargo.toml
@@ -6,7 +6,7 @@ version = "0.1.0"
[features]
inbound = ["dep:axum", "dep:model_user", "dep:utoipa"]
-outbound = []
+outbound = ["dep:sqlx"]
[dependencies]
@@ -25,7 +25,7 @@ recursion = { workspace = true }
rootcause = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
-sqlx = { workspace = true }
+sqlx = { workspace = true, optional = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
diff --git a/rust/cloud-storage/comms/src/domain/models/channel_name.rs b/rust/cloud-storage/comms/src/domain/models/channel_name.rs
index 5267bce370..b124509e47 100644
--- a/rust/cloud-storage/comms/src/domain/models/channel_name.rs
+++ b/rust/cloud-storage/comms/src/domain/models/channel_name.rs
@@ -31,6 +31,10 @@ pub fn resolve_channel_name(
ChannelType::DirectMessage => match resolve_direct_message_channel_name(channel_name, participants, &channel_id.0, user_id, name_lookup) {
Ok(c) | Err(c) => c,
}
+ ChannelType::Team => channel_name.map(|name| name.to_string()).unwrap_or_else(|| {
+ tracing::warn!(channel_id=?channel_id, "team channel should have a name");
+ "Team".to_string()
+ }),
}
}
diff --git a/rust/cloud-storage/comms/src/domain/models/channel_name/tests.rs b/rust/cloud-storage/comms/src/domain/models/channel_name/tests.rs
index 3f54e55449..c3abef8ad9 100644
--- a/rust/cloud-storage/comms/src/domain/models/channel_name/tests.rs
+++ b/rust/cloud-storage/comms/src/domain/models/channel_name/tests.rs
@@ -29,6 +29,7 @@ fn test_resolve_private_channel_name() {
name: Some("test".to_string()),
channel_type: ChannelType::Private,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
@@ -39,6 +40,7 @@ fn test_resolve_private_channel_name() {
name: None,
channel_type: ChannelType::Private,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
@@ -72,6 +74,7 @@ fn test_resolve_direct_message_channel_name() {
name: None,
channel_type: ChannelType::DirectMessage,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
@@ -99,6 +102,7 @@ fn test_resolve_direct_message_channel_name_for_other() {
name: None,
channel_type: ChannelType::DirectMessage,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
@@ -127,6 +131,7 @@ fn test_resolve_organization_and_public_channel_name() {
name: Some("organization_channel".to_string()),
channel_type: ChannelType::Organization,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
@@ -137,6 +142,7 @@ fn test_resolve_organization_and_public_channel_name() {
name: Some("public_channel".to_string()),
channel_type: ChannelType::Public,
org_id: None,
+ team_id: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
diff --git a/rust/cloud-storage/comms/src/inbound.rs b/rust/cloud-storage/comms/src/inbound.rs
index 4f6fd92213..f368b57c32 100644
--- a/rust/cloud-storage/comms/src/inbound.rs
+++ b/rust/cloud-storage/comms/src/inbound.rs
@@ -198,6 +198,7 @@ pub enum ChannelType {
Organization,
Private,
DirectMessage,
+ Team,
}
#[derive(Debug, Clone, Serialize, ToSchema, Doppleganger)]
diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
index 05b3af29a3..22cc76ed65 100644
--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
@@ -24,6 +24,7 @@ pub enum ChannelType {
Organization,
Private,
DirectMessage,
+ Team,
}
#[tracing::instrument(skip(db))]
@@ -60,6 +61,7 @@ pub async fn get_user_channels_with_participants(
uc.id as "id!",
uc.name as "name",
uc.channel_type as "channel_type!: ChannelType",
+ uc.team_id,
uc.org_id,
uc.created_at as "created_at!",
uc.updated_at as "updated_at!",
@@ -77,6 +79,7 @@ pub async fn get_user_channels_with_participants(
name: row.name,
channel_type: ChannelType::mirror(row.channel_type),
org_id: row.org_id.map(|id| OrganizationId(id as u32)),
+ team_id: row.team_id,
created_at: row.created_at,
updated_at: row.updated_at,
owner_id: MacroUserIdStr::parse_from_str(&row.owner_id)
diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs
index 25959b188e..c062f48ba2 100644
--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs
+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs
@@ -48,6 +48,7 @@ static CHANNEL_SELECT: &str = r#"
uc.name as "name",
uc.channel_type as "channel_type",
uc.org_id as "org_id",
+ uc.team_id as "team_id",
uc.created_at as "created_at",
uc.updated_at as "updated_at",
uc.owner_id as "owner_id",
@@ -135,6 +136,9 @@ fn build_channel_filter(ast: Option<&Expr<ChannelLiteral>>) -> String {
filter_ast::ExprFrame::Literal(ChannelLiteral::OrganizationId(org_id)) => {
format!("c.org_id = {org_id}")
}
+ filter_ast::ExprFrame::Literal(ChannelLiteral::TeamId(team_id)) => {
+ format!("c.team_id = '{team_id}'")
+ }
filter_ast::ExprFrame::Literal(ChannelLiteral::ChannelType(ct)) => {
format!("c.channel_type = '{ct}'")
}
@@ -177,6 +181,7 @@ struct ChannelRow {
name: Option<String>,
channel_type: super::ChannelType,
org_id: Option<i64>,
+ team_id: Option<uuid::Uuid>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
owner_id: String,
@@ -192,6 +197,7 @@ impl ChannelRow {
name: self.name,
channel_type: super::ChannelType::mirror(self.channel_type),
org_id: self.org_id.map(|id| OrganizationId(id as u32)),
+ team_id: self.team_id,
created_at: self.created_at,
updated_at: self.updated_at,
owner_id: MacroUserIdStr::parse_from_str(&self.owner_id)
@@ -243,6 +249,7 @@ pub async fn get_user_channels_dynamic(
name: row.try_get("name")?,
channel_type: row.try_get("channel_type")?,
org_id: row.try_get("org_id")?,
+ team_id: row.try_get("team_id")?,
created_at: row.try_get("created_at")?,
updated_at: row.try_get("updated_at")?,
owner_id: row.try_get("owner_id")?,
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json b/rust/cloud-storage/comms_db_client/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json
index f9421f4a18..8f303de688 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json
@@ -23,7 +23,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json b/rust/cloud-storage/comms_db_client/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json
new file mode 100644
index 0000000000..c6eb93ad48
--- /dev/null
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channels (id, name, owner_id, org_id, team_id, channel_type)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Int8",
+ "Uuid",
+ {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9"
+}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json b/rust/cloud-storage/comms_db_client/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json
index 362ab4c5bc..a8e38250f7 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json
@@ -44,7 +44,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json b/rust/cloud-storage/comms_db_client/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json
index 60ce77419d..dd32fa44a6 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json
@@ -14,7 +14,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json b/rust/cloud-storage/comms_db_client/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json
index f022f2e754..df6dfbd303 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json
@@ -24,7 +24,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json b/rust/cloud-storage/comms_db_client/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json
index 5b53ca5db2..d509d3fe6f 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json
@@ -24,7 +24,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json b/rust/cloud-storage/comms_db_client/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json
index db4be8c299..f86bbc7421 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json
@@ -24,7 +24,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-17432fef4e393db73e68309b6abb0f2e32f5d21a7b510741e4e5e57b7e4d8749.json b/rust/cloud-storage/comms_db_client/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json
similarity index 68%
rename from rust/cloud-storage/comms_db_client/.sqlx/query-17432fef4e393db73e68309b6abb0f2e32f5d21a7b510741e4e5e57b7e4d8749.json
rename to rust/cloud-storage/comms_db_client/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json
index 52c54feb1c..4cce0a41ea 100644
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-17432fef4e393db73e68309b6abb0f2e32f5d21a7b510741e4e5e57b7e4d8749.json
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT \n c.id as channel_id,\n c.name as channel_name,\n c.channel_type as \"channel_type: ChannelType\",\n (\n SELECT COUNT(*) \n FROM comms_channel_participants cp_count \n WHERE cp_count.channel_id = c.id \n AND cp_count.left_at IS NULL\n ) as \"participants!: i32\",\n CASE WHEN (\n c.channel_type = 'public'\n OR\n (c.channel_type = 'organization' AND $3::bigint IS NOT NULL AND c.org_id = $3)\n OR\n (c.channel_type IN ('private', 'direct_message') AND EXISTS (\n SELECT 1 FROM comms_channel_participants cp \n WHERE cp.channel_id = c.id \n AND cp.user_id = $2\n AND cp.left_at IS NULL\n ))\n ) THEN true ELSE false END as \"has_access!: bool\"\n FROM\n comms_channels c\n WHERE\n c.id::text = ANY($1)\n AND (c.channel_type != 'organization' OR $3::bigint IS NOT NULL)\n GROUP BY \n c.id,\n c.name,\n c.channel_type,\n c.org_id\n ",
+ "query": "\n SELECT \n c.id as channel_id,\n c.name as channel_name,\n c.channel_type as \"channel_type: ChannelType\",\n (\n SELECT COUNT(*) \n FROM comms_channel_participants cp_count \n WHERE cp_count.channel_id = c.id \n AND cp_count.left_at IS NULL\n ) as \"participants!: i32\",\n CASE WHEN (\n c.channel_type = 'public'\n OR\n (c.channel_type = 'organization' AND $3::bigint IS NOT NULL AND c.org_id = $3)\n OR\n (c.channel_type IN ('private', 'direct_message', 'team') AND EXISTS (\n SELECT 1 FROM comms_channel_participants cp \n WHERE cp.channel_id = c.id \n AND cp.user_id = $2\n AND cp.left_at IS NULL\n ))\n ) THEN true ELSE false END as \"has_access!: bool\"\n FROM\n comms_channels c\n WHERE\n c.id::text = ANY($1)\n AND (c.channel_type != 'organization' OR $3::bigint IS NOT NULL)\n GROUP BY \n c.id,\n c.name,\n c.channel_type,\n c.org_id\n ",
"describe": {
"columns": [
{
@@ -24,7 +24,8 @@
"public",
"organization",
"private",
- "direct_message"
+ "direct_message",
+ "team"
]
}
}
@@ -56,5 +57,5 @@
null
]
},
- "hash": "17432fef4e393db73e68309b6abb0f2e32f5d21a7b510741e4e5e57b7e4d8749"
+ "hash": "ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9"
}
diff --git a/rust/cloud-storage/comms_db_client/src/channels/create_channel.rs b/rust/cloud-storage/comms_db_client/src/channels/create_channel.rs
index abe044640a..db64ddc578 100644
--- a/rust/cloud-storage/comms_db_client/src/channels/create_channel.rs
+++ b/rust/cloud-storage/comms_db_client/src/channels/create_channel.rs
@@ -12,6 +12,7 @@ pub struct CreateChannelOptions {
pub org_id: Option<i64>,
pub channel_type: ChannelType,
pub participants: Vec<String>,
+ pub team_id: Option<uuid::Uuid>,
}
pub async fn create_channel(db: &Pool<Postgres>, options: CreateChannelOptions) -> Result<Uuid> {
@@ -21,14 +22,15 @@ pub async fn create_channel(db: &Pool<Postgres>, options: CreateChannelOptions)
// create the channel
let channel = sqlx::query!(
r#"
- INSERT INTO comms_channels (id, name, owner_id, org_id, channel_type)
- VALUES ($1, $2, $3, $4, $5)
+ INSERT INTO comms_channels (id, name, owner_id, org_id, team_id, channel_type)
+ VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id
"#,
channel_id,
options.name,
options.owner_id,
options.org_id,
+ options.team_id,
options.channel_type as ChannelType
)
.fetch_one(&mut *transaction)
diff --git a/rust/cloud-storage/comms_db_client/src/preview/mod.rs b/rust/cloud-storage/comms_db_client/src/preview/mod.rs
index 41ef1f3c03..174faef972 100644
--- a/rust/cloud-storage/comms_db_client/src/preview/mod.rs
+++ b/rust/cloud-storage/comms_db_client/src/preview/mod.rs
@@ -44,7 +44,7 @@ pub async fn batch_get_channel_preview(
OR
(c.channel_type = 'organization' AND $3::bigint IS NOT NULL AND c.org_id = $3)
OR
- (c.channel_type IN ('private', 'direct_message') AND EXISTS (
+ (c.channel_type IN ('private', 'direct_message', 'team') AND EXISTS (
SELECT 1 FROM comms_channel_participants cp
WHERE cp.channel_id = c.id
AND cp.user_id = $2
diff --git a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
index 1761d51653..a6afc4c1f3 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
@@ -17,6 +17,8 @@ pub struct CreateChannelRequest {
pub name: Option<String>,
/// The type of channel
pub channel_type: ChannelType,
+ /// If the channel_type is team, provide the id of the team you are creating the channel for
+ pub team_id: Option<uuid::Uuid>,
/// list of participants not including the owner
pub participants: Vec<String>,
}
@@ -40,6 +42,7 @@ pub fn to_lowercase(strings: &[String]) -> Vec<String> {
(status = 201, body=CreateChannelResponse),
(status = 400, body=String),
(status = 401, body=String),
+ (status = 403, body=String),
(status = 404, body=String),
(status = 500, body=String),
)
@@ -50,6 +53,43 @@ pub async fn create_channel_handler(
user_context: Extension<UserContext>,
extract::Json(req): extract::Json<CreateChannelRequest>,
) -> Result<(StatusCode, Json<CreateChannelResponse>), (StatusCode, String)> {
+ if req.channel_type == ChannelType::Team {
+ let team_id = if let Some(team_id) = req.team_id.as_ref() {
+ team_id
+ } else {
+ return Err((
+ StatusCode::BAD_REQUEST,
+ "team id missing for team channel type".to_string(),
+ ));
+ };
+
+ let teams = macro_db_client::team::get::get_user_teams(&ctx.db, &user_context.user_id)
+ .await
+ .map_err(|e| {
+ tracing::error!(error=?e, "unable to get_user_teams");
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ "unable to validate team".to_string(),
+ )
+ })?;
+
+ if !teams.into_iter().any(|t| team_id.eq(&t.id)) {
+ return Err((
+ StatusCode::FORBIDDEN,
+ "you do not have access to that team".to_string(),
+ ));
+ }
+ }
+
+ if req.team_id.is_some() && req.channel_type != ChannelType::Team {
+ return Err((
+ StatusCode::BAD_REQUEST,
+ "team channels need team channel type".to_string(),
+ ));
+ }
+
+ // safety check to make sure you don't provide a team id in a non-team id channel
+
// We only need to define the org_id for organization channels
let org_id_for_channel = match req.channel_type {
ChannelType::Organization => user_context.organization_id.map(|org_id| org_id as i64),
@@ -83,6 +123,7 @@ pub async fn create_channel_handler(
owner_id: user_context.user_id.clone(),
org_id: org_id_for_channel,
channel_type: req.channel_type,
+ team_id: req.team_id,
participants: participants.clone(),
},
)
diff --git a/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs b/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
index 343b7b425f..c88ed643a4 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/get_channel_metadata.rs
@@ -72,6 +72,7 @@ pub async fn get_channel_name_and_type(
model::comms::ChannelType::DirectMessage => {
models_comms::channel::ChannelType::DirectMessage
}
+ model::comms::ChannelType::Team => models_comms::channel::ChannelType::Team,
},
channel.name.as_deref(),
&participants,
diff --git a/rust/cloud-storage/comms_service/src/api/channels/get_or_create_dm.rs b/rust/cloud-storage/comms_service/src/api/channels/get_or_create_dm.rs
index 619c6c84e5..736c695044 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/get_or_create_dm.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/get_or_create_dm.rs
@@ -96,6 +96,7 @@ pub async fn handler(
org_id: None,
channel_type: ChannelType::DirectMessage,
participants: vec![user_id.clone(), recipient_id.clone()],
+ team_id: None,
},
)
.await
diff --git a/rust/cloud-storage/comms_service/src/api/channels/get_or_create_private.rs b/rust/cloud-storage/comms_service/src/api/channels/get_or_create_private.rs
index 11fd550db8..7ea7fd9b17 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/get_or_create_private.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/get_or_create_private.rs
@@ -99,6 +99,7 @@ pub async fn handler(
org_id: None,
channel_type: ChannelType::Private,
participants: recipients.clone(),
+ team_id: None,
},
)
.await
diff --git a/rust/cloud-storage/comms_service/src/api/extractors.rs b/rust/cloud-storage/comms_service/src/api/extractors.rs
index 5bb8bf3f39..6f3f7242ce 100644
--- a/rust/cloud-storage/comms_service/src/api/extractors.rs
+++ b/rust/cloud-storage/comms_service/src/api/extractors.rs
@@ -244,6 +244,7 @@ where
model::comms::ChannelType::DirectMessage => {
models_comms::channel::ChannelType::DirectMessage
}
+ model::comms::ChannelType::Team => models_comms::channel::ChannelType::Team,
}))
}
}
diff --git a/rust/cloud-storage/comms_service/src/utils/previews.rs b/rust/cloud-storage/comms_service/src/utils/previews.rs
index 7f892792e3..200b13957f 100644
--- a/rust/cloud-storage/comms_service/src/utils/previews.rs
+++ b/rust/cloud-storage/comms_service/src/utils/previews.rs
@@ -61,6 +61,7 @@ pub fn resolve_previews(
model::comms::ChannelType::DirectMessage => {
models_comms::channel::ChannelType::DirectMessage
}
+ model::comms::ChannelType::Team => models_comms::channel::ChannelType::Team,
},
preview.channel_name.as_deref(),
&participants,
diff --git a/rust/cloud-storage/item_filters/src/ast/channel.rs b/rust/cloud-storage/item_filters/src/ast/channel.rs
index 23077b30a3..a56d94488e 100644
--- a/rust/cloud-storage/item_filters/src/ast/channel.rs
+++ b/rust/cloud-storage/item_filters/src/ast/channel.rs
@@ -22,6 +22,8 @@ pub enum ChannelTypeFilter {
Private,
/// a direct message channel
DirectMessage,
+ /// a team channel
+ Team,
}
impl ParseFromStr for ChannelTypeFilter {
@@ -31,6 +33,7 @@ impl ParseFromStr for ChannelTypeFilter {
"organization" => Ok(Self::Organization),
"private" => Ok(Self::Private),
"direct_message" => Ok(Self::DirectMessage),
+ "team" => Ok(Self::Team),
_ => Err(UnknownValue(
s.as_ref().to_string(),
std::marker::PhantomData,
@@ -48,6 +51,8 @@ pub enum ChannelLiteral {
Mention(MacroUserIdStr<'static>),
/// the message is in some organization
OrganizationId(i64),
+ /// the message is in some team
+ TeamId(Uuid),
/// the message is in some channel id
ChannelId(Uuid),
/// the message comes from some sender x
@@ -72,6 +77,7 @@ impl ExpandFrame<ChannelLiteral> for ChannelFilters {
thread_ids,
mentions,
org_id,
+ team_id,
channel_ids,
sender_ids,
channel_types,
@@ -93,6 +99,11 @@ impl ExpandFrame<ChannelLiteral> for ChannelFilters {
.into_iter()
.expand(ChannelLiteral::OrganizationId, Expr::or);
+ let teams = team_id
+ .into_iter()
+ .map(|s| Uuid::parse_str(&s))
+ .try_expand(|r| r.map(ChannelLiteral::TeamId), Expr::or)?;
+
let channel_ids = channel_ids
.iter()
.map(|s| Uuid::parse_str(s))
@@ -120,6 +131,7 @@ impl ExpandFrame<ChannelLiteral> for ChannelFilters {
thread_ids,
mentions,
organizations,
+ teams,
channel_ids,
sender_ids,
channel_type_nodes,
diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rs
index 51bea9e2fa..bf74bd1195 100644
--- a/rust/cloud-storage/item_filters/src/lib.rs
+++ b/rust/cloud-storage/item_filters/src/lib.rs
@@ -290,6 +290,9 @@ pub struct ChannelFilters {
/// Channel organization ID to search within. Empty to ignore organization filtering.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub org_id: Option<i64>,
+ /// Channel team ID to search within. Empty to ignore team filtering.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub team_id: Option<String>,
/// Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub channel_ids: Vec<String>,
@@ -316,6 +319,7 @@ impl IsEmpty for ChannelFilters {
thread_ids,
mentions,
org_id,
+ team_id,
channel_ids,
sender_ids,
channel_types,
@@ -325,6 +329,7 @@ impl IsEmpty for ChannelFilters {
thread_ids.is_empty()
&& mentions.is_empty()
&& org_id.is_none()
+ && team_id.is_none()
&& channel_ids.is_empty()
&& sender_ids.is_empty()
&& channel_types.is_empty()
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260324133321_add_team_channel_type.sql b/rust/cloud-storage/macro_db_client/migrations/20260324133321_add_team_channel_type.sql
new file mode 100644
index 0000000000..adf15db7a5
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260324133321_add_team_channel_type.sql
@@ -0,0 +1,2 @@
+-- Add new channel type of 'team'
+ALTER TYPE comms_channel_type ADD VALUE 'team';
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260324141059_add_team_channel_support.sql b/rust/cloud-storage/macro_db_client/migrations/20260324141059_add_team_channel_support.sql
new file mode 100644
index 0000000000..d1990af727
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260324141059_add_team_channel_support.sql
@@ -0,0 +1,27 @@
+-- Add team_id column with foreign key and cascade delete
+ALTER TABLE comms_channels
+ ADD COLUMN team_id uuid REFERENCES team(id) ON DELETE CASCADE;
+
+-- Add constraint team_id required for 'team' channels, null otherwise
+ALTER TABLE comms_channels
+ ADD CONSTRAINT valid_team_channel CHECK (
+ (channel_type = 'team' AND team_id IS NOT NULL)
+ OR (channel_type <> 'team' AND team_id IS NULL)
+ );
+
+-- Update valid_channel_name to include 'team' channels requiring a name
+ALTER TABLE comms_channels
+ DROP CONSTRAINT valid_channel_name,
+ ADD CONSTRAINT valid_channel_name CHECK (
+ (channel_type = 'direct_message' AND name IS NULL)
+ OR (channel_type = ANY (ARRAY [
+ 'public'::comms_channel_type,
+ 'organization'::comms_channel_type,
+ 'team'::comms_channel_type
+ ]) AND name IS NOT NULL)
+ OR (channel_type = 'private')
+ );
+
+-- Partial index: only indexes rows where team_id is not null
+CREATE INDEX idx_comms_channels_team_id ON comms_channels(team_id)
+ WHERE team_id IS NOT NULL;
diff --git a/rust/cloud-storage/model/src/comms/mod.rs b/rust/cloud-storage/model/src/comms/mod.rs
index 2aff5fd7b8..8199a8a14c 100644
--- a/rust/cloud-storage/model/src/comms/mod.rs
+++ b/rust/cloud-storage/model/src/comms/mod.rs
@@ -100,6 +100,7 @@ pub enum ChannelType {
Organization,
Private,
DirectMessage,
+ Team,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq, Doppleganger)]
diff --git a/rust/cloud-storage/model_notifications/src/metadata.rs b/rust/cloud-storage/model_notifications/src/metadata.rs
index f2fe5bfcf2..24e2bcd496 100644
--- a/rust/cloud-storage/model_notifications/src/metadata.rs
+++ b/rust/cloud-storage/model_notifications/src/metadata.rs
@@ -34,6 +34,8 @@ pub enum ChannelType {
Private,
#[serde(alias = "DirectMessage", alias = "direct_message")]
DirectMessage,
+ #[serde(alias = "Team", alias = "team")]
+ Team,
}
impl ChannelType {
@@ -43,6 +45,7 @@ impl ChannelType {
ChannelType::Organization => models_comms::channel::ChannelType::Organization,
ChannelType::Private => models_comms::channel::ChannelType::Private,
ChannelType::DirectMessage => models_comms::channel::ChannelType::DirectMessage,
+ ChannelType::Team => models_comms::channel::ChannelType::Team,
}
}
}
diff --git a/rust/cloud-storage/models_comms/src/channel.rs b/rust/cloud-storage/models_comms/src/channel.rs
index 5100419508..9b70bbdae4 100644
--- a/rust/cloud-storage/models_comms/src/channel.rs
+++ b/rust/cloud-storage/models_comms/src/channel.rs
@@ -14,6 +14,7 @@ pub enum ChannelType {
Organization,
Private,
DirectMessage,
+ Team,
}
#[derive(Debug, Clone)]
@@ -58,6 +59,7 @@ pub struct Channel {
pub name: Option<String>,
pub channel_type: ChannelType,
pub org_id: Option<OrganizationId>,
+ pub team_id: Option<uuid::Uuid>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub owner_id: MacroUserIdStr<'static>,
diff --git a/rust/cloud-storage/models_soup/src/comms.rs b/rust/cloud-storage/models_soup/src/comms.rs
index f8893868d7..acf630edfe 100644
--- a/rust/cloud-storage/models_soup/src/comms.rs
+++ b/rust/cloud-storage/models_soup/src/comms.rs
@@ -58,6 +58,8 @@ pub struct Channel {
pub channel_type: ChannelType,
#[cfg_attr(feature = "schema", schema(value_type = Option<u32>))]
pub org_id: Option<OrganizationId>,
+ #[cfg_attr(feature = "schema", schema(value_type = Option<uuid::Uuid>))]
+ pub team_id: Option<uuid::Uuid>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
#[cfg_attr(feature = "schema", schema(value_type = String))]
@@ -73,6 +75,7 @@ pub enum ChannelType {
Organization,
Private,
DirectMessage,
+ Team,
}
#[derive(Debug, Doppleganger, Serialize, Deserialize)]
diff --git a/rust/cloud-storage/roles_and_permissions/Cargo.toml b/rust/cloud-storage/roles_and_permissions/Cargo.toml
index 88bb1c867a..fddb467d42 100644
--- a/rust/cloud-storage/roles_and_permissions/Cargo.toml
+++ b/rust/cloud-storage/roles_and_permissions/Cargo.toml
@@ -4,14 +4,19 @@ name = "roles_and_permissions"
publish = false
version = "0.1.0"
+[features]
+default = ["outbound", "ports"]
+outbound = ["dep:sqlx", "ports"]
+ports = []
+
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
macro_user_id = { path = "../macro_user_id" }
-sqlx = { workspace = true }
+non_empty = { path = "../non_empty" }
+sqlx = { workspace = true, optional = true }
thiserror = { workspace = true }
tracing = { workspace = true }
-non_empty = { path = "../non_empty" }
[dev-dependencies]
macro_db_migrator = { path = "../macro_db_migrator" }
diff --git a/rust/cloud-storage/roles_and_permissions/src/domain.rs b/rust/cloud-storage/roles_and_permissions/src/domain.rs
index cc61b5e8f3..dfc1c94ab7 100644
--- a/rust/cloud-storage/roles_and_permissions/src/domain.rs
+++ b/rust/cloud-storage/roles_and_permissions/src/domain.rs
@@ -1,5 +1,7 @@
+pub mod model;
+
+#[cfg(feature = "ports")]
pub mod port;
+#[cfg(feature = "ports")]
pub mod service;
-
-pub mod model;
diff --git a/rust/cloud-storage/roles_and_permissions/src/lib.rs b/rust/cloud-storage/roles_and_permissions/src/lib.rs
index bfd6830b44..6e96ab022b 100644
--- a/rust/cloud-storage/roles_and_permissions/src/lib.rs
+++ b/rust/cloud-storage/roles_and_permissions/src/lib.rs
@@ -5,4 +5,5 @@
pub mod domain;
/// Contains the outbound logic for roles and permissions
+#[cfg(feature = "outbound")]
pub mod outbound;
diff --git a/rust/cloud-storage/scribe/src/channel/client.rs b/rust/cloud-storage/scribe/src/channel/client.rs
index 9cf6e502c1..af6516acdb 100644
--- a/rust/cloud-storage/scribe/src/channel/client.rs
+++ b/rust/cloud-storage/scribe/src/channel/client.rs
@@ -73,6 +73,7 @@ impl ChannelClient {
model::comms::ChannelType::DirectMessage => {
models_comms::channel::ChannelType::DirectMessage
}
+ model::comms::ChannelType::Team => models_comms::channel::ChannelType::Team,
},
})
}
diff --git a/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs b/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs
index 7b5bcbd008..0f1e53f1da 100644
--- a/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs
+++ b/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs
@@ -121,6 +121,7 @@ async fn create(args: CreateArgs, ctx: SeedCliContext) -> anyhow::Result<()> {
channel_type: args.channel_type.into(),
org_id: args.org_id,
participants: args.channel_members,
+ team_id: None,
};
let channel_id = ctx.db.create_channel(options).await?;
diff --git a/rust/cloud-storage/soup/Cargo.toml b/rust/cloud-storage/soup/Cargo.toml
index f37cb7bd3f..d8e7423dd0 100644
--- a/rust/cloud-storage/soup/Cargo.toml
+++ b/rust/cloud-storage/soup/Cargo.toml
@@ -5,25 +5,19 @@ publish = false
version = "0.1.0"
[features]
-all = [
- "ai_tools",
- "axum",
- "inbound",
- "outbound",
- "ports",
-]
ai_tools = [
+ "comms/outbound",
"dep:ai",
"dep:async-trait",
"dep:schemars",
- "models_soup/schema",
- "ports",
- "outbound",
+ "email/outbound",
"frecency/outbound",
"frecency/postgres",
- "email/outbound",
- "comms/outbound",
+ "models_soup/schema",
+ "outbound",
+ "ports",
]
+all = ["ai_tools", "axum", "inbound", "outbound", "ports"]
axum = [
"dep:axum",
"dep:axum-extra",
@@ -36,19 +30,19 @@ axum = [
"models_soup/schema",
]
inbound = ["email/inbound", "ports"]
-outbound = ["ports"]
+outbound = ["dep:sqlx", "ports"]
ports = ["dep:tokio", "frecency/ports"]
[dependencies]
ai = { path = "../ai", optional = true }
anyhow = { workspace = true }
-cowlike = { path = "../cowlike" }
async-trait = { workspace = true, optional = true }
axum = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true }
chrono = { workspace = true }
-comms = { path = "../comms" }
+comms = { path = "../comms", default-features = false }
+cowlike = { path = "../cowlike" }
document_sub_type = { path = "../document_sub_type" }
doppleganger = { workspace = true, features = ["chrono", "uuid"] }
either = { workspace = true }
@@ -68,7 +62,7 @@ properties_db_client = { path = "../properties_db_client/" }
recursion = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
-sqlx = { workspace = true }
+sqlx = { workspace = true, optional = true }
system_properties = { path = "../system_properties" }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros"], optional = true }
@@ -77,7 +71,9 @@ utoipa = { workspace = true, optional = true }
uuid = { workspace = true }
[dev-dependencies]
+ai = { path = "../ai" }
cool_asserts = "2"
+entity_access = { path = "../entity_access" }
filter_ast = { path = "../filter_ast" }
frecency = { path = "../frecency", features = ["mock", "outbound"] }
futures = { workspace = true }
@@ -90,8 +86,6 @@ rootcause = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tower = { workspace = true }
-ai = { path = "../ai" }
-entity_access = { path = "../entity_access" }
[[example]]
name = "ai_tools_cli"
diff --git a/rust/cloud-storage/teams/.sqlx/query-63b8a0bc87e00d95ca046f0602a14ef73e9c8ebffb19a40ed7e059004d9bdb9a.json b/rust/cloud-storage/teams/.sqlx/query-63b8a0bc87e00d95ca046f0602a14ef73e9c8ebffb19a40ed7e059004d9bdb9a.json
new file mode 100644
index 0000000000..2e97e18d29
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-63b8a0bc87e00d95ca046f0602a14ef73e9c8ebffb19a40ed7e059004d9bdb9a.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_channel_participants\n WHERE user_id = $2\n AND channel_id IN (\n SELECT id FROM comms_channels WHERE team_id = $1\n )\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "63b8a0bc87e00d95ca046f0602a14ef73e9c8ebffb19a40ed7e059004d9bdb9a"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-7d4385b8207bd320c290edc420c68c86028ac0ecb586a78fe55438f5e13b9106.json b/rust/cloud-storage/teams/.sqlx/query-7d4385b8207bd320c290edc420c68c86028ac0ecb586a78fe55438f5e13b9106.json
new file mode 100644
index 0000000000..a63d6d21d2
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-7d4385b8207bd320c290edc420c68c86028ac0ecb586a78fe55438f5e13b9106.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channel_participants (channel_id, user_id, role, joined_at)\n SELECT cc.id, $2, 'member'::comms_participant_role, NOW()\n FROM comms_channels cc\n WHERE cc.team_id = $1\n ON CONFLICT (channel_id, user_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7d4385b8207bd320c290edc420c68c86028ac0ecb586a78fe55438f5e13b9106"
+}
diff --git a/rust/cloud-storage/teams/Cargo.toml b/rust/cloud-storage/teams/Cargo.toml
index d3a8f5d2a4..a81908ac18 100644
--- a/rust/cloud-storage/teams/Cargo.toml
+++ b/rust/cloud-storage/teams/Cargo.toml
@@ -28,7 +28,9 @@ chrono = { workspace = true }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
non_empty = { path = "../non_empty" }
-roles_and_permissions = { path = "../roles_and_permissions" }
+roles_and_permissions = { path = "../roles_and_permissions", default-features = false, features = [
+ "ports",
+] }
serde = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
diff --git a/rust/cloud-storage/teams/fixtures/team_channels.sql b/rust/cloud-storage/teams/fixtures/team_channels.sql
new file mode 100644
index 0000000000..1c3e961315
--- /dev/null
+++ b/rust/cloud-storage/teams/fixtures/team_channels.sql
@@ -0,0 +1,29 @@
+INSERT INTO "macro_user" (id, username, email, stripe_customer_id)
+VALUES
+ ('a1111111-1111-1111-1111-111111111111', '[email protected]', '[email protected]', 'cus_1234'),
+ ('a2222222-2222-2222-2222-222222222222', '[email protected]', '[email protected]', 'stripe_user2'),
+ ('a3333333-3333-3333-3333-333333333333', '[email protected]', '[email protected]', 'stripe_user3');
+
+INSERT INTO "User" ("id", "email", "name", "stripeCustomerId", "macro_user_id") VALUES
+('macro|[email protected]', '[email protected]', 'User', 'cus_1234', 'a1111111-1111-1111-1111-111111111111'),
+('macro|[email protected]', '[email protected]', 'User2', NULL, 'a2222222-2222-2222-2222-222222222222'),
+('macro|[email protected]', '[email protected]', 'User3', NULL, 'a3333333-3333-3333-3333-333333333333');
+
+INSERT INTO team(id, name, owner_id, subscription_id, seat_count)
+VALUES ('11111111-1111-1111-1111-111111111111', 'team1', 'macro|[email protected]', 'sub_1', 2);
+
+INSERT INTO team_user (team_id, user_id, team_role)
+VALUES ('11111111-1111-1111-1111-111111111111', 'macro|[email protected]', 'owner'),
+ ('11111111-1111-1111-1111-111111111111', 'macro|[email protected]', 'member');
+
+-- Team channels for team1
+INSERT INTO comms_channels (id, name, channel_type, team_id, owner_id, created_at, updated_at)
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'General', 'team', '11111111-1111-1111-1111-111111111111', 'macro|[email protected]', NOW(), NOW()),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Random', 'team', '11111111-1111-1111-1111-111111111111', 'macro|[email protected]', NOW(), NOW());
+
+-- Owner is participant in both channels
+INSERT INTO comms_channel_participants (channel_id, user_id, role, joined_at)
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'macro|[email protected]', 'owner', NOW()),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'macro|[email protected]', 'owner', NOW()),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'macro|[email protected]', 'member', NOW()),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'macro|[email protected]', 'member', NOW());
diff --git a/rust/cloud-storage/teams/src/domain/model.rs b/rust/cloud-storage/teams/src/domain/model.rs
index ffd468dff2..5208af985e 100644
--- a/rust/cloud-storage/teams/src/domain/model.rs
+++ b/rust/cloud-storage/teams/src/domain/model.rs
@@ -35,6 +35,8 @@ impl std::fmt::Display for TeamRole {
#[derive(Debug, Clone, serde::Serialize)]
#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
pub struct TeamMember<'a> {
+ /// The id of the team
+ pub team_id: uuid::Uuid,
/// The user id of the team member
#[cfg_attr(feature = "axum", schema(value_type = String))]
pub user_id: MacroUserIdStr<'a>,
diff --git a/rust/cloud-storage/teams/src/domain/team_repo.rs b/rust/cloud-storage/teams/src/domain/team_repo.rs
index 8f88192825..b28a2797d6 100644
--- a/rust/cloud-storage/teams/src/domain/team_repo.rs
+++ b/rust/cloud-storage/teams/src/domain/team_repo.rs
@@ -9,6 +9,23 @@ use crate::domain::model::{
TeamMember, TeamRole, TeamWithMembers,
};
+/// The TeamChannelsRepository defines a set of actions related to team channels
+pub trait TeamChannelsRepository: Clone + Send + Sync + 'static {
+ /// Adds a team member to all team channels
+ fn add_team_member_to_channels(
+ &self,
+ team_id: &uuid::Uuid,
+ user_id: &MacroUserIdStr<'_>,
+ ) -> impl Future<Output = Result<(), TeamError>> + Send;
+
+ /// Removes a team member from all team channels
+ fn remove_team_member_from_channels(
+ &self,
+ team_id: &uuid::Uuid,
+ user_id: &MacroUserIdStr<'_>,
+ ) -> impl Future<Output = Result<(), TeamError>> + Send;
+}
+
/// The TeamRepository defines a set of actions to perform on teams data
pub trait TeamRepository: Clone + Send + Sync + 'static {
/// Gets the stripe customer id for a user
diff --git a/rust/cloud-storage/teams/src/domain/team_service.rs b/rust/cloud-storage/teams/src/domain/team_service.rs
index 969d99cadb..2f322b3d0f 100644
--- a/rust/cloud-storage/teams/src/domain/team_service.rs
+++ b/rust/cloud-storage/teams/src/domain/team_service.rs
@@ -22,15 +22,16 @@ use crate::domain::{
RemoveTeamInviteError, RemoveUserFromTeamError, RevokePermissionsForTeamMembersError, Team,
TeamError, TeamInvite, TeamInviteDetails, TeamMember, TeamRole, TeamWithMembers,
},
- team_repo::{TeamRepository, TeamService},
+ team_repo::{TeamChannelsRepository, TeamRepository, TeamService},
};
/// Implementation of the TeamService using a TeamRepository
#[derive(Debug)]
-pub struct TeamServiceImpl<TR, CR, URPS, NI>
+pub struct TeamServiceImpl<TR, CR, TCR, URPS, NI>
where
TR: TeamRepository,
CR: CustomerRepository,
+ TCR: TeamChannelsRepository,
URPS: UserRolesAndPermissionsService,
NI: NotificationIngress,
{
@@ -38,16 +39,19 @@ where
team_repository: TR,
/// The underlying customer repository
customer_repository: CR,
+ /// The team channels repository
+ team_channels_repository: TCR,
/// The underlying user roles and permissions service
user_roles_and_permissions_service: URPS,
/// The notification ingress service
notification_ingress: Arc<NI>,
}
-impl<TR, CR, URPS, NI> Clone for TeamServiceImpl<TR, CR, URPS, NI>
+impl<TR, CR, TCR, URPS, NI> Clone for TeamServiceImpl<TR, CR, TCR, URPS, NI>
where
TR: TeamRepository,
CR: CustomerRepository,
+ TCR: TeamChannelsRepository,
URPS: UserRolesAndPermissionsService,
NI: NotificationIngress,
{
@@ -55,16 +59,18 @@ where
Self {
team_repository: self.team_repository.clone(),
customer_repository: self.customer_repository.clone(),
+ team_channels_repository: self.team_channels_repository.clone(),
user_roles_and_permissions_service: self.user_roles_and_permissions_service.clone(),
notification_ingress: self.notification_ingress.clone(),
}
}
}
-impl<TR, CR, URPS, NI> TeamServiceImpl<TR, CR, URPS, NI>
+impl<TR, CR, TCR, URPS, NI> TeamServiceImpl<TR, CR, TCR, URPS, NI>
where
TR: TeamRepository,
CR: CustomerRepository,
+ TCR: TeamChannelsRepository,
URPS: UserRolesAndPermissionsService,
NI: NotificationIngress,
{
@@ -72,22 +78,25 @@ where
pub fn new(
team_repository: TR,
customer_repository: CR,
+ team_channels_repository: TCR,
user_roles_and_permissions_service: URPS,
notification_ingress: Arc<NI>,
) -> Self {
Self {
team_repository,
customer_repository,
+ team_channels_repository,
user_roles_and_permissions_service,
notification_ingress,
}
}
}
-impl<TR, CR, URPS, NI> TeamServiceImpl<TR, CR, URPS, NI>
+impl<TR, CR, TCR, URPS, NI> TeamServiceImpl<TR, CR, TCR, URPS, NI>
where
TR: TeamRepository,
CR: CustomerRepository,
+ TCR: TeamChannelsRepository,
URPS: UserRolesAndPermissionsService,
NI: NotificationIngress,
{
@@ -129,10 +138,11 @@ where
}
}
-impl<TR, CR, URPS, NI> TeamService for TeamServiceImpl<TR, CR, URPS, NI>
+impl<TR, CR, TCR, URPS, NI> TeamService for TeamServiceImpl<TR, CR, TCR, URPS, NI>
where
TR: TeamRepository,
CR: CustomerRepository,
+ TCR: TeamChannelsRepository,
URPS: UserRolesAndPermissionsService,
NI: NotificationIngress,
{
@@ -241,6 +251,10 @@ where
// The user was part of the team and was removed
if result.is_ok() {
+ self.team_channels_repository
+ .remove_team_member_from_channels(team_id, user_id)
+ .await?;
+
let subscription_id = self
.team_repository
.get_team_subscription_id(team_id)
@@ -396,6 +410,10 @@ where
.await
.map_err(JoinTeamError::AddRolesToUserError)?;
+ self.team_channels_repository
+ .add_team_member_to_channels(&team_member.team_id, user_id)
+ .await?;
+
Ok(team_member)
}
diff --git a/rust/cloud-storage/teams/src/outbound.rs b/rust/cloud-storage/teams/src/outbound.rs
index f19fdf07c4..f60665a3c3 100644
--- a/rust/cloud-storage/teams/src/outbound.rs
+++ b/rust/cloud-storage/teams/src/outbound.rs
@@ -1,2 +1,3 @@
pub mod customer_repo;
+pub mod team_channels_repo;
pub mod team_repo;
diff --git a/rust/cloud-storage/teams/src/outbound/team_channels_repo.rs b/rust/cloud-storage/teams/src/outbound/team_channels_repo.rs
new file mode 100644
index 0000000000..1ae36c1b1b
--- /dev/null
+++ b/rust/cloud-storage/teams/src/outbound/team_channels_repo.rs
@@ -0,0 +1,71 @@
+//! Implementation for TeamChannelsRepository using MacroDB.
+use crate::domain::{model::TeamError, team_repo::TeamChannelsRepository};
+use macro_user_id::user_id::MacroUserIdStr;
+use sqlx::PgPool;
+
+#[cfg(test)]
+mod test;
+
+/// The TeamChannelsRepositoryImpl struct is a wrapper around sqlx::PgPool connected to macrodb.
+#[derive(Clone)]
+pub struct TeamChannelsRepositoryImpl {
+ /// The underlying sqlx::PgPool connected to macrodb.
+ pool: PgPool,
+}
+
+impl TeamChannelsRepositoryImpl {
+ /// Creates a new instance of TeamChannelsRepositoryImpl
+ pub fn new(pool: PgPool) -> Self {
+ Self { pool }
+ }
+}
+
+impl TeamChannelsRepository for TeamChannelsRepositoryImpl {
+ #[tracing::instrument(skip(self), err)]
+ async fn add_team_member_to_channels(
+ &self,
+ team_id: &uuid::Uuid,
+ user_id: &MacroUserIdStr<'_>,
+ ) -> Result<(), TeamError> {
+ sqlx::query!(
+ r#"
+ INSERT INTO comms_channel_participants (channel_id, user_id, role, joined_at)
+ SELECT cc.id, $2, 'member'::comms_participant_role, NOW()
+ FROM comms_channels cc
+ WHERE cc.team_id = $1
+ ON CONFLICT (channel_id, user_id) DO NOTHING
+ "#,
+ team_id,
+ user_id.as_ref(),
+ )
+ .execute(&self.pool)
+ .await
+ .map_err(|e| TeamError::StorageLayerError(e.into()))?;
+
+ Ok(())
+ }
+
+ #[tracing::instrument(skip(self), err)]
+ async fn remove_team_member_from_channels(
+ &self,
+ team_id: &uuid::Uuid,
+ user_id: &MacroUserIdStr<'_>,
+ ) -> Result<(), TeamError> {
+ sqlx::query!(
+ r#"
+ DELETE FROM comms_channel_participants
+ WHERE user_id = $2
+ AND channel_id IN (
+ SELECT id FROM comms_channels WHERE team_id = $1
+ )
+ "#,
+ team_id,
+ user_id.as_ref(),
+ )
+ .execute(&self.pool)
+ .await
+ .map_err(|e| TeamError::StorageLayerError(e.into()))?;
+
+ Ok(())
+ }
+}
diff --git a/rust/cloud-storage/teams/src/outbound/team_channels_repo/test.rs b/rust/cloud-storage/teams/src/outbound/team_channels_repo/test.rs
new file mode 100644
index 0000000000..e69fbc862f
--- /dev/null
+++ b/rust/cloud-storage/teams/src/outbound/team_channels_repo/test.rs
@@ -0,0 +1,130 @@
+use macro_db_migrator::MACRO_DB_MIGRATIONS;
+use macro_user_id::user_id::MacroUserIdStr;
+use sqlx::{Pool, Postgres};
+
+use super::*;
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("team_channels"))
+)]
+async fn test_add_team_member_to_channels(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = TeamChannelsRepositoryImpl::new(pool.clone());
+
+ let team_id = macro_uuid::string_to_uuid("11111111-1111-1111-1111-111111111111")?;
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;
+
+ repo.add_team_member_to_channels(&team_id, &user_id).await?;
+
+ // Verify user3 was added to both team channels
+ let count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM comms_channel_participants
+ WHERE user_id = $1
+ AND role = 'member'::comms_participant_role
+ "#,
+ user_id.as_ref(),
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 2);
+
+ // Calling again should be idempotent (ON CONFLICT DO NOTHING)
+ repo.add_team_member_to_channels(&team_id, &user_id).await?;
+
+ let count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM comms_channel_participants
+ WHERE user_id = $1
+ AND role = 'member'::comms_participant_role
+ "#,
+ user_id.as_ref(),
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 2);
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("team_channels"))
+)]
+async fn test_remove_team_member_from_channels(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = TeamChannelsRepositoryImpl::new(pool.clone());
+
+ let team_id = macro_uuid::string_to_uuid("11111111-1111-1111-1111-111111111111")?;
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;
+
+ // Verify user2 is in both channels before removal
+ let count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM comms_channel_participants
+ WHERE user_id = $1
+ "#,
+ user_id.as_ref(),
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 2);
+
+ repo.remove_team_member_from_channels(&team_id, &user_id)
+ .await?;
+
+ // Verify user2 was removed from both team channels
+ let count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM comms_channel_participants
+ WHERE user_id = $1
+ "#,
+ user_id.as_ref(),
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 0);
+
+ // Removing again should be a no-op
+ repo.remove_team_member_from_channels(&team_id, &user_id)
+ .await?;
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("team_channels"))
+)]
+async fn test_add_member_to_team_with_no_channels(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = TeamChannelsRepositoryImpl::new(pool.clone());
+
+ // Use a team_id that has no channels
+ let team_id = macro_uuid::string_to_uuid("99999999-9999-9999-9999-999999999999")?;
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;
+
+ // Should succeed without inserting anything
+ repo.add_team_member_to_channels(&team_id, &user_id).await?;
+
+ let count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM comms_channel_participants
+ WHERE user_id = $1
+ "#,
+ user_id.as_ref(),
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 0);
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/teams/src/outbound/team_repo.rs b/rust/cloud-storage/teams/src/outbound/team_repo.rs
index ec9c390648..54c19e0af6 100644
--- a/rust/cloud-storage/teams/src/outbound/team_repo.rs
+++ b/rust/cloud-storage/teams/src/outbound/team_repo.rs
@@ -461,6 +461,7 @@ impl TeamRepository for TeamRepositoryImpl {
Ok(TeamMember {
user_id,
role: row.team_role,
+ team_id: *team_id,
})
} else {
Err(anyhow::anyhow!("unable to parse user id"))
@@ -528,6 +529,7 @@ impl TeamRepository for TeamRepositoryImpl {
let team_member: TeamMember = TeamMember {
user_id: user_id.clone().into_owned(),
role: team_member.role,
+ team_id: invite.team_id,
};
Ok(team_member)
@@ -577,6 +579,7 @@ impl TeamRepository for TeamRepositoryImpl {
Ok(TeamMember {
user_id,
role: row.team_role,
+ team_id: *team_id,
})
} else {
Err(anyhow::anyhow!("unable to parse user id"))
@@ -662,6 +665,7 @@ impl TeamRepository for TeamRepositoryImpl {
.map(|id| TeamMember {
user_id: id.into_owned(),
role: row.team_role,
+ team_id: *team_id,
})
.ok()
})