mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Move revision header warnings into custom fields
Summary: Ref T5495. We currently show one warning in revision headers, about not having any reviewers. I want to add a second warning (for missing Legalpad signatures). At least one install would like to add custom warnings (see T5495) which are so specific that we can't reasonably cover them in the upstream. Generalize these header warnings by moving them to CustomField, so I can implement the Legalpad stuff without making a mess and the install in T5495 can use an extension. Test Plan: Hit all three header states, they look exactly like they did before this change: {F173265} Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5495 Differential Revision: https://secure.phabricator.com/D9793
This commit is contained in:
parent
394dcb7900
commit
5a158b5b19
3 changed files with 72 additions and 29 deletions
|
@ -115,6 +115,22 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
}
|
||||
}
|
||||
|
||||
$field_list = PhabricatorCustomField::getObjectFields(
|
||||
$revision,
|
||||
PhabricatorCustomField::ROLE_VIEW);
|
||||
|
||||
$field_list->setViewer($user);
|
||||
$field_list->readFieldsFromStorage($revision);
|
||||
|
||||
$warning_handle_map = array();
|
||||
foreach ($field_list->getFields() as $key => $field) {
|
||||
$req = $field->getRequiredHandlePHIDsForRevisionHeaderWarnings();
|
||||
foreach ($req as $phid) {
|
||||
$warning_handle_map[$key][] = $phid;
|
||||
$object_phids[] = $phid;
|
||||
}
|
||||
}
|
||||
|
||||
$handles = $this->loadViewerHandles($object_phids);
|
||||
|
||||
$request_uri = $request->getRequestURI();
|
||||
|
@ -169,13 +185,6 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
$visible_changesets = $changesets;
|
||||
}
|
||||
|
||||
$field_list = PhabricatorCustomField::getObjectFields(
|
||||
$revision,
|
||||
PhabricatorCustomField::ROLE_VIEW);
|
||||
|
||||
$field_list->setViewer($user);
|
||||
$field_list->readFieldsFromStorage($revision);
|
||||
|
||||
|
||||
// TODO: This should be in a DiffQuery or similar.
|
||||
$need_props = array();
|
||||
|
@ -245,8 +254,15 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
|
||||
$revision_detail_box = $revision_detail->render();
|
||||
|
||||
$revision_warnings = $this->buildRevisionWarnings($revision, $handles);
|
||||
$revision_warnings = $this->buildRevisionWarnings(
|
||||
$revision,
|
||||
$field_list,
|
||||
$warning_handle_map,
|
||||
$handles);
|
||||
if ($revision_warnings) {
|
||||
$revision_warnings = id(new AphrontErrorView())
|
||||
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
|
||||
->setErrors($revision_warnings);
|
||||
$revision_detail_box->setErrorView($revision_warnings);
|
||||
}
|
||||
|
||||
|
@ -935,32 +951,21 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
|
||||
private function buildRevisionWarnings(
|
||||
DifferentialRevision $revision,
|
||||
PhabricatorCustomFieldList $field_list,
|
||||
array $warning_handle_map,
|
||||
array $handles) {
|
||||
|
||||
$status_needs_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
|
||||
if ($revision->getStatus() != $status_needs_review) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($revision->getReviewers() as $reviewer) {
|
||||
if (!$handles[$reviewer]->isDisabled()) {
|
||||
return;
|
||||
$warnings = array();
|
||||
foreach ($field_list->getFields() as $key => $field) {
|
||||
$phids = idx($warning_handle_map, $key, array());
|
||||
$field_handles = array_select_keys($handles, $phids);
|
||||
$field_warnings = $field->getWarningsForRevisionHeader($field_handles);
|
||||
foreach ($field_warnings as $warning) {
|
||||
$warnings[] = $warning;
|
||||
}
|
||||
}
|
||||
|
||||
$warnings = array();
|
||||
if ($revision->getReviewers()) {
|
||||
$warnings[] = pht(
|
||||
'This revision needs review, but all specified reviewers are '.
|
||||
'disabled or inactive.');
|
||||
} else {
|
||||
$warnings[] = pht(
|
||||
'This revision needs review, but there are no reviewers specified.');
|
||||
}
|
||||
|
||||
return id(new AphrontErrorView())
|
||||
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
|
||||
->setErrors($warnings);
|
||||
return $warnings;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,6 +74,14 @@ abstract class DifferentialCustomField
|
|||
return array();
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDsForRevisionHeaderWarnings() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getWarningsForRevisionHeader(array $handles) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/* -( Integration with Commit Messages )----------------------------------- */
|
||||
|
||||
|
||||
|
|
|
@ -191,5 +191,35 @@ final class DifferentialReviewersField
|
|||
}
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDsForRevisionHeaderWarnings() {
|
||||
return mpull($this->getValue(), 'getReviewerPHID');
|
||||
}
|
||||
|
||||
public function getWarningsForRevisionHeader(array $handles) {
|
||||
$revision = $this->getObject();
|
||||
|
||||
$status_needs_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
|
||||
if ($revision->getStatus() != $status_needs_review) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($this->getValue() as $reviewer) {
|
||||
if (!$handles[$reviewer->getReviewerPHID()]->isDisabled()) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
$warnings = array();
|
||||
if ($this->getValue()) {
|
||||
$warnings[] = pht(
|
||||
'This revision needs review, but all specified reviewers are '.
|
||||
'disabled or inactive.');
|
||||
} else {
|
||||
$warnings[] = pht(
|
||||
'This revision needs review, but there are no reviewers specified.');
|
||||
}
|
||||
|
||||
return $warnings;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue