@@ -55,6 +55,7 @@ def mutate
5555 attach_files ( document_signed_ids )
5656 # topic.persisted? means that we are updating existing topic and documents can be removed
5757 shadow_delete_documents ( docs_to_delete ) if topic . persisted?
58+ rename_files ( document_signed_ids )
5859 # document_signed_ids.any? means that some new documents were attached and we need to sync them
5960 sync_docs_for_topic_updates if document_signed_ids . any?
6061 [ :ok , topic ]
@@ -71,6 +72,30 @@ def attach_files(signed_ids)
7172 end
7273 end
7374
75+ def rename_files ( signed_ids )
76+ return if signed_ids . blank?
77+ signed_ids . each do |signed_id |
78+ document = topic . documents . find { |doc | doc . blob . signed_id == signed_id }
79+ next unless document
80+
81+ new_filename = topic . custom_file_name ( document )
82+ rename_document ( document , new_filename )
83+ end
84+ end
85+
86+ def rename_document ( document , new_filename )
87+ return unless document . blob . filename . to_s . split ( "_" ) . first == "rename"
88+ return if document . filename == new_filename
89+
90+ file_io = StringIO . new ( document . download )
91+ topic . documents . attach (
92+ io : file_io ,
93+ filename : new_filename ,
94+ content_type : document . content_type
95+ )
96+ document . purge
97+ end
98+
7499 def sync_docs_for_topic_updates
75100 topic . documents_attachments . each do |doc |
76101 DocumentsSyncJob . perform_later (
0 commit comments