1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Modernize and clean up "PhabricatorAuditStatusConstants"

Summary:
Ref T13631. Move "PhabricatorAuditStatusConstants" to a more modern object ("PhabricatorAuditRequestStatus").

Expose the status value via Conduit.

Test Plan:
  - Ran `bin/audit delete`.
  - Viewed a commit with auditors in the web UI.
  - Grepped for affected symbols.
  - Called Conduit with the "auditors" attachment, saw auditor statuses.

Maniphest Tasks: T13631

Differential Revision: https://secure.phabricator.com/D21599
This commit is contained in:
epriestley 2021-03-10 08:54:21 -08:00
parent 2636d84d0c
commit ac2f5a1046
17 changed files with 121 additions and 133 deletions

View file

@ -2305,7 +2305,7 @@ phutil_register_library_map(array(
'PhabricatorAuditManagementDeleteWorkflow' => 'applications/audit/management/PhabricatorAuditManagementDeleteWorkflow.php',
'PhabricatorAuditManagementWorkflow' => 'applications/audit/management/PhabricatorAuditManagementWorkflow.php',
'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php',
'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php',
'PhabricatorAuditRequestStatus' => 'applications/audit/constants/PhabricatorAuditRequestStatus.php',
'PhabricatorAuditSynchronizeManagementWorkflow' => 'applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php',
'PhabricatorAuditTransaction' => 'applications/audit/storage/PhabricatorAuditTransaction.php',
'PhabricatorAuditTransactionComment' => 'applications/audit/storage/PhabricatorAuditTransactionComment.php',
@ -8651,7 +8651,7 @@ phutil_register_library_map(array(
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
'PhabricatorAuditManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorAuditReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhabricatorAuditStatusConstants' => 'Phobject',
'PhabricatorAuditRequestStatus' => 'Phobject',
'PhabricatorAuditSynchronizeManagementWorkflow' => 'PhabricatorAuditManagementWorkflow',
'PhabricatorAuditTransaction' => 'PhabricatorModularTransaction',
'PhabricatorAuditTransactionComment' => array(

View file

@ -0,0 +1,80 @@
<?php
final class PhabricatorAuditRequestStatus extends Phobject {
const AUDIT_REQUIRED = 'audit-required';
const CONCERNED = 'concerned';
const ACCEPTED = 'accepted';
const AUDIT_REQUESTED = 'requested';
const RESIGNED = 'resigned';
private $key;
public static function newForStatus($status) {
$result = new self();
$result->key = $status;
return $result;
}
public function getIconIcon() {
return $this->getMapProperty('icon');
}
public function getIconColor() {
return $this->getMapProperty('icon.color');
}
public function getStatusName() {
$name = $this->getMapProperty('name');
if ($name !== null) {
return $name;
}
return pht('Unknown Audit Request Status ("%s")', $this->key);
}
public function getStatusValue() {
return $this->key;
}
public function isResigned() {
return ($this->key === self::RESIGNED);
}
private function getMapProperty($key, $default = null) {
$map = self::newStatusMap();
$spec = idx($map, $this->key, array());
return idx($spec, $key, $default);
}
private static function newStatusMap() {
return array(
self::AUDIT_REQUIRED => array(
'name' => pht('Audit Required'),
'icon' => 'fa-exclamation-circle',
'icon.color' => 'orange',
),
self::AUDIT_REQUESTED => array(
'name' => pht('Audit Requested'),
'icon' => 'fa-exclamation-circle',
'icon.color' => 'orange',
),
self::CONCERNED => array(
'name' => pht('concern Raised'),
'icon' => 'fa-times-circle',
'icon.color' => 'red',
),
self::ACCEPTED => array(
'name' => pht('Accepted'),
'icon' => 'fa-check-circle',
'icon.color' => 'green',
),
self::RESIGNED => array(
'name' => pht('Resigned'),
'icon' => 'fa-times',
'icon.color' => 'grey',
),
);
}
}

View file

@ -1,90 +0,0 @@
<?php
final class PhabricatorAuditStatusConstants extends Phobject {
const AUDIT_REQUIRED = 'audit-required';
const CONCERNED = 'concerned';
const ACCEPTED = 'accepted';
const AUDIT_REQUESTED = 'requested';
const RESIGNED = 'resigned';
public static function getStatusNameMap() {
$map = array(
self::AUDIT_REQUIRED => pht('Audit Required'),
self::CONCERNED => pht('Concern Raised'),
self::ACCEPTED => pht('Accepted'),
self::AUDIT_REQUESTED => pht('Audit Requested'),
self::RESIGNED => pht('Resigned'),
);
return $map;
}
public static function getActionRequiredStatusConstants() {
return array(
self::AUDIT_REQUIRED,
self::AUDIT_REQUESTED,
);
}
public static function getStatusName($code) {
return idx(self::getStatusNameMap(), $code, pht('Unknown'));
}
public static function getStatusColor($code) {
switch ($code) {
case self::CONCERNED:
$color = 'red';
break;
case self::AUDIT_REQUIRED:
case self::AUDIT_REQUESTED:
$color = 'orange';
break;
case self::ACCEPTED:
$color = 'green';
break;
case self::RESIGNED:
$color = 'grey';
break;
default:
$color = 'bluegrey';
break;
}
return $color;
}
public static function getStatusIcon($code) {
switch ($code) {
case self::AUDIT_REQUIRED:
case self::AUDIT_REQUESTED:
$icon = PHUIStatusItemView::ICON_WARNING;
break;
case self::CONCERNED:
$icon = PHUIStatusItemView::ICON_REJECT;
break;
case self::ACCEPTED:
$icon = PHUIStatusItemView::ICON_ACCEPT;
break;
case self::RESIGNED:
$icon = 'fa-times';
break;
default:
$icon = PHUIStatusItemView::ICON_QUESTION;
break;
}
return $icon;
}
public static function getOpenStatusConstants() {
return array(
self::AUDIT_REQUIRED,
self::AUDIT_REQUESTED,
self::CONCERNED,
);
}
public static function isOpenStatus($status) {
return in_array($status, self::getOpenStatusConstants());
}
}

View file

@ -178,11 +178,6 @@ final class PhabricatorAuditEditor
}
$object->attachAudits($commit->getAudits());
$status_concerned = PhabricatorAuditStatusConstants::CONCERNED;
$status_resigned = PhabricatorAuditStatusConstants::RESIGNED;
$status_accepted = PhabricatorAuditStatusConstants::ACCEPTED;
$status_concerned = PhabricatorAuditStatusConstants::CONCERNED;
$actor_phid = $this->getActingAsPHID();
$actor_is_author = ($object->getAuthorPHID()) &&
($actor_phid == $object->getAuthorPHID());

View file

@ -153,13 +153,13 @@ final class PhabricatorAuditManagementDeleteWorkflow
foreach ($commit_audits as $audit) {
$audit_id = $audit->getID();
$status = $audit->getAuditRequestStatusObject();
$description = sprintf(
'%10d %-16s %-16s %s: %s',
$audit_id,
$handles[$audit->getAuditorPHID()]->getName(),
PhabricatorAuditStatusConstants::getStatusName(
$audit->getAuditStatus()),
$status->getStatusName(),
$commit->getRepository()->formatCommitName(
$commit->getCommitIdentifier()),
trim($commit->getSummary()));

View file

@ -898,12 +898,13 @@ final class DiffusionCommitController extends DiffusionController {
$view = new PHUIStatusListView();
foreach ($audit_requests as $request) {
$code = $request->getAuditStatus();
$status = $request->getAuditRequestStatusObject();
$item = new PHUIStatusItemView();
$item->setIcon(
PhabricatorAuditStatusConstants::getStatusIcon($code),
PhabricatorAuditStatusConstants::getStatusColor($code),
PhabricatorAuditStatusConstants::getStatusName($code));
$status->getIconIcon(),
$status->getIconColor(),
$status->getStatusName());
$auditor_phid = $request->getAuditorPHID();
$target = $viewer->renderHandle($auditor_phid);

View file

@ -98,9 +98,9 @@ final class DiffusionDoorkeeperCommitFeedStoryPublisher
}
switch ($status) {
case PhabricatorAuditStatusConstants::AUDIT_REQUIRED:
case PhabricatorAuditStatusConstants::AUDIT_REQUESTED:
case PhabricatorAuditStatusConstants::CONCERNED:
case PhabricatorAuditRequestStatus::AUDIT_REQUIRED:
case PhabricatorAuditRequestStatus::AUDIT_REQUESTED:
case PhabricatorAuditRequestStatus::CONCERNED:
$active += array_fuse($request_phids);
break;
default:

View file

@ -20,8 +20,11 @@ final class DiffusionAuditorsSearchEngineAttachment
$list = array();
foreach ($auditors as $auditor) {
$status = $auditor->getAuditRequestStatusObject();
$list[] = array(
'auditorPHID' => $auditor->getAuditorPHID(),
'status' => $status->getStatusValue(),
);
}

View file

@ -166,8 +166,8 @@ final class HeraldCommitAdapter
public function loadAuditNeededPackages() {
if ($this->auditNeededPackages === null) {
$status_arr = array(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED,
PhabricatorAuditStatusConstants::CONCERNED,
PhabricatorAuditRequestStatus::AUDIT_REQUIRED,
PhabricatorAuditRequestStatus::CONCERNED,
);
$requests = id(new PhabricatorRepositoryAuditRequest())
->loadAllWhere(

View file

@ -90,7 +90,7 @@ final class DiffusionCommitRequiredActionResultBucket
$objects = $this->objects;
$has_concern = array(
PhabricatorAuditStatusConstants::CONCERNED,
PhabricatorAuditRequestStatus::CONCERNED,
);
$has_concern = array_fuse($has_concern);
@ -119,8 +119,8 @@ final class DiffusionCommitRequiredActionResultBucket
$objects = $this->objects;
$should_audit = array(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED,
PhabricatorAuditStatusConstants::AUDIT_REQUESTED,
PhabricatorAuditRequestStatus::AUDIT_REQUIRED,
PhabricatorAuditRequestStatus::AUDIT_REQUESTED,
);
$should_audit = array_fuse($should_audit);

View file

@ -31,7 +31,7 @@ final class DiffusionCommitAcceptTransaction
}
public function applyExternalEffects($object, $value) {
$status = PhabricatorAuditStatusConstants::ACCEPTED;
$status = PhabricatorAuditRequestStatus::ACCEPTED;
$actor = $this->getActor();
$this->applyAuditorEffect($object, $actor, $value, $status);
}

View file

@ -21,12 +21,12 @@ abstract class DiffusionCommitAuditTransaction
PhabricatorRepositoryCommit $commit,
PhabricatorUser $viewer) {
// This omits various inactive states like "Resigned" and "Not Required".
// This omits inactive states; currently just "Resigned".
$active = array(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED,
PhabricatorAuditStatusConstants::CONCERNED,
PhabricatorAuditStatusConstants::ACCEPTED,
PhabricatorAuditStatusConstants::AUDIT_REQUESTED,
PhabricatorAuditRequestStatus::AUDIT_REQUIRED,
PhabricatorAuditRequestStatus::CONCERNED,
PhabricatorAuditRequestStatus::ACCEPTED,
PhabricatorAuditRequestStatus::AUDIT_REQUESTED,
);
$active = array_fuse($active);
@ -42,7 +42,7 @@ abstract class DiffusionCommitAuditTransaction
$commit,
$viewer,
array(
PhabricatorAuditStatusConstants::ACCEPTED,
PhabricatorAuditRequestStatus::ACCEPTED,
));
}
@ -53,7 +53,7 @@ abstract class DiffusionCommitAuditTransaction
$commit,
$viewer,
array(
PhabricatorAuditStatusConstants::CONCERNED,
PhabricatorAuditRequestStatus::CONCERNED,
));
}
@ -117,7 +117,7 @@ abstract class DiffusionCommitAuditTransaction
$map = array();
$with_authority = ($status != PhabricatorAuditStatusConstants::RESIGNED);
$with_authority = ($status != PhabricatorAuditRequestStatus::RESIGNED);
if ($with_authority) {
foreach ($audits as $audit) {
if ($commit->hasAuditAuthority($actor, $audit, $acting_phid)) {

View file

@ -16,7 +16,7 @@ final class DiffusionCommitAuditorsTransaction
$auditors = $this->generateOldValue($object);
$old_auditors = $auditors;
$request_status = PhabricatorAuditStatusConstants::AUDIT_REQUESTED;
$request_status = PhabricatorAuditRequestStatus::AUDIT_REQUESTED;
$rem = idx($value, '-', array());
foreach ($rem as $phid) {

View file

@ -37,7 +37,7 @@ final class DiffusionCommitConcernTransaction
}
public function applyExternalEffects($object, $value) {
$status = PhabricatorAuditStatusConstants::CONCERNED;
$status = PhabricatorAuditRequestStatus::CONCERNED;
$actor = $this->getActor();
$this->applyAuditorEffect($object, $actor, $value, $status);
}

View file

@ -36,7 +36,7 @@ final class DiffusionCommitResignTransaction
}
public function applyExternalEffects($object, $value) {
$status = PhabricatorAuditStatusConstants::RESIGNED;
$status = PhabricatorAuditRequestStatus::RESIGNED;
$actor = $this->getActor();
$this->applyAuditorEffect($object, $actor, $value, $status);
}

View file

@ -50,14 +50,13 @@ final class PhabricatorRepositoryAuditRequest
}
public function isResigned() {
switch ($this->getAuditStatus()) {
case PhabricatorAuditStatusConstants::RESIGNED:
return true;
}
return false;
return $this->getAuditRequestStatusObject()->isResigned();
}
public function getAuditRequestStatusObject() {
$status = $this->getAuditStatus();
return PhabricatorAuditRequestStatus::newForStatus($status);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -312,14 +312,14 @@ final class PhabricatorRepositoryCommit
foreach ($requests as $request) {
switch ($request->getAuditStatus()) {
case PhabricatorAuditStatusConstants::AUDIT_REQUIRED:
case PhabricatorAuditStatusConstants::AUDIT_REQUESTED:
case PhabricatorAuditRequestStatus::AUDIT_REQUIRED:
case PhabricatorAuditRequestStatus::AUDIT_REQUESTED:
$any_need = true;
break;
case PhabricatorAuditStatusConstants::ACCEPTED:
case PhabricatorAuditRequestStatus::ACCEPTED:
$any_accept = true;
break;
case PhabricatorAuditStatusConstants::CONCERNED:
case PhabricatorAuditRequestStatus::CONCERNED:
$any_concern = true;
break;
}