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
feat: update code file type in backend (#2368)
gbirman97798f4ca936
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgs.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgs.tsindex 975f98f5ee..3242a56cff 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgs.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgs.ts@@ -5,6 +5,7 @@* OpenAPI spec version: 0.1.0*/import type { EditDocumentServiceArgsDocumentName } from './editDocumentServiceArgsDocumentName';+import type { EditDocumentServiceArgsFileType } from './editDocumentServiceArgsFileType';import type { EditDocumentServiceArgsProjectId } from './editDocumentServiceArgsProjectId';import type { EditDocumentServiceArgsSharePermission } from './editDocumentServiceArgsSharePermission';@@ -14,6 +15,7 @@ import type { EditDocumentServiceArgsSharePermission } from './editDocumentServiexport interface EditDocumentServiceArgs {/** The name of the document. */documentName?: EditDocumentServiceArgsDocumentName;+ fileType?: EditDocumentServiceArgsFileType;/** The new project id of the document. */projectId?: EditDocumentServiceArgsProjectId;sharePermission?: EditDocumentServiceArgsSharePermission;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgsFileType.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgsFileType.tsnew file mode 100644index 0000000000..c5f3dadaef--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editDocumentServiceArgsFileType.ts@@ -0,0 +1,9 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */+import type { FileTypeUpdate } from './fileTypeUpdate';++export type EditDocumentServiceArgsFileType = null | FileTypeUpdate;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdate.ts b/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdate.tsnew file mode 100644index 0000000000..e80242454e--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdate.ts@@ -0,0 +1,12 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */+import type { FileTypeUpdateOneOf } from './fileTypeUpdateOneOf';++/**+ * Represents a file type update: either set to a specific type or clear to null.+ */+export type FileTypeUpdate = FileTypeUpdateOneOf | 'clear';diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdateOneOf.ts b/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdateOneOf.tsnew file mode 100644index 0000000000..90237cd541--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/fileTypeUpdateOneOf.ts@@ -0,0 +1,15 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */+import type { FileType } from './fileType';++/**+ * Set the file type to a specific value.+ */+export type FileTypeUpdateOneOf = {+ /** Set the file type to a specific value. */+ set: FileType;+};diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.tsindex e12327f24a..6f10acd29d 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts@@ -251,6 +251,7 @@ export * from './editCommentResponseAllOfFileType';export * from './editDocumentResponse';export * from './editDocumentServiceArgs';export * from './editDocumentServiceArgsDocumentName';+export * from './editDocumentServiceArgsFileType';export * from './editDocumentServiceArgsProjectId';export * from './editDocumentServiceArgsSharePermission';export * from './editPdfAnchorRequest';@@ -298,6 +299,8 @@ export * from './fileSystemNodeWithIdsOneOfThreeContent';export * from './fileSystemNodeWithIdsOneOfThreeType';export * from './fileSystemNodeWithIdsOneOfType';export * from './fileType';+export * from './fileTypeUpdate';+export * from './fileTypeUpdateOneOf';export * from './folderItem';export * from './folderItemFileType';export * from './genericErrorResponse';diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex fbc04df47c..e191135ac4 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -2136,6 +2136,450 @@ export const editDocumentParams = zod.object({export const editDocumentBody = zod.object({documentName: zod.string().nullish().describe('The name of the document.'),+ fileType: zod+ .union([+ zod.null(),+ zod+ .union([+ zod+ .object({+ set: zod+ .enum([+ 'docx',+ 'pdf',+ 'md',+ 'canvas',+ 'coffee',+ 'cson',+ 'iced',+ 'c',+ 'i',+ 'cpp',+ 'cppm',+ 'cc',+ 'ccm',+ 'cxx',+ 'cxxm',+ 'cplusplus',+ 'cplusplusm',+ 'hpp',+ 'hh',+ 'hxx',+ 'hplusplus',+ 'h',+ 'ii',+ 'ino',+ 'inl',+ 'ipp',+ 'ixx',+ 'tpp',+ 'txx',+ 'hppin',+ 'hin',+ 'cu',+ 'cuh',+ 'cs',+ 'csx',+ 'cake',+ 'css',+ 'dart',+ 'diff',+ 'patch',+ 'rej',+ 'dockerfile',+ 'containerfile',+ 'go',+ 'handlebars',+ 'hbs',+ 'hjs',+ 'hlsl',+ 'hlsli',+ 'fx',+ 'fxh',+ 'vsh',+ 'psh',+ 'cginc',+ 'compute',+ 'html',+ 'htm',+ 'shtml',+ 'xhtml',+ 'xht',+ 'mdoc',+ 'jsp',+ 'asp',+ 'aspx',+ 'jshtm',+ 'volt',+ 'ejs',+ 'rhtml',+ 'ini',+ 'conf',+ 'properties',+ 'cfg',+ 'directory',+ 'gitattributes',+ 'gitconfig',+ 'gitmodules',+ 'editorconfig',+ 'repo',+ 'java',+ 'jav',+ 'jsx',+ 'js',+ 'es6',+ 'mjs',+ 'cjs',+ 'pac',+ 'json',+ 'bowerrc',+ 'jscsrc',+ 'webmanifest',+ 'jsmap',+ 'cssmap',+ 'tsmap',+ 'har',+ 'jslintrc',+ 'jsonld',+ 'geojson',+ 'ipynb',+ 'vuerc',+ 'jsonc',+ 'eslintrc',+ 'eslintrcjson',+ 'jsfmtrc',+ 'jshintrc',+ 'swcrc',+ 'hintrc',+ 'babelrc',+ 'jsonl',+ 'ndjson',+ 'codesnippets',+ 'jl',+ 'jmd',+ 'sty',+ 'cls',+ 'bbx',+ 'cbx',+ 'tex',+ 'ltx',+ 'ctx',+ 'bib',+ 'less',+ 'log',+ 'lua',+ 'mak',+ 'mk',+ 'mkd',+ 'mdwn',+ 'mdown',+ 'markdown',+ 'markdn',+ 'mdtxt',+ 'mdtext',+ 'workbook',+ 'm',+ 'mm',+ 'pl',+ 'pm',+ 'pod',+ 't',+ 'psgi',+ 'raku',+ 'rakumod',+ 'rakutest',+ 'rakudoc',+ 'nqp',+ 'p6',+ 'pl6',+ 'pm6',+ 'php',+ 'php4',+ 'php5',+ 'phtml',+ 'ctp',+ 'ps1',+ 'psm1',+ 'psd1',+ 'pssc',+ 'psrc',+ 'py',+ 'rpy',+ 'pyw',+ 'cpy',+ 'gyp',+ 'gypi',+ 'pyi',+ 'ipy',+ 'pyt',+ 'r',+ 'rhistory',+ 'rprofile',+ 'rt',+ 'cshtml',+ 'razor',+ 'rb',+ 'rbx',+ 'rjs',+ 'gemspec',+ 'rake',+ 'ru',+ 'erb',+ 'podspec',+ 'rbi',+ 'rs',+ 'scss',+ 'sass',+ 'shader',+ 'sh',+ 'bash',+ 'bashrc',+ 'bashaliases',+ 'bashprofile',+ 'bashlogin',+ 'ebuild',+ 'eclass',+ 'profile',+ 'bashlogout',+ 'xprofile',+ 'xsession',+ 'xsessionrc',+ 'zsh',+ 'zshrc',+ 'zprofile',+ 'zlogin',+ 'zlogout',+ 'zshenv',+ 'zshtheme',+ 'fish',+ 'ksh',+ 'csh',+ 'cshrc',+ 'tcshrc',+ 'yashrc',+ 'yashprofile',+ 'sql',+ 'dsql',+ 'swift',+ 'ts',+ 'cts',+ 'mts',+ 'tsx',+ 'tsbuildinfo',+ 'xml',+ 'xsd',+ 'ascx',+ 'atom',+ 'axml',+ 'axaml',+ 'bpmn',+ 'cpt',+ 'csl',+ 'csproj',+ 'csprojuser',+ 'dita',+ 'ditamap',+ 'dtd',+ 'ent',+ 'mod',+ 'dtml',+ 'fsproj',+ 'fxml',+ 'iml',+ 'isml',+ 'jmx',+ 'launch',+ 'menu',+ 'mxml',+ 'nuspec',+ 'opml',+ 'owl',+ 'proj',+ 'props',+ 'pt',+ 'publishsettings',+ 'pubxml',+ 'pubxmluser',+ 'rbxlx',+ 'rbxmx',+ 'rdf',+ 'rng',+ 'rss',+ 'shproj',+ 'storyboard',+ 'targets',+ 'tld',+ 'tmx',+ 'vbproj',+ 'vbprojuser',+ 'vcxproj',+ 'vcxprojfilters',+ 'wsdl',+ 'wxi',+ 'wxl',+ 'wxs',+ 'xaml',+ 'xbl',+ 'xib',+ 'xlf',+ 'xliff',+ 'xpdl',+ 'xul',+ 'xoml',+ 'xsl',+ 'xslt',+ 'yaml',+ 'yml',+ 'eyaml',+ 'eyml',+ 'cff',+ 'yamltmlanguage',+ 'yamltmpreferences',+ 'yamltmtheme',+ 'winget',+ 'txt',+ 'csv',+ 'tsv',+ 'jpeg',+ 'jpg',+ 'png',+ 'gif',+ 'svg',+ 'webp',+ 'avif',+ 'bmp',+ 'ico',+ 'tiff',+ 'tif',+ 'heic',+ 'heif',+ 'tar',+ 'targz',+ 'tgz',+ 'gz',+ 'bz2',+ 'tarbz2',+ 'tbz2',+ 'z',+ 'tarz',+ 'lz',+ 'tarlz',+ 'xz',+ 'tarxz',+ 'txz',+ 'lzma',+ 'tarlzma',+ 'rar',+ 'sevenz',+ 'zst',+ 'tarzst',+ 'tzst',+ 'zip',+ 'exe',+ 'msi',+ 'dll',+ 'bat',+ 'cmd',+ 'com',+ 'appimage',+ 'app',+ 'bin',+ 'deb',+ 'rpm',+ 'apk',+ 'dmg',+ 'pkg',+ 'crx',+ 'xpi',+ 'mp3',+ 'wav',+ 'ogg',+ 'flac',+ 'aac',+ 'm4a',+ 'wma',+ 'mid',+ 'midi',+ 'mp4',+ 'mkv',+ 'webm',+ 'avi',+ 'mov',+ 'wmv',+ 'mpg',+ 'mpeg',+ 'm4v',+ 'flv',+ 'f4v',+ 'threegp',+ 'ttf',+ 'otf',+ 'woff',+ 'woff2',+ 'eot',+ 'rtf',+ 'odt',+ 'ods',+ 'odp',+ 'odg',+ 'odf',+ 'epub',+ 'mobi',+ 'azw',+ 'azw3',+ 'djvu',+ 'xls',+ 'ppt',+ 'pptx',+ 'xlsx',+ 'db',+ 'sqlite',+ 'sqlite3',+ 'mdb',+ 'accdb',+ 'dbf',+ 'plist',+ 'toml',+ 'env',+ 'dot',+ 'gv',+ 'torrent',+ 'ics',+ 'vcf',+ 'ai',+ 'eps',+ 'ps',+ 'dxf',+ 'dwg',+ 'stl',+ 'obj',+ 'fbx',+ 'blend',+ 'dae',+ 'threeds',+ 'gltf',+ 'glb',+ 'vhd',+ 'vhdx',+ 'vmdk',+ 'ova',+ 'ovf',+ 'iso',+ 'img',+ 'swf',+ ])+ .describe(+ 'Generates a FileType enum and associated ContentType enum with their implementations.\n\nThis macro takes a list of tuples in the format:\n(Variant, \"extension\", \"mime_type\", CONTENT_TYPE_VARIANT)\n\nFor each tuple it generates:\n- A variant in the FileType enum\n- A variant in the ContentType enum\n- Implementations for:\n - FileType::to_str() - Converts FileType to extension string\n - FileType::from_str() - Converts extension string to FileType\n - From<FileType> for ContentType - Maps FileType to ContentType\n - ContentType::mime_type() - Gets MIME type for ContentType\n'+ ),+ })+ .describe('Set the file type to a specific value.'),+ zod.enum(['clear']).describe('Clear the file type (set to null).'),+ ])+ .describe(+ 'Represents a file type update: either set to a specific type or clear to null.'+ ),+ ])+ .optional(),projectId: zod.string().nullish()diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 572cfc6af0..f8102df7f8 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -7113,6 +7113,17 @@"type": ["string", "null"],"description": "The name of the document."},+ "fileType": {+ "oneOf": [+ {+ "type": "null"+ },+ {+ "$ref": "#/components/schemas/FileTypeUpdate",+ "description": "The new file type for the document (null to clear)."+ }+ ]+ },"projectId": {"type": ["string", "null"],"description": "The new project id of the document."@@ -7950,6 +7961,27 @@"swf"]},+ "FileTypeUpdate": {+ "oneOf": [+ {+ "type": "object",+ "description": "Set the file type to a specific value.",+ "required": ["set"],+ "properties": {+ "set": {+ "$ref": "#/components/schemas/FileType",+ "description": "Set the file type to a specific value."+ }+ }+ },+ {+ "type": "string",+ "description": "Clear the file type (set to null).",+ "enum": ["clear"]+ }+ ],+ "description": "Represents a file type update: either set to a specific type or clear to null."+ },"FolderItem": {"type": "object","required": ["name", "fullName", "relativePath", "sha"],diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 32b7141568..76b398da36 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -5916,6 +5916,7 @@ dependencies = ["mockall","model","model-entity",+ "model_file_type","models_dcs","models_opensearch","models_pagination",diff --git a/rust/cloud-storage/documents/src/domain/models.rs b/rust/cloud-storage/documents/src/domain/models.rsindex 55bee844b1..fb3baa2489 100644--- a/rust/cloud-storage/documents/src/domain/models.rs+++ b/rust/cloud-storage/documents/src/domain/models.rs@@ -68,6 +68,17 @@ pub struct CloudFrontConfig {pub browser_cache_expiry_seconds: u64,}+/// Represents a file type update: either set to a specific type or clear to null.+#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, Clone)]+#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]+#[serde(rename_all = "camelCase")]+pub enum FileTypeUpdate {+ /// Set the file type to a specific value.+ Set(FileType),+ /// Clear the file type (set to null).+ Clear,+}+/// Arguments for editing a document in the repository.pub struct EditDocumentRepoArgs {/// The document ID to edit.@@ -79,6 +90,8 @@ pub struct EditDocumentRepoArgs {/// Updated share permissions.pub share_permission:Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,+ /// New file type (None = no change).+ pub file_type: Option<FileTypeUpdate>,}/// Arguments for the edit_document service call.@@ -93,6 +106,9 @@ pub struct EditDocumentServiceArgs {/// Updated share permissions for the document.pub share_permission:Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,+ /// The new file type for the document (null to clear).+ #[serde(default)]+ pub file_type: Option<FileTypeUpdate>,}/// Query parameters for the location_v3 endpoint.diff --git a/rust/cloud-storage/documents/src/domain/service.rs b/rust/cloud-storage/documents/src/domain/service.rsindex 1c9ce05278..d83fc4ba40 100644--- a/rust/cloud-storage/documents/src/domain/service.rs+++ b/rust/cloud-storage/documents/src/domain/service.rs@@ -21,7 +21,7 @@ use model::document::response::{CreateDocumentResponseData, DocumentResponse, DocumentResponseMetadata,GetDocumentResponseData, LocationResponseData, LocationResponseV3,};-use model::document::{ContentType, DocumentBasic, FileType, FileTypeExt};+use model::document::{ContentType, DocumentBasic, FileAssociation, FileType, FileTypeExt};use model::response::PresignedUrl;use s3_key::{build_cloud_storage_bucket_document_key, build_docx_staging_bucket_document_key,@@ -31,7 +31,8 @@ use tracing;use super::models::{CloudFrontConfig, CreateDocumentRepoArgs, CreateTaskRequest, CreateTaskResponse, DocumentError,- EMPTY_SHA256, EditDocumentRepoArgs, EditDocumentServiceArgs, LocationQueryParams,+ EMPTY_SHA256, EditDocumentRepoArgs, EditDocumentServiceArgs, FileTypeUpdate,+ LocationQueryParams,};use super::ports::{DocumentRepo, DocumentService, PresignedUploadUrlPort, TaskPropertiesPort};@@ -609,6 +610,37 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne}}+ if let Some(file_type_update) = &args.file_type {+ let current_file_type = document_context+ .file_type+ .as_ref()+ .and_then(|ft| FileType::from_str(ft).ok())+ .ok_or_else(|| {+ DocumentError::BadRequest(+ "cannot change file type of a document with no file type".to_string(),+ )+ })?;++ let current_association = current_file_type.macro_app_path();++ if !matches!(current_association, FileAssociation::Code(_)) {+ return Err(DocumentError::BadRequest(+ "file type changes are only supported for code files".to_string(),+ ));+ }++ if let FileTypeUpdate::Set(new_file_type) = file_type_update {+ let new_association = new_file_type.macro_app_path();+ if std::mem::discriminant(¤t_association)+ != std::mem::discriminant(&new_association)+ {+ return Err(DocumentError::BadRequest(+ "cannot change file type to a different association".to_string(),+ ));+ }+ }+ }+// Clean the document name (remove file extension if present)let document_name = args.document_name@@ -620,6 +652,7 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Connedocument_name,project_id: args.project_id.clone(),share_permission: args.share_permission,+ file_type: args.file_type,}).await.map_err(|e| DocumentError::Internal(e.into()))?;diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo.rsindex 96c024f79e..48e657c16b 100644--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs@@ -485,11 +485,18 @@ impl DocumentRepo for PgDocumentRepo {async fn edit_document(&self, args: EditDocumentRepoArgs) -> Result<(), Self::Err> {let mut transaction = self.pool.begin().await?;+ use crate::domain::models::FileTypeUpdate;+ let file_type_db = args.file_type.map(|update| match update {+ FileTypeUpdate::Set(ft) => Some(ft.to_string()),+ FileTypeUpdate::Clear => None,+ });+edit::update_document_metadata(&mut transaction,&args.document_id,args.document_name.as_deref(),args.project_id.as_deref(),+ file_type_db,).await?;diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rsindex a79279a924..a01aeedcbc 100644--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs@@ -4,12 +4,15 @@ use models_permissions::share_permission::UpdateSharePermissionRequestV2;use models_permissions::share_permission::channel_share_permission::UpdateOperation;use sqlx::{Postgres, Transaction};-/// Update document metadata (name, projectId, updatedAt).+/// Update document metadata (name, projectId, fileType, updatedAt).+///+/// `file_type`: None = no change, Some(None) = set to NULL, Some(Some(ft)) = set to ft.pub(super) async fn update_document_metadata(transaction: &mut Transaction<'_, Postgres>,document_id: &str,document_name: Option<&str>,project_id: Option<&str>,+ file_type: Option<Option<String>>,) -> Result<(), sqlx::Error> {let mut query = "UPDATE \"Document\" SET ".to_string();let mut parameters: Vec<Option<&str>> = Vec::new();@@ -29,6 +32,11 @@ pub(super) async fn update_document_metadata(}}+ if let Some(ref ft_update) = file_type {+ set_parts.push(format!("\"fileType\" = ${}", parameters.len() + 2));+ parameters.push(ft_update.as_deref());+ }+query += &set_parts.join(", ");if !set_parts.is_empty() {diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rsindex 8d6732df6b..ae0e06abcc 100644--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs@@ -6,7 +6,7 @@ use models_permissions::share_permission::channel_share_permission::{};use sqlx::{Pool, Postgres};-use crate::domain::models::EditDocumentRepoArgs;+use crate::domain::models::{EditDocumentRepoArgs, FileTypeUpdate};use crate::domain::ports::DocumentRepo;use crate::outbound::pg_document_repo::PgDocumentRepo;@@ -120,6 +120,7 @@ async fn test_edit_document_name(pool: Pool<Postgres>) {document_name: Some("new-name".to_string()),project_id: None,share_permission: None,+ file_type: None,}).await.unwrap();@@ -128,6 +129,48 @@ async fn test_edit_document_name(pool: Pool<Postgres>) {assert_eq!(doc.document_name, "new-name");}+#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../fixtures", scripts("documents_test_data"))+)]+async fn test_edit_document_set_file_type(pool: Pool<Postgres>) {+ let repo = PgDocumentRepo::new(pool.clone());++ repo.edit_document(EditDocumentRepoArgs {+ document_id: "document-one".to_string(),+ document_name: None,+ project_id: None,+ share_permission: None,+ file_type: Some(FileTypeUpdate::Set(model_file_type::FileType::Rs)),+ })+ .await+ .unwrap();++ let doc = repo.get_basic_document("document-one").await.unwrap();+ assert_eq!(doc.file_type, Some("rs".to_string()));+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../fixtures", scripts("documents_test_data"))+)]+async fn test_edit_document_clear_file_type(pool: Pool<Postgres>) {+ let repo = PgDocumentRepo::new(pool.clone());++ repo.edit_document(EditDocumentRepoArgs {+ document_id: "document-one".to_string(),+ document_name: None,+ project_id: None,+ share_permission: None,+ file_type: Some(FileTypeUpdate::Clear),+ })+ .await+ .unwrap();++ let doc = repo.get_basic_document("document-one").await.unwrap();+ assert_eq!(doc.file_type, None);+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS",fixtures(path = "../../../fixtures", scripts("documents_test_data"))@@ -140,6 +183,7 @@ async fn test_edit_document_project(pool: Pool<Postgres>) {document_name: None,project_id: Some("new-project".to_string()),share_permission: None,+ file_type: None,}).await.unwrap();@@ -161,6 +205,7 @@ async fn test_edit_document_remove_project(pool: Pool<Postgres>) {document_name: None,project_id: Some("new-project".to_string()),share_permission: None,+ file_type: None,}).await.unwrap();@@ -174,6 +219,7 @@ async fn test_edit_document_remove_project(pool: Pool<Postgres>) {document_name: None,project_id: Some("".to_string()),share_permission: None,+ file_type: None,}).await.unwrap();@@ -198,6 +244,7 @@ async fn test_edit_document_share_permission(pool: Pool<Postgres>) {public_access_level: None,channel_share_permissions: None,}),+ file_type: None,}).await.unwrap();@@ -236,6 +283,7 @@ async fn test_edit_document_set_public_access_level(pool: Pool<Postgres>) {public_access_level: Some(AccessLevel::Edit),channel_share_permissions: None,}),+ file_type: None,}).await.unwrap();@@ -272,6 +320,7 @@ async fn test_edit_document_name_and_project(pool: Pool<Postgres>) {public_access_level: Some(AccessLevel::Edit),channel_share_permissions: None,}),+ file_type: None,}).await.unwrap();@@ -570,6 +619,7 @@ async fn test_edit_document_channel_share_creates_user_item_access(pool: Pool<Poaccess_level: Some(AccessLevel::View),}]),}),+ file_type: None,}).await.unwrap();@@ -648,6 +698,7 @@ async fn test_edit_document_channel_share_idempotent(pool: Pool<Postgres>) {access_level: Some(AccessLevel::View),}]),}),+ file_type: None,};// Call twice — second call should upsert without duplicatesdiff --git a/rust/cloud-storage/macro_db_client/Cargo.toml b/rust/cloud-storage/macro_db_client/Cargo.tomlindex 3da5353750..cf03ca2ffa 100644--- a/rust/cloud-storage/macro_db_client/Cargo.toml+++ b/rust/cloud-storage/macro_db_client/Cargo.toml@@ -21,6 +21,7 @@ macro_user_id = { path = "../macro_user_id" }macro_uuid = { path = "../macro_uuid" }mockall = { workspace = true }model = { path = "../model" }+model_file_type = { path = "../model_file_type" }model-entity = { path = "../model-entity" }models_dcs = { path = "../models_dcs" }models_opensearch = { path = "../models_opensearch" }diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs b/rust/cloud-storage/macro_db_client/src/document/v2/edit.rsindex c6f9c9c817..5e3df086b6 100644--- a/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs+++ b/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs@@ -3,11 +3,13 @@ use models_permissions::share_permission::UpdateSharePermissionRequestV2;use crate::share_permission;#[tracing::instrument(skip(transaction))]+/// `file_type`: None = no change, Some(None) = set to NULL, Some(Some(ft)) = set to ft.pub async fn edit_document(transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,document_id: &str,document_name: Option<&str>,project_id: Option<&str>,+ file_type: Option<Option<&str>>,share_permission: Option<&UpdateSharePermissionRequestV2>,) -> anyhow::Result<()> {let mut query = "UPDATE \"Document\" SET ".to_string();@@ -28,6 +30,11 @@ pub async fn edit_document(}}+ if let Some(ft_update) = file_type {+ set_parts.push("\"fileType\" = $".to_string() + &(parameters.len() + 2).to_string());+ parameters.push(ft_update);+ }+query += &set_parts.join(", ");if !set_parts.is_empty() {@@ -78,6 +85,7 @@ mod tests {"document-one",Some("new-name"),Some("new-project"),+ None,Some(&UpdateSharePermissionRequestV2 {is_public: Some(true),public_access_level: Some(AccessLevel::Edit),@@ -99,9 +107,53 @@ mod tests {document_metadata.project_id,Some("new-project".to_string()));- edit_document(&mut transaction, "document-one", None, None, None).await?;+ edit_document(&mut transaction, "document-one", None, None, None, None).await?;+ transaction.commit().await?;++ Ok(())+ }++ #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]+ async fn test_edit_document_set_file_type(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let mut transaction = pool.begin().await?;++ edit_document(+ &mut transaction,+ "document-one",+ None,+ None,+ Some(Some("rs")),+ None,+ )+ .await?;++ transaction.commit().await?;++ let document_metadata = get_document(&pool, "document-one").await?;+ assert_eq!(document_metadata.file_type, Some("rs".to_string()));++ Ok(())+ }++ #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]+ async fn test_edit_document_clear_file_type(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let mut transaction = pool.begin().await?;++ edit_document(+ &mut transaction,+ "document-one",+ None,+ None,+ Some(None),+ None,+ )+ .await?;+transaction.commit().await?;+ let document_metadata = get_document(&pool, "document-one").await?;+ assert_eq!(document_metadata.file_type, None);+Ok(())}@@ -119,7 +171,7 @@ mod tests {);let mut transaction = pool.begin().await?;- edit_document(&mut transaction, "document-one", None, Some(""), None).await?;+ edit_document(&mut transaction, "document-one", None, Some(""), None, None).await?;transaction.commit().await?;let document_metadata = get_document(&pool, "document-one").await?;diff --git a/rust/cloud-storage/model/src/document/file_type/mod.rs b/rust/cloud-storage/model/src/document/file_type/mod.rsindex 2eac71c7d8..17460c622b 100644--- a/rust/cloud-storage/model/src/document/file_type/mod.rs+++ b/rust/cloud-storage/model/src/document/file_type/mod.rs@@ -1,5 +1,5 @@mod suffix_trie;-pub use model_file_type::{ContentType, FileType};+pub use model_file_type::{ContentType, FileAssociation, FileType};use std::sync::LazyLock;use suffix_trie::ReversedSuffixTrie;