mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-25 04:59:06 +01:00
Summary: Ref T11114. This replaces the old edit controller with a new one based entirely on EditEngine. This removes the CustomFieldEditEngineExtension hack for Differential, since remaining field types are fairly straightforward and work with existing EditEngine support, as far as I can tell. Test Plan: - Created a revision via web diffs. - Updated a revision via web diffs. - Edited a revision via web. - Edited nonstandard custom fields ("Blame Revision", "JIRA Issues"). - Created a revision via CLI. - Updated a revision via CLI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11114 Differential Revision: https://secure.phabricator.com/D17054
141 lines
3.8 KiB
PHP
141 lines
3.8 KiB
PHP
<?php
|
|
|
|
final class DifferentialRequiredSignaturesField
|
|
extends DifferentialCoreCustomField {
|
|
|
|
public function getFieldKey() {
|
|
return 'differential:required-signatures';
|
|
}
|
|
|
|
public function getFieldName() {
|
|
return pht('Required Signatures');
|
|
}
|
|
|
|
public function getFieldDescription() {
|
|
return pht('Display required legal agreements.');
|
|
}
|
|
|
|
public function shouldAppearInPropertyView() {
|
|
return true;
|
|
}
|
|
|
|
protected function readValueFromRevision(DifferentialRevision $revision) {
|
|
return self::loadForRevision($revision);
|
|
}
|
|
|
|
public static function loadForRevision($revision) {
|
|
$app_legalpad = 'PhabricatorLegalpadApplication';
|
|
if (!PhabricatorApplication::isClassInstalled($app_legalpad)) {
|
|
return array();
|
|
}
|
|
|
|
if (!$revision->getPHID()) {
|
|
return array();
|
|
}
|
|
|
|
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
$revision->getPHID(),
|
|
LegalpadObjectNeedsSignatureEdgeType::EDGECONST);
|
|
|
|
if ($phids) {
|
|
|
|
// NOTE: We're bypassing permissions to pull these. We have to expose
|
|
// some information about signature status in order to implement this
|
|
// field meaningfully (otherwise, we could not tell reviewers that they
|
|
// can't accept the revision yet), but that's OK because the only way to
|
|
// require signatures is with a "Global" Herald rule, which requires a
|
|
// high level of access.
|
|
|
|
$signatures = id(new LegalpadDocumentSignatureQuery())
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
->withDocumentPHIDs($phids)
|
|
->withSignerPHIDs(array($revision->getAuthorPHID()))
|
|
->execute();
|
|
$signatures = mpull($signatures, null, 'getDocumentPHID');
|
|
|
|
$phids = array_fuse($phids);
|
|
foreach ($phids as $phid) {
|
|
$phids[$phid] = isset($signatures[$phid]);
|
|
}
|
|
}
|
|
|
|
return $phids;
|
|
}
|
|
|
|
public function getRequiredHandlePHIDsForPropertyView() {
|
|
return array_keys($this->getValue());
|
|
}
|
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
if (!$handles) {
|
|
return null;
|
|
}
|
|
|
|
$author_phid = $this->getObject()->getAuthorPHID();
|
|
$viewer_phid = $this->getViewer()->getPHID();
|
|
|
|
$viewer_is_author = ($author_phid == $viewer_phid);
|
|
|
|
$view = new PHUIStatusListView();
|
|
foreach ($handles as $handle) {
|
|
$item = id(new PHUIStatusItemView())
|
|
->setTarget($handle->renderLink());
|
|
|
|
// NOTE: If the viewer isn't the author, we just show generic document
|
|
// icons, because the granular information isn't very useful and there
|
|
// is no need to disclose it.
|
|
|
|
// If the viewer is the author, we show exactly what they need to sign.
|
|
|
|
if (!$viewer_is_author) {
|
|
$item->setIcon('fa-file-text-o bluegrey');
|
|
} else {
|
|
if (idx($this->getValue(), $handle->getPHID())) {
|
|
$item->setIcon('fa-check-square-o green');
|
|
} else {
|
|
$item->setIcon('fa-times red');
|
|
}
|
|
}
|
|
|
|
$view->addItem($item);
|
|
}
|
|
|
|
return $view;
|
|
}
|
|
|
|
public function getWarningsForDetailView() {
|
|
if (!$this->haveAnyUnsignedDocuments()) {
|
|
return array();
|
|
}
|
|
|
|
return array(
|
|
pht(
|
|
'The author of this revision has not signed all the required '.
|
|
'legal documents. The revision can not be accepted until the '.
|
|
'documents are signed.'),
|
|
);
|
|
}
|
|
|
|
private function haveAnyUnsignedDocuments() {
|
|
foreach ($this->getValue() as $phid => $signed) {
|
|
if (!$signed) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getWarningsForRevisionHeader(array $handles) {
|
|
if (!$this->haveAnyUnsignedDocuments()) {
|
|
return array();
|
|
}
|
|
|
|
return array(
|
|
pht(
|
|
'This revision can not be accepted until the required legal '.
|
|
'agreements have been signed.'),
|
|
);
|
|
}
|
|
|
|
}
|