From bdda7eed07345b86bff018830e0dd3963717ef39 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 1 Jun 2021 06:08:07 -0700 Subject: [PATCH] Improve display behavior for write locks held by omnipotent users Summary: Ref T13614. When an omnipotent user calls "synchronizeWorkingCopyBeforeWrite()", we record a WorkingCopyVersion record with a null "userPHID". The UI then renders this as "Unknown Object (????)". Improve this behavior: - When no PHID is available, just render nothing in the UI (this doesn't seem meaningfully different from no version existing at all). - Allow callers to provide an acting user PHID, similar to Editor. There's currently no way to perform this kind of write legitimately in the upstream, but T13614 is providing one. Test Plan: - Wrote a script that calls "synchronizeWorkingCopyBeforeWrite()" as the omnipotent user. - Ran script, saw "Unknown Object (????)" in the UI. - Applied UI fix, saw empty UI. - Applied "acting as" fix, modified script to act as the Diffusion application, ran script, saw "Diffusion" attribution in UI. {F8814806} Maniphest Tasks: T13614 Differential Revision: https://secure.phabricator.com/D21669 --- ...fusionRepositoryStorageManagementPanel.php | 14 +++++++----- .../DiffusionRepositoryClusterEngine.php | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php index f657a81641..2b92c73c97 100644 --- a/src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php +++ b/src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php @@ -190,15 +190,19 @@ final class DiffusionRepositoryStorageManagementPanel } } + $last_writer = null; + $writer_epoch = null; if ($write_properties) { $writer_phid = idx($write_properties, 'userPHID'); - $last_writer = $viewer->renderHandle($writer_phid); + + if ($writer_phid) { + $last_writer = $viewer->renderHandle($writer_phid); + } $writer_epoch = idx($write_properties, 'epoch'); - $writer_epoch = phabricator_datetime($writer_epoch, $viewer); - } else { - $last_writer = null; - $writer_epoch = null; + if ($writer_epoch) { + $writer_epoch = phabricator_datetime($writer_epoch, $viewer); + } } $rows[] = array( diff --git a/src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php b/src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php index 9df37c7fb5..a364828397 100644 --- a/src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php +++ b/src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php @@ -11,6 +11,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject { private $repository; private $viewer; + private $actingAsPHID; private $logger; private $clusterWriteLock; @@ -44,6 +45,23 @@ final class DiffusionRepositoryClusterEngine extends Phobject { return $this; } + public function setActingAsPHID($acting_as_phid) { + $this->actingAsPHID = $acting_as_phid; + return $this; + } + + public function getActingAsPHID() { + return $this->actingAsPHID; + } + + private function getEffectiveActingAsPHID() { + if ($this->actingAsPHID) { + return $this->actingAsPHID; + } + + return $this->getViewer()->getPHID(); + } + /* -( Cluster Synchronization )-------------------------------------------- */ @@ -402,7 +420,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject { $repository_phid, $device_phid, array( - 'userPHID' => $viewer->getPHID(), + 'userPHID' => $this->getEffectiveActingAsPHID(), 'epoch' => PhabricatorTime::getNow(), 'devicePHID' => $device_phid, ), @@ -433,8 +451,6 @@ final class DiffusionRepositoryClusterEngine extends Phobject { return; } - $viewer = $this->getViewer(); - $device = AlmanacKeys::getLiveDevice(); $device_phid = $device->getPHID();