@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.

Give visual feedback when a Drydock resource or lease is releasing

Summary: Ref T9252. Show the user when a resource or lease has a pending release command in queue.

Test Plan: Released a resource and lease from the web UI. In both cases, saw a "releasing" tag and the action disable.

Reviewers: hach-que, chad

Reviewed By: chad

Maniphest Tasks: T9252

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

+110 -2
+9
src/applications/drydock/controller/DrydockLeaseViewController.php
··· 9 9 $lease = id(new DrydockLeaseQuery()) 10 10 ->setViewer($viewer) 11 11 ->withIDs(array($id)) 12 + ->needUnconsumedCommands(true) 12 13 ->executeOne(); 13 14 if (!$lease) { 14 15 return new Aphront404Response(); ··· 20 21 21 22 $header = id(new PHUIHeaderView()) 22 23 ->setHeader($title); 24 + 25 + if ($lease->isReleasing()) { 26 + $header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing')); 27 + } 23 28 24 29 $actions = $this->buildActionListView($lease); 25 30 $properties = $this->buildPropertyListView($lease, $actions); ··· 78 83 $id = $lease->getID(); 79 84 80 85 $can_release = $lease->canRelease(); 86 + if ($lease->isReleasing()) { 87 + $can_release = false; 88 + } 89 + 81 90 $can_edit = PhabricatorPolicyFilter::hasCapability( 82 91 $viewer, 83 92 $lease,
+9
src/applications/drydock/controller/DrydockResourceViewController.php
··· 9 9 $resource = id(new DrydockResourceQuery()) 10 10 ->setViewer($viewer) 11 11 ->withIDs(array($id)) 12 + ->needUnconsumedCommands(true) 12 13 ->executeOne(); 13 14 if (!$resource) { 14 15 return new Aphront404Response(); ··· 20 21 ->setUser($viewer) 21 22 ->setPolicyObject($resource) 22 23 ->setHeader($title); 24 + 25 + if ($resource->isReleasing()) { 26 + $header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing')); 27 + } 23 28 24 29 $actions = $this->buildActionListView($resource); 25 30 $properties = $this->buildPropertyListView($resource, $actions); ··· 82 87 ->setObject($resource); 83 88 84 89 $can_release = $resource->canRelease(); 90 + if ($resource->isReleasing()) { 91 + $can_release = false; 92 + } 93 + 85 94 $can_edit = PhabricatorPolicyFilter::hasCapability( 86 95 $viewer, 87 96 $resource,
+25 -1
src/applications/drydock/query/DrydockLeaseQuery.php
··· 7 7 private $resourcePHIDs; 8 8 private $statuses; 9 9 private $datasourceQuery; 10 - private $needCommands; 10 + private $needUnconsumedCommands; 11 11 12 12 public function withIDs(array $ids) { 13 13 $this->ids = $ids; ··· 31 31 32 32 public function withDatasourceQuery($query) { 33 33 $this->datasourceQuery = $query; 34 + return $this; 35 + } 36 + 37 + public function needUnconsumedCommands($need) { 38 + $this->needUnconsumedCommands = $need; 34 39 return $this; 35 40 } 36 41 ··· 66 71 } 67 72 } 68 73 $lease->attachResource($resource); 74 + } 75 + 76 + return $leases; 77 + } 78 + 79 + protected function didFilterPage(array $leases) { 80 + if ($this->needUnconsumedCommands) { 81 + $commands = id(new DrydockCommandQuery()) 82 + ->setViewer($this->getViewer()) 83 + ->setParentQuery($this) 84 + ->withTargetPHIDs(mpull($leases, 'getPHID')) 85 + ->withConsumed(false) 86 + ->execute(); 87 + $commands = mgroup($commands, 'getTargetPHID'); 88 + 89 + foreach ($leases as $lease) { 90 + $list = idx($commands, $lease->getPHID(), array()); 91 + $lease->attachUnconsumedCommands($list); 92 + } 69 93 } 70 94 71 95 return $leases;
+25
src/applications/drydock/query/DrydockResourceQuery.php
··· 8 8 private $types; 9 9 private $blueprintPHIDs; 10 10 private $datasourceQuery; 11 + private $needUnconsumedCommands; 11 12 12 13 public function withIDs(array $ids) { 13 14 $this->ids = $ids; ··· 39 40 return $this; 40 41 } 41 42 43 + public function needUnconsumedCommands($need) { 44 + $this->needUnconsumedCommands = $need; 45 + return $this; 46 + } 47 + 42 48 public function newResultObject() { 43 49 return new DrydockResource(); 44 50 } ··· 64 70 continue; 65 71 } 66 72 $resource->attachBlueprint($blueprint); 73 + } 74 + 75 + return $resources; 76 + } 77 + 78 + protected function didFilterPage(array $resources) { 79 + if ($this->needUnconsumedCommands) { 80 + $commands = id(new DrydockCommandQuery()) 81 + ->setViewer($this->getViewer()) 82 + ->setParentQuery($this) 83 + ->withTargetPHIDs(mpull($resources, 'getPHID')) 84 + ->withConsumed(false) 85 + ->execute(); 86 + $commands = mgroup($commands, 'getTargetPHID'); 87 + 88 + foreach ($resources as $resource) { 89 + $list = idx($commands, $resource->getPHID(), array()); 90 + $resource->attachUnconsumedCommands($list); 91 + } 67 92 } 68 93 69 94 return $resources;
+21
src/applications/drydock/storage/DrydockLease.php
··· 11 11 protected $status = DrydockLeaseStatus::STATUS_PENDING; 12 12 13 13 private $resource = self::ATTACHABLE; 14 + private $unconsumedCommands = self::ATTACHABLE; 15 + 14 16 private $releaseOnDestruction; 15 17 private $isAcquired = false; 16 18 private $isActivated = false; ··· 102 104 103 105 public function hasAttachedResource() { 104 106 return ($this->resource !== null); 107 + } 108 + 109 + public function getUnconsumedCommands() { 110 + return $this->assertAttached($this->unconsumedCommands); 111 + } 112 + 113 + public function attachUnconsumedCommands(array $commands) { 114 + $this->unconsumedCommands = $commands; 115 + return $this; 116 + } 117 + 118 + public function isReleasing() { 119 + foreach ($this->getUnconsumedCommands() as $command) { 120 + if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) { 121 + return true; 122 + } 123 + } 124 + 125 + return false; 105 126 } 106 127 107 128 public function queueForActivation() {
+21 -1
src/applications/drydock/storage/DrydockResource.php
··· 8 8 protected $blueprintPHID; 9 9 protected $status; 10 10 protected $until; 11 - 12 11 protected $type; 13 12 protected $name; 14 13 protected $attributes = array(); ··· 16 15 protected $ownerPHID; 17 16 18 17 private $blueprint = self::ATTACHABLE; 18 + private $unconsumedCommands = self::ATTACHABLE; 19 + 19 20 private $isAllocated = false; 20 21 private $isActivated = false; 21 22 private $activateWhenAllocated = false; ··· 78 79 public function attachBlueprint(DrydockBlueprint $blueprint) { 79 80 $this->blueprint = $blueprint; 80 81 return $this; 82 + } 83 + 84 + public function getUnconsumedCommands() { 85 + return $this->assertAttached($this->unconsumedCommands); 86 + } 87 + 88 + public function attachUnconsumedCommands(array $commands) { 89 + $this->unconsumedCommands = $commands; 90 + return $this; 91 + } 92 + 93 + public function isReleasing() { 94 + foreach ($this->getUnconsumedCommands() as $command) { 95 + if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) { 96 + return true; 97 + } 98 + } 99 + 100 + return false; 81 101 } 82 102 83 103 public function setActivateWhenAllocated($activate) {