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.

add [properties-be] - pass in specific message id for threads (#538)

Daniel Kweon34930fb7b15e
diff --git a/js/app/packages/service-clients/service-properties/generated/schemas/entityReference.ts b/js/app/packages/service-clients/service-properties/generated/schemas/entityReference.ts
index 248b0b99b4..6179fb8c56 100644
--- a/js/app/packages/service-clients/service-properties/generated/schemas/entityReference.ts
+++ b/js/app/packages/service-clients/service-properties/generated/schemas/entityReference.ts
@@ -5,6 +5,7 @@
* OpenAPI spec version: 0.1.0
*/
import type { EntityType } from './entityType';
+import type { EntityReferenceSpecificMessageId } from './entityReferenceSpecificMessageId';
/**
* Entity reference for entity-type property values.
@@ -12,4 +13,7 @@ import type { EntityType } from './entityType';
export interface EntityReference {
entity_id: string;
entity_type: EntityType;
+ /** For CHANNEL, CHAT, THREAD entity types - optional specific message ID.
+This allows referencing a specific message within a thread/channel/chat. */
+ specific_message_id?: EntityReferenceSpecificMessageId;
}
diff --git a/js/app/packages/service-clients/service-properties/generated/schemas/entityReferenceSpecificMessageId.ts b/js/app/packages/service-clients/service-properties/generated/schemas/entityReferenceSpecificMessageId.ts
new file mode 100644
index 0000000000..bfd9fa3982
--- /dev/null
+++ b/js/app/packages/service-clients/service-properties/generated/schemas/entityReferenceSpecificMessageId.ts
@@ -0,0 +1,12 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * properties_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * For CHANNEL, CHAT, THREAD entity types - optional specific message ID.
+This allows referencing a specific message within a thread/channel/chat.
+ */
+export type EntityReferenceSpecificMessageId = string | null;
diff --git a/js/app/packages/service-clients/service-properties/generated/zod.ts b/js/app/packages/service-clients/service-properties/generated/zod.ts
index c95f717383..7fcc54b8a4 100644
--- a/js/app/packages/service-clients/service-properties/generated/zod.ts
+++ b/js/app/packages/service-clients/service-properties/generated/zod.ts
@@ -276,7 +276,8 @@ export const getEntityPropertiesResponse = zod.object({
"type": zod.enum(['EntityReference']),
"value": zod.array(zod.object({
"entity_id": zod.string(),
- "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.')
+ "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.'),
+ "specific_message_id": zod.string().uuid().nullish().describe('For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread/channel/chat.')
}).describe('Entity reference for entity-type property values.')).describe('Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)')
}).describe('Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)'),zod.object({
"type": zod.enum(['Link']),
@@ -317,13 +318,15 @@ export const setEntityPropertyBody = zod.object({
}).describe('Multiple select options by ID (for multi-select properties)'),zod.object({
"reference": zod.object({
"entity_id": zod.string(),
- "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.')
+ "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.'),
+ "specific_message_id": zod.string().uuid().nullish().describe('For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread/channel/chat.')
}).describe('Entity reference for entity-type property values.'),
"type": zod.enum(['entity_reference'])
}).describe('Entity reference'),zod.object({
"references": zod.array(zod.object({
"entity_id": zod.string(),
- "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.')
+ "entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).describe('Type of entity that can be referenced by entity properties.'),
+ "specific_message_id": zod.string().uuid().nullish().describe('For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread/channel/chat.')
}).describe('Entity reference for entity-type property values.')),
"type": zod.enum(['multi_entity_reference'])
}).describe('Multiple entity references (for multi-select entity properties)'),zod.object({
diff --git a/js/app/packages/service-clients/service-properties/openapi.json b/js/app/packages/service-clients/service-properties/openapi.json
index 9306dafcb8..8075cd836c 100644
--- a/js/app/packages/service-clients/service-properties/openapi.json
+++ b/js/app/packages/service-clients/service-properties/openapi.json
@@ -309,6 +309,9 @@
],
"responses": {
"204": { "description": "Entity property removed successfully" },
+ "403": {
+ "description": "Property is required and cannot be removed"
+ },
"404": { "description": "Entity property not found" },
"500": { "description": "Internal server error" }
}
@@ -502,10 +505,15 @@
"EntityReference": {
"type": "object",
"description": "Entity reference for entity-type property values.",
- "required": ["entity_type", "entity_id"],
+ "required": ["entity_id", "entity_type"],
"properties": {
"entity_id": { "type": "string" },
- "entity_type": { "$ref": "#/components/schemas/EntityType" }
+ "entity_type": { "$ref": "#/components/schemas/EntityType" },
+ "specific_message_id": {
+ "type": ["string", "null"],
+ "format": "uuid",
+ "description": "For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread/channel/chat."
+ }
}
},
"EntityType": {
diff --git a/rust/cloud-storage/email_service/src/util/upload_attachment.rs b/rust/cloud-storage/email_service/src/util/upload_attachment.rs
index 769d442b94..5539316d48 100644
--- a/rust/cloud-storage/email_service/src/util/upload_attachment.rs
+++ b/rust/cloud-storage/email_service/src/util/upload_attachment.rs
@@ -308,7 +308,7 @@ async fn set_email_attachment_properties(
source: Some(SourceEntity {
entity_type: models_properties::EntityType::Thread,
entity_id: p.attachment_metadata.thread_db_id.to_string(),
- specific_message_id: Some(p.attachment_metadata.message_db_id.to_string()),
+ specific_message_id: Some(p.attachment_metadata.message_db_id),
}),
// TODO: companies support
companies: None,
diff --git a/rust/cloud-storage/models_properties/src/shared/entity_reference.rs b/rust/cloud-storage/models_properties/src/shared/entity_reference.rs
index 7192d6e3bb..bba0a58e26 100644
--- a/rust/cloud-storage/models_properties/src/shared/entity_reference.rs
+++ b/rust/cloud-storage/models_properties/src/shared/entity_reference.rs
@@ -11,6 +11,34 @@ use super::EntityType;
pub struct EntityReference {
pub entity_id: String,
pub entity_type: EntityType,
+ /// For CHANNEL, CHAT, THREAD entity types - optional specific message ID.
+ /// This allows referencing a specific message within a thread/channel/chat.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub specific_message_id: Option<Uuid>,
+}
+
+impl EntityReference {
+ /// Create a new entity reference without a specific message ID
+ pub fn new(entity_id: impl Into<String>, entity_type: EntityType) -> Self {
+ Self {
+ entity_id: entity_id.into(),
+ entity_type,
+ specific_message_id: None,
+ }
+ }
+
+ /// Create a new entity reference with a specific message ID
+ pub fn with_message_id(
+ entity_id: impl Into<String>,
+ entity_type: EntityType,
+ message_id: Uuid,
+ ) -> Self {
+ Self {
+ entity_id: entity_id.into(),
+ entity_type,
+ specific_message_id: Some(message_id),
+ }
+ }
}
/// Reference to an entity property, including the property definition ID.
diff --git a/rust/cloud-storage/properties_db_client/src/entity_properties/delete.rs b/rust/cloud-storage/properties_db_client/src/entity_properties/delete.rs
index 9b1ca1468f..0a6e0eb45c 100644
--- a/rust/cloud-storage/properties_db_client/src/entity_properties/delete.rs
+++ b/rust/cloud-storage/properties_db_client/src/entity_properties/delete.rs
@@ -102,10 +102,7 @@ mod tests {
async fn test_delete_entity(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let entity_ref = EntityReference {
- entity_id: "doc1".to_string(),
- entity_type: EntityType::Document,
- };
+ let entity_ref = EntityReference::new("doc1", EntityType::Document);
// Verify entity has properties before deletion
let properties_before = crate::entity_properties::get::get_entity_properties_values(
@@ -140,10 +137,7 @@ mod tests {
) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let entity_ref = EntityReference {
- entity_id: "doc1".to_string(),
- entity_type: EntityType::Document,
- };
+ let entity_ref = EntityReference::new("doc1", EntityType::Document);
// Get properties for doc2 before deletion
let doc2_properties_before = crate::entity_properties::get::get_entity_properties_values(
@@ -176,10 +170,7 @@ mod tests {
async fn test_delete_nonexistent_entity(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let entity_ref = EntityReference {
- entity_id: "nonexistent".to_string(),
- entity_type: EntityType::Document,
- };
+ let entity_ref = EntityReference::new("nonexistent", EntityType::Document);
// Deleting non-existent entity should succeed (no error)
let result = delete_entity(&pool, &entity_ref).await;
@@ -196,14 +187,8 @@ mod tests {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
// Delete all document entities
- let doc1_ref = EntityReference {
- entity_id: "doc1".to_string(),
- entity_type: EntityType::Document,
- };
- let doc2_ref = EntityReference {
- entity_id: "doc2".to_string(),
- entity_type: EntityType::Document,
- };
+ let doc1_ref = EntityReference::new("doc1", EntityType::Document);
+ let doc2_ref = EntityReference::new("doc2", EntityType::Document);
// Verify documents have no properties
let doc1_before = crate::entity_properties::get::get_entity_properties_values(
diff --git a/rust/cloud-storage/properties_db_client/src/entity_properties/get.rs b/rust/cloud-storage/properties_db_client/src/entity_properties/get.rs
index a67acf07c6..e811022257 100644
--- a/rust/cloud-storage/properties_db_client/src/entity_properties/get.rs
+++ b/rust/cloud-storage/properties_db_client/src/entity_properties/get.rs
@@ -579,18 +579,9 @@ mod tests {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
let entity_refs = vec![
- EntityReference {
- entity_id: "doc1".to_string(),
- entity_type: EntityType::Document,
- },
- EntityReference {
- entity_id: "doc2".to_string(),
- entity_type: EntityType::Document,
- },
- EntityReference {
- entity_id: "proj1".to_string(),
- entity_type: EntityType::Project,
- },
+ EntityReference::new("doc1", EntityType::Document),
+ EntityReference::new("doc2", EntityType::Document),
+ EntityReference::new("proj1", EntityType::Project),
];
let properties_map = get_bulk_entity_properties_values(&pool, &entity_refs).await?;
@@ -612,14 +603,8 @@ mod tests {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
let entity_refs = vec![
- EntityReference {
- entity_id: "doc1".to_string(),
- entity_type: EntityType::Document,
- },
- EntityReference {
- entity_id: "nonexistent".to_string(),
- entity_type: EntityType::Document,
- },
+ EntityReference::new("doc1", EntityType::Document),
+ EntityReference::new("nonexistent", EntityType::Document),
];
let properties_map = get_bulk_entity_properties_values(&pool, &entity_refs).await?;
diff --git a/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rs b/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rs
index a42f0d44d4..e0d66ed2f6 100644
--- a/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rs
+++ b/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rs
@@ -465,14 +465,8 @@ mod tests {
let property_id = "33333333-3333-3333-3333-333333333333"
.parse::<Uuid>()
.unwrap();
- let entity_ref_1 = EntityReference {
- entity_type: EntityType::User,
- entity_id: "user1".to_string(),
- };
- let entity_ref_2 = EntityReference {
- entity_type: EntityType::User,
- entity_id: "user2".to_string(),
- };
+ let entity_ref_1 = EntityReference::new("user1", EntityType::User);
+ let entity_ref_2 = EntityReference::new("user2", EntityType::User);
let value = PropertyValue::EntityRef(vec![entity_ref_1, entity_ref_2]);
upsert_entity_property_values(
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
index cfa98f03c9..58a06cfbdd 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
@@ -62,10 +62,7 @@ pub async fn delete_entity(
) -> Result<StatusCode, DeleteEntityErr> {
tracing::info!("deleting all properties for entity");
- let entity_reference = EntityReference {
- entity_id: entity_id.clone(),
- entity_type,
- };
+ let entity_reference = EntityReference::new(entity_id.clone(), entity_type);
entity_properties_delete::delete_entity(&context.db, &entity_reference)
.await
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
index c3ad50b63e..fc93c5dd74 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
@@ -105,10 +105,7 @@ pub async fn delete_entity_property(
return Err(DeleteEntityPropertyErr::RequiredProperty);
}
- let entity_ref = EntityReference {
- entity_id: property_info.entity_id,
- entity_type: property_info.entity_type,
- };
+ let entity_ref = EntityReference::new(property_info.entity_id, property_info.entity_type);
crate::api::permissions::check_entity_edit_permission(
&context,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
index ba83bab85f..922529ac0e 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
@@ -81,10 +81,7 @@ pub async fn get_entity_properties(
"retrieving entity properties"
);
- let entity_ref = models_properties::EntityReference {
- entity_id: entity_id.clone(),
- entity_type,
- };
+ let entity_ref = models_properties::EntityReference::new(entity_id.clone(), entity_type);
crate::api::permissions::check_entity_view_permission(
&context,
&user_context.user_id,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
index ab69e194c0..77d2a3744f 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
@@ -84,10 +84,7 @@ pub async fn set_entity_property(
) -> Result<StatusCode, SetEntityPropertyErr> {
tracing::info!("setting entity property");
- let entity_ref = EntityReference {
- entity_id: entity_id.clone(),
- entity_type,
- };
+ let entity_ref = EntityReference::new(entity_id.clone(), entity_type);
crate::api::permissions::check_entity_edit_permission(
&context,
&user_context.user_id,
@@ -232,6 +229,7 @@ fn convert_property_value_to_jsonb(value: &SetPropertyValue) -> Option<PropertyV
PropertyValue::EntityRef(vec![EntityReference {
entity_type: reference.entity_type,
entity_id: reference.entity_id.clone(),
+ specific_message_id: reference.specific_message_id,
}])
}
@@ -246,6 +244,7 @@ fn convert_property_value_to_jsonb(value: &SetPropertyValue) -> Option<PropertyV
.map(|ref_| EntityReference {
entity_type: ref_.entity_type,
entity_id: ref_.entity_id.clone(),
+ specific_message_id: ref_.specific_message_id,
})
.collect();
@@ -435,18 +434,9 @@ mod tests {
fn test_multi_entity_reference_deduplication() {
use models_properties::EntityReference;
- let entity_ref_1 = EntityReference {
- entity_type: EntityType::Document,
- entity_id: "doc-1".to_string(),
- };
- let entity_ref_2 = EntityReference {
- entity_type: EntityType::User,
- entity_id: "user-1".to_string(),
- };
- let entity_ref_1_dup = EntityReference {
- entity_type: EntityType::Document,
- entity_id: "doc-1".to_string(), // Same as entity_ref_1
- };
+ let entity_ref_1 = EntityReference::new("doc-1", EntityType::Document);
+ let entity_ref_2 = EntityReference::new("user-1", EntityType::User);
+ let entity_ref_1_dup = EntityReference::new("doc-1", EntityType::Document); // Same as entity_ref_1
// Test with duplicate entity references
let multi_entity_ref_with_dupes = SetPropertyValue::MultiEntityReference {
@@ -483,14 +473,8 @@ mod tests {
// Test that same ID with different entity types ARE considered duplicates
// (deduplicating by entity_id only, keeping first occurrence)
- let entity_ref_1 = EntityReference {
- entity_type: EntityType::Document,
- entity_id: "123".to_string(),
- };
- let entity_ref_2 = EntityReference {
- entity_type: EntityType::User,
- entity_id: "123".to_string(), // Same ID but different type
- };
+ let entity_ref_1 = EntityReference::new("123", EntityType::Document);
+ let entity_ref_2 = EntityReference::new("123", EntityType::User); // Same ID but different type
let multi_entity_ref = SetPropertyValue::MultiEntityReference {
references: vec![entity_ref_1, entity_ref_2],
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
index a874ab750b..1f14ceab44 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
@@ -70,10 +70,7 @@ pub async fn set_property_status_complete(
tracing::info!("setting entity status to complete");
// Check edit permissions
- let entity_ref = EntityReference {
- entity_id: entity_id.clone(),
- entity_type,
- };
+ let entity_ref = EntityReference::new(entity_id.clone(), entity_type);
check_entity_edit_permission(&context, &user_context.user_id, &entity_ref).await?;
// Delegate to service layer for business logic
diff --git a/rust/cloud-storage/properties_service/src/api/properties/metadata.rs b/rust/cloud-storage/properties_service/src/api/properties/metadata.rs
index ecde6e08de..d4d0687c35 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/metadata.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/metadata.rs
@@ -61,10 +61,7 @@ pub async fn get_document_metadata_properties(
// 2. Owner property
if !document_metadata.owner.is_empty() {
- let owner_entity_ref = EntityReference {
- entity_id: document_metadata.owner,
- entity_type: EntityType::User,
- };
+ let owner_entity_ref = EntityReference::new(document_metadata.owner, EntityType::User);
metadata_properties.push(create_metadata_property_entity_ref(
metadata::OWNER,
models_properties::DataType::Entity,
@@ -92,10 +89,7 @@ pub async fn get_document_metadata_properties(
// 5. Project property
if let Some(project_id) = document_metadata.project_id {
- let project_entity_ref = EntityReference {
- entity_id: project_id,
- entity_type: EntityType::Project,
- };
+ let project_entity_ref = EntityReference::new(project_id, EntityType::Project);
metadata_properties.push(create_metadata_property_entity_ref(
metadata::PROJECT,
models_properties::DataType::Entity,
diff --git a/rust/cloud-storage/system_properties/src/domain/model/inbound/source_entity.rs b/rust/cloud-storage/system_properties/src/domain/model/inbound/source_entity.rs
index 312b26728f..d35eec829b 100644
--- a/rust/cloud-storage/system_properties/src/domain/model/inbound/source_entity.rs
+++ b/rust/cloud-storage/system_properties/src/domain/model/inbound/source_entity.rs
@@ -2,6 +2,7 @@
use models_properties::EntityType;
use serde::{Deserialize, Serialize};
+use uuid::Uuid;
/// Entity reference for Source property.
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -12,5 +13,5 @@ pub struct SourceEntity {
pub entity_id: String,
/// For CHANNEL, CHAT, THREAD entity types - optional specific message ID.
#[serde(skip_serializing_if = "Option::is_none")]
- pub specific_message_id: Option<String>,
+ pub specific_message_id: Option<Uuid>,
}
diff --git a/rust/cloud-storage/system_properties/src/domain/model/repository/property_row.rs b/rust/cloud-storage/system_properties/src/domain/model/repository/property_row.rs
index 5008975050..a23126c0bd 100644
--- a/rust/cloud-storage/system_properties/src/domain/model/repository/property_row.rs
+++ b/rust/cloud-storage/system_properties/src/domain/model/repository/property_row.rs
@@ -29,7 +29,7 @@ impl PropertyRow {
property_definition_id: Uuid,
ref_type: EntityType,
ref_ids: Vec<String>,
- specific_message_id: Option<String>,
+ specific_message_id: Option<Uuid>,
) -> Self {
let refs: Vec<serde_json::Value> = ref_ids
.into_iter()