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
fix [properties] - only allow entity type tasks to have parent and subtask properties (#616)
Daniel Kweond08cabbeb514
diff --git a/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx b/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsxindex 2aaa9de3b0..f197147a9b 100644--- a/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx+++ b/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx@@ -34,7 +34,11 @@ export function SelectPropertyModal(props: PropertySelectorProps) {filteredProperties,fetchAvailableProperties,togglePropertySelection,- } = usePropertySelection(props.existingPropertyIds, () => searchQuery());+ } = usePropertySelection(+ props.existingPropertyIds,+ () => searchQuery(),+ entityType+ );const handleAddProperties = async () => {const selected = state().selectedPropertyIds;diff --git a/js/app/packages/core/component/Properties/hooks/usePropertySelection.ts b/js/app/packages/core/component/Properties/hooks/usePropertySelection.tsindex 1bdf8533ef..ac6be9d6b7 100644--- a/js/app/packages/core/component/Properties/hooks/usePropertySelection.ts+++ b/js/app/packages/core/component/Properties/hooks/usePropertySelection.ts@@ -1,5 +1,6 @@import { isErr } from '@core/util/maybeResult';import { propertiesServiceClient } from '@service-properties/client';+import type { EntityType } from '@service-properties/generated/schemas/entityType';import { createMemo, createSignal } from 'solid-js';import type { PropertyDefinitionFlat } from '../types';import { ERROR_MESSAGES } from '../utils/errorHandling';@@ -14,10 +15,14 @@ export interface PropertySelectionState {/*** Hook for managing property selection in the "Add Properties" modal* Handles fetching available properties, filtering, and tracking selections+ * @param existingPropertyIds - IDs of properties already attached to the entity+ * @param searchQuery - Optional search query for filtering+ * @param entityType - Optional entity type to filter properties applicable to this type*/export function usePropertySelection(existingPropertyIds: () => string[],- searchQuery?: () => string+ searchQuery?: () => string,+ entityType?: EntityType) {const [state, setState] = createSignal<PropertySelectionState>({availableProperties: [],@@ -75,6 +80,7 @@ export function usePropertySelection(const result = await propertiesServiceClient.listProperties({scope: 'all',include_options: true,+ for_entity_type: entityType,});if (isErr(result)) {diff --git a/js/app/packages/service-clients/service-properties/client.ts b/js/app/packages/service-clients/service-properties/client.tsindex 963b537967..8c5f0b41b1 100644--- a/js/app/packages/service-clients/service-properties/client.ts+++ b/js/app/packages/service-clients/service-properties/client.ts@@ -87,6 +87,9 @@ export const propertiesServiceClient = {if (args.include_options !== undefined) {queryParams.set('include_options', String(args.include_options));}+ if (args.for_entity_type !== undefined && args.for_entity_type !== null) {+ queryParams.set('for_entity_type', args.for_entity_type);+ }return await propertiesFetch<PropertyDefinitionResponse[]>(`/properties/definitions?${queryParams}`,diff --git a/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesParams.ts b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesParams.tsindex 602d3d6580..8252ba1ae7 100644--- a/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesParams.ts+++ b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesParams.ts@@ -5,6 +5,7 @@* OpenAPI spec version: 0.1.0*/import type { PropertyScope } from './propertyScope';+import type { EntityType } from './entityType';export type ListPropertiesParams = {/**@@ -15,4 +16,8 @@ scope: PropertyScope;* Whether to include property options in the response*/include_options?: boolean;+/**+ * Filter properties applicable to a specific entity type+ */+for_entity_type?: EntityType;};diff --git a/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQuery.ts b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQuery.tsindex 31b826b4a9..5001fb49d9 100644--- a/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQuery.ts+++ b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQuery.ts@@ -4,12 +4,14 @@* properties_service* OpenAPI spec version: 0.1.0*/+import type { ListPropertiesQueryForEntityType } from './listPropertiesQueryForEntityType';import type { PropertyScope } from './propertyScope';/*** Query parameters for listing properties*/export interface ListPropertiesQuery {+ for_entity_type?: ListPropertiesQueryForEntityType;/** Whether to include property options in the response */include_options?: boolean;/** Scope filter for properties */diff --git a/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQueryForEntityType.ts b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQueryForEntityType.tsnew file mode 100644index 0000000000..ac09d666c2--- /dev/null+++ b/js/app/packages/service-clients/service-properties/generated/schemas/listPropertiesQueryForEntityType.ts@@ -0,0 +1,9 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * properties_service+ * OpenAPI spec version: 0.1.0+ */+import type { EntityType } from './entityType';++export type ListPropertiesQueryForEntityType = null | EntityType;diff --git a/js/app/packages/service-clients/service-properties/generated/zod.ts b/js/app/packages/service-clients/service-properties/generated/zod.tsindex 7fcc54b8a4..28d4f77267 100644--- a/js/app/packages/service-clients/service-properties/generated/zod.ts+++ b/js/app/packages/service-clients/service-properties/generated/zod.ts@@ -14,7 +14,8 @@ import {*/export const listPropertiesQueryParams = zod.object({"scope": zod.enum(['user', 'org', 'system', 'all']).describe('Filter by scope: \'user\', \'org\', \'system\', or \'all\''),- "include_options": zod.boolean().optional().describe('Whether to include property options in the response')+ "include_options": zod.boolean().optional().describe('Whether to include property options in the response'),+ "for_entity_type": zod.enum(['CHANNEL', 'CHAT', 'COMPANY', 'DOCUMENT', 'PROJECT', 'TASK', 'THREAD', 'USER']).optional().describe('Filter properties applicable to a specific entity type')})export const listPropertiesResponseItem = zod.union([zod.object({diff --git a/js/app/packages/service-clients/service-properties/openapi.json b/js/app/packages/service-clients/service-properties/openapi.jsonindex 8075cd836c..513fbd5531 100644--- a/js/app/packages/service-clients/service-properties/openapi.json+++ b/js/app/packages/service-clients/service-properties/openapi.json@@ -27,6 +27,13 @@"description": "Whether to include property options in the response","required": false,"schema": { "type": "boolean" }+ },+ {+ "name": "for_entity_type",+ "in": "query",+ "description": "Filter properties applicable to a specific entity type",+ "required": false,+ "schema": { "$ref": "#/components/schemas/EntityType" }}],"responses": {@@ -535,6 +542,15 @@"description": "Query parameters for listing properties","required": ["scope"],"properties": {+ "for_entity_type": {+ "oneOf": [+ { "type": "null" },+ {+ "$ref": "#/components/schemas/EntityType",+ "description": "Filter properties applicable to a specific entity type.\nWhen provided, excludes properties that cannot be attached to this entity type\n(e.g., Parent Task and Subtasks are excluded for non-task entities)."+ }+ ]+ },"include_options": {"type": "boolean","description": "Whether to include property options in the 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.rsindex b953d7e834..8f25ff0a3d 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@@ -10,11 +10,13 @@ use utoipa::ToSchema;use crate::api::context::ApiContext;use model::user::UserContext;+use models_properties::EntityType;use models_properties::service::property_definition::PropertyDefinition;use models_properties::service::property_definition_with_options::PropertyDefinitionWithOptions;use properties_db_client::{error::PropertiesDatabaseError, property_definitions::get as property_definitions_get,};+use system_properties::SystemPropertyKey;#[derive(Debug, Error)]pub enum ListPropertiesErr {@@ -69,6 +71,10 @@ pub struct ListPropertiesQuery {/// Whether to include property options in the response#[serde(default)]pub include_options: bool,+ /// Filter properties applicable to a specific entity type.+ /// When provided, excludes properties that cannot be attached to this entity type+ /// (e.g., Parent Task and Subtasks are excluded for non-task entities).+ pub for_entity_type: Option<EntityType>,}/// Response for property definition with optional property options@@ -85,7 +91,8 @@ pub enum PropertyDefinitionResponse {path = "/properties/definitions",params(("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")+ ("include_options" = Option<bool>, Query, description = "Whether to include property options in the response"),+ ("for_entity_type" = Option<EntityType>, Query, description = "Filter properties applicable to a specific entity type")),responses((status = 200, description = "Properties retrieved successfully", body = Vec<PropertyDefinitionResponse>),@@ -116,10 +123,13 @@ pub async fn list_properties(organization_id = ?org_id,scope = ?query.scope,include_system = include_system,+ for_entity_type = ?query.for_entity_type,user_id = %user_context.user_id,"listing properties");+ let filter_entity_type = query.for_entity_type;+if query.scope == PropertyScope::Org && org_id.is_none() {return Err(ListPropertiesErr::MissingOrganizationId);}@@ -144,6 +154,11 @@ pub async fn list_properties(let response: Vec<PropertyDefinitionResponse> = properties_with_options.into_iter()+ .filter(|p| {+ filter_entity_type+ .map(|et| is_property_applicable_to(p.definition.id, et))+ .unwrap_or(true)+ }).map(PropertyDefinitionResponse::WithOptions).collect();@@ -175,6 +190,11 @@ pub async fn list_properties(let response: Vec<PropertyDefinitionResponse> = properties.into_iter()+ .filter(|p| {+ filter_entity_type+ .map(|et| is_property_applicable_to(p.id, et))+ .unwrap_or(true)+ }).map(PropertyDefinitionResponse::Simple).collect();@@ -190,3 +210,15 @@ pub async fn list_properties(Ok(Json(response))}++/// Check if a property can be attached to the given entity type.+pub fn is_property_applicable_to(property_id: uuid::Uuid, entity_type: EntityType) -> bool {+ // Task-only properties: Parent Task and Subtasks+ if property_id == SystemPropertyKey::PARENT_TASK_UUID+ || property_id == SystemPropertyKey::SUBTASKS_UUID+ {+ return entity_type == EntityType::Task;+ }++ true+}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.rsindex c3e0871d6a..c4a804ced0 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@@ -9,7 +9,12 @@ use system_properties::SystemPropertyKey;use thiserror::Error;use uuid::Uuid;-use crate::api::{context::ApiContext, properties::entities::types::SetEntityPropertyRequest};+use crate::api::{+ context::ApiContext,+ properties::{+ definitions::list::is_property_applicable_to, entities::types::SetEntityPropertyRequest,+ },+};use model::user::UserContext;use models_properties::service::property_value::PropertyValue;use models_properties::{EntityReference, EntityType, api::SetPropertyValue};@@ -162,10 +167,17 @@ pub async fn set_entity_property(tracing::debug!(has_value = has_value, "setting property in database");+ // Check if this property can be attached to the given entity type+ if !is_property_applicable_to(property_uuid, entity_type) {+ return Err(SetEntityPropertyErr::InvalidRequest(+ "This property cannot be attached to this entity type".to_string(),+ ));+ }+// Handle bidirectional linking for task Parent Task / Subtasks properties- if entity_type == EntityType::Task- && (property_uuid == SystemPropertyKey::PARENT_TASK_UUID- || property_uuid == SystemPropertyKey::SUBTASKS_UUID)+ // (if is_parent_or_subtask_property is true, entity_type is guaranteed to be Task by the earlier check)+ if property_uuid == SystemPropertyKey::PARENT_TASK_UUID+ || property_uuid == SystemPropertyKey::SUBTASKS_UUID{let task_id = Uuid::parse_str(&entity_id).map_err(|_| SetEntityPropertyErr::InvalidRequest("Invalid task ID".to_string()))?;