1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-25 14:08:19 +01:00

Begin transitioning audits to modern (string) status constants, from legacy (integer) status constants

Summary:
Ref T13195. See PHI851. Audits currently have older integer status constants. We've moved almost all object types away from this to string constants (which are better in basically every way, and particularly way better for exposing over the API).

Commits/audits are currently accessible over the API and expose these constants via a "statuses" constraint.

Prepare to move toward modern string constants by defining a new, more modern map of status details and defining the existing methods in terms of it.

Test Plan: Browsed audits checking for icons/names/open-ness, saw no changes. This change should have no user-visible effects, as it just reorganizes code.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13195

Differential Revision: https://secure.phabricator.com/D19642
This commit is contained in:
epriestley 2018-09-05 10:26:02 -07:00
parent 5a38b75f16
commit ef26b06ca8

View file

@ -9,17 +9,16 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
const FULLY_AUDITED = 4; const FULLY_AUDITED = 4;
const NEEDS_VERIFICATION = 5; const NEEDS_VERIFICATION = 5;
public static function getStatusNameMap() { const MODERN_NONE = 'none';
$map = array( const MODERN_NEEDS_AUDIT = 'needs-audit';
self::NONE => pht('No Audits'), const MODERN_CONCERN_RAISED = 'concern-raised';
self::NEEDS_AUDIT => pht('Audit Required'), const MODERN_PARTIALLY_AUDITED = 'partially-audited';
self::CONCERN_RAISED => pht('Concern Raised'), const MODERN_AUDITED = 'audited';
self::NEEDS_VERIFICATION => pht('Needs Verification'), const MODERN_NEEDS_VERIFICATION = 'needs-verification';
self::PARTIALLY_AUDITED => pht('Partially Audited'),
self::FULLY_AUDITED => pht('Audited'),
);
return $map; public static function getStatusNameMap() {
$map = self::getMap();
return ipull($map, 'name', 'legacy');
} }
public static function getStatusName($code) { public static function getStatusName($code) {
@ -27,66 +26,71 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
} }
public static function getOpenStatusConstants() { public static function getOpenStatusConstants() {
return array( $constants = array();
self::CONCERN_RAISED, foreach (self::getMap() as $map) {
self::NEEDS_AUDIT, if (!$map['closed']) {
self::NEEDS_VERIFICATION, $constants[] = $map['legacy'];
self::PARTIALLY_AUDITED, }
); }
return $constants;
} }
public static function getStatusColor($code) { public static function getStatusColor($code) {
switch ($code) { $map = self::getMap();
case self::CONCERN_RAISED: $map = ipull($map, 'color', 'legacy');
$color = 'red'; return idx($map, $code);
break;
case self::NEEDS_AUDIT:
$color = 'orange';
break;
case self::PARTIALLY_AUDITED:
$color = 'yellow';
break;
case self::FULLY_AUDITED:
$color = 'green';
break;
case self::NONE:
$color = 'bluegrey';
break;
case self::NEEDS_VERIFICATION:
$color = 'indigo';
break;
default:
$color = null;
break;
}
return $color;
} }
public static function getStatusIcon($code) { public static function getStatusIcon($code) {
switch ($code) { $map = self::getMap();
case self::CONCERN_RAISED: $map = ipull($map, 'icon', 'legacy');
$icon = 'fa-times-circle'; return idx($map, $code);
break;
case self::NEEDS_AUDIT:
$icon = 'fa-exclamation-circle';
break;
case self::PARTIALLY_AUDITED:
$icon = 'fa-check-circle-o';
break;
case self::FULLY_AUDITED:
$icon = 'fa-check-circle';
break;
case self::NONE:
$icon = 'fa-check';
break;
case self::NEEDS_VERIFICATION:
$icon = 'fa-refresh';
break;
default:
$icon = null;
break;
}
return $icon;
} }
private static function getMap() {
return array(
self::MODERN_NONE => array(
'name' => pht('No Audits'),
'legacy' => self::NONE,
'icon' => 'fa-check',
'color' => 'bluegrey',
'closed' => true,
),
self::MODERN_NEEDS_AUDIT => array(
'name' => pht('Audit Required'),
'legacy' => self::NEEDS_AUDIT,
'icon' => 'fa-exclamation-circle',
'color' => 'orange',
'closed' => false,
),
self::MODERN_CONCERN_RAISED => array(
'name' => pht('Concern Raised'),
'legacy' => self::CONCERN_RAISED,
'icon' => 'fa-times-circle',
'color' => 'red',
'closed' => false,
),
self::MODERN_PARTIALLY_AUDITED => array(
'name' => pht('Partially Audited'),
'legacy' => self::PARTIALLY_AUDITED,
'icon' => 'fa-check-circle-o',
'color' => 'yellow',
'closed' => false,
),
self::MODERN_AUDITED => array(
'name' => pht('Audited'),
'legacy' => self::FULLY_AUDITED,
'icon' => 'fa-check-circle',
'color' => 'green',
'closed' => true,
),
self::MODERN_NEEDS_VERIFICATION => array(
'name' => pht('Needs Verification'),
'legacy' => self::NEEDS_VERIFICATION,
'icon' => 'fa-refresh',
'color' => 'indigo',
'closed' => false,
),
);
}
} }