1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Continue converting Audit constants, allowing the Query to handle either strings or integers

Summary: Ref T13197. We're almost ready to migrate: let the Query accept either older integer values or new string values. Then move some callsites to use strings.

Test Plan: Called `audit.query`, browsed audits, audited commits.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19650
This commit is contained in:
epriestley 2018-09-10 11:35:11 -07:00
parent bae8a95114
commit 853a816b3c
6 changed files with 40 additions and 23 deletions

View file

@ -68,17 +68,17 @@ final class AuditQueryConduitAPIMethod extends AuditConduitAPIMethod {
$status_map = array( $status_map = array(
self::AUDIT_LEGACYSTATUS_OPEN => array( self::AUDIT_LEGACYSTATUS_OPEN => array(
PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT, PhabricatorAuditCommitStatusConstants::MODERN_NEEDS_AUDIT,
PhabricatorAuditCommitStatusConstants::CONCERN_RAISED, PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED,
), ),
self::AUDIT_LEGACYSTATUS_CONCERN => array( self::AUDIT_LEGACYSTATUS_CONCERN => array(
PhabricatorAuditCommitStatusConstants::CONCERN_RAISED, PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED,
), ),
self::AUDIT_LEGACYSTATUS_ACCEPTED => array( self::AUDIT_LEGACYSTATUS_ACCEPTED => array(
PhabricatorAuditCommitStatusConstants::FULLY_AUDITED, PhabricatorAuditCommitStatusConstants::MODERN_AUDITED,
), ),
self::AUDIT_LEGACYSTATUS_PARTIAL => array( self::AUDIT_LEGACYSTATUS_PARTIAL => array(
PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED, PhabricatorAuditCommitStatusConstants::MODERN_PARTIALLY_AUDITED,
), ),
); );

View file

@ -22,11 +22,13 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
public static function newForLegacyStatus($status) { public static function newForLegacyStatus($status) {
$map = self::getMap(); $map = self::getMap();
if (is_int($status) || ctype_digit($status)) {
foreach ($map as $key => $spec) { foreach ($map as $key => $spec) {
if (idx($spec, 'legacy') == $status) { if ((int)idx($spec, 'legacy') === (int)$status) {
return self::newForStatus($key); return self::newForStatus($key);
} }
} }
}
return self::newForStatus($status); return self::newForStatus($status);
} }
@ -56,6 +58,10 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
return idx($this->spec, 'color'); return idx($this->spec, 'color');
} }
public function getLegacyKey() {
return idx($this->spec, 'legacy');
}
public function getName() { public function getName() {
return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key)); return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key));
} }
@ -64,6 +70,10 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
return ($this->key == self::MODERN_NONE); return ($this->key == self::MODERN_NONE);
} }
public function isNeedsAudit() {
return ($this->key == self::MODERN_NEEDS_AUDIT);
}
public function isConcernRaised() { public function isConcernRaised() {
return ($this->key == self::MODERN_CONCERN_RAISED); return ($this->key == self::MODERN_CONCERN_RAISED);
} }

View file

@ -714,10 +714,17 @@ final class DiffusionCommitQuery
} }
if ($this->statuses !== null) { if ($this->statuses !== null) {
$statuses = array();
foreach ($this->statuses as $status) {
$object = PhabricatorAuditCommitStatusConstants::newForLegacyStatus(
$status);
$statuses[] = $object->getLegacyKey();
}
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'commit.auditStatus IN (%Ld)', 'commit.auditStatus IN (%Ld)',
$this->statuses); $statuses);
} }
if ($this->packagePHIDs !== null) { if ($this->packagePHIDs !== null) {

View file

@ -164,15 +164,13 @@ final class DiffusionCommitRequiredActionResultBucket
$results = array(); $results = array();
$objects = $this->objects; $objects = $this->objects;
$status_waiting = array(
PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT,
PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION,
PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED,
);
$status_waiting = array_fuse($status_waiting);
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
if (empty($status_waiting[$object->getAuditStatus()])) { $any_waiting =
$object->isAuditStatusNeedsAudit() ||
$object->isAuditStatusNeedsVerification() ||
$object->isAuditStatusPartiallyAudited();
if (!$any_waiting) {
continue; continue;
} }

View file

@ -71,7 +71,8 @@ final class PhabricatorOwnersDetailController
'package' => $package->getPHID(), 'package' => $package->getPHID(),
)); ));
$status_concern = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED; $status_concern =
PhabricatorAuditCommitStatusConstants::MODERN_CONCERN_RAISED;
$attention_commits = id(new DiffusionCommitQuery()) $attention_commits = id(new DiffusionCommitQuery())
->setViewer($request->getUser()) ->setViewer($request->getUser())

View file

@ -381,14 +381,11 @@ final class PhabricatorRepositoryCommit
} }
} }
$current_status = $this->getAuditStatus();
$status_verify = PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION;
if ($any_concern) { if ($any_concern) {
if ($current_status == $status_verify) { if ($this->isAuditStatusNeedsVerification()) {
// If the change is in "Needs Verification", we keep it there as // If the change is in "Needs Verification", we keep it there as
// long as any auditors still have concerns. // long as any auditors still have concerns.
$status = $status_verify; $status = PhabricatorAuditCommitStatusConstants::NEEDS_VERIFICATION;
} else { } else {
$status = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED; $status = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED;
} }
@ -539,6 +536,10 @@ final class PhabricatorRepositoryCommit
return $this->getAuditStatusObject()->isNoAudit(); return $this->getAuditStatusObject()->isNoAudit();
} }
public function isAuditStatusNeedsAudit() {
return $this->getAuditStatusObject()->isNeedsAudit();
}
public function isAuditStatusConcernRaised() { public function isAuditStatusConcernRaised() {
return $this->getAuditStatusObject()->isConcernRaised(); return $this->getAuditStatusObject()->isConcernRaised();
} }