Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
add [properties-be] - system properties for tasks and email (#436)
Daniel Kweon332b66ee7324
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex c9c276c0f9..a94e4766a2 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -8530,6 +8530,19 @@ dependencies = ["libc",]+[[package]]+name = "system_properties"+version = "0.1.0"+dependencies = [+ "models_properties",+ "serde",+ "serde_json",+ "sqlx",+ "thiserror 2.0.17",+ "tracing",+ "uuid",+]+[[package]]name = "teams"version = "0.1.0"diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.tomlindex de4b8f2e64..fddae0aac4 100644--- a/rust/cloud-storage/Cargo.toml+++ b/rust/cloud-storage/Cargo.toml@@ -109,6 +109,7 @@ members = ["static_file_service","static_file_service_client","sync_service_client",+ "system_properties","teams","unfurl_service","upload_extractor_lambda_handler",diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfileindex b85a021241..59128f7ac4 100644--- a/rust/cloud-storage/justfile+++ b/rust/cloud-storage/justfile@@ -56,6 +56,7 @@ setup_test_envs:echo "DATABASE_URL={{ MACRODB }}" >> ./frecency/.envecho "DATABASE_URL={{ MACRODB }}" >> ./soup/.envecho "DATABASE_URL={{ MACRODB }}" >> ./email/.env+ echo "DATABASE_URL={{ MACRODB }}" >> ./system_properties/.envsetup_macrodb:just macro_db_client/migrate_dbdiff --git a/rust/cloud-storage/macro_db_client/migrations/20251128000000_add_system_properties.sql b/rust/cloud-storage/macro_db_client/migrations/20251128000000_add_system_properties.sqlnew file mode 100644index 0000000000..8e4f1a5fcf--- /dev/null+++ b/rust/cloud-storage/macro_db_client/migrations/20251128000000_add_system_properties.sql@@ -0,0 +1,33 @@+-- System Properties Migration - Schema Changes++ALTER TYPE property_entity_type ADD VALUE IF NOT EXISTS 'COMPANY';+ALTER TYPE property_entity_type ADD VALUE IF NOT EXISTS 'TASK';++ALTER TABLE property_definitions ADD COLUMN is_system BOOLEAN NOT NULL DEFAULT FALSE;++ALTER TABLE property_definitions DROP CONSTRAINT owned_by_org_or_user;+ALTER TABLE property_definitions ADD CONSTRAINT owned_by_org_or_user_or_system+ CHECK (+ is_system = TRUE+ OR organization_id IS NOT NULL+ OR user_id IS NOT NULL+ );++-- Prevent custom properties from having the same display_name as system properties+CREATE OR REPLACE FUNCTION check_property_name_not_system()+RETURNS TRIGGER AS $$+BEGIN+ IF NEW.is_system = FALSE AND EXISTS (+ SELECT 1 FROM property_definitions+ WHERE is_system = TRUE AND LOWER(display_name) = LOWER(NEW.display_name)+ ) THEN+ RAISE EXCEPTION 'Cannot create custom property with reserved system property name: %', NEW.display_name;+ END IF;+ RETURN NEW;+END;+$$ LANGUAGE plpgsql;++CREATE TRIGGER prevent_system_property_name_conflict+ BEFORE INSERT OR UPDATE ON property_definitions+ FOR EACH ROW+ EXECUTE FUNCTION check_property_name_not_system();diff --git a/rust/cloud-storage/macro_db_client/migrations/20251128000001_seed_system_properties.sql b/rust/cloud-storage/macro_db_client/migrations/20251128000001_seed_system_properties.sqlnew file mode 100644index 0000000000..92c7e03954--- /dev/null+++ b/rust/cloud-storage/macro_db_client/migrations/20251128000001_seed_system_properties.sql@@ -0,0 +1,428 @@+-- System Properties Migration - Seed Data++-- Assignees (multi-select entity reference to users)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000001',+ NULL,+ NULL,+ 'Assignees',+ 'ENTITY',+ true,+ 'USER',+ true+ );++-- Status (single-select string)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000002',+ NULL,+ NULL,+ 'Status',+ 'SELECT_STRING',+ false,+ NULL,+ true+ );++-- Priority (single-select string)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000003',+ NULL,+ NULL,+ 'Priority',+ 'SELECT_STRING',+ false,+ NULL,+ true+ );++-- Due Date (date)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000004',+ NULL,+ NULL,+ 'Due Date',+ 'DATE',+ false,+ NULL,+ true+ );++-- Parent Task (single entity reference to task)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000005',+ NULL,+ NULL,+ 'Parent Task',+ 'ENTITY',+ false,+ 'TASK',+ true+ );++-- Subtasks (multi-select entity reference to tasks)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000006',+ NULL,+ NULL,+ 'Subtasks',+ 'ENTITY',+ true,+ 'TASK',+ true+ );++-- Depends On (multi-select entity reference to tasks)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000007',+ NULL,+ NULL,+ 'Depends On',+ 'ENTITY',+ true,+ 'TASK',+ true+ );++-- Effort (single-select string)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000008',+ NULL,+ NULL,+ 'Effort',+ 'SELECT_STRING',+ false,+ NULL,+ true+ );++-- Story Points (single-select number)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-000000000009',+ NULL,+ NULL,+ 'Story Points',+ 'NUMBER',+ false,+ NULL,+ true+ );++-- Relevant Documents (multi-select entity reference to documents)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000a',+ NULL,+ NULL,+ 'Relevant Documents',+ 'ENTITY',+ true,+ 'DOCUMENT',+ true+ );++-- Source (single entity reference to any)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000b',+ NULL,+ NULL,+ 'Source',+ 'ENTITY',+ false,+ NULL,+ true+ );++-- Companies (multi-select entity reference to companies)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000c',+ NULL,+ NULL,+ 'Companies',+ 'ENTITY',+ true,+ 'COMPANY',+ true+ );++-- Sender (single entity reference to user)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000d',+ NULL,+ NULL,+ 'Sender',+ 'ENTITY',+ false,+ 'USER',+ true+ );++-- Recipients (multi-select entity reference to users)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000e',+ NULL,+ NULL,+ 'Recipients',+ 'ENTITY',+ true,+ 'USER',+ true+ );++-- Subject (string)+INSERT INTO property_definitions (+ id,+ organization_id,+ user_id,+ display_name,+ data_type,+ is_multi_select,+ specific_entity_type,+ is_system+ )+VALUES (+ '00000001-0000-0000-0000-00000000000f',+ NULL,+ NULL,+ 'Subject',+ 'STRING',+ false,+ NULL,+ true+ );++-- Status options+INSERT INTO property_options (+ id,+ property_definition_id,+ display_order,+ string_value+ )+VALUES (+ '00000001-0000-0000-0002-000000000001',+ '00000001-0000-0000-0000-000000000002',+ 0,+ 'Not Started'+ ),+ (+ '00000001-0000-0000-0002-000000000002',+ '00000001-0000-0000-0000-000000000002',+ 1,+ 'In Progress'+ ),+ (+ '00000001-0000-0000-0002-000000000003',+ '00000001-0000-0000-0000-000000000002',+ 2,+ 'In Review'+ ),+ (+ '00000001-0000-0000-0002-000000000004',+ '00000001-0000-0000-0000-000000000002',+ 3,+ 'Completed'+ ),+ (+ '00000001-0000-0000-0002-000000000005',+ '00000001-0000-0000-0000-000000000002',+ 4,+ 'Canceled'+ );++-- Priority options+INSERT INTO property_options (+ id,+ property_definition_id,+ display_order,+ string_value+ )+VALUES (+ '00000001-0000-0000-0003-000000000001',+ '00000001-0000-0000-0000-000000000003',+ 0,+ 'Low'+ ),+ (+ '00000001-0000-0000-0003-000000000002',+ '00000001-0000-0000-0000-000000000003',+ 1,+ 'Medium'+ ),+ (+ '00000001-0000-0000-0003-000000000003',+ '00000001-0000-0000-0000-000000000003',+ 2,+ 'High'+ ),+ (+ '00000001-0000-0000-0003-000000000004',+ '00000001-0000-0000-0000-000000000003',+ 3,+ 'Critical'+ );++-- Effort options+INSERT INTO property_options (+ id,+ property_definition_id,+ display_order,+ string_value+ )+VALUES (+ '00000001-0000-0000-0008-000000000001',+ '00000001-0000-0000-0000-000000000008',+ 0,+ 'Small'+ ),+ (+ '00000001-0000-0000-0008-000000000002',+ '00000001-0000-0000-0000-000000000008',+ 1,+ 'Medium'+ ),+ (+ '00000001-0000-0000-0008-000000000003',+ '00000001-0000-0000-0000-000000000008',+ 2,+ 'Large'+ );+diff --git a/rust/cloud-storage/models_properties/src/shared/entity_type.rs b/rust/cloud-storage/models_properties/src/shared/entity_type.rsindex 3e3e350c10..e946410e6e 100644--- a/rust/cloud-storage/models_properties/src/shared/entity_type.rs+++ b/rust/cloud-storage/models_properties/src/shared/entity_type.rs@@ -14,8 +14,10 @@ use utoipa::ToSchema;pub enum EntityType {Channel,Chat,+ Company,Document,Project,+ Task,Thread,User,}@@ -25,8 +27,10 @@ impl fmt::Display for EntityType {match self {EntityType::Channel => write!(f, "channel"),EntityType::Chat => write!(f, "chat"),+ EntityType::Company => write!(f, "company"),EntityType::Document => write!(f, "document"),EntityType::Project => write!(f, "project"),+ EntityType::Task => write!(f, "task"),EntityType::Thread => write!(f, "thread"),EntityType::User => write!(f, "user"),}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-3f99042ec859c30190f667c30fe1163b7574328dd2be7ce1113ee212812b3627.json b/rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.jsonsimilarity index 87%rename from rust/cloud-storage/properties_db_client/.sqlx/query-3f99042ec859c30190f667c30fe1163b7574328dd2be7ce1113ee212812b3627.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.jsonindex f3e5d4b97c..973436002a 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-3f99042ec859c30190f667c30fe1163b7574328dd2be7ce1113ee212812b3627.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n pd.id,\n pd.organization_id,\n pd.user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at,\n pd.updated_at,\n po.id as \"option_id?\",\n po.display_order as \"option_display_order?\",\n po.number_value as option_number_value,\n po.string_value as option_string_value,\n po.created_at as \"option_created_at?\",\n po.updated_at as \"option_updated_at?\"\n FROM property_definitions pd\n LEFT JOIN property_options po ON pd.id = po.property_definition_id\n WHERE \n ($1::int IS NOT NULL AND pd.organization_id = $1) \n OR ($2::text IS NOT NULL AND pd.user_id = $2)\n ORDER BY LOWER(pd.display_name), po.display_order, po.number_value, LOWER(po.string_value)\n ",+ "query": "\n SELECT \n pd.id,\n pd.organization_id,\n pd.user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at,\n pd.updated_at,\n po.id as \"option_id?\",\n po.display_order as \"option_display_order?\",\n po.number_value as option_number_value,\n po.string_value as option_string_value,\n po.created_at as \"option_created_at?\",\n po.updated_at as \"option_updated_at?\"\n FROM property_definitions pd\n LEFT JOIN property_options po ON pd.id = po.property_definition_id\n WHERE \n pd.is_system = FALSE\n AND (\n ($1::int IS NOT NULL AND pd.organization_id = $1) \n OR ($2::text IS NOT NULL AND pd.user_id = $2)\n )\n ORDER BY LOWER(pd.display_name), po.display_order, po.number_value, LOWER(po.string_value)\n ","describe": {"columns": [{@@ -62,7 +62,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -133,5 +135,5 @@false]},- "hash": "3f99042ec859c30190f667c30fe1163b7574328dd2be7ce1113ee212812b3627"+ "hash": "2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28"}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-b6338b4c4a7688506ebb22f10f055faa03349dbde1b900667fa2722875d61157.json b/rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.jsonsimilarity index 91%rename from rust/cloud-storage/properties_db_client/.sqlx/query-b6338b4c4a7688506ebb22f10f055faa03349dbde1b900667fa2722875d61157.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.jsonindex 5a5a3ea4b6..3ea3c0bf6d 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-b6338b4c4a7688506ebb22f10f055faa03349dbde1b900667fa2722875d61157.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE id = $1\n ",+ "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE id = $1\n AND is_system = FALSE\n ","describe": {"columns": [{@@ -62,7 +62,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -96,5 +98,5 @@false]},- "hash": "b6338b4c4a7688506ebb22f10f055faa03349dbde1b900667fa2722875d61157"+ "hash": "67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01"}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json b/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.jsonindex 4ab88b9b9e..ee2f2fb38a 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json@@ -21,7 +21,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-bf640556cbea279e94ba70d0213c5b6b25332b970c42c5aa7cbc80a895f18031.json b/rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.jsonsimilarity index 91%rename from rust/cloud-storage/properties_db_client/.sqlx/query-bf640556cbea279e94ba70d0213c5b6b25332b970c42c5aa7cbc80a895f18031.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.jsonindex 09fa23f2df..0ae51da397 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-bf640556cbea279e94ba70d0213c5b6b25332b970c42c5aa7cbc80a895f18031.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at\n FROM entity_properties ep\n INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\n WHERE (ep.entity_id, ep.entity_type) IN (\n SELECT * FROM UNNEST($1::TEXT[], $2::property_entity_type[])\n )\n ",+ "query": "\n SELECT \n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at\n FROM entity_properties ep\n INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\n WHERE (ep.entity_id, ep.entity_type) IN (\n SELECT * FROM UNNEST($1::TEXT[], $2::property_entity_type[])\n )\n AND pd.is_system = FALSE\n ","describe": {"columns": [{@@ -26,7 +26,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -106,7 +108,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -128,7 +132,7 @@"TextArray",{"Custom": {- "name": "_property_entity_type",+ "name": "property_entity_type[]","kind": {"Array": {"Custom": {@@ -140,7 +144,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -168,5 +174,5 @@false]},- "hash": "bf640556cbea279e94ba70d0213c5b6b25332b970c42c5aa7cbc80a895f18031"+ "hash": "737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0"}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json b/rust/cloud-storage/properties_db_client/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.jsonindex 21cdfcab7d..a33e79f60e 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json@@ -17,7 +17,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-f63638ff3ec30e4252915205687a0daafbfd58d258adef45d0792a05856509db.json b/rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.jsonsimilarity index 84%rename from rust/cloud-storage/properties_db_client/.sqlx/query-f63638ff3ec30e4252915205687a0daafbfd58d258adef45d0792a05856509db.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.jsonindex 39530d9fbd..b6a86b82a8 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-f63638ff3ec30e4252915205687a0daafbfd58d258adef45d0792a05856509db.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE \n ($1::int IS NOT NULL AND organization_id = $1) \n OR ($2::text IS NOT NULL AND user_id = $2)\n ORDER BY LOWER(display_name) ASC\n ",+ "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE \n is_system = FALSE\n AND (\n ($1::int IS NOT NULL AND organization_id = $1) \n OR ($2::text IS NOT NULL AND user_id = $2)\n )\n ORDER BY LOWER(display_name) ASC\n ","describe": {"columns": [{@@ -62,7 +62,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -97,5 +99,5 @@false]},- "hash": "f63638ff3ec30e4252915205687a0daafbfd58d258adef45d0792a05856509db"+ "hash": "807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d"}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json b/rust/cloud-storage/properties_db_client/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.jsonindex 6f16ac8a54..e2aa061544 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json@@ -16,7 +16,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-da79225600967e4c50eaca6a4cbaa4cc6a0ebef51a5192abb74f34ef2134ccdc.json b/rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.jsonsimilarity index 92%rename from rust/cloud-storage/properties_db_client/.sqlx/query-da79225600967e4c50eaca6a4cbaa4cc6a0ebef51a5192abb74f34ef2134ccdc.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.jsonindex 1411ed3b41..c7a786278b 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-da79225600967e4c50eaca6a4cbaa4cc6a0ebef51a5192abb74f34ef2134ccdc.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at\n FROM entity_properties ep\n INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\n WHERE ep.entity_id = $1 AND ep.entity_type = $2\n ",+ "query": "\n SELECT \n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at\n FROM entity_properties ep\n INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\n WHERE ep.entity_id = $1 AND ep.entity_type = $2\n AND pd.is_system = FALSE\n ","describe": {"columns": [{@@ -26,7 +26,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -106,7 +108,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -136,7 +140,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -161,5 +167,5 @@false]},- "hash": "da79225600967e4c50eaca6a4cbaa4cc6a0ebef51a5192abb74f34ef2134ccdc"+ "hash": "d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3"}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json b/rust/cloud-storage/properties_db_client/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.jsonindex 2848f329e1..a6d8c54236 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json@@ -62,7 +62,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -113,7 +115,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-8dd49cd84c7a54e7af425a2b377388117dadb9ee8aa8e9d39926364542688549.json b/rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.jsonsimilarity index 87%rename from rust/cloud-storage/properties_db_client/.sqlx/query-8dd49cd84c7a54e7af425a2b377388117dadb9ee8aa8e9d39926364542688549.jsonrename to rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.jsonindex bc86ad748d..e28d19d33b 100644--- a/rust/cloud-storage/properties_db_client/.sqlx/query-8dd49cd84c7a54e7af425a2b377388117dadb9ee8aa8e9d39926364542688549.json+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE id = $1\n AND (\n user_id = $2\n OR ($3::int IS NOT NULL AND organization_id = $3)\n )\n ",+ "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n FROM property_definitions\n WHERE id = $1\n AND is_system = FALSE\n AND (\n user_id = $2\n OR ($3::int IS NOT NULL AND organization_id = $3)\n )\n ","describe": {"columns": [{@@ -62,7 +62,9 @@"DOCUMENT","PROJECT","THREAD",- "USER"+ "USER",+ "COMPANY",+ "TASK"]}}@@ -98,5 +100,5 @@false]},- "hash": "8dd49cd84c7a54e7af425a2b377388117dadb9ee8aa8e9d39926364542688549"+ "hash": "f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3"}diff --git a/rust/cloud-storage/properties_db_client/fixtures/properties.sql b/rust/cloud-storage/properties_db_client/fixtures/properties.sqlindex fb75fb647c..d93c0e618b 100644--- a/rust/cloud-storage/properties_db_client/fixtures/properties.sql+++ b/rust/cloud-storage/properties_db_client/fixtures/properties.sql@@ -12,24 +12,25 @@ VALUES ('user1', '[email protected]', 'Test User 1', 'cus_test1'),ON CONFLICT (id) DO NOTHING;-- Property definitions with various data types+-- Note: Names are prefixed with "Test" to avoid conflicts with system propertiesINSERT INTO property_definitions (id, organization_id, user_id, display_name, data_type, is_multi_select, specific_entity_type)VALUES-- Organization-owned properties- ('11111111-1111-1111-1111-111111111111', 1, NULL, 'Priority', 'SELECT_STRING', false, NULL),- ('22222222-2222-2222-2222-222222222222', 1, NULL, 'Department', 'SELECT_STRING', true, NULL),- ('33333333-3333-3333-3333-333333333333', 1, NULL, 'Assigned To', 'ENTITY', true, 'USER'),- ('44444444-4444-4444-4444-444444444444', 1, NULL, 'Score', 'SELECT_NUMBER', false, NULL),- ('55555555-5555-5555-5555-555555555555', 1, NULL, 'Completed', 'BOOLEAN', false, NULL),- ('66666666-6666-6666-6666-666666666666', 1, NULL, 'Due Date', 'DATE', false, NULL),- ('77777777-7777-7777-7777-777777777777', 1, NULL, 'Budget', 'NUMBER', false, NULL),- ('88888888-8888-8888-8888-888888888888', 1, NULL, 'Description', 'STRING', false, NULL),- ('99999999-9999-9999-9999-999999999999', 1, NULL, 'Website', 'LINK', false, NULL),- ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 1, NULL, 'Relevant Documents', 'ENTITY', false, 'DOCUMENT'),+ ('11111111-1111-1111-1111-111111111111', 1, NULL, 'Test Priority', 'SELECT_STRING', false, NULL),+ ('22222222-2222-2222-2222-222222222222', 1, NULL, 'Test Department', 'SELECT_STRING', true, NULL),+ ('33333333-3333-3333-3333-333333333333', 1, NULL, 'Test Assigned To', 'ENTITY', true, 'USER'),+ ('44444444-4444-4444-4444-444444444444', 1, NULL, 'Test Score', 'SELECT_NUMBER', false, NULL),+ ('55555555-5555-5555-5555-555555555555', 1, NULL, 'Test Completed', 'BOOLEAN', false, NULL),+ ('66666666-6666-6666-6666-666666666666', 1, NULL, 'Test Due Date', 'DATE', false, NULL),+ ('77777777-7777-7777-7777-777777777777', 1, NULL, 'Test Budget', 'NUMBER', false, NULL),+ ('88888888-8888-8888-8888-888888888888', 1, NULL, 'Test Description', 'STRING', false, NULL),+ ('99999999-9999-9999-9999-999999999999', 1, NULL, 'Test Website', 'LINK', false, NULL),+ ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 1, NULL, 'Test Relevant Documents', 'ENTITY', false, 'DOCUMENT'),-- User-owned properties- ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', NULL, 'user1', 'Personal Priority', 'SELECT_STRING', false, NULL),- ('cccccccc-cccc-cccc-cccc-cccccccccccc', NULL, 'user1', 'Notes', 'STRING', false, NULL),+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', NULL, 'user1', 'Test Personal Priority', 'SELECT_STRING', false, NULL),+ ('cccccccc-cccc-cccc-cccc-cccccccccccc', NULL, 'user1', 'Test Notes', 'STRING', false, NULL),-- Mixed ownership property (org and user)- ('dddddddd-dddd-dddd-dddd-dddddddddddd', 2, 'user2', 'Shared Status', 'SELECT_STRING', false, NULL);+ ('dddddddd-dddd-dddd-dddd-dddddddddddd', 2, 'user2', 'Test Shared Status', 'SELECT_STRING', false, NULL);-- Property options for select typesINSERT INTO property_options (id, property_definition_id, display_order, number_value, string_value)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.rsindex 53b8a49912..af8f736cfc 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@@ -1,4 +1,7 @@//! Entity property get operations.+//!+//! TODO: The `pd.is_system = FALSE` filters are temporary. In a future PR, system properties+//! will be properly supported and returned to users via the API.use crate::error::PropertiesDatabaseError;use sqlx::{Pool, Postgres};@@ -280,6 +283,7 @@ pub async fn get_entity_properties_values(FROM entity_properties epINNER JOIN property_definitions pd ON ep.property_definition_id = pd.idWHERE ep.entity_id = $1 AND ep.entity_type = $2+ AND pd.is_system = FALSE"#,entity_id,entity_type as EntityType@@ -357,6 +361,7 @@ pub async fn get_bulk_entity_properties_values(WHERE (ep.entity_id, ep.entity_type) IN (SELECT * FROM UNNEST($1::TEXT[], $2::property_entity_type[]))+ AND pd.is_system = FALSE"#,&entity_ids,&entity_types as &[EntityType]@@ -436,12 +441,12 @@ mod tests {assert_eq!(properties.len(), 6);// Verify they are sorted by display name (case-insensitive alphabetical)- assert_eq!(properties[0].definition.display_name, "Assigned To");- assert_eq!(properties[1].definition.display_name, "Completed");- assert_eq!(properties[2].definition.display_name, "Department");- assert_eq!(properties[3].definition.display_name, "Description");- assert_eq!(properties[4].definition.display_name, "Due Date");- assert_eq!(properties[5].definition.display_name, "Priority");+ assert_eq!(properties[0].definition.display_name, "Test Assigned To");+ assert_eq!(properties[1].definition.display_name, "Test Completed");+ assert_eq!(properties[2].definition.display_name, "Test Department");+ assert_eq!(properties[3].definition.display_name, "Test Description");+ assert_eq!(properties[4].definition.display_name, "Test Due Date");+ assert_eq!(properties[5].definition.display_name, "Test Priority");Ok(())}@@ -460,7 +465,7 @@ mod tests {// Find Priority propertylet priority_prop = properties.iter()- .find(|p| p.definition.display_name == "Priority")+ .find(|p| p.definition.display_name == "Test Priority").unwrap();// Verify it has options attached@@ -485,7 +490,7 @@ mod tests {// Find Completed property (boolean)let completed_prop = properties.iter()- .find(|p| p.definition.display_name == "Completed")+ .find(|p| p.definition.display_name == "Test Completed").unwrap();// Verify boolean value@@ -512,7 +517,7 @@ mod tests {// Find Description property (string)let desc_prop = properties.iter()- .find(|p| p.definition.display_name == "Description")+ .find(|p| p.definition.display_name == "Test Description").unwrap();// Verify string value@@ -694,7 +699,7 @@ mod tests {// Find Assigned To property (ENTITY type with 1 user)let assigned_prop = properties.iter()- .find(|p| p.definition.display_name == "Assigned To")+ .find(|p| p.definition.display_name == "Test Assigned To").unwrap();// Verify it's an ENTITY type property@@ -731,7 +736,7 @@ mod tests {// Find Assigned To property (ENTITY type with 2 users)let assigned_prop = properties.iter()- .find(|p| p.definition.display_name == "Assigned To")+ .find(|p| p.definition.display_name == "Test Assigned To").unwrap();// Verify it has 2 user references@@ -768,7 +773,7 @@ mod tests {// Find Assigned To property (NULL value)let assigned_prop = properties.iter()- .find(|p| p.definition.display_name == "Assigned To")+ .find(|p| p.definition.display_name == "Test Assigned To").unwrap();// Verify the property exists but value is NULL@@ -792,7 +797,7 @@ mod tests {// Find Department property (multi-select SELECT_STRING)let dept_prop = properties.iter()- .find(|p| p.definition.display_name == "Department")+ .find(|p| p.definition.display_name == "Test Department").unwrap();// Verify it's multi-select@@ -831,7 +836,7 @@ mod tests {// Find Due Date property (DATE type)let date_prop = properties.iter()- .find(|p| p.definition.display_name == "Due Date")+ .find(|p| p.definition.display_name == "Test Due Date").unwrap();// Verify it's a DATE type@@ -862,7 +867,7 @@ mod tests {// Find Website property (LINK type)let link_prop = properties.iter()- .find(|p| p.definition.display_name == "Website")+ .find(|p| p.definition.display_name == "Test Website").unwrap();// Verify it's a LINK type@@ -891,7 +896,7 @@ mod tests {// Find Budget property (NUMBER type)let budget_prop = properties.iter()- .find(|p| p.definition.display_name == "Budget")+ .find(|p| p.definition.display_name == "Test Budget").unwrap();// Verify it's a NUMBER typediff --git a/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rs b/rust/cloud-storage/properties_db_client/src/entity_properties/upsert.rsindex 229b9c897c..a42f0d44d4 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@@ -160,7 +160,7 @@ mod tests {.await?;let desc_prop_before = properties_before.iter()- .find(|p| p.definition.display_name == "Description");+ .find(|p| p.definition.display_name == "Test Description");assert!(desc_prop_before.is_none());let property_id = "88888888-8888-8888-8888-888888888888"@@ -186,7 +186,7 @@ mod tests {.await?;let desc_prop = properties.iter()- .find(|p| p.definition.display_name == "Description");+ .find(|p| p.definition.display_name == "Test Description");assert!(desc_prop.is_some());let desc_prop = desc_prop.unwrap();@@ -231,7 +231,7 @@ mod tests {.await?;let desc_prop = properties.iter()- .find(|p| p.definition.display_name == "Description")+ .find(|p| p.definition.display_name == "Test Description").unwrap();if let Some(PropertyValue::Str(val)) = &desc_prop.value {@@ -269,7 +269,7 @@ mod tests {.await?;let desc_prop = properties.iter()- .find(|p| p.definition.display_name == "Description")+ .find(|p| p.definition.display_name == "Test Description").unwrap();assert!(desc_prop.value.is_none());@@ -309,7 +309,7 @@ mod tests {.await?;let completed_prop = properties.iter()- .find(|p| p.definition.display_name == "Completed");+ .find(|p| p.definition.display_name == "Test Completed");assert!(completed_prop.is_some());if let Some(PropertyValue::Bool(val)) = completed_prop.unwrap().value {@@ -351,7 +351,7 @@ mod tests {.await?;let budget_prop = properties.iter()- .find(|p| p.definition.display_name == "Budget")+ .find(|p| p.definition.display_name == "Test Budget").unwrap();if let Some(PropertyValue::Num(val)) = budget_prop.value {@@ -380,7 +380,7 @@ mod tests {.await?;let priority_prop_before = properties_before.iter()- .find(|p| p.definition.display_name == "Priority")+ .find(|p| p.definition.display_name == "Test Priority").unwrap();if let Some(PropertyValue::SelectOption(ids)) = &priority_prop_before.value {assert_eq!(ids.len(), 1);@@ -420,7 +420,7 @@ mod tests {.await?;let priority_prop = properties.iter()- .find(|p| p.definition.display_name == "Priority")+ .find(|p| p.definition.display_name == "Test Priority").unwrap();if let Some(PropertyValue::SelectOption(ids)) = &priority_prop.value {@@ -451,7 +451,7 @@ mod tests {.await?;let assigned_prop_before = properties_before.iter()- .find(|p| p.definition.display_name == "Assigned To")+ .find(|p| p.definition.display_name == "Test Assigned To").unwrap();if let Some(PropertyValue::EntityRef(refs)) = &assigned_prop_before.value {@@ -493,7 +493,7 @@ mod tests {.await?;let assigned_prop = properties.iter()- .find(|p| p.definition.display_name == "Assigned To")+ .find(|p| p.definition.display_name == "Test Assigned To").unwrap();if let Some(PropertyValue::EntityRef(refs)) = &assigned_prop.value {diff --git a/rust/cloud-storage/properties_db_client/src/property_definitions/get.rs b/rust/cloud-storage/properties_db_client/src/property_definitions/get.rsindex e6b7c02d5f..60c1bad0c7 100644--- a/rust/cloud-storage/properties_db_client/src/property_definitions/get.rs+++ b/rust/cloud-storage/properties_db_client/src/property_definitions/get.rs@@ -1,4 +1,7 @@//! Property definitions get operations.+//!+//! TODO: The `is_system = FALSE` filters are temporary. In a future PR, system properties+//! will be properly supported and returned to users via the API.use crate::error::PropertiesDatabaseError;use models_properties::service::property_definition::PropertyDefinition;@@ -32,8 +35,11 @@ pub async fn get_properties(updated_atFROM property_definitionsWHERE- ($1::int IS NOT NULL AND organization_id = $1)- OR ($2::text IS NOT NULL AND user_id = $2)+ is_system = FALSE+ AND (+ ($1::int IS NOT NULL AND organization_id = $1)+ OR ($2::text IS NOT NULL AND user_id = $2)+ )ORDER BY LOWER(display_name) ASC"#,organization_id,@@ -83,6 +89,7 @@ pub async fn get_property_definition(updated_atFROM property_definitionsWHERE id = $1+ AND is_system = FALSE"#,property_id)@@ -130,6 +137,7 @@ pub async fn get_property_definition_with_owner(updated_atFROM property_definitionsWHERE id = $1+ AND is_system = FALSEAND (user_id = $2OR ($3::int IS NOT NULL AND organization_id = $3)@@ -188,8 +196,11 @@ pub async fn get_properties_with_options(FROM property_definitions pdLEFT JOIN property_options po ON pd.id = po.property_definition_idWHERE- ($1::int IS NOT NULL AND pd.organization_id = $1)- OR ($2::text IS NOT NULL AND pd.user_id = $2)+ pd.is_system = FALSE+ AND (+ ($1::int IS NOT NULL AND pd.organization_id = $1)+ OR ($2::text IS NOT NULL AND pd.user_id = $2)+ )ORDER BY LOWER(pd.display_name), po.display_order, po.number_value, LOWER(po.string_value)"#,organization_id,@@ -294,16 +305,16 @@ mod tests {assert_eq!(properties.len(), 10); // Organization 1 has 10 properties// Verify they are sorted by display name (case-insensitive alphabetical)- assert_eq!(properties[0].display_name, "Assigned To");- assert_eq!(properties[1].display_name, "Budget");- assert_eq!(properties[2].display_name, "Completed");- assert_eq!(properties[3].display_name, "Department");- assert_eq!(properties[4].display_name, "Description");- assert_eq!(properties[5].display_name, "Due Date");- assert_eq!(properties[6].display_name, "Priority");- assert_eq!(properties[7].display_name, "Relevant Documents");- assert_eq!(properties[8].display_name, "Score");- assert_eq!(properties[9].display_name, "Website");+ assert_eq!(properties[0].display_name, "Test Assigned To");+ assert_eq!(properties[1].display_name, "Test Budget");+ assert_eq!(properties[2].display_name, "Test Completed");+ assert_eq!(properties[3].display_name, "Test Department");+ assert_eq!(properties[4].display_name, "Test Description");+ assert_eq!(properties[5].display_name, "Test Due Date");+ assert_eq!(properties[6].display_name, "Test Priority");+ assert_eq!(properties[7].display_name, "Test Relevant Documents");+ assert_eq!(properties[8].display_name, "Test Score");+ assert_eq!(properties[9].display_name, "Test Website");Ok(())}@@ -318,8 +329,8 @@ mod tests {let properties = get_properties(&pool, None, Some("user1")).await?;assert_eq!(properties.len(), 2); // User1 has 2 properties- assert_eq!(properties[0].display_name, "Notes");- assert_eq!(properties[1].display_name, "Personal Priority");+ assert_eq!(properties[0].display_name, "Test Notes");+ assert_eq!(properties[1].display_name, "Test Personal Priority");Ok(())}@@ -338,7 +349,7 @@ mod tests {assert!(property.is_some());let property = property.unwrap();- assert_eq!(property.display_name, "Priority");+ assert_eq!(property.display_name, "Test Priority");assert_eq!(property.data_type, DataType::SelectString);assert!(!property.is_multi_select);@@ -400,7 +411,7 @@ mod tests {// Find Priority property which should have 4 optionslet priority_prop = properties.iter()- .find(|p| p.definition.display_name == "Priority")+ .find(|p| p.definition.display_name == "Test Priority").unwrap();assert_eq!(priority_prop.property_options.len(), 4);@@ -432,7 +443,7 @@ mod tests {// Find non-select properties (should have 0 options)let completed_prop = properties.iter()- .find(|p| p.definition.display_name == "Completed")+ .find(|p| p.definition.display_name == "Test Completed").unwrap();assert_eq!(completed_prop.definition.data_type, DataType::Boolean);@@ -453,7 +464,7 @@ mod tests {// Find Score property which has number optionslet score_prop = properties.iter()- .find(|p| p.definition.display_name == "Score")+ .find(|p| p.definition.display_name == "Test Score").unwrap();assert_eq!(score_prop.property_options.len(), 5);@@ -485,7 +496,7 @@ mod tests {// Find Department property which is multi-selectlet dept_prop = properties.iter()- .find(|p| p.definition.display_name == "Department")+ .find(|p| p.definition.display_name == "Test Department").unwrap();assert!(dept_prop.definition.is_multi_select);diff --git a/rust/cloud-storage/properties_db_client/src/property_definitions/insert.rs b/rust/cloud-storage/properties_db_client/src/property_definitions/insert.rsindex d63a7c4a77..a80872f464 100644--- a/rust/cloud-storage/properties_db_client/src/property_definitions/insert.rs+++ b/rust/cloud-storage/properties_db_client/src/property_definitions/insert.rs@@ -300,7 +300,7 @@ mod tests {&pool,Some(1),None,- "Priority", // Already exists in fixtures+ "Test Priority", // Already exists in fixturesDataType::String,false,None,diff --git a/rust/cloud-storage/properties_service/src/api/permissions.rs b/rust/cloud-storage/properties_service/src/api/permissions.rsindex 3ef86f5b11..46bd0cc022 100644--- a/rust/cloud-storage/properties_service/src/api/permissions.rs+++ b/rust/cloud-storage/properties_service/src/api/permissions.rs@@ -75,8 +75,8 @@ async fn get_access_level(EntityType::Project => "project",EntityType::Thread => "thread",EntityType::Channel => "channel",- EntityType::User => {- tracing::warn!("property operations not supported for User entity type");+ EntityType::Company | EntityType::Task | EntityType::User => {+ tracing::warn!("property operations not supported for this entity type");return Err(PermissionError::UnsupportedEntityType);}};diff --git a/rust/cloud-storage/system_properties/Cargo.toml b/rust/cloud-storage/system_properties/Cargo.tomlnew file mode 100644index 0000000000..e7fccd0e37--- /dev/null+++ b/rust/cloud-storage/system_properties/Cargo.toml@@ -0,0 +1,14 @@+[package]+edition = "2024"+name = "system_properties"+publish = false+version = "0.1.0"++[dependencies]+models_properties = { path = "../models_properties" }+serde = { workspace = true }+serde_json = { workspace = true }+sqlx = { workspace = true }+thiserror = { workspace = true }+tracing = { workspace = true }+uuid = { workspace = true }diff --git a/rust/cloud-storage/system_properties/justfile b/rust/cloud-storage/system_properties/justfilenew file mode 100644index 0000000000..6d461b006d--- /dev/null+++ b/rust/cloud-storage/system_properties/justfile@@ -0,0 +1,7 @@+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"++mod sqlx '../sqlx.just'++prepare_db:+ just sqlx::prepare_db {{ DATABASE_URL }}+diff --git a/rust/cloud-storage/system_properties/src/domain/mod.rs b/rust/cloud-storage/system_properties/src/domain/mod.rsnew file mode 100644index 0000000000..3e6bf10ac5--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/mod.rs@@ -0,0 +1,7 @@+//! Domain layer for system properties.+//!+//! Contains models, port definitions (traits), and service logic.++pub mod model;+pub mod port;+pub mod service;diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/mod.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/mod.rsnew file mode 100644index 0000000000..e110c7955d--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/mod.rs@@ -0,0 +1,7 @@+//! Domain constants - enums and constants used by the service layer.++mod options;+mod system_property_key;++pub use options::{EffortOption, PriorityOption, StatusOption};+pub use system_property_key::SystemPropertyKey;diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/options/effort.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/options/effort.rsnew file mode 100644index 0000000000..990e89ba32--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/options/effort.rs@@ -0,0 +1,47 @@+//! Effort option enum.++use serde::{Deserialize, Serialize};+use uuid::Uuid;++/// Type-safe enum for Effort property options.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum EffortOption {+ Small,+ Medium,+ Large,+}++impl EffortOption {+ pub const SMALL_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0008_000000000001);+ pub const MEDIUM_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0008_000000000002);+ pub const LARGE_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0008_000000000003);++ /// Get the UUID for this option.+ pub const fn uuid(&self) -> Uuid {+ match self {+ Self::Small => Self::SMALL_UUID,+ Self::Medium => Self::MEDIUM_UUID,+ Self::Large => Self::LARGE_UUID,+ }+ }++ /// Get the display value for this option.+ pub const fn display_value(&self) -> &'static str {+ match self {+ Self::Small => "Small",+ Self::Medium => "Medium",+ Self::Large => "Large",+ }+ }++ /// Try to get an EffortOption from an option UUID.+ pub fn from_uuid(uuid: Uuid) -> Option<Self> {+ match uuid {+ u if u == Self::SMALL_UUID => Some(Self::Small),+ u if u == Self::MEDIUM_UUID => Some(Self::Medium),+ u if u == Self::LARGE_UUID => Some(Self::Large),+ _ => None,+ }+ }+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/options/mod.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/options/mod.rsnew file mode 100644index 0000000000..55dab23cd4--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/options/mod.rs@@ -0,0 +1,9 @@+//! Select option enums.++mod effort;+mod priority;+mod status;++pub use effort::EffortOption;+pub use priority::PriorityOption;+pub use status::StatusOption;diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/options/priority.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/options/priority.rsnew file mode 100644index 0000000000..01d415d1a7--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/options/priority.rs@@ -0,0 +1,52 @@+//! Priority option enum.++use serde::{Deserialize, Serialize};+use uuid::Uuid;++/// Type-safe enum for Priority property options.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum PriorityOption {+ Low,+ Medium,+ High,+ Critical,+}++impl PriorityOption {+ pub const LOW_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0003_000000000001);+ pub const MEDIUM_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0003_000000000002);+ pub const HIGH_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0003_000000000003);+ pub const CRITICAL_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0003_000000000004);++ /// Get the UUID for this option.+ pub const fn uuid(&self) -> Uuid {+ match self {+ Self::Low => Self::LOW_UUID,+ Self::Medium => Self::MEDIUM_UUID,+ Self::High => Self::HIGH_UUID,+ Self::Critical => Self::CRITICAL_UUID,+ }+ }++ /// Get the display value for this option.+ pub const fn display_value(&self) -> &'static str {+ match self {+ Self::Low => "Low",+ Self::Medium => "Medium",+ Self::High => "High",+ Self::Critical => "Critical",+ }+ }++ /// Try to get a PriorityOption from an option UUID.+ pub fn from_uuid(uuid: Uuid) -> Option<Self> {+ match uuid {+ u if u == Self::LOW_UUID => Some(Self::Low),+ u if u == Self::MEDIUM_UUID => Some(Self::Medium),+ u if u == Self::HIGH_UUID => Some(Self::High),+ u if u == Self::CRITICAL_UUID => Some(Self::Critical),+ _ => None,+ }+ }+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/options/status.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/options/status.rsnew file mode 100644index 0000000000..92f0b56f3c--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/options/status.rs@@ -0,0 +1,57 @@+//! Status option enum.++use serde::{Deserialize, Serialize};+use uuid::Uuid;++/// Type-safe enum for Status property options.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum StatusOption {+ NotStarted,+ InProgress,+ InReview,+ Completed,+ Canceled,+}++impl StatusOption {+ pub const NOT_STARTED_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0002_000000000001);+ pub const IN_PROGRESS_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0002_000000000002);+ pub const IN_REVIEW_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0002_000000000003);+ pub const COMPLETED_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0002_000000000004);+ pub const CANCELED_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0002_000000000005);++ /// Get the UUID for this option.+ pub const fn uuid(&self) -> Uuid {+ match self {+ Self::NotStarted => Self::NOT_STARTED_UUID,+ Self::InProgress => Self::IN_PROGRESS_UUID,+ Self::InReview => Self::IN_REVIEW_UUID,+ Self::Completed => Self::COMPLETED_UUID,+ Self::Canceled => Self::CANCELED_UUID,+ }+ }++ /// Get the display value for this option.+ pub const fn display_value(&self) -> &'static str {+ match self {+ Self::NotStarted => "Not Started",+ Self::InProgress => "In Progress",+ Self::InReview => "In Review",+ Self::Completed => "Completed",+ Self::Canceled => "Canceled",+ }+ }++ /// Try to get a StatusOption from an option UUID.+ pub fn from_uuid(uuid: Uuid) -> Option<Self> {+ match uuid {+ u if u == Self::NOT_STARTED_UUID => Some(Self::NotStarted),+ u if u == Self::IN_PROGRESS_UUID => Some(Self::InProgress),+ u if u == Self::IN_REVIEW_UUID => Some(Self::InReview),+ u if u == Self::COMPLETED_UUID => Some(Self::Completed),+ u if u == Self::CANCELED_UUID => Some(Self::Canceled),+ _ => None,+ }+ }+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/constants/system_property_key.rs b/rust/cloud-storage/system_properties/src/domain/model/constants/system_property_key.rsnew file mode 100644index 0000000000..478de788dd--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/constants/system_property_key.rs@@ -0,0 +1,119 @@+//! System property key enum.++use serde::{Deserialize, Serialize};+use uuid::Uuid;++/// System property keys with stable UUIDs.+///+/// These are predefined properties managed by the system.+/// Users cannot create or delete these, but can apply them to entities.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum SystemPropertyKey {+ // Tasks+ Assignees,+ Status,+ Priority,+ DueDate,+ ParentTask,+ Subtasks,+ DependsOn,+ Effort,+ StoryPoints,+ RelevantDocuments,++ // Emails Attachments+ Source,+ Companies,+ Sender,+ Recipients,+ Subject,+}++impl SystemPropertyKey {+ pub const ASSIGNEES_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000001);+ pub const STATUS_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000002);+ pub const PRIORITY_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000003);+ pub const DUE_DATE_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000004);+ pub const PARENT_TASK_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000005);+ pub const SUBTASKS_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000006);+ pub const DEPENDS_ON_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000007);+ pub const EFFORT_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000008);+ pub const STORY_POINTS_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000009);+ pub const RELEVANT_DOCUMENTS_UUID: Uuid =+ Uuid::from_u128(0x00000001_0000_0000_0000_00000000000a);+ pub const SOURCE_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_00000000000b);+ pub const COMPANIES_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_00000000000c);+ pub const SENDER_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_00000000000d);+ pub const RECIPIENTS_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_00000000000e);+ pub const SUBJECT_UUID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_00000000000f);++ /// Get the UUID for this system property.+ pub const fn uuid(&self) -> Uuid {+ match self {+ Self::Assignees => Self::ASSIGNEES_UUID,+ Self::Status => Self::STATUS_UUID,+ Self::Priority => Self::PRIORITY_UUID,+ Self::DueDate => Self::DUE_DATE_UUID,+ Self::ParentTask => Self::PARENT_TASK_UUID,+ Self::Subtasks => Self::SUBTASKS_UUID,+ Self::DependsOn => Self::DEPENDS_ON_UUID,+ Self::Effort => Self::EFFORT_UUID,+ Self::StoryPoints => Self::STORY_POINTS_UUID,+ Self::RelevantDocuments => Self::RELEVANT_DOCUMENTS_UUID,+ Self::Source => Self::SOURCE_UUID,+ Self::Companies => Self::COMPANIES_UUID,+ Self::Sender => Self::SENDER_UUID,+ Self::Recipients => Self::RECIPIENTS_UUID,+ Self::Subject => Self::SUBJECT_UUID,+ }+ }++ /// Get the display name for this system property.+ pub const fn display_name(&self) -> &'static str {+ match self {+ Self::Assignees => "Assignees",+ Self::Status => "Status",+ Self::Priority => "Priority",+ Self::DueDate => "Due Date",+ Self::ParentTask => "Parent Task",+ Self::Subtasks => "Subtasks",+ Self::DependsOn => "Depends On",+ Self::Effort => "Effort",+ Self::StoryPoints => "Story Points",+ Self::RelevantDocuments => "Relevant Documents",+ Self::Source => "Source",+ Self::Companies => "Companies",+ Self::Sender => "Sender",+ Self::Recipients => "Recipients",+ Self::Subject => "Subject",+ }+ }++ /// Try to get a SystemPropertyKey from a UUID.+ pub fn from_uuid(uuid: Uuid) -> Option<Self> {+ match uuid {+ u if u == Self::ASSIGNEES_UUID => Some(Self::Assignees),+ u if u == Self::STATUS_UUID => Some(Self::Status),+ u if u == Self::PRIORITY_UUID => Some(Self::Priority),+ u if u == Self::DUE_DATE_UUID => Some(Self::DueDate),+ u if u == Self::PARENT_TASK_UUID => Some(Self::ParentTask),+ u if u == Self::SUBTASKS_UUID => Some(Self::Subtasks),+ u if u == Self::DEPENDS_ON_UUID => Some(Self::DependsOn),+ u if u == Self::EFFORT_UUID => Some(Self::Effort),+ u if u == Self::STORY_POINTS_UUID => Some(Self::StoryPoints),+ u if u == Self::RELEVANT_DOCUMENTS_UUID => Some(Self::RelevantDocuments),+ u if u == Self::SOURCE_UUID => Some(Self::Source),+ u if u == Self::COMPANIES_UUID => Some(Self::Companies),+ u if u == Self::SENDER_UUID => Some(Self::Sender),+ u if u == Self::RECIPIENTS_UUID => Some(Self::Recipients),+ u if u == Self::SUBJECT_UUID => Some(Self::Subject),+ _ => None,+ }+ }++ /// Check if a UUID is a system property UUID.+ pub fn is_system_uuid(uuid: Uuid) -> bool {+ Self::from_uuid(uuid).is_some()+ }+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/error.rs b/rust/cloud-storage/system_properties/src/domain/model/error.rsnew file mode 100644index 0000000000..5eac1321da--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/error.rs@@ -0,0 +1,19 @@+//! Error types for system properties.++use thiserror::Error;++/// Errors that can occur when working with system properties.+#[derive(Debug, Error)]+pub enum SystemPropertyError {+ /// Database error+ #[error("Database error: {0}")]+ Database(#[from] sqlx::Error),++ /// Serialization error+ #[error("Serialization error: {0}")]+ Serialization(#[from] serde_json::Error),++ /// Validation error+ #[error("Validation error: {0}")]+ Validation(String),+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/inbound/email_attachment.rs b/rust/cloud-storage/system_properties/src/domain/model/inbound/email_attachment.rsnew file mode 100644index 0000000000..d393b326e8--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/inbound/email_attachment.rs@@ -0,0 +1,27 @@+//! Email attachment property types.++use super::source_entity::SourceEntity;++/// Email attachment properties to set on an entity.+#[derive(Debug, Clone, Default)]+pub struct EmailAttachmentProperty {+ /// Source entity reference (single).+ pub source: Option<SourceEntity>,+ /// Company entity IDs.+ pub companies: Option<Vec<String>>,+ /// Sender user ID.+ pub sender: Option<String>,+ /// Recipient user IDs.+ pub recipients: Option<Vec<String>>,+ /// Subject line.+ pub subject: Option<String>,+}++/// Input for bulk email attachment property setting.+#[derive(Debug, Clone)]+pub struct EmailAttachmentInput {+ /// The entity ID to set properties on.+ pub entity_id: String,+ /// The properties to set.+ pub properties: EmailAttachmentProperty,+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/inbound/mod.rs b/rust/cloud-storage/system_properties/src/domain/model/inbound/mod.rsnew file mode 100644index 0000000000..cd5c354de0--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/inbound/mod.rs@@ -0,0 +1,7 @@+//! Inbound types - types from inbound adapters (commands/inputs).++mod email_attachment;+mod source_entity;++pub use email_attachment::{EmailAttachmentInput, EmailAttachmentProperty};+pub use source_entity::SourceEntity;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.rsnew file mode 100644index 0000000000..312b26728f--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/inbound/source_entity.rs@@ -0,0 +1,16 @@+//! Source entity reference type.++use models_properties::EntityType;+use serde::{Deserialize, Serialize};++/// Entity reference for Source property.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct SourceEntity {+ /// The type of entity being referenced.+ pub entity_type: EntityType,+ /// The ID of the entity being referenced.+ 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>,+}diff --git a/rust/cloud-storage/system_properties/src/domain/model/mod.rs b/rust/cloud-storage/system_properties/src/domain/model/mod.rsnew file mode 100644index 0000000000..1c6f3a9791--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/mod.rs@@ -0,0 +1,11 @@+//! Domain models for system properties.++mod constants;+mod error;+mod inbound;+mod repository;++pub use constants::{EffortOption, PriorityOption, StatusOption, SystemPropertyKey};+pub use error::SystemPropertyError;+pub use inbound::{EmailAttachmentInput, EmailAttachmentProperty, SourceEntity};+pub use repository::PropertyRow;diff --git a/rust/cloud-storage/system_properties/src/domain/model/repository/mod.rs b/rust/cloud-storage/system_properties/src/domain/model/repository/mod.rsnew file mode 100644index 0000000000..9ea20e6cdf--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/repository/mod.rs@@ -0,0 +1,5 @@+//! Repository types - types for repository (outbound adapter).++mod property_row;++pub use property_row::PropertyRow;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.rsnew file mode 100644index 0000000000..0b3dfbefdb--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/model/repository/property_row.rs@@ -0,0 +1,102 @@+//! Property row for repository persistence.++use models_properties::EntityType;+use uuid::Uuid;++/// A single property row to upsert.+///+/// Fields are private to enforce valid JSON structure via constructors.+#[derive(Debug)]+pub struct PropertyRow {+ entity_id: String,+ entity_type: EntityType,+ property_definition_id: Uuid,+ values: serde_json::Value,+}++impl PropertyRow {+ // =========================================================================+ // Constructors - enforce valid JSON structure+ // =========================================================================++ /// Create a property row with entity references.+ ///+ /// `specific_message_id` is included on each reference if provided.+ /// Use this for CHANNEL/CHAT/THREAD refs that need message context.+ pub fn entity_reference(+ entity_id: impl Into<String>,+ entity_type: EntityType,+ property_definition_id: Uuid,+ ref_type: EntityType,+ ref_ids: Vec<String>,+ specific_message_id: Option<String>,+ ) -> Self {+ let refs: Vec<serde_json::Value> = ref_ids+ .into_iter()+ .map(|id| {+ let mut obj = serde_json::json!({+ "entity_type": ref_type,+ "entity_id": id+ });+ if let Some(ref msg_id) = specific_message_id {+ obj.as_object_mut()+ .expect("json object")+ .insert("specific_message_id".to_string(), serde_json::json!(msg_id));+ }+ obj+ })+ .collect();++ Self {+ entity_id: entity_id.into(),+ entity_type,+ property_definition_id,+ values: serde_json::json!({+ "type": "EntityReference",+ "value": refs+ }),+ }+ }++ /// Create a property row with a string value.+ pub fn string_value(+ entity_id: impl Into<String>,+ entity_type: EntityType,+ property_definition_id: Uuid,+ value: impl Into<String>,+ ) -> Self {+ Self {+ entity_id: entity_id.into(),+ entity_type,+ property_definition_id,+ values: serde_json::json!({+ "type": "String",+ "value": value.into()+ }),+ }+ }++ // =========================================================================+ // Getters - for repository access+ // =========================================================================++ /// Get the entity ID.+ pub fn entity_id(&self) -> &str {+ &self.entity_id+ }++ /// Get the entity type.+ pub fn entity_type(&self) -> EntityType {+ self.entity_type+ }++ /// Get the property definition ID.+ pub fn property_definition_id(&self) -> Uuid {+ self.property_definition_id+ }++ /// Get the values JSON.+ pub fn values(&self) -> &serde_json::Value {+ &self.values+ }+}diff --git a/rust/cloud-storage/system_properties/src/domain/port.rs b/rust/cloud-storage/system_properties/src/domain/port.rsnew file mode 100644index 0000000000..3fc956edd1--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/port.rs@@ -0,0 +1,18 @@+//! Port definitions for system properties.+//!+//! These traits define the interfaces that the domain layer uses.+//! Implementations live in the outbound module.++use crate::domain::model::SystemPropertyError;++/// Repository trait for system property database operations.+///+/// This trait abstracts the database layer, allowing for different implementations+/// (e.g., PostgreSQL, mock for testing).+pub trait SystemPropertiesRepository: Clone + Send + Sync + 'static {+ /// Bulk upsert property rows in a single query.+ fn bulk_upsert_properties(+ &self,+ rows: Vec<crate::domain::model::PropertyRow>,+ ) -> impl Future<Output = Result<(), SystemPropertyError>> + Send;+}diff --git a/rust/cloud-storage/system_properties/src/domain/service.rs b/rust/cloud-storage/system_properties/src/domain/service.rsnew file mode 100644index 0000000000..b2a559a233--- /dev/null+++ b/rust/cloud-storage/system_properties/src/domain/service.rs@@ -0,0 +1,130 @@+//! Service layer for system properties.++use models_properties::EntityType;++use crate::domain::{+ model::{+ EmailAttachmentInput, EmailAttachmentProperty, PropertyRow, SystemPropertyError,+ SystemPropertyKey,+ },+ port::SystemPropertiesRepository,+};++/// Service trait for system property operations.+pub trait SystemPropertiesService: Clone + Send + Sync + 'static {+ /// Set email attachment properties for multiple entities.+ ///+ /// Only properties that are `Some` will be updated.+ /// All properties are upserted in a single query.+ fn set_email_attachment_properties(+ &self,+ items: Vec<EmailAttachmentInput>,+ ) -> impl Future<Output = Result<(), SystemPropertyError>> + Send;+}++/// Implementation of SystemPropertiesService using a repository.+#[derive(Debug, Clone)]+pub struct SystemPropertiesServiceImpl<R>+where+ R: SystemPropertiesRepository,+{+ repository: R,+}++impl<R> SystemPropertiesServiceImpl<R>+where+ R: SystemPropertiesRepository,+{+ /// Create a new SystemPropertiesService.+ pub fn new(repository: R) -> Self {+ Self { repository }+ }+}++impl<R> SystemPropertiesService for SystemPropertiesServiceImpl<R>+where+ R: SystemPropertiesRepository,+{+ #[tracing::instrument(skip(self, items))]+ async fn set_email_attachment_properties(+ &self,+ items: Vec<EmailAttachmentInput>,+ ) -> Result<(), SystemPropertyError> {+ let rows: Vec<PropertyRow> = items+ .into_iter()+ .flat_map(|item| collect_email_property_rows(&item.entity_id, item.properties))+ .collect();++ self.repository.bulk_upsert_properties(rows).await+ }+}++/// Collect property rows for a single entity's email attachment properties.+/// Email attachments are always applied to Document entities.+fn collect_email_property_rows(+ entity_id: &str,+ properties: EmailAttachmentProperty,+) -> Vec<PropertyRow> {+ let mut rows = Vec::new();+ let entity_type = EntityType::Document;++ // Source (single entity reference with optional specific_message_id)+ if let Some(source) = properties.source {+ rows.push(PropertyRow::entity_reference(+ entity_id,+ entity_type,+ SystemPropertyKey::Source.uuid(),+ source.entity_type,+ vec![source.entity_id],+ source.specific_message_id,+ ));+ }++ // Companies (multi entity reference)+ if let Some(company_ids) = properties.companies {+ rows.push(PropertyRow::entity_reference(+ entity_id,+ entity_type,+ SystemPropertyKey::Companies.uuid(),+ EntityType::Company,+ company_ids,+ None,+ ));+ }++ // Sender (single user reference)+ if let Some(user_id) = properties.sender {+ rows.push(PropertyRow::entity_reference(+ entity_id,+ entity_type,+ SystemPropertyKey::Sender.uuid(),+ EntityType::User,+ vec![user_id],+ None,+ ));+ }++ // Recipients (multi user reference)+ if let Some(user_ids) = properties.recipients {+ rows.push(PropertyRow::entity_reference(+ entity_id,+ entity_type,+ SystemPropertyKey::Recipients.uuid(),+ EntityType::User,+ user_ids,+ None,+ ));+ }++ // Subject (string)+ if let Some(subject) = properties.subject {+ rows.push(PropertyRow::string_value(+ entity_id,+ entity_type,+ SystemPropertyKey::Subject.uuid(),+ subject,+ ));+ }++ rows+}diff --git a/rust/cloud-storage/system_properties/src/lib.rs b/rust/cloud-storage/system_properties/src/lib.rsnew file mode 100644index 0000000000..c8fd77b539--- /dev/null+++ b/rust/cloud-storage/system_properties/src/lib.rs@@ -0,0 +1,55 @@+//! System properties crate.+//!+//! Provides types and database operations for system-managed properties.+//! System properties are predefined by the system and cannot be created or deleted by users,+//! but users can apply them to entities and manage their values.+//!+//! # Architecture+//!+//! This crate follows hexagonal architecture:+//! - `domain::model` - Domain models (entities, value objects, errors)+//! - `domain::port` - Port definitions (traits/interfaces)+//! - `domain::service` - Service trait and implementation+//! - `outbound` - Outbound adapters (e.g., PostgreSQL implementation)+//!+//! # Example+//!+//! ```ignore+//! use system_properties::{+//! domain::{+//! model::{EmailAttachmentInput, EmailAttachmentProperty},+//! service::{SystemPropertiesService, SystemPropertiesServiceImpl},+//! },+//! outbound::pgpool::PgSystemPropertiesRepository,+//! };+//!+//! let repository = PgSystemPropertiesRepository::new(pool);+//! let service = SystemPropertiesServiceImpl::new(repository);+//!+//! service.set_email_attachment_properties(vec![+//! EmailAttachmentInput {+//! entity_id: "doc_123".to_string(),+//! entity_type: EntityType::Document,+//! properties: EmailAttachmentProperty {+//! subject: Some("Hello".to_string()),+//! ..Default::default()+//! },+//! },+//! ]).await?;+//! ```++/// Domain layer containing models, ports, and services.+pub mod domain;++/// Outbound adapters for database implementations.+pub mod outbound;++// Re-export commonly used types for convenience+pub use domain::model::PropertyRow;+pub use domain::model::{+ EffortOption, EmailAttachmentInput, EmailAttachmentProperty, PriorityOption, SourceEntity,+ StatusOption, SystemPropertyError, SystemPropertyKey,+};+pub use domain::port::SystemPropertiesRepository;+pub use domain::service::{SystemPropertiesService, SystemPropertiesServiceImpl};+pub use outbound::pgpool::PgSystemPropertiesRepository;diff --git a/rust/cloud-storage/system_properties/src/outbound/mod.rs b/rust/cloud-storage/system_properties/src/outbound/mod.rsnew file mode 100644index 0000000000..7bc6aa2b6a--- /dev/null+++ b/rust/cloud-storage/system_properties/src/outbound/mod.rs@@ -0,0 +1,5 @@+//! Outbound adapters for system properties.+//!+//! Contains implementations of port traits.++pub mod pgpool;diff --git a/rust/cloud-storage/system_properties/src/outbound/pgpool.rs b/rust/cloud-storage/system_properties/src/outbound/pgpool.rsnew file mode 100644index 0000000000..90ed964b71--- /dev/null+++ b/rust/cloud-storage/system_properties/src/outbound/pgpool.rs@@ -0,0 +1,80 @@+//! PostgreSQL implementation for system properties repository.++use sqlx::{Pool, Postgres};+use uuid::Uuid;++use crate::domain::{+ model::{PropertyRow, SystemPropertyError},+ port::SystemPropertiesRepository,+};++/// PostgreSQL implementation of SystemPropertiesRepository.+#[derive(Clone)]+pub struct PgSystemPropertiesRepository {+ pool: Pool<Postgres>,+}++impl PgSystemPropertiesRepository {+ /// Create a new PgSystemPropertiesRepository.+ pub fn new(pool: Pool<Postgres>) -> Self {+ Self { pool }+ }+}++impl SystemPropertiesRepository for PgSystemPropertiesRepository {+ async fn bulk_upsert_properties(+ &self,+ rows: Vec<PropertyRow>,+ ) -> Result<(), SystemPropertyError> {+ if rows.is_empty() {+ return Ok(());+ }++ let ids: Vec<Uuid> = rows.iter().map(|_| Uuid::now_v7()).collect();+ let entity_ids: Vec<&str> = rows.iter().map(|r| r.entity_id()).collect();+ let entity_types: Vec<String> = rows+ .iter()+ .map(|r| {+ serde_json::to_value(r.entity_type())+ .expect("EntityType serializes to JSON")+ .as_str()+ .expect("EntityType serializes to string")+ .to_string()+ })+ .collect();+ let property_ids: Vec<Uuid> = rows.iter().map(|r| r.property_definition_id()).collect();+ let values: Vec<serde_json::Value> = rows.iter().map(|r| r.values().clone()).collect();++ sqlx::query(+ r#"+ INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)+ SELECT+ u.id,+ u.entity_id,+ u.entity_type::property_entity_type,+ u.property_definition_id,+ u.values+ FROM UNNEST(+ $1::UUID[],+ $2::TEXT[],+ $3::TEXT[],+ $4::UUID[],+ $5::JSONB[]+ ) AS u(id, entity_id, entity_type, property_definition_id, values)+ ON CONFLICT (entity_id, entity_type, property_definition_id)+ DO UPDATE SET+ values = EXCLUDED.values,+ updated_at = NOW()+ "#,+ )+ .bind(&ids)+ .bind(&entity_ids)+ .bind(&entity_types)+ .bind(&property_ids)+ .bind(&values)+ .execute(&self.pool)+ .await?;++ Ok(())+ }+}