@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Only attach files that are both referenced in Remarkup and attached by explicit metadata

Summary:
Ref T13682. When a user uploads a file, then changes their mind and deletes the reference to the file, we don't actually want to attach the file.

When choosing which files to attach, only attach files which are both referenced in Remarkup and explicitly attached in remarkup metadata.

Test Plan:
- Dropped a file into a comment, submitted it, saw it attach normally.
- Dropped a file into a comment, deleted the reference, submitted it, saw no attachment.

Maniphest Tasks: T13682

Differential Revision: https://secure.phabricator.com/D21832

+49 -1
+49 -1
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 447 447 $old_map = ipull($rows, 'attachmentMode', 'filePHID'); 448 448 } 449 449 450 + $mode_ref = PhabricatorFileAttachment::MODE_REFERENCE; 451 + $mode_detach = PhabricatorFileAttachment::MODE_DETACH; 452 + 450 453 $new_map = $old_map; 451 454 452 455 foreach ($new as $file_phid => $attachment_mode) { 453 - if ($attachment_mode == PhabricatorFileAttachment::MODE_DETACH) { 456 + $is_ref = ($attachment_mode === $mode_ref); 457 + $is_detach = ($attachment_mode === $mode_detach); 458 + 459 + if ($is_detach) { 454 460 unset($new_map[$file_phid]); 455 461 continue; 462 + } 463 + 464 + $old_mode = idx($old_map, $file_phid); 465 + 466 + // If we're adding a reference to a file but it is already attached, 467 + // don't touch it. 468 + 469 + if ($is_ref) { 470 + if ($old_mode !== null) { 471 + continue; 472 + } 456 473 } 457 474 458 475 $new_map[$file_phid] = $attachment_mode; ··· 2246 2263 2247 2264 $new_map = array(); 2248 2265 2266 + $viewer = $this->getActor(); 2267 + 2268 + $old_blocks = mpull($remarkup_changes, 'getOldValue'); 2269 + $new_blocks = mpull($remarkup_changes, 'getNewValue'); 2270 + 2271 + $old_refs = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 2272 + $viewer, 2273 + $old_blocks); 2274 + $old_refs = array_fuse($old_refs); 2275 + 2276 + $new_refs = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 2277 + $viewer, 2278 + $new_blocks); 2279 + $new_refs = array_fuse($new_refs); 2280 + 2281 + $add_refs = array_diff_key($new_refs, $old_refs); 2282 + foreach ($add_refs as $file_phid) { 2283 + $new_map[$file_phid] = PhabricatorFileAttachment::MODE_REFERENCE; 2284 + } 2285 + 2249 2286 foreach ($remarkup_changes as $remarkup_change) { 2250 2287 $metadata = $remarkup_change->getMetadata(); 2251 2288 2252 2289 $attached_phids = idx($metadata, 'attachedFilePHIDs', array()); 2253 2290 foreach ($attached_phids as $file_phid) { 2291 + 2292 + // If the blocks don't include a new embedded reference to this file, 2293 + // do not actually attach it. A common way for this to happen is for 2294 + // a user to upload a file, then change their mind and remove the 2295 + // reference. We do not want to attach the file if they decided against 2296 + // referencing it. 2297 + 2298 + if (!isset($new_map[$file_phid])) { 2299 + continue; 2300 + } 2301 + 2254 2302 $new_map[$file_phid] = PhabricatorFileAttachment::MODE_ATTACH; 2255 2303 } 2256 2304 }