Differential D14790 Diff 35773 src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | final class PhabricatorOwnersPackageTransactionEditor | ||||
protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorOwnersPackageTransaction::TYPE_NAME: | case PhabricatorOwnersPackageTransaction::TYPE_NAME: | ||||
case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: | case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: | ||||
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: | |||||
case PhabricatorOwnersPackageTransaction::TYPE_STATUS: | case PhabricatorOwnersPackageTransaction::TYPE_STATUS: | ||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: | |||||
$new = $xaction->getNewValue(); | |||||
foreach ($new as $key => $info) { | |||||
$new[$key]['excluded'] = (int)idx($info, 'excluded'); | |||||
} | |||||
return $new; | |||||
case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: | case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: | ||||
return (int)$xaction->getNewValue(); | return (int)$xaction->getNewValue(); | ||||
case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: | case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: | ||||
$phids = $xaction->getNewValue(); | $phids = $xaction->getNewValue(); | ||||
$phids = array_unique($phids); | $phids = array_unique($phids); | ||||
$phids = array_values($phids); | $phids = array_values($phids); | ||||
return $phids; | return $phids; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | switch ($type) { | ||||
pht('Required'), | pht('Required'), | ||||
pht('Package name is required.'), | pht('Package name is required.'), | ||||
nonempty(last($xactions), null)); | nonempty(last($xactions), null)); | ||||
$error->setIsMissingFieldError(true); | $error->setIsMissingFieldError(true); | ||||
$errors[] = $error; | $errors[] = $error; | ||||
} | } | ||||
break; | break; | ||||
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: | |||||
$old = mpull($object->getPaths(), 'getRef'); | |||||
foreach ($xactions as $xaction) { | |||||
$new = $xaction->getNewValue(); | |||||
// Check that we have a list of paths. | |||||
if (!is_array($new)) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht('Path specification must be a list of paths.'), | |||||
$xaction); | |||||
continue; | |||||
} | |||||
// Check that each item in the list is formatted properly. | |||||
$type_exception = null; | |||||
foreach ($new as $key => $value) { | |||||
try { | |||||
PhutilTypeSpec::checkMap( | |||||
$value, | |||||
array( | |||||
'repositoryPHID' => 'string', | |||||
'path' => 'string', | |||||
'excluded' => 'optional wild', | |||||
)); | |||||
} catch (PhutilTypeCheckException $ex) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Path specification list contains invalid value '. | |||||
'in key "%s": %s.', | |||||
$key, | |||||
$ex->getMessage()), | |||||
$xaction); | |||||
$type_exception = $ex; | |||||
} | |||||
} | |||||
if ($type_exception) { | |||||
continue; | |||||
} | |||||
// Check that any new paths reference legitimate repositories which | |||||
// the viewer has permission to see. | |||||
list($rem, $add) = PhabricatorOwnersPath::getTransactionValueChanges( | |||||
$old, | |||||
$new); | |||||
if ($add) { | |||||
$repository_phids = ipull($add, 'repositoryPHID'); | |||||
$repositories = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs($repository_phids) | |||||
->execute(); | |||||
$repositories = mpull($repositories, null, 'getPHID'); | |||||
foreach ($add as $ref) { | |||||
$repository_phid = $ref['repositoryPHID']; | |||||
if (isset($repositories[$repository_phid])) { | |||||
continue; | |||||
} | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Path specification list references repository PHID "%s", '. | |||||
'but that is not a valid, visible repository.', | |||||
$repository_phid)); | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
protected function shouldSendMail( | protected function shouldSendMail( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |