mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 06:50:55 +01:00
In Owners Packages, make the API representation of the "Auditing" field more consistent
Summary: Ref T13244. See PHI1047. A while ago, the "Review" field changed from "yes/no" to 20 flavors of "Non-Owner Blocking Under A Full Moon". The sky didn't fall, so we'll probably do this to "Audit" eventually too. The "owners.search" API method anticipates this and returns "none" or "audit" to describe package audit statuses, so it can begin returning "audit-non-owner-reviewers" or whatever in the future. However, the "owners.edit" API method doesn't work the same way, and takes strings, and the strings have to be numbers. This is goofy and confusing and generally bad. Make "owners.edit" take the same strings that "owners.search" emits. For now, continue accepting the old values of "0" and "1". Test Plan: - Edited audit status of packages via API using "none", "audit", "0", "1" (worked), and invalid values like "quack" (helpful error). - Edited audit status of packages via web UI. - Used `owners.search` to retrieve package information. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13244 Differential Revision: https://secure.phabricator.com/D20091
This commit is contained in:
parent
4675306615
commit
ee24eb60b7
3 changed files with 67 additions and 6 deletions
|
@ -140,11 +140,11 @@ EOTEXT
|
||||||
->setTransactionType(
|
->setTransactionType(
|
||||||
PhabricatorOwnersPackageAuditingTransaction::TRANSACTIONTYPE)
|
PhabricatorOwnersPackageAuditingTransaction::TRANSACTIONTYPE)
|
||||||
->setIsCopyable(true)
|
->setIsCopyable(true)
|
||||||
->setValue($object->getAuditingEnabled())
|
->setValue($object->getAuditingState())
|
||||||
->setOptions(
|
->setOptions(
|
||||||
array(
|
array(
|
||||||
'' => pht('Disabled'),
|
PhabricatorOwnersPackage::AUDITING_NONE => pht('No Auditing'),
|
||||||
'1' => pht('Enabled'),
|
PhabricatorOwnersPackage::AUDITING_AUDIT => pht('Audit Commits'),
|
||||||
)),
|
)),
|
||||||
id(new PhabricatorRemarkupEditField())
|
id(new PhabricatorRemarkupEditField())
|
||||||
->setKey('description')
|
->setKey('description')
|
||||||
|
|
|
@ -38,6 +38,9 @@ final class PhabricatorOwnersPackage
|
||||||
const AUTOREVIEW_BLOCK = 'block';
|
const AUTOREVIEW_BLOCK = 'block';
|
||||||
const AUTOREVIEW_BLOCK_ALWAYS = 'block-always';
|
const AUTOREVIEW_BLOCK_ALWAYS = 'block-always';
|
||||||
|
|
||||||
|
const AUDITING_NONE = 'none';
|
||||||
|
const AUDITING_AUDIT = 'audit';
|
||||||
|
|
||||||
const DOMINION_STRONG = 'strong';
|
const DOMINION_STRONG = 'strong';
|
||||||
const DOMINION_WEAK = 'weak';
|
const DOMINION_WEAK = 'weak';
|
||||||
|
|
||||||
|
@ -564,6 +567,14 @@ final class PhabricatorOwnersPackage
|
||||||
return '/owners/package/'.$this->getID().'/';
|
return '/owners/package/'.$this->getID().'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuditingState() {
|
||||||
|
if ($this->getAuditingEnabled()) {
|
||||||
|
return self::AUDITING_AUDIT;
|
||||||
|
} else {
|
||||||
|
return self::AUDITING_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -720,11 +731,10 @@ final class PhabricatorOwnersPackage
|
||||||
'label' => $review_label,
|
'label' => $review_label,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$audit_value = $this->getAuditingState();
|
||||||
if ($this->getAuditingEnabled()) {
|
if ($this->getAuditingEnabled()) {
|
||||||
$audit_value = 'audit';
|
|
||||||
$audit_label = pht('Auditing Enabled');
|
$audit_label = pht('Auditing Enabled');
|
||||||
} else {
|
} else {
|
||||||
$audit_value = 'none';
|
|
||||||
$audit_label = pht('No Auditing');
|
$audit_label = pht('No Auditing');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,15 @@ final class PhabricatorOwnersPackageAuditingTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateNewValue($object, $value) {
|
public function generateNewValue($object, $value) {
|
||||||
return (int)$value;
|
switch ($value) {
|
||||||
|
case PhabricatorOwnersPackage::AUDITING_AUDIT:
|
||||||
|
return 1;
|
||||||
|
case '1':
|
||||||
|
// TODO: Remove, deprecated.
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyInternalEffects($object, $value) {
|
public function applyInternalEffects($object, $value) {
|
||||||
|
@ -29,4 +37,47 @@ final class PhabricatorOwnersPackageAuditingTransaction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
// See PHI1047. This transaction type accepted some weird stuff. Continue
|
||||||
|
// supporting it for now, but move toward sensible consistency.
|
||||||
|
|
||||||
|
$modern_options = array(
|
||||||
|
PhabricatorOwnersPackage::AUDITING_NONE =>
|
||||||
|
sprintf('"%s"', PhabricatorOwnersPackage::AUDITING_NONE),
|
||||||
|
PhabricatorOwnersPackage::AUDITING_AUDIT =>
|
||||||
|
sprintf('"%s"', PhabricatorOwnersPackage::AUDITING_AUDIT),
|
||||||
|
);
|
||||||
|
|
||||||
|
$deprecated_options = array(
|
||||||
|
'0' => '"0"',
|
||||||
|
'1' => '"1"',
|
||||||
|
'' => pht('"" (empty string)'),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$new_value = $xaction->getNewValue();
|
||||||
|
|
||||||
|
if (isset($modern_options[$new_value])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($deprecated_options[$new_value])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'Package auditing value "%s" is not supported. Supported options '.
|
||||||
|
'are: %s. Deprecated options are: %s.',
|
||||||
|
$new_value,
|
||||||
|
implode(', ', $modern_options),
|
||||||
|
implode(', ', $deprecated_options)),
|
||||||
|
$xaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue