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

Differential - allow setting viewPolicy from web ui during diff creation process

Summary: Fixes T6152, T6237. This introduces a viewPolicy column to the DifferentialDiff, and re-jiggers the DifferentialDiff policy implementation such that things behave as before once associated with a revision, else use the DifferentialDiff policy column value.

Test Plan: made a diff with a non-standard view policy and noted that policy was still selected in the revision step. arc lint.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6237, T6152

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

+107 -25
+5
resources/sql/autopatches/20141119.differential.diff.policy.sql
··· 1 + ALTER TABLE {$NAMESPACE}_differential.differential_diff 2 + ADD viewPolicy VARBINARY(64) NOT NULL; 3 + 4 + UPDATE {$NAMESPACE}_differential.differential_diff 5 + SET viewPolicy = 'users' WHERE viewPolicy = '';
+3 -1
src/applications/differential/__tests__/DifferentialParseRenderTestCase.php
··· 35 35 $parser = new ArcanistDiffParser(); 36 36 $changes = $parser->parseDiff($data); 37 37 38 - $diff = DifferentialDiff::newFromRawChanges($changes); 38 + $diff = DifferentialDiff::newFromRawChanges( 39 + PhabricatorUser::getOmnipotentUser(), 40 + $changes); 39 41 if (count($diff->getChangesets()) !== 1) { 40 42 throw new Exception("Expected one changeset: {$file}"); 41 43 }
+1 -1
src/applications/differential/conduit/DifferentialCreateDiffConduitAPIMethod.php
··· 69 69 $changes[] = ArcanistDiffChange::newFromDictionary($dict); 70 70 } 71 71 72 - $diff = DifferentialDiff::newFromRawChanges($changes); 72 + $diff = DifferentialDiff::newFromRawChanges($viewer, $changes); 73 73 74 74 // TODO: Remove repository UUID eventually; for now continue writing 75 75 // the UUID. Note that we'll overwrite it below if we identify a
+8 -1
src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php
··· 15 15 return array( 16 16 'diff' => 'required string', 17 17 'repositoryPHID' => 'optional string', 18 + 'viewPolicy' => 'optional string', 18 19 ); 19 20 } 20 21 ··· 45 46 46 47 $parser = new ArcanistDiffParser(); 47 48 $changes = $parser->parseDiff($raw_diff); 48 - $diff = DifferentialDiff::newFromRawChanges($changes); 49 + $diff = DifferentialDiff::newFromRawChanges($viewer, $changes); 49 50 50 51 $diff_data_dict = array( 51 52 'creationMethod' => 'web', ··· 57 58 $xactions = array(id(new DifferentialTransaction()) 58 59 ->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE) 59 60 ->setNewValue($diff_data_dict),); 61 + 62 + if ($request->getValue('viewPolicy')) { 63 + $xactions[] = id(new DifferentialTransaction()) 64 + ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 65 + ->setNewValue($request->getValue('viewPolicy')); 66 + } 60 67 61 68 id(new DifferentialDiffEditor()) 62 69 ->setActor($viewer)
+19 -3
src/applications/differential/controller/DifferentialDiffCreateController.php
··· 5 5 public function processRequest() { 6 6 7 7 $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 8 9 9 10 $diff = null; 11 + // This object is just for policy stuff 12 + $diff_object = DifferentialDiff::initializeNewDiff($viewer); 10 13 $repository_phid = null; 11 14 $repository_value = array(); 12 15 $errors = array(); ··· 41 44 'differential.createrawdiff', 42 45 array( 43 46 'diff' => $diff, 44 - 'repositoryPHID' => $repository_phid,)); 45 - $call->setUser($request->getUser()); 47 + 'repositoryPHID' => $repository_phid, 48 + 'viewPolicy' => $request->getStr('viewPolicy'),)); 49 + $call->setUser($viewer); 46 50 $result = $call->execute(); 47 51 $path = id(new PhutilURI($result['uri']))->getPath(); 48 52 return id(new AphrontRedirectResponse())->setURI($path); ··· 68 72 $repository_value = $this->loadViewerHandles(array($repository_phid)); 69 73 } 70 74 75 + $policies = id(new PhabricatorPolicyQuery()) 76 + ->setViewer($viewer) 77 + ->setObject($diff_object) 78 + ->execute(); 79 + 71 80 $form 72 81 ->setAction('/differential/diff/create/') 73 82 ->setEncType('multipart/form-data') 74 - ->setUser($request->getUser()) 83 + ->setUser($viewer) 75 84 ->appendInstructions( 76 85 pht( 77 86 'The best way to create a Differential diff is by using %s, but you '. ··· 100 109 ->setDatasource(new DiffusionRepositoryDatasource()) 101 110 ->setValue($repository_value) 102 111 ->setLimit(1)) 112 + ->appendChild( 113 + id(new AphrontFormPolicyControl()) 114 + ->setUser($viewer) 115 + ->setName('viewPolicy') 116 + ->setPolicyObject($diff_object) 117 + ->setPolicies($policies) 118 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) 103 119 ->appendChild( 104 120 id(new AphrontFormSubmitControl()) 105 121 ->addCancelButton($cancel_uri)
+7
src/applications/differential/controller/DifferentialRevisionEditController.php
··· 79 79 if ($repository_field) { 80 80 $repository_field->setValue($request->getStr($repo_key)); 81 81 } 82 + $view_policy_key = id(new DifferentialViewPolicyField())->getFieldKey(); 83 + $view_policy_field = idx( 84 + $field_list->getFields(), 85 + $view_policy_key); 86 + if ($view_policy_field) { 87 + $view_policy_field->setValue($diff->getViewPolicy()); 88 + } 82 89 } 83 90 84 91 $validation_exception = null;
+5
src/applications/differential/editor/DifferentialDiffEditor.php
··· 22 22 public function getTransactionTypes() { 23 23 $types = parent::getTransactionTypes(); 24 24 25 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 25 26 $types[] = DifferentialDiffTransaction::TYPE_DIFF_CREATE; 26 27 27 28 return $types; ··· 61 62 $dict = $this->diffDataDict; 62 63 $this->updateDiffFromDict($object, $dict); 63 64 return; 65 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 66 + $object->setViewPolicy($xaction->getNewValue()); 67 + return; 64 68 } 65 69 66 70 return parent::applyCustomInternalTransaction($object, $xaction); ··· 72 76 73 77 switch ($xaction->getTransactionType()) { 74 78 case DifferentialDiffTransaction::TYPE_DIFF_CREATE: 79 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 75 80 return; 76 81 } 77 82
+3 -1
src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
··· 40 40 throw new Exception("Expected 1 changeset for '{$name}'!"); 41 41 } 42 42 43 - $diff = DifferentialDiff::newFromRawChanges($changes); 43 + $diff = DifferentialDiff::newFromRawChanges( 44 + PhabricatorUser::getOmnipotentUser(), 45 + $changes); 44 46 return head($diff->getChangesets())->getHunks(); 45 47 } 46 48
-1
src/applications/differential/query/DifferentialDiffQuery.php
··· 62 62 63 63 foreach ($diffs as $key => $diff) { 64 64 if (!$diff->getRevisionID()) { 65 - $diff->attachRevision(null); 66 65 continue; 67 66 } 68 67
+31 -8
src/applications/differential/storage/DifferentialDiff.php
··· 33 33 34 34 protected $description; 35 35 36 + protected $viewPolicy; 37 + 36 38 private $unsavedChangesets = array(); 37 39 private $changesets = self::ATTACHABLE; 38 40 private $arcanistProject = self::ATTACHABLE; ··· 136 138 return $ret; 137 139 } 138 140 139 - public static function newFromRawChanges(array $changes) { 141 + public static function initializeNewDiff(PhabricatorUser $actor) { 142 + $app = id(new PhabricatorApplicationQuery()) 143 + ->setViewer($actor) 144 + ->withClasses(array('PhabricatorDifferentialApplication')) 145 + ->executeOne(); 146 + $view_policy = $app->getPolicy( 147 + DifferentialDefaultViewCapability::CAPABILITY); 148 + 149 + $diff = id(new DifferentialDiff()) 150 + ->setViewPolicy($view_policy); 151 + 152 + return $diff; 153 + } 154 + 155 + public static function newFromRawChanges( 156 + PhabricatorUser $actor, 157 + array $changes) { 158 + 140 159 assert_instances_of($changes, 'ArcanistDiffChange'); 141 - $diff = new DifferentialDiff(); 142 160 161 + $diff = self::initializeNewDiff($actor); 143 162 // There may not be any changes; initialize the changesets list so that 144 163 // we don't throw later when accessing it. 145 164 $diff->attachChangesets(array()); ··· 289 308 return $changes; 290 309 } 291 310 311 + public function hasRevision() { 312 + return $this->revision !== self::ATTACHABLE; 313 + } 314 + 292 315 public function getRevision() { 293 316 return $this->assertAttached($this->revision); 294 317 } ··· 318 341 } 319 342 320 343 public function getPolicy($capability) { 321 - if ($this->getRevision()) { 344 + if ($this->hasRevision()) { 322 345 return $this->getRevision()->getPolicy($capability); 323 346 } 324 347 325 - return PhabricatorPolicies::POLICY_USER; 348 + return $this->viewPolicy; 326 349 } 327 350 328 351 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 329 - if ($this->getRevision()) { 352 + if ($this->hasRevision()) { 330 353 return $this->getRevision()->hasAutomaticCapability($capability, $viewer); 331 354 } 332 355 333 - return false; 356 + return ($this->getAuthorPHID() == $viewer->getPhid()); 334 357 } 335 358 336 359 public function describeAutomaticCapability($capability) { 337 - if ($this->getRevision()) { 360 + if ($this->hasRevision()) { 338 361 return pht( 339 362 'This diff is attached to a revision, and inherits its policies.'); 340 363 } 341 - return null; 364 + return pht('The author of a diff can see it.'); 342 365 } 343 366 344 367
+4 -1
src/applications/differential/storage/__tests__/DifferentialDiffTestCase.php
··· 7 7 $parser = new ArcanistDiffParser(); 8 8 9 9 $diff = DifferentialDiff::newFromRawChanges( 10 + PhabricatorUser::getOmnipotentUser(), 10 11 $parser->parseDiff(Filesystem::readFile($root.'lint_engine.diff'))); 11 12 $copies = idx(head($diff->getChangesets())->getMetadata(), 'copy:lines'); 12 13 ··· 46 47 {$oblock} 47 48 EODIFF; 48 49 49 - $diff = DifferentialDiff::newFromRawChanges($parser->parseDiff($raw_diff)); 50 + $diff = DifferentialDiff::newFromRawChanges( 51 + PhabricatorUser::getOmnipotentUser(), 52 + $parser->parseDiff($raw_diff)); 50 53 51 54 $this->assertTrue(true); 52 55 }
+3 -1
src/applications/diffusion/controller/DiffusionChangeController.php
··· 22 22 $drequest->updateSymbolicCommit($data['effectiveCommit']); 23 23 24 24 $raw_changes = ArcanistDiffChange::newFromConduit($data['changes']); 25 - $diff = DifferentialDiff::newFromRawChanges($raw_changes); 25 + $diff = DifferentialDiff::newFromRawChanges( 26 + $viewer, 27 + $raw_changes); 26 28 $changesets = $diff->getChangesets(); 27 29 $changeset = reset($changesets); 28 30
+1
src/applications/diffusion/controller/DiffusionCommitController.php
··· 276 276 $content[] = $change_panel; 277 277 278 278 $changesets = DiffusionPathChange::convertToDifferentialChangesets( 279 + $user, 279 280 $changes); 280 281 281 282 $vcs = $repository->getVersionControlSystem();
+3 -1
src/applications/diffusion/controller/DiffusionDiffController.php
··· 54 54 )); 55 55 $drequest->updateSymbolicCommit($data['effectiveCommit']); 56 56 $raw_changes = ArcanistDiffChange::newFromConduit($data['changes']); 57 - $diff = DifferentialDiff::newFromRawChanges($raw_changes); 57 + $diff = DifferentialDiff::newFromRawChanges( 58 + $user, 59 + $raw_changes); 58 60 $changesets = $diff->getChangesets(); 59 61 $changeset = reset($changesets); 60 62
+4 -2
src/applications/diffusion/data/DiffusionPathChange.php
··· 142 142 return array_select_keys($result, $direct); 143 143 } 144 144 145 - final public static function convertToDifferentialChangesets(array $changes) { 145 + final public static function convertToDifferentialChangesets( 146 + PhabricatorUser $user, 147 + array $changes) { 146 148 assert_instances_of($changes, 'DiffusionPathChange'); 147 149 $arcanist_changes = self::convertToArcanistChanges($changes); 148 - $diff = DifferentialDiff::newFromRawChanges($arcanist_changes); 150 + $diff = DifferentialDiff::newFromRawChanges($user, $arcanist_changes); 149 151 return $diff->getChangesets(); 150 152 } 151 153
+3 -1
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 1115 1115 1116 1116 $parser = new ArcanistDiffParser(); 1117 1117 $changes = $parser->parseDiff($raw_diff); 1118 - $diff = DifferentialDiff::newFromRawChanges($changes); 1118 + $diff = DifferentialDiff::newFromRawChanges( 1119 + $this->getViewer(), 1120 + $changes); 1119 1121 return $diff->getChangesets(); 1120 1122 } 1121 1123
+3 -1
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 346 346 $parser = new ArcanistDiffParser(); 347 347 $changes = $parser->parseDiff($raw); 348 348 349 - $diff = DifferentialDiff::newFromRawChanges($changes); 349 + $diff = DifferentialDiff::newFromRawChanges( 350 + PhabricatorUser::getOmnipotentUser(), 351 + $changes); 350 352 return $diff; 351 353 } 352 354
+1 -1
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
··· 265 265 $changes = array(); 266 266 } 267 267 268 - $diff = DifferentialDiff::newFromRawChanges($changes) 268 + $diff = DifferentialDiff::newFromRawChanges($viewer, $changes) 269 269 ->setRepositoryPHID($this->repository->getPHID()) 270 270 ->setAuthorPHID($actor_phid) 271 271 ->setCreationMethod('commit')
+3 -1
src/infrastructure/diff/PhabricatorDifferenceEngine.php
··· 163 163 $diff = $this->generateRawDiffFromFileContent($old, $new); 164 164 165 165 $changes = id(new ArcanistDiffParser())->parseDiff($diff); 166 - $diff = DifferentialDiff::newFromRawChanges($changes); 166 + $diff = DifferentialDiff::newFromRawChanges( 167 + PhabricatorUser::getOmnipotentUser(), 168 + $changes); 167 169 return head($diff->getChangesets()); 168 170 } 169 171