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] - properties service handling system (#456)

Daniel Kweon6ce17bc8b2df
diff --git a/rust/cloud-storage/models_properties/src/api/responses.rs b/rust/cloud-storage/models_properties/src/api/responses.rs
index 45fb6d0d87..b25a9de67d 100644
--- a/rust/cloud-storage/models_properties/src/api/responses.rs
+++ b/rust/cloud-storage/models_properties/src/api/responses.rs
@@ -21,6 +21,8 @@ pub struct PropertyDefinitionResponse {
pub data_type: DataType,
pub is_multi_select: bool,
pub specific_entity_type: Option<EntityType>,
+ /// Flag to indicate if this is a system property (managed by the system)
+ pub is_system: bool,
/// Flag to indicate if this is a system-generated metadata property
pub is_metadata: bool,
#[serde(skip_serializing_if = "Option::is_none")]
diff --git a/rust/cloud-storage/models_properties/src/db/property_definition.rs b/rust/cloud-storage/models_properties/src/db/property_definition.rs
index 0e4f8b3cd3..0801ac373d 100644
--- a/rust/cloud-storage/models_properties/src/db/property_definition.rs
+++ b/rust/cloud-storage/models_properties/src/db/property_definition.rs
@@ -18,6 +18,7 @@ pub struct PropertyDefinition {
pub specific_entity_type: Option<EntityType>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
+ pub is_system: bool,
}
// ===== Conversions =====
@@ -26,8 +27,7 @@ impl From<PropertyDefinition> for crate::service::property_definition::PropertyD
fn from(db: PropertyDefinition) -> Self {
use crate::shared::PropertyOwner;
- let owner = PropertyOwner::from_optional_ids(db.organization_id, db.user_id)
- .expect("PropertyDefinition must have at least one owner (user_id or organization_id)");
+ let owner = PropertyOwner::from_optional_ids(db.organization_id, db.user_id, db.is_system);
Self {
id: db.id,
@@ -38,8 +38,9 @@ impl From<PropertyDefinition> for crate::service::property_definition::PropertyD
specific_entity_type: db.specific_entity_type,
created_at: db.created_at,
updated_at: db.updated_at,
- // is_metadata is a service layer concept, not stored in DB
- // Default to false (user-defined property)
+ is_system: db.is_system,
+ // is_metadata is a service layer concept for computed properties
+ // Default to false (stored property)
is_metadata: false,
}
}
diff --git a/rust/cloud-storage/models_properties/src/service/property_definition.rs b/rust/cloud-storage/models_properties/src/service/property_definition.rs
index 4e30ef7467..b8a3cae6de 100644
--- a/rust/cloud-storage/models_properties/src/service/property_definition.rs
+++ b/rust/cloud-storage/models_properties/src/service/property_definition.rs
@@ -17,6 +17,8 @@ pub struct PropertyDefinition {
pub specific_entity_type: Option<EntityType>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
+ /// Flag to indicate if this is a system property (stored in DB).
+ pub is_system: bool,
/// Flag to indicate if this is a system-generated metadata property.
/// Not stored in database - computed at service layer.
pub is_metadata: bool,
@@ -33,6 +35,7 @@ impl From<PropertyDefinition> for crate::api::PropertyDefinitionResponse {
data_type: svc.data_type,
is_multi_select: svc.is_multi_select,
specific_entity_type: svc.specific_entity_type,
+ is_system: svc.is_system,
is_metadata: svc.is_metadata,
created_at: Some(svc.created_at),
updated_at: Some(svc.updated_at),
diff --git a/rust/cloud-storage/models_properties/src/shared/property_owner.rs b/rust/cloud-storage/models_properties/src/shared/property_owner.rs
index 0ad68da8f7..7f2092c0ee 100644
--- a/rust/cloud-storage/models_properties/src/shared/property_owner.rs
+++ b/rust/cloud-storage/models_properties/src/shared/property_owner.rs
@@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
-/// Defines who owns a property - user-scoped, org-scoped, or both.
+/// Defines who owns a property - user-scoped, org-scoped, system, or both user and org.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq)]
#[serde(rename_all = "snake_case", tag = "scope")]
pub enum PropertyOwner {
@@ -16,6 +16,8 @@ pub enum PropertyOwner {
user_id: String,
organization_id: i32,
},
+ /// System-owned property (no user or org owner)
+ System,
}
impl PropertyOwner {
@@ -26,7 +28,7 @@ impl PropertyOwner {
PropertyOwner::UserAndOrganization {
organization_id, ..
} => Some(*organization_id),
- PropertyOwner::User { .. } => None,
+ PropertyOwner::User { .. } | PropertyOwner::System => None,
}
}
@@ -35,25 +37,33 @@ impl PropertyOwner {
match self {
PropertyOwner::User { user_id } => Some(user_id.as_str()),
PropertyOwner::UserAndOrganization { user_id, .. } => Some(user_id.as_str()),
- PropertyOwner::Organization { .. } => None,
+ PropertyOwner::Organization { .. } | PropertyOwner::System => None,
}
}
- /// Create from optional org_id and user_id (for DB conversions)
+ /// Create from optional org_id, user_id, and is_system flag (for DB conversions)
pub fn from_optional_ids(
organization_id: Option<i32>,
user_id: Option<String>,
- ) -> Option<Self> {
+ is_system: bool,
+ ) -> Self {
+ if is_system {
+ return PropertyOwner::System;
+ }
match (organization_id, user_id) {
- (Some(org_id), Some(uid)) => Some(PropertyOwner::UserAndOrganization {
+ (Some(org_id), Some(uid)) => PropertyOwner::UserAndOrganization {
user_id: uid,
organization_id: org_id,
- }),
- (Some(org_id), None) => Some(PropertyOwner::Organization {
+ },
+ (Some(org_id), None) => PropertyOwner::Organization {
organization_id: org_id,
- }),
- (None, Some(uid)) => Some(PropertyOwner::User { user_id: uid }),
- (None, None) => None,
+ },
+ (None, Some(uid)) => PropertyOwner::User { user_id: uid },
+ (None, None) => {
+ // This should not happen for non-system properties
+ // but we handle it gracefully by returning System
+ PropertyOwner::System
+ }
}
}
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json b/rust/cloud-storage/properties_db_client/.sqlx/query-17bcb8a4765cf0bfc406a98a2a8829342f248afbdfddef55ef1f44aa4c9b034e.json
similarity index 66%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-17bcb8a4765cf0bfc406a98a2a8829342f248afbdfddef55ef1f44aa4c9b034e.json
index ee2f2fb38a..72c36bfbe7 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-17bcb8a4765cf0bfc406a98a2a8829342f248afbdfddef55ef1f44aa4c9b034e.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT \n entity_id,\n entity_type as \"entity_type: EntityType\"\n FROM entity_properties\n WHERE id = $1\n ",
+ "query": "\n SELECT \n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\"\n FROM entity_properties ep\n JOIN property_definitions pd ON ep.property_definition_id = pd.id\n WHERE ep.id = $1\n AND pd.is_system = FALSE\n ",
"describe": {
"columns": [
{
@@ -40,5 +40,5 @@
false
]
},
- "hash": "68ba9622c30c931881f5c842be79232d322b97f87acbc445963e81d75dcf60de"
+ "hash": "17bcb8a4765cf0bfc406a98a2a8829342f248afbdfddef55ef1f44aa4c9b034e"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.json b/rust/cloud-storage/properties_db_client/.sqlx/query-3413f40533fe26ef9d719996855f91926f21273aeb1dc34489925ebcd39829b6.json
similarity index 90%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-3413f40533fe26ef9d719996855f91926f21273aeb1dc34489925ebcd39829b6.json
index c7a786278b..b0ab4cd82e 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-3413f40533fe26ef9d719996855f91926f21273aeb1dc34489925ebcd39829b6.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 AND pd.is_system = FALSE\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 pd.is_system as definition_is_system\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 ",
"describe": {
"columns": [
{
@@ -125,6 +125,11 @@
"ordinal": 14,
"name": "definition_updated_at",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "definition_is_system",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -164,8 +169,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "d77d511766deedda664b4732067506878765eb029f4a63a32374284de29a33f3"
+ "hash": "3413f40533fe26ef9d719996855f91926f21273aeb1dc34489925ebcd39829b6"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.json b/rust/cloud-storage/properties_db_client/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.json
similarity index 83%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.json
index e28d19d33b..c853ae04b7 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.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 is_system = FALSE\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 is_system\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": [
{
@@ -79,6 +79,11 @@
"ordinal": 8,
"name": "updated_at",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_system",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -97,8 +102,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "f476964b8bcedb7b69ad1bb708586065adea1bd5c2f00e3f3050ae00470546c3"
+ "hash": "5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.json b/rust/cloud-storage/properties_db_client/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.json
similarity index 88%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.json
index 3ea3c0bf6d..ea49b9c1cd 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.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 is_system = FALSE\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 is_system\n FROM property_definitions\n WHERE id = $1\n ",
"describe": {
"columns": [
{
@@ -79,6 +79,11 @@
"ordinal": 8,
"name": "updated_at",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_system",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -95,8 +100,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "67ba643e4fdd16f0a02353cf3775a1debbcb5d5f044191c5d7509cbac8e1ed01"
+ "hash": "732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.json b/rust/cloud-storage/properties_db_client/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.json
similarity index 80%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.json
index b6a86b82a8..d172804854 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.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 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 ",
+ "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 is_system\n FROM property_definitions\n WHERE \n ($3 AND is_system)\n OR (\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": [
{
@@ -79,12 +79,18 @@
"ordinal": 8,
"name": "updated_at",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_system",
+ "type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int4",
- "Text"
+ "Text",
+ "Bool"
]
},
"nullable": [
@@ -96,8 +102,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "807d4e925f1cbe4c6d5de2a83413476861135a271c1a6086857b1d1f93c7cf3d"
+ "hash": "827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.json b/rust/cloud-storage/properties_db_client/.sqlx/query-9eae6bc7ff21a0c2f6f7aea33188ba4097305e77f341ac67c7d9779889ed7434.json
similarity index 89%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-9eae6bc7ff21a0c2f6f7aea33188ba4097305e77f341ac67c7d9779889ed7434.json
index 0ae51da397..d1ba0f0a0b 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-9eae6bc7ff21a0c2f6f7aea33188ba4097305e77f341ac67c7d9779889ed7434.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 AND pd.is_system = FALSE\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 pd.is_system as definition_is_system\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 ",
"describe": {
"columns": [
{
@@ -125,6 +125,11 @@
"ordinal": 14,
"name": "definition_updated_at",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "definition_is_system",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -171,8 +176,9 @@
false,
true,
false,
+ false,
false
]
},
- "hash": "737da87bf11318482132fcee1271a62fbe6556f248044122e0777a9886686bf0"
+ "hash": "9eae6bc7ff21a0c2f6f7aea33188ba4097305e77f341ac67c7d9779889ed7434"
}
diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.json b/rust/cloud-storage/properties_db_client/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.json
similarity index 74%
rename from rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.json
rename to rust/cloud-storage/properties_db_client/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.json
index 973436002a..4063a3122f 100644
--- a/rust/cloud-storage/properties_db_client/.sqlx/query-2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28.json
+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.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 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 ",
+ "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 pd.is_system,\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 ($3 AND pd.is_system)\n OR (\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": [
{
@@ -82,31 +82,36 @@
},
{
"ordinal": 9,
+ "name": "is_system",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 10,
"name": "option_id?",
"type_info": "Uuid"
},
{
- "ordinal": 10,
+ "ordinal": 11,
"name": "option_display_order?",
"type_info": "Int4"
},
{
- "ordinal": 11,
+ "ordinal": 12,
"name": "option_number_value",
"type_info": "Float8"
},
{
- "ordinal": 12,
+ "ordinal": 13,
"name": "option_string_value",
"type_info": "Text"
},
{
- "ordinal": 13,
+ "ordinal": 14,
"name": "option_created_at?",
"type_info": "Timestamptz"
},
{
- "ordinal": 14,
+ "ordinal": 15,
"name": "option_updated_at?",
"type_info": "Timestamptz"
}
@@ -114,7 +119,8 @@
"parameters": {
"Left": [
"Int4",
- "Text"
+ "Text",
+ "Bool"
]
},
"nullable": [
@@ -129,11 +135,12 @@
false,
false,
false,
+ false,
true,
true,
false,
false
]
},
- "hash": "2b6ead03620858bb4da3829775ff08046004123d7a8c865d77e4b283cf194a28"
+ "hash": "b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b"
}
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 af8f736cfc..4d219648c4 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,7 +1,4 @@
//! 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};
@@ -32,6 +29,7 @@ struct EntityPropertyRow {
specific_entity_type: Option<Option<EntityType>>,
definition_created_at: chrono::DateTime<chrono::Utc>,
definition_updated_at: chrono::DateTime<chrono::Utc>,
+ definition_is_system: bool,
values: Option<sqlx::types::JsonValue>,
}
@@ -42,8 +40,8 @@ fn row_to_entity_property_with_definition(
let owner = models_properties::PropertyOwner::from_optional_ids(
row.definition_organization_id,
row.definition_user_id,
- )
- .unwrap();
+ row.definition_is_system,
+ );
let property_definition = PropertyDefinition {
id: row.property_definition_id,
@@ -54,6 +52,7 @@ fn row_to_entity_property_with_definition(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.definition_created_at,
updated_at: row.definition_updated_at,
+ is_system: row.definition_is_system,
is_metadata: false,
};
@@ -231,6 +230,9 @@ async fn attach_property_options(
/// Gets the entity_id and entity_type for a given entity_property_id.
/// Used for permission checking before deletion.
+///
+/// Note: This excludes system properties (is_system = TRUE). System properties
+/// cannot be deleted, so this function will return None for them.
#[tracing::instrument(skip(db))]
pub async fn get_entity_type_from_entity_property(
db: &Pool<Postgres>,
@@ -239,10 +241,12 @@ pub async fn get_entity_type_from_entity_property(
let row = sqlx::query!(
r#"
SELECT
- entity_id,
- entity_type as "entity_type: EntityType"
- FROM entity_properties
- WHERE id = $1
+ ep.entity_id,
+ ep.entity_type as "entity_type: EntityType"
+ FROM entity_properties ep
+ JOIN property_definitions pd ON ep.property_definition_id = pd.id
+ WHERE ep.id = $1
+ AND pd.is_system = FALSE
"#,
entity_property_id
)
@@ -256,6 +260,7 @@ pub async fn get_entity_type_from_entity_property(
}
/// Gets entity properties with their definitions and values.
+/// Includes both custom and system properties.
#[tracing::instrument(skip(db))]
pub async fn get_entity_properties_values(
db: &Pool<Postgres>,
@@ -279,11 +284,11 @@ pub async fn get_entity_properties_values(
pd.is_multi_select,
pd.specific_entity_type as "specific_entity_type: Option<EntityType>",
pd.created_at as definition_created_at,
- pd.updated_at as definition_updated_at
+ pd.updated_at as definition_updated_at,
+ pd.is_system as definition_is_system
FROM entity_properties ep
INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id
WHERE ep.entity_id = $1 AND ep.entity_type = $2
- AND pd.is_system = FALSE
"#,
entity_id,
entity_type as EntityType
@@ -309,6 +314,7 @@ pub async fn get_entity_properties_values(
specific_entity_type: row.specific_entity_type,
definition_created_at: row.definition_created_at,
definition_updated_at: row.definition_updated_at,
+ definition_is_system: row.definition_is_system,
values: row.values,
})
})
@@ -325,6 +331,7 @@ pub async fn get_entity_properties_values(
/// Gets entity properties with their definitions and values for multiple entities.
/// Returns a HashMap where the key is the entity_id and the value is Vec<EntityPropertyWithDefinition>.
+/// Includes both custom and system properties.
#[tracing::instrument(skip(db))]
pub async fn get_bulk_entity_properties_values(
db: &Pool<Postgres>,
@@ -355,13 +362,13 @@ pub async fn get_bulk_entity_properties_values(
pd.is_multi_select,
pd.specific_entity_type as "specific_entity_type: Option<EntityType>",
pd.created_at as definition_created_at,
- pd.updated_at as definition_updated_at
+ pd.updated_at as definition_updated_at,
+ pd.is_system as definition_is_system
FROM entity_properties ep
INNER JOIN property_definitions pd ON ep.property_definition_id = pd.id
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]
@@ -390,6 +397,7 @@ pub async fn get_bulk_entity_properties_values(
specific_entity_type: row.specific_entity_type,
definition_created_at: row.definition_created_at,
definition_updated_at: row.definition_updated_at,
+ definition_is_system: row.definition_is_system,
values: row.values,
})?;
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.rs
index 60c1bad0c7..d89433b4e5 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,7 +1,4 @@
//! 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;
@@ -15,11 +12,13 @@ use uuid::Uuid;
type Result<T> = std::result::Result<T, PropertiesDatabaseError>;
/// Gets property definitions based on optional organization and optional user access.
+/// Set `include_system` to true to also include system properties.
#[tracing::instrument(skip(db))]
pub async fn get_properties(
db: &Pool<Postgres>,
organization_id: Option<i32>,
user_id: Option<&str>,
+ include_system: bool,
) -> Result<Vec<PropertyDefinition>> {
let rows = sqlx::query!(
r#"
@@ -32,18 +31,20 @@ pub async fn get_properties(
is_multi_select,
specific_entity_type as "specific_entity_type: Option<EntityType>",
created_at,
- updated_at
+ updated_at,
+ is_system
FROM property_definitions
WHERE
- is_system = FALSE
- AND (
+ ($3 AND is_system)
+ OR (
($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,
- user_id
+ user_id,
+ include_system
)
.fetch_all(db)
.await?;
@@ -61,6 +62,7 @@ pub async fn get_properties(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: row.is_system,
};
PropertyDefinition::from(db_def)
})
@@ -69,7 +71,7 @@ pub async fn get_properties(
Ok(result)
}
-/// Gets a single property definition by ID.
+/// Gets a single property definition by ID (includes system properties).
#[tracing::instrument(skip(db))]
pub async fn get_property_definition(
db: &Pool<Postgres>,
@@ -86,10 +88,10 @@ pub async fn get_property_definition(
is_multi_select,
specific_entity_type as "specific_entity_type: Option<EntityType>",
created_at,
- updated_at
+ updated_at,
+ is_system
FROM property_definitions
WHERE id = $1
- AND is_system = FALSE
"#,
property_id
)
@@ -107,6 +109,7 @@ pub async fn get_property_definition(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: row.is_system,
};
PropertyDefinition::from(db_prop)
});
@@ -115,7 +118,8 @@ pub async fn get_property_definition(
}
/// Gets a single property definition by ID with ownership validation.
-/// Returns None if the property doesn't exist or if the user doesn't own it.
+/// Returns None if the property doesn't exist, if the user doesn't own it, or if it's a system property.
+/// System properties don't have owners and should be fetched via `get_property_definition`.
#[tracing::instrument(skip(db))]
pub async fn get_property_definition_with_owner(
db: &Pool<Postgres>,
@@ -134,7 +138,8 @@ pub async fn get_property_definition_with_owner(
is_multi_select,
specific_entity_type as "specific_entity_type: Option<EntityType>",
created_at,
- updated_at
+ updated_at,
+ is_system
FROM property_definitions
WHERE id = $1
AND is_system = FALSE
@@ -161,6 +166,7 @@ pub async fn get_property_definition_with_owner(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: row.is_system,
};
PropertyDefinition::from(db_prop)
});
@@ -169,11 +175,13 @@ pub async fn get_property_definition_with_owner(
}
/// Gets property definitions with options based on organization and optional user access.
+/// Set `include_system` to true to also include system properties.
#[tracing::instrument(skip(db))]
pub async fn get_properties_with_options(
db: &Pool<Postgres>,
organization_id: Option<i32>,
user_id: Option<&str>,
+ include_system: bool,
) -> Result<Vec<PropertyDefinitionWithOptions>> {
let rows = sqlx::query!(
r#"
@@ -187,6 +195,7 @@ pub async fn get_properties_with_options(
pd.specific_entity_type as "specific_entity_type: Option<EntityType>",
pd.created_at,
pd.updated_at,
+ pd.is_system,
po.id as "option_id?",
po.display_order as "option_display_order?",
po.number_value as option_number_value,
@@ -196,15 +205,16 @@ pub async fn get_properties_with_options(
FROM property_definitions pd
LEFT JOIN property_options po ON pd.id = po.property_definition_id
WHERE
- pd.is_system = FALSE
- AND (
+ ($3 AND pd.is_system)
+ OR (
($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,
- user_id
+ user_id,
+ include_system
)
.fetch_all(db)
.await?;
@@ -215,8 +225,8 @@ pub async fn get_properties_with_options(
let owner = models_properties::PropertyOwner::from_optional_ids(
row.organization_id,
row.user_id.clone(),
- )
- .unwrap();
+ row.is_system,
+ );
let property_def = PropertyDefinition {
id: row.id,
@@ -227,6 +237,7 @@ pub async fn get_properties_with_options(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: row.is_system,
is_metadata: false,
};
@@ -300,7 +311,7 @@ mod tests {
async fn test_get_properties_by_organization(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS; // Dummy reference for IDE
- let properties = get_properties(&pool, Some(1), None).await?;
+ let properties = get_properties(&pool, Some(1), None, false).await?;
assert_eq!(properties.len(), 10); // Organization 1 has 10 properties
@@ -326,7 +337,7 @@ mod tests {
async fn test_get_properties_by_user(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let properties = get_properties(&pool, None, Some("user1")).await?;
+ let properties = get_properties(&pool, None, Some("user1"), false).await?;
assert_eq!(properties.len(), 2); // User1 has 2 properties
assert_eq!(properties[0].display_name, "Test Notes");
@@ -404,7 +415,7 @@ mod tests {
async fn test_get_properties_with_options(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let properties = get_properties_with_options(&pool, Some(1), None).await?;
+ let properties = get_properties_with_options(&pool, Some(1), None, false).await?;
assert_eq!(properties.len(), 10);
@@ -438,7 +449,7 @@ mod tests {
) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let properties = get_properties_with_options(&pool, Some(1), None).await?;
+ let properties = get_properties_with_options(&pool, Some(1), None, false).await?;
// Find non-select properties (should have 0 options)
let completed_prop = properties
@@ -459,7 +470,7 @@ mod tests {
async fn test_get_properties_with_number_options(pool: Pool<Postgres>) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let properties = get_properties_with_options(&pool, Some(1), None).await?;
+ let properties = get_properties_with_options(&pool, Some(1), None, false).await?;
// Find Score property which has number options
let score_prop = properties
@@ -491,7 +502,7 @@ mod tests {
) -> anyhow::Result<()> {
const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
- let properties = get_properties_with_options(&pool, Some(1), None).await?;
+ let properties = get_properties_with_options(&pool, Some(1), None, false).await?;
// Find Department property which is multi-select
let dept_prop = properties
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.rs
index a80872f464..48ab0201d1 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
@@ -69,6 +69,7 @@ pub async fn create_property_definition(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: false, // User-created properties are never system properties
};
Ok(PropertyDefinition::from(db_result))
@@ -159,6 +160,7 @@ pub async fn create_property_definition_with_options(
specific_entity_type: row.specific_entity_type.flatten(),
created_at: row.created_at,
updated_at: row.updated_at,
+ is_system: false, // User-created properties are never system properties
};
for option in options {
diff --git a/rust/cloud-storage/properties_service/src/api/permissions.rs b/rust/cloud-storage/properties_service/src/api/permissions.rs
index f5a973581d..6ececad7ea 100644
--- a/rust/cloud-storage/properties_service/src/api/permissions.rs
+++ b/rust/cloud-storage/properties_service/src/api/permissions.rs
@@ -7,13 +7,13 @@ use crate::api::context::ApiContext;
#[derive(Debug, Error)]
pub enum PermissionError {
- #[error("Entity type not supported for property operations")]
+ #[error("Unsupported entity type")]
UnsupportedEntityType,
- #[error("Unauthorized: user does not have sufficient access")]
+ #[error("Access denied")]
Unauthorized,
- #[error("Internal error checking permissions: {0}")]
+ #[error("An internal error occurred")]
InternalError(String),
}
@@ -30,7 +30,7 @@ impl PermissionError {
/// Checks if a user has view access to an entity (View, Comment, Edit, or Owner level).
/// Supports: Document, Chat, Project, Thread, Channel, Macro.
/// For anonymous users (empty user_id), only allows access to publicly shared entities.
-#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type))]
+#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
pub async fn check_entity_view_permission(
context: &ApiContext,
user_id: &str,
@@ -46,7 +46,7 @@ pub async fn check_entity_view_permission(
/// Checks if a user has edit access to an entity (Edit or Owner level).
/// Supports: Document, Chat, Project, Thread, Channel, Macro.
-#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type))]
+#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
pub async fn check_entity_edit_permission(
context: &ApiContext,
user_id: &str,
@@ -64,7 +64,7 @@ pub async fn check_entity_edit_permission(
///
/// NOTE: Makes a separate DB query (+ HTTP call for channels). Not worth inlining into
/// properties query due to complex recursive CTEs and entity-specific permission logic.
-#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type))]
+#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
async fn get_access_level(
context: &ApiContext,
user_id: &str,
@@ -94,7 +94,6 @@ async fn get_access_level(
tracing::error!(
status_code = ?status_code,
message = %message,
- entity_type = ?entity_ref.entity_type,
"failed to get user access level"
);
PermissionError::InternalError(message)
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
index 8597791b3b..04c6ca545f 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
@@ -18,9 +18,9 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum CreatePropertyDefinitionErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
#[error("{0}")]
InvalidRequest(String),
@@ -58,7 +58,7 @@ impl IntoResponse for CreatePropertyDefinitionErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id))]
+#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id), err)]
pub async fn create_property_definition(
State(context): State<ApiContext>,
Extension(user_context): Extension<UserContext>,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
index 9ea716bb86..7d38c37ccd 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
@@ -17,11 +17,13 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum DeletePropertyDefinitionError {
- #[error("property definition not found")]
+ #[error("Property definition not found")]
NotFound,
- #[error("internal server error")]
+ #[error("Cannot modify system properties")]
+ SystemPropertyNotModifiable,
+ #[error("An internal error occurred")]
InternalServerError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
}
@@ -29,6 +31,7 @@ impl IntoResponse for DeletePropertyDefinitionError {
fn into_response(self) -> Response {
let status_code = match &self {
DeletePropertyDefinitionError::NotFound => StatusCode::NOT_FOUND,
+ DeletePropertyDefinitionError::SystemPropertyNotModifiable => StatusCode::FORBIDDEN,
DeletePropertyDefinitionError::InternalServerError(_)
| DeletePropertyDefinitionError::DatabaseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
};
@@ -55,22 +58,30 @@ impl IntoResponse for DeletePropertyDefinitionError {
responses(
(status = 204, description = "Property definition deleted successfully"),
(status = 400, description = "Invalid property ID"),
+ (status = 403, description = "Cannot modify system properties"),
(status = 404, description = "Property definition not found"),
(status = 500, description = "Internal server error")
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context))]
+#[tracing::instrument(skip(context, user_context), err)]
pub async fn delete_property_definition(
Path(property_uuid): Path<Uuid>,
State(context): State<ApiContext>,
Extension(user_context): Extension<UserContext>,
) -> Result<Response, DeletePropertyDefinitionError> {
- tracing::info!(
- property_id = %property_uuid,
- "deleting property definition"
- );
+ tracing::info!("deleting property definition");
+ // First check if property exists and if it's a system property
+ let property = property_definitions_get::get_property_definition(&context.db, property_uuid)
+ .await?
+ .ok_or(DeletePropertyDefinitionError::NotFound)?;
+
+ if property.is_system {
+ return Err(DeletePropertyDefinitionError::SystemPropertyNotModifiable);
+ }
+
+ // Then verify ownership
let _property = property_definitions_get::get_property_definition_with_owner(
&context.db,
property_uuid,
@@ -82,10 +93,7 @@ pub async fn delete_property_definition(
property_definitions_delete::delete_property_definition(&context.db, property_uuid).await?;
- tracing::info!(
- property_id = %property_uuid,
- "successfully deleted property definition"
- );
+ tracing::info!("successfully deleted property definition");
Ok(StatusCode::NO_CONTENT.into_response())
}
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
index c04d11f904..b953d7e834 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
@@ -18,11 +18,11 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum ListPropertiesErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
- #[error("organization_id is required for org scope")]
+ #[error("Organization ID is required for org scope")]
MissingOrganizationId,
}
@@ -55,7 +55,9 @@ pub enum PropertyScope {
User,
/// Organization-scoped properties only
Org,
- /// Both user and organization properties
+ /// System properties only
+ System,
+ /// User, organization, and system properties
All,
}
@@ -82,7 +84,7 @@ pub enum PropertyDefinitionResponse {
get,
path = "/properties/definitions",
params(
- ("scope" = PropertyScope, Query, description = "Filter by scope: 'user' for user-scoped only, 'org' for organization-scoped only, 'all' for both scopes"),
+ ("scope" = PropertyScope, Query, description = "Filter by scope: 'user', 'org', 'system', or 'all'"),
("include_options" = Option<bool>, Query, description = "Whether to include property options in the response")
),
responses(
@@ -92,24 +94,28 @@ pub enum PropertyDefinitionResponse {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context))]
+#[tracing::instrument(skip(context, user_context), err)]
pub async fn list_properties(
Query(query): Query<ListPropertiesQuery>,
State(context): State<ApiContext>,
Extension(user_context): Extension<UserContext>,
) -> Result<Json<Vec<PropertyDefinitionResponse>>, ListPropertiesErr> {
- let (org_id, user_id_opt) = match query.scope {
- PropertyScope::Org => (user_context.organization_id, None),
- PropertyScope::User => (None, Some(user_context.user_id.as_str())),
+ // Determine query parameters based on scope
+ let (org_id, user_id_opt, include_system) = match query.scope {
+ PropertyScope::User => (None, Some(user_context.user_id.as_str()), false),
+ PropertyScope::Org => (user_context.organization_id, None, false),
+ PropertyScope::System => (None, None, true),
PropertyScope::All => (
user_context.organization_id,
Some(user_context.user_id.as_str()),
+ true,
),
};
tracing::info!(
organization_id = ?org_id,
scope = ?query.scope,
+ include_system = include_system,
user_id = %user_context.user_id,
"listing properties"
);
@@ -119,18 +125,22 @@ pub async fn list_properties(
}
let response = if query.include_options {
- let properties_with_options =
- property_definitions_get::get_properties_with_options(&context.db, org_id, user_id_opt)
- .await
- .inspect_err(|e| {
- tracing::error!(
- error = ?e,
- organization_id = ?org_id,
- scope = ?query.scope,
- user_id = %user_context.user_id,
- "failed to retrieve properties with options"
- );
- })?;
+ let properties_with_options = property_definitions_get::get_properties_with_options(
+ &context.db,
+ org_id,
+ user_id_opt,
+ include_system,
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ organization_id = ?org_id,
+ scope = ?query.scope,
+ user_id = %user_context.user_id,
+ "failed to retrieve properties with options"
+ );
+ })?;
let response: Vec<PropertyDefinitionResponse> = properties_with_options
.into_iter()
@@ -146,17 +156,22 @@ pub async fn list_properties(
);
response
} else {
- let properties = property_definitions_get::get_properties(&context.db, org_id, user_id_opt)
- .await
- .inspect_err(|e| {
- tracing::error!(
- error = ?e,
- organization_id = ?org_id,
- scope = ?query.scope,
- user_id = %user_context.user_id,
- "failed to retrieve properties"
- );
- })?;
+ let properties = property_definitions_get::get_properties(
+ &context.db,
+ org_id,
+ user_id_opt,
+ include_system,
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ organization_id = ?org_id,
+ scope = ?query.scope,
+ user_id = %user_context.user_id,
+ "failed to retrieve properties"
+ );
+ })?;
let response: Vec<PropertyDefinitionResponse> = properties
.into_iter()
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 64615da98e..cfa98f03c9 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
@@ -14,9 +14,9 @@ use properties_db_client::{
#[allow(dead_code)]
#[derive(Debug, Error)]
pub enum DeleteEntityErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
Internal(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
Database(#[from] PropertiesDatabaseError),
}
@@ -55,16 +55,12 @@ impl IntoResponse for DeleteEntityErr {
),
tag = "Internal"
)]
-#[tracing::instrument(skip(context))]
+#[tracing::instrument(skip(context), err)]
pub async fn delete_entity(
Path((entity_type, entity_id)): Path<(EntityType, String)>,
State(context): State<ApiContext>,
) -> Result<StatusCode, DeleteEntityErr> {
- tracing::info!(
- entity_type = %entity_type,
- entity_id = %entity_id,
- "deleting all properties for entity"
- );
+ tracing::info!("deleting all properties for entity");
let entity_reference = EntityReference {
entity_id: entity_id.clone(),
@@ -76,17 +72,11 @@ pub async fn delete_entity(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- entity_type = %entity_type,
- entity_id = %entity_id,
"failed to delete entity properties"
);
})?;
- tracing::info!(
- entity_type = %entity_type,
- entity_id = %entity_id,
- "successfully deleted all properties for entity"
- );
+ tracing::info!("successfully deleted all properties for entity");
Ok(StatusCode::NO_CONTENT)
}
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 e11a1093df..735ca1a51a 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
@@ -9,17 +9,19 @@ use uuid::Uuid;
use crate::api::context::ApiContext;
use model::user::UserContext;
use properties_db_client::{
- entity_properties::{delete as entity_properties_delete, get as entity_properties_get},
+ entity_properties::{
+ delete as entity_properties_delete, get::get_entity_type_from_entity_property,
+ },
error::PropertiesDatabaseError,
};
#[derive(Debug, Error)]
pub enum DeleteEntityPropertyErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
- #[error("Permission error: {0}")]
+ #[error("{0}")]
Permission(#[from] crate::api::permissions::PermissionError),
#[error("Entity property not found")]
NotFound,
@@ -60,37 +62,26 @@ impl IntoResponse for DeleteEntityPropertyErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), fields(entity_property_id = %entity_property_uuid, user_id = %user_context.user_id))]
+#[tracing::instrument(skip(context, user_context), fields(entity_property_id = %entity_property_uuid, user_id = %user_context.user_id), err)]
pub async fn delete_entity_property(
Path(entity_property_uuid): Path<Uuid>,
State(context): State<ApiContext>,
Extension(user_context): Extension<UserContext>,
) -> Result<StatusCode, DeleteEntityPropertyErr> {
- tracing::info!(
- entity_property_id = %entity_property_uuid,
- "removing entity property"
- );
+ tracing::info!("removing entity property");
// Get entity property metadata to check permissions
- let entity_ref = entity_properties_get::get_entity_type_from_entity_property(
- &context.db,
- entity_property_uuid,
- )
- .await
- .inspect_err(|e| {
- tracing::error!(
- error = ?e,
- entity_property_id = %entity_property_uuid,
- "failed to get entity property metadata"
- );
- })?
- .ok_or_else(|| {
- tracing::warn!(
- entity_property_id = %entity_property_uuid,
- "entity property not found"
- );
- DeleteEntityPropertyErr::NotFound
- })?;
+ // Note: get_entity_type_from_entity_property excludes system properties,
+ // so system properties will return NotFound here.
+ let entity_ref = get_entity_type_from_entity_property(&context.db, entity_property_uuid)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ "failed to get entity property metadata"
+ );
+ })?
+ .ok_or(DeleteEntityPropertyErr::NotFound)?;
tracing::debug!(
entity_id = %entity_ref.entity_id,
@@ -110,15 +101,11 @@ pub async fn delete_entity_property(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- entity_property_id = %entity_property_uuid,
"failed to remove entity property"
);
})?;
- tracing::info!(
- entity_property_id = %entity_property_uuid,
- "successfully removed entity property"
- );
+ tracing::info!("successfully removed entity property");
Ok(StatusCode::NO_CONTENT)
}
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 8eb3fd88b6..e7b53e5f7e 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
@@ -18,15 +18,15 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum GetEntityPropertiesErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
Internal(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
Database(#[from] PropertiesDatabaseError),
- #[error("Document metadata error: {0}")]
+ #[error("{0}")]
Metadata(#[from] crate::api::properties::metadata::MetadataError),
- #[error("Permission error: {0}")]
+ #[error("{0}")]
Permission(#[from] crate::api::permissions::PermissionError),
}
@@ -69,7 +69,7 @@ impl IntoResponse for GetEntityPropertiesErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id, entity_type = ?entity_type, include_metadata = query.include_metadata))]
+#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id, entity_type = ?entity_type, include_metadata = query.include_metadata), err)]
pub async fn get_entity_properties(
Path((entity_type, entity_id)): Path<(EntityType, String)>,
Query(query): Query<EntityQueryParams>,
@@ -78,8 +78,6 @@ pub async fn get_entity_properties(
) -> Result<Json<EntityPropertiesResponse>, GetEntityPropertiesErr> {
tracing::info!(
entity_id = %entity_id,
- entity_type = ?entity_type,
- include_metadata = query.include_metadata,
"retrieving entity properties"
);
@@ -126,7 +124,6 @@ pub async fn get_entity_properties(
tracing::error!(
error = ?e,
entity_id = %entity_id,
- entity_type = ?entity_type,
"failed to retrieve entity properties from database"
);
})?;
@@ -135,7 +132,6 @@ pub async fn get_entity_properties(
tracing::error!(
error = ?e,
entity_id = %entity_id,
- entity_type = ?entity_type,
"failed to get document system properties"
);
})?;
@@ -154,7 +150,6 @@ pub async fn get_entity_properties(
tracing::error!(
error = ?e,
entity_id = %entity_id,
- entity_type = ?entity_type,
"failed to retrieve entity properties from database"
);
})?;
@@ -173,8 +168,6 @@ pub async fn get_entity_properties(
tracing::info!(
entity_id = %entity_id,
properties_count = response.properties.len(),
- include_metadata = query.include_metadata,
- user_id = %user_context.user_id,
"successfully retrieved entity properties"
);
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
index 1ff5fdc3d3..6ff913fcb3 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
@@ -17,11 +17,11 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum GetBulkEntityPropertiesErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
- #[error("Invalid request: entities array cannot be empty")]
+ #[error("Entities array cannot be empty")]
InvalidRequest,
}
@@ -57,7 +57,7 @@ impl IntoResponse for GetBulkEntityPropertiesErr {
),
tag = "Internal"
)]
-#[tracing::instrument(skip(context, request), fields(entity_count = request.entities.len()))]
+#[tracing::instrument(skip(context, request), fields(entity_count = request.entities.len()), err)]
pub async fn get_bulk_entity_properties(
State(context): State<ApiContext>,
Json(request): Json<BulkEntityPropertiesRequest>,
@@ -67,10 +67,7 @@ pub async fn get_bulk_entity_properties(
return Err(GetBulkEntityPropertiesErr::InvalidRequest);
}
- tracing::info!(
- entity_count = request.entities.len(),
- "retrieving bulk entity properties"
- );
+ tracing::info!("retrieving bulk entity properties");
let bulk_properties =
entity_properties_get::get_bulk_entity_properties_values(&context.db, &request.entities)
@@ -78,7 +75,6 @@ pub async fn get_bulk_entity_properties(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- entity_count = request.entities.len(),
"failed to retrieve bulk entity properties"
);
})?;
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 a8e1a4d409..ab69e194c0 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
@@ -19,17 +19,17 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum SetEntityPropertyErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
- #[error("Permission error: {0}")]
+ #[error("{0}")]
Permission(#[from] crate::api::permissions::PermissionError),
#[error("Property definition not found")]
PropertyNotFound,
#[error("{0}")]
InvalidRequest(String),
- #[error("One or more option IDs do not belong to this property")]
+ #[error("Invalid property options")]
InvalidPropertyOptions,
}
@@ -75,7 +75,7 @@ impl IntoResponse for SetEntityPropertyErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(entity_id = %entity_id, property_id = %property_uuid, entity_type = ?entity_type, user_id = %user_context.user_id, request = ?request))]
+#[tracing::instrument(skip(context, user_context), fields(entity_id = %entity_id, property_id = %property_uuid, entity_type = ?entity_type, user_id = %user_context.user_id, request = ?request), err)]
pub async fn set_entity_property(
Path((entity_type, entity_id, property_uuid)): Path<(EntityType, String, Uuid)>,
State(context): State<ApiContext>,
@@ -101,17 +101,10 @@ pub async fn set_entity_property(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- property_id = %property_uuid,
"failed to get property definition"
);
})?
- .ok_or_else(|| {
- tracing::error!(
- property_id = %property_uuid,
- "property definition not found"
- );
- SetEntityPropertyErr::PropertyNotFound
- })?;
+ .ok_or(SetEntityPropertyErr::PropertyNotFound)?;
// Determine the value to set (if any) and validate
let property_value = match &request.value {
@@ -122,7 +115,6 @@ pub async fn set_entity_property(
property_definition.is_multi_select,
) {
tracing::error!(
- property_id = %property_uuid,
data_type = ?property_definition.data_type,
is_multi_select = property_definition.is_multi_select,
value_type = ?value,
@@ -155,8 +147,6 @@ pub async fn set_entity_property(
if matches!(e, PropertiesDatabaseError::InvalidPropertyOptions { .. }) {
tracing::warn!(
error = %e,
- entity_id = %entity_id,
- property_id = %property_uuid,
"invalid property options provided"
);
return SetEntityPropertyErr::InvalidPropertyOptions;
@@ -186,8 +176,6 @@ pub async fn set_entity_property(
if matches!(e, PropertiesDatabaseError::InvalidPropertyOptions { .. }) {
tracing::warn!(
error = %e,
- entity_id = %entity_id,
- property_id = %property_uuid,
"invalid property options provided"
);
return SetEntityPropertyErr::InvalidPropertyOptions;
@@ -195,9 +183,6 @@ pub async fn set_entity_property(
tracing::error!(
error = ?e,
- entity_id = %entity_id,
- property_id = %property_uuid,
- entity_type = ?entity_type,
"failed to set entity property"
);
SetEntityPropertyErr::InternalError(anyhow::anyhow!(
@@ -206,13 +191,7 @@ pub async fn set_entity_property(
))
})?;
- tracing::info!(
- entity_id = %entity_id,
- property_id = %property_uuid,
- entity_type = ?entity_type,
- has_value = has_value,
- "successfully set entity property"
- );
+ tracing::info!(has_value = has_value, "successfully set entity property");
Ok(StatusCode::NO_CONTENT)
}
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 f1e222295b..a5ba3a67c6 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/metadata.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/metadata.rs
@@ -14,7 +14,7 @@ pub enum MetadataError {
#[error("Document not found")]
NotFound,
- #[error("Failed to fetch document metadata from database: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
}
@@ -36,13 +36,7 @@ pub async fn get_document_metadata_properties(
"failed to get document metadata from database"
);
})?
- .ok_or_else(|| {
- tracing::warn!(
- document_id = %document_id,
- "document not found in database"
- );
- MetadataError::NotFound
- })?;
+ .ok_or(MetadataError::NotFound)?;
tracing::debug!(
document_id = %document_id,
@@ -56,7 +50,7 @@ pub async fn get_document_metadata_properties(
// 1. Document name property
if !document_metadata.name.is_empty() {
- metadata_properties.push(create_system_property_str(
+ metadata_properties.push(create_metadata_property_str(
metadata::DOCUMENT_NAME,
models_properties::DataType::String,
document_metadata.name,
@@ -70,7 +64,7 @@ pub async fn get_document_metadata_properties(
entity_id: document_metadata.owner,
entity_type: EntityType::User,
};
- metadata_properties.push(create_system_property_entity_ref(
+ metadata_properties.push(create_metadata_property_entity_ref(
metadata::OWNER,
models_properties::DataType::Entity,
owner_entity_ref,
@@ -79,7 +73,7 @@ pub async fn get_document_metadata_properties(
}
// 3. Created time property
- metadata_properties.push(create_system_property_date(
+ metadata_properties.push(create_metadata_property_date(
metadata::CREATED_AT,
models_properties::DataType::Date,
document_metadata.created_at,
@@ -87,7 +81,7 @@ pub async fn get_document_metadata_properties(
));
// 4. Last updated time property
- metadata_properties.push(create_system_property_date(
+ metadata_properties.push(create_metadata_property_date(
metadata::LAST_UPDATED,
models_properties::DataType::Date,
document_metadata.updated_at,
@@ -100,7 +94,7 @@ pub async fn get_document_metadata_properties(
entity_id: project_id,
entity_type: EntityType::Project,
};
- metadata_properties.push(create_system_property_entity_ref(
+ metadata_properties.push(create_metadata_property_entity_ref(
metadata::PROJECT,
models_properties::DataType::Entity,
project_entity_ref,
@@ -108,7 +102,7 @@ pub async fn get_document_metadata_properties(
));
} else {
// Add project property with null value
- metadata_properties.push(create_system_property_null(
+ metadata_properties.push(create_metadata_property_null(
metadata::PROJECT,
models_properties::DataType::Entity,
EntityType::Document,
@@ -118,54 +112,52 @@ pub async fn get_document_metadata_properties(
tracing::debug!(
document_id = %document_id,
metadata_properties_count = metadata_properties.len(),
- "created document system properties"
+ "created document metadata properties"
);
Ok(metadata_properties)
}
-/// Create a system property with a value (metadata properties are always single-value)
-pub fn create_system_property_str(
+/// Create a metadata property with a string value
+pub fn create_metadata_property_str(
display_name: &str,
data_type: models_properties::DataType,
value: String,
entity_type: EntityType,
) -> EntityPropertyWithDefinition {
let property_value = PropertyValue::Str(value);
- create_system_property_inner(display_name, data_type, Some(property_value), entity_type)
+ create_metadata_property_inner(display_name, data_type, Some(property_value), entity_type)
}
-pub fn create_system_property_date(
+pub fn create_metadata_property_date(
display_name: &str,
data_type: models_properties::DataType,
value: chrono::DateTime<chrono::Utc>,
entity_type: EntityType,
) -> EntityPropertyWithDefinition {
let property_value = PropertyValue::Date(value);
- create_system_property_inner(display_name, data_type, Some(property_value), entity_type)
+ create_metadata_property_inner(display_name, data_type, Some(property_value), entity_type)
}
-pub fn create_system_property_entity_ref(
+pub fn create_metadata_property_entity_ref(
display_name: &str,
data_type: models_properties::DataType,
value: EntityReference,
entity_type: EntityType,
) -> EntityPropertyWithDefinition {
let property_value = PropertyValue::EntityRef(vec![value]);
- create_system_property_inner(display_name, data_type, Some(property_value), entity_type)
+ create_metadata_property_inner(display_name, data_type, Some(property_value), entity_type)
}
-fn create_system_property_inner(
+fn create_metadata_property_inner(
display_name: &str,
data_type: models_properties::DataType,
value: Option<PropertyValue>,
entity_type: EntityType,
) -> EntityPropertyWithDefinition {
- // System properties don't have a real owner, use a placeholder
- // These are computed on-the-fly and never persisted
- let owner = models_properties::PropertyOwner::User {
- user_id: String::new(),
- };
+ // Metadata properties are computed on-the-fly and never persisted
+ // Use System owner since they don't belong to any user or org
+ let owner = models_properties::PropertyOwner::System;
let property_definition = PropertyDefinition {
id: METADATA_PROPERTY_ID,
@@ -176,6 +168,7 @@ fn create_system_property_inner(
specific_entity_type: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
+ is_system: false, // Metadata properties are not DB-stored system properties
is_metadata: true,
};
@@ -196,11 +189,11 @@ fn create_system_property_inner(
}
}
-/// Helper function to create a system property with null/empty value
-pub fn create_system_property_null(
+/// Create a metadata property with null/empty value
+pub fn create_metadata_property_null(
property_name: &str,
data_type: models_properties::DataType,
entity_type: EntityType,
) -> EntityPropertyWithDefinition {
- create_system_property_inner(property_name, data_type, None, entity_type)
+ create_metadata_property_inner(property_name, data_type, None, entity_type)
}
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/create.rs b/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
index 858be4f6ec..2f6d385224 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
@@ -18,12 +18,14 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum AddPropertyOptionErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
- #[error("Property not found")]
+ #[error("Property definition not found")]
PropertyNotFound,
+ #[error("Cannot modify system properties")]
+ SystemPropertyNotModifiable,
#[error("{0}")]
InvalidRequest(String),
}
@@ -35,6 +37,7 @@ impl IntoResponse for AddPropertyOptionErr {
StatusCode::INTERNAL_SERVER_ERROR
}
AddPropertyOptionErr::PropertyNotFound => StatusCode::NOT_FOUND,
+ AddPropertyOptionErr::SystemPropertyNotModifiable => StatusCode::FORBIDDEN,
AddPropertyOptionErr::InvalidRequest(_) => StatusCode::BAD_REQUEST,
};
@@ -61,12 +64,13 @@ impl IntoResponse for AddPropertyOptionErr {
responses(
(status = 201, description = "Property option created successfully", body = PropertyOption),
(status = 400, description = "Invalid request"),
+ (status = 403, description = "Cannot modify system properties"),
(status = 404, description = "Property not found"),
(status = 500, description = "Internal server error")
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(property_id = %property_uuid, request = ?request))]
+#[tracing::instrument(skip(context, user_context), fields(property_id = %property_uuid, request = ?request), err)]
pub async fn add_property_option(
Path(property_uuid): Path<Uuid>,
State(context): State<ApiContext>,
@@ -75,6 +79,22 @@ pub async fn add_property_option(
) -> Result<(StatusCode, Json<PropertyOption>), AddPropertyOptionErr> {
tracing::info!("adding property option");
+ // First check if property exists and if it's a system property
+ let property = property_definitions_get::get_property_definition(&context.db, property_uuid)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ "failed to fetch property definition"
+ );
+ })?
+ .ok_or(AddPropertyOptionErr::PropertyNotFound)?;
+
+ if property.is_system {
+ return Err(AddPropertyOptionErr::SystemPropertyNotModifiable);
+ }
+
+ // Then verify ownership
let property_definition = property_definitions_get::get_property_definition_with_owner(
&context.db,
property_uuid,
@@ -84,16 +104,14 @@ pub async fn add_property_option(
.await
.inspect_err(|e| {
tracing::error!(
- property_id = %property_uuid,
error = ?e,
- "failed to fetch property definition"
+ "failed to fetch property definition with owner"
);
})?
.ok_or(AddPropertyOptionErr::PropertyNotFound)?;
if let Err(err) = request.validate() {
tracing::error!(
- property_id = %property_uuid,
error = %err,
"option value validation failed"
);
@@ -102,7 +120,6 @@ pub async fn add_property_option(
if let Err(err) = request.validate_compatibility(&property_definition.data_type) {
tracing::error!(
- property_id = %property_uuid,
data_type = ?property_definition.data_type,
request_type = ?request,
error = %err,
@@ -132,13 +149,11 @@ pub async fn add_property_option(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- property_id = %property_uuid,
"failed to add property option"
);
})?;
tracing::info!(
- property_id = %property_uuid,
option_id = %option.id,
display_order = option.display_order,
"successfully added property option"
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs b/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
index 36f19b9e73..4bcea43499 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
@@ -16,12 +16,14 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum DeletePropertyOptionErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
InternalError(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
DatabaseError(#[from] PropertiesDatabaseError),
#[error("Property definition not found")]
PropertyNotFound,
+ #[error("Cannot modify system properties")]
+ SystemPropertyNotModifiable,
#[error("Property option not found")]
OptionNotFound,
}
@@ -34,6 +36,7 @@ impl IntoResponse for DeletePropertyOptionErr {
DeletePropertyOptionErr::PropertyNotFound | DeletePropertyOptionErr::OptionNotFound => {
StatusCode::NOT_FOUND
}
+ DeletePropertyOptionErr::SystemPropertyNotModifiable => StatusCode::FORBIDDEN,
};
if status_code.is_server_error() {
@@ -59,23 +62,36 @@ impl IntoResponse for DeletePropertyOptionErr {
responses(
(status = 204, description = "Property option deleted successfully"),
(status = 400, description = "Invalid option ID"),
+ (status = 403, description = "Cannot modify system properties"),
(status = 404, description = "Property option not found"),
(status = 500, description = "Internal server error")
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context))]
+#[tracing::instrument(skip(context, user_context), err)]
pub async fn delete_property_option(
Path((def_uuid, option_uuid)): Path<(Uuid, Uuid)>,
State(context): State<ApiContext>,
Extension(user_context): Extension<UserContext>,
) -> Result<StatusCode, DeletePropertyOptionErr> {
- tracing::info!(
- def_id = %def_uuid,
- option_id = %option_uuid,
- "deleting property option"
- );
+ tracing::info!("deleting property option");
+ // First check if property exists and if it's a system property
+ let property = property_definitions_get::get_property_definition(&context.db, def_uuid)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ "failed to fetch property definition"
+ );
+ })?
+ .ok_or(DeletePropertyOptionErr::PropertyNotFound)?;
+
+ if property.is_system {
+ return Err(DeletePropertyOptionErr::SystemPropertyNotModifiable);
+ }
+
+ // Then verify ownership
let _property_definition = property_definitions_get::get_property_definition_with_owner(
&context.db,
def_uuid,
@@ -86,44 +102,22 @@ pub async fn delete_property_option(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- def_id = %def_uuid,
- "failed to fetch property definition"
+ "failed to fetch property definition with owner"
);
})?
- .ok_or_else(|| {
- tracing::warn!(
- def_id = %def_uuid,
- "property definition not found"
- );
- DeletePropertyOptionErr::PropertyNotFound
- })?;
+ .ok_or(DeletePropertyOptionErr::PropertyNotFound)?;
let option = property_options_get::get_property_option_by_id(&context.db, option_uuid)
.await
.inspect_err(|e| {
tracing::error!(
error = ?e,
- def_id = %def_uuid,
- option_id = %option_uuid,
"failed to fetch property option"
);
})?
- .ok_or_else(|| {
- tracing::warn!(
- def_id = %def_uuid,
- option_id = %option_uuid,
- "property option not found"
- );
- DeletePropertyOptionErr::OptionNotFound
- })?;
+ .ok_or(DeletePropertyOptionErr::OptionNotFound)?;
if option.property_definition_id != def_uuid {
- tracing::warn!(
- def_id = %def_uuid,
- option_id = %option_uuid,
- actual_def_id = %option.property_definition_id,
- "property option does not belong to specified definition"
- );
return Err(DeletePropertyOptionErr::OptionNotFound);
}
@@ -132,25 +126,14 @@ pub async fn delete_property_option(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- def_id = %def_uuid,
- option_id = %option_uuid,
"failed to delete property option"
);
})?;
if deleted {
- tracing::info!(
- def_id = %def_uuid,
- option_id = %option_uuid,
- "successfully deleted property option"
- );
+ tracing::info!("successfully deleted property option");
Ok(StatusCode::NO_CONTENT)
} else {
- tracing::error!(
- def_id = %def_uuid,
- option_id = %option_uuid,
- "property option disappeared between fetch and delete"
- );
Err(DeletePropertyOptionErr::OptionNotFound)
}
}
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/get.rs b/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
index deaa56bf5f..0ae0f9c8a5 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
@@ -16,9 +16,9 @@ use properties_db_client::{
#[derive(Debug, Error)]
pub enum GetPropertyOptionsErr {
- #[error("An unknown error has occurred")]
+ #[error("An internal error occurred")]
Internal(#[from] anyhow::Error),
- #[error("Database error: {0}")]
+ #[error("An internal error occurred")]
Database(#[from] PropertiesDatabaseError),
}
@@ -56,7 +56,7 @@ impl IntoResponse for GetPropertyOptionsErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, _user_context))]
+#[tracing::instrument(skip(context, _user_context), err)]
pub async fn get_property_options(
Path(property_uuid): Path<Uuid>,
State(context): State<ApiContext>,
@@ -69,13 +69,11 @@ pub async fn get_property_options(
.inspect_err(|e| {
tracing::error!(
error = ?e,
- property_id = %property_uuid,
"failed to retrieve property options"
);
})?;
tracing::info!(
- property_id = %property_uuid,
options_count = options.len(),
"successfully retrieved property options"
);