1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-25 21:19:21 +01:00
phorge-phorge/src/applications/differential/customfield/DifferentialRequiredSignaturesField.php

147 lines
3.8 KiB
PHP
Raw Normal View History

Allow Herald to "Require legal signatures" for reviews Summary: Ref T3116. Add a Herald action "Require legal signatures" which requires revision authors to accept legal agreements before their revisions can be accepted. - Herald will check which documents the author has signed, and trigger a "you have to sign X, Y, Z" for other documents. - If the author has already signed everything, we don't spam the revision -- basically, this only triggers when signatures are missing. - The UI will show which documents must be signed and warn that the revision can't be accepted until they're completed. - Users aren't allowed to "Accept" the revision until documents are cleared. Fixes T1157. The original install making the request (Hive) no longer uses Phabricator, and this satisfies our requirements. Test Plan: - Added a Herald rule. - Created a revision, saw the rule trigger. - Viewed as author and non-author, saw field UI (generic for non-author, specific for author), transaction UI, and accept-warning UI. - Tried to accept revision. - Signed document, saw UI update. Note that signatures don't currently //push// an update to the revision, but could eventually (like blocking tasks work). - Accepted revision. - Created another revision, saw rules not add the document (since it's already signed, this is the "no spam" case). Reviewers: btrahan, chad Reviewed By: chad Subscribers: asherkin, epriestley Maniphest Tasks: T1157, T3116 Differential Revision: https://secure.phabricator.com/D9771
2014-06-29 07:53:53 -07:00
<?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;
}
public function shouldAppearInEditView() {
return false;
}
protected function readValueFromRevision(DifferentialRevision $revision) {
return self::loadForRevision($revision);
}
public static function loadForRevision($revision) {
$app_legalpad = 'PhabricatorApplicationLegalpad';
if (!PhabricatorApplication::isClassInstalled($app_legalpad)) {
return array();
}
if (!$revision->getPHID()) {
return array();
}
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$revision->getPHID(),
PhabricatorEdgeConfig::TYPE_OBJECT_NEEDS_SIGNATURE);
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.'),
);
}
Allow Herald to "Require legal signatures" for reviews Summary: Ref T3116. Add a Herald action "Require legal signatures" which requires revision authors to accept legal agreements before their revisions can be accepted. - Herald will check which documents the author has signed, and trigger a "you have to sign X, Y, Z" for other documents. - If the author has already signed everything, we don't spam the revision -- basically, this only triggers when signatures are missing. - The UI will show which documents must be signed and warn that the revision can't be accepted until they're completed. - Users aren't allowed to "Accept" the revision until documents are cleared. Fixes T1157. The original install making the request (Hive) no longer uses Phabricator, and this satisfies our requirements. Test Plan: - Added a Herald rule. - Created a revision, saw the rule trigger. - Viewed as author and non-author, saw field UI (generic for non-author, specific for author), transaction UI, and accept-warning UI. - Tried to accept revision. - Signed document, saw UI update. Note that signatures don't currently //push// an update to the revision, but could eventually (like blocking tasks work). - Accepted revision. - Created another revision, saw rules not add the document (since it's already signed, this is the "no spam" case). Reviewers: btrahan, chad Reviewed By: chad Subscribers: asherkin, epriestley Maniphest Tasks: T1157, T3116 Differential Revision: https://secure.phabricator.com/D9771
2014-06-29 07:53:53 -07:00
}