2011-03-25 05:32:26 +01:00
|
|
|
<?php
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
final class HeraldDifferentialRevisionAdapter
|
|
|
|
extends HeraldDifferentialAdapter {
|
2011-03-25 05:32:26 +01:00
|
|
|
|
|
|
|
protected $revision;
|
|
|
|
|
|
|
|
protected $explicitCCs;
|
|
|
|
protected $explicitReviewers;
|
|
|
|
protected $forbiddenCCs;
|
|
|
|
|
|
|
|
protected $newCCs = array();
|
|
|
|
protected $remCCs = array();
|
2011-05-28 00:52:26 +02:00
|
|
|
protected $emailPHIDs = array();
|
2013-10-05 19:36:26 +02:00
|
|
|
protected $addReviewerPHIDs = array();
|
2013-10-07 12:41:00 +02:00
|
|
|
protected $blockingReviewerPHIDs = array();
|
2013-11-09 01:48:17 +01:00
|
|
|
protected $buildPlans = array();
|
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 16:53:53 +02:00
|
|
|
protected $requiredSignatureDocumentPHIDs = array();
|
2011-03-25 05:32:26 +01:00
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
protected $affectedPackages;
|
|
|
|
protected $changesets;
|
2014-04-14 21:06:26 +02:00
|
|
|
private $haveHunks;
|
2011-04-06 05:49:31 +02:00
|
|
|
|
2013-10-05 00:15:48 +02:00
|
|
|
public function getAdapterApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDifferentialApplication';
|
2013-08-02 17:55:13 +02:00
|
|
|
}
|
|
|
|
|
2013-10-05 21:55:34 +02:00
|
|
|
public function getObject() {
|
|
|
|
return $this->revision;
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:07:13 +01:00
|
|
|
public function getDiff() {
|
|
|
|
return $this->diff;
|
|
|
|
}
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public function getAdapterContentType() {
|
|
|
|
return 'differential';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdapterContentName() {
|
|
|
|
return pht('Differential Revisions');
|
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:33 +01:00
|
|
|
public function getAdapterContentDescription() {
|
|
|
|
return pht(
|
|
|
|
"React to revisions being created or updated.\n".
|
|
|
|
"Revision rules can send email, flag revisions, add reviewers, ".
|
|
|
|
"and run build plans.");
|
|
|
|
}
|
|
|
|
|
2013-12-31 01:48:07 +01:00
|
|
|
public function supportsRuleType($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
|
|
return true;
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 19:25:45 +02:00
|
|
|
public function getFields() {
|
2013-10-04 02:53:12 +02:00
|
|
|
return array_merge(
|
|
|
|
array(
|
|
|
|
self::FIELD_TITLE,
|
|
|
|
self::FIELD_BODY,
|
|
|
|
self::FIELD_AUTHOR,
|
2013-10-05 21:04:31 +02:00
|
|
|
self::FIELD_AUTHOR_PROJECTS,
|
2013-10-04 02:53:12 +02:00
|
|
|
self::FIELD_REVIEWERS,
|
|
|
|
self::FIELD_CC,
|
|
|
|
self::FIELD_REPOSITORY,
|
2014-01-10 00:56:24 +01:00
|
|
|
self::FIELD_REPOSITORY_PROJECTS,
|
2013-10-04 02:53:12 +02:00
|
|
|
self::FIELD_DIFF_FILE,
|
|
|
|
self::FIELD_DIFF_CONTENT,
|
2013-10-04 15:37:32 +02:00
|
|
|
self::FIELD_DIFF_ADDED_CONTENT,
|
|
|
|
self::FIELD_DIFF_REMOVED_CONTENT,
|
2013-10-04 02:53:12 +02:00
|
|
|
self::FIELD_AFFECTED_PACKAGE,
|
|
|
|
self::FIELD_AFFECTED_PACKAGE_OWNER,
|
2014-02-06 21:43:36 +01:00
|
|
|
self::FIELD_IS_NEW_OBJECT,
|
2014-03-11 21:15:01 +01:00
|
|
|
self::FIELD_ARCANIST_PROJECT,
|
2013-10-04 02:53:12 +02:00
|
|
|
),
|
|
|
|
parent::getFields());
|
2013-08-02 19:25:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-02 21:35:33 +02:00
|
|
|
public function getRepetitionOptions() {
|
|
|
|
return array(
|
|
|
|
HeraldRepetitionPolicyConfig::EVERY,
|
|
|
|
HeraldRepetitionPolicyConfig::FIRST,
|
|
|
|
);
|
|
|
|
}
|
2013-08-02 19:25:45 +02:00
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
public static function newLegacyAdapter(
|
2011-04-06 05:49:31 +02:00
|
|
|
DifferentialRevision $revision,
|
|
|
|
DifferentialDiff $diff) {
|
2013-08-02 17:55:13 +02:00
|
|
|
$object = new HeraldDifferentialRevisionAdapter();
|
|
|
|
|
2013-10-05 01:30:43 +02:00
|
|
|
// Reload the revision to pick up relationship information.
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($revision->getID()))
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->needRelationships(true)
|
|
|
|
->needReviewerStatus(true)
|
|
|
|
->executeOne();
|
|
|
|
|
2013-08-02 17:55:13 +02:00
|
|
|
$object->revision = $revision;
|
|
|
|
$object->diff = $diff;
|
|
|
|
|
|
|
|
return $object;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setExplicitCCs($explicit_ccs) {
|
|
|
|
$this->explicitCCs = $explicit_ccs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setExplicitReviewers($explicit_reviewers) {
|
|
|
|
$this->explicitReviewers = $explicit_reviewers;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setForbiddenCCs($forbidden_ccs) {
|
|
|
|
$this->forbiddenCCs = $forbidden_ccs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCCsAddedByHerald() {
|
|
|
|
return array_diff_key($this->newCCs, $this->remCCs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCCsRemovedByHerald() {
|
|
|
|
return $this->remCCs;
|
|
|
|
}
|
|
|
|
|
2011-05-28 00:52:26 +02:00
|
|
|
public function getEmailPHIDsAddedByHerald() {
|
|
|
|
return $this->emailPHIDs;
|
|
|
|
}
|
|
|
|
|
2013-10-05 19:36:26 +02:00
|
|
|
public function getReviewersAddedByHerald() {
|
|
|
|
return $this->addReviewerPHIDs;
|
|
|
|
}
|
|
|
|
|
2013-10-07 02:09:24 +02:00
|
|
|
public function getBlockingReviewersAddedByHerald() {
|
|
|
|
return $this->blockingReviewerPHIDs;
|
|
|
|
}
|
|
|
|
|
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 16:53:53 +02:00
|
|
|
public function getRequiredSignatureDocumentPHIDs() {
|
|
|
|
return $this->requiredSignatureDocumentPHIDs;
|
|
|
|
}
|
|
|
|
|
2013-11-09 01:48:17 +01:00
|
|
|
public function getBuildPlans() {
|
|
|
|
return $this->buildPlans;
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
public function getPHID() {
|
|
|
|
return $this->revision->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeraldName() {
|
|
|
|
return $this->revision->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadChangesets() {
|
2011-04-06 05:49:31 +02:00
|
|
|
if ($this->changesets === null) {
|
|
|
|
$this->changesets = $this->diff->loadChangesets();
|
|
|
|
}
|
|
|
|
return $this->changesets;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
protected function loadChangesetsWithHunks() {
|
2014-04-14 21:06:26 +02:00
|
|
|
$changesets = $this->loadChangesets();
|
|
|
|
|
|
|
|
if ($changesets && !$this->haveHunks) {
|
|
|
|
$this->haveHunks = true;
|
|
|
|
|
|
|
|
id(new DifferentialHunkQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withChangesets($changesets)
|
|
|
|
->needAttachToChangesets(true)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $changesets;
|
|
|
|
}
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
public function loadAffectedPackages() {
|
|
|
|
if ($this->affectedPackages === null) {
|
|
|
|
$this->affectedPackages = array();
|
|
|
|
|
|
|
|
$repository = $this->loadRepository();
|
|
|
|
if ($repository) {
|
|
|
|
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
|
|
|
|
$repository,
|
|
|
|
$this->loadAffectedPaths());
|
|
|
|
$this->affectedPackages = $packages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->affectedPackages;
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
public function getHeraldField($field) {
|
|
|
|
switch ($field) {
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_TITLE:
|
2011-03-25 05:32:26 +01:00
|
|
|
return $this->revision->getTitle();
|
|
|
|
break;
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_BODY:
|
2011-03-25 05:32:26 +01:00
|
|
|
return $this->revision->getSummary()."\n".
|
|
|
|
$this->revision->getTestPlan();
|
|
|
|
break;
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_AUTHOR:
|
2011-03-25 05:32:26 +01:00
|
|
|
return $this->revision->getAuthorPHID();
|
|
|
|
break;
|
2013-10-05 21:04:31 +02:00
|
|
|
case self::FIELD_AUTHOR_PROJECTS:
|
|
|
|
$author_phid = $this->revision->getAuthorPHID();
|
|
|
|
if (!$author_phid) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$projects = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withMemberPHIDs(array($author_phid))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
return mpull($projects, 'getPHID');
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_DIFF_FILE:
|
2011-04-06 05:49:31 +02:00
|
|
|
return $this->loadAffectedPaths();
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_CC:
|
2011-03-25 05:32:26 +01:00
|
|
|
if (isset($this->explicitCCs)) {
|
|
|
|
return array_keys($this->explicitCCs);
|
|
|
|
} else {
|
|
|
|
return $this->revision->getCCPHIDs();
|
|
|
|
}
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_REVIEWERS:
|
2011-03-25 05:32:26 +01:00
|
|
|
if (isset($this->explicitReviewers)) {
|
|
|
|
return array_keys($this->explicitReviewers);
|
|
|
|
} else {
|
|
|
|
return $this->revision->getReviewers();
|
|
|
|
}
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_REPOSITORY:
|
2011-04-06 05:49:31 +02:00
|
|
|
$repository = $this->loadRepository();
|
2011-03-25 05:32:26 +01:00
|
|
|
if (!$repository) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-04-06 05:49:31 +02:00
|
|
|
return $repository->getPHID();
|
2014-01-10 00:56:24 +01:00
|
|
|
case self::FIELD_REPOSITORY_PROJECTS:
|
|
|
|
$repository = $this->loadRepository();
|
|
|
|
if (!$repository) {
|
2014-01-14 01:08:30 +01:00
|
|
|
return array();
|
2014-01-10 00:56:24 +01:00
|
|
|
}
|
|
|
|
return $repository->getProjectPHIDs();
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_DIFF_CONTENT:
|
2011-04-06 05:49:31 +02:00
|
|
|
return $this->loadContentDictionary();
|
2013-10-04 15:37:32 +02:00
|
|
|
case self::FIELD_DIFF_ADDED_CONTENT:
|
|
|
|
return $this->loadAddedContentDictionary();
|
|
|
|
case self::FIELD_DIFF_REMOVED_CONTENT:
|
|
|
|
return $this->loadRemovedContentDictionary();
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_AFFECTED_PACKAGE:
|
2011-04-06 05:49:31 +02:00
|
|
|
$packages = $this->loadAffectedPackages();
|
|
|
|
return mpull($packages, 'getPHID');
|
2013-08-02 19:54:19 +02:00
|
|
|
case self::FIELD_AFFECTED_PACKAGE_OWNER:
|
2011-04-06 05:49:31 +02:00
|
|
|
$packages = $this->loadAffectedPackages();
|
2012-03-31 00:46:32 +02:00
|
|
|
return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(
|
|
|
|
mpull($packages, 'getID'));
|
2014-03-11 21:15:01 +01:00
|
|
|
case self::FIELD_ARCANIST_PROJECT:
|
|
|
|
return $this->revision->getArcanistProjectPHID();
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
2013-08-05 19:02:40 +02:00
|
|
|
|
|
|
|
return parent::getHeraldField($field);
|
2013-08-02 20:32:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getActions($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
Support custom actions in Herald
Summary:
This was significantly easier than expected. Here's an example of what an extension class might look like:
```
<?php
final class AddRiskReviewHeraldCustomAction extends HeraldCustomAction {
public function appliesToAdapter(HeraldAdapter $adapter) {
return $adapter instanceof HeraldDifferentialRevisionAdapter;
}
public function appliesToRuleType($rule_type) {
return $rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL ||
$rule_type == HeraldRuleTypeConfig::RULE_TYPE_OBJECT;
}
public function getActionKey() {
return 'custom:add-risk';
}
public function getActionName() {
return 'Add risk rating (JSON)';
}
public function getActionType() {
return HeraldAdapter::VALUE_TEXT;
}
public function applyEffect(
HeraldAdapter $adapter,
$object,
HeraldEffect $effect) {
$key = "phragile:risk-rating";
// Read existing value.
$field_list = PhabricatorCustomField::getObjectFields(
$object,
PhabricatorCustomField::ROLE_VIEW);
$field_list->readFieldsFromStorage($object);
$field_list = mpull($field_list->getFields(), null, 'getFieldKey');
$field = $field_list[$key];
$field->setObject($object);
$field->setViewer(PhabricatorUser::getOmnipotentUser());
$risk = $field->getValue();
$old_risk = $risk; // PHP copies arrays by default!
// Add new value to array.
$herald_args = phutil_json_decode($effect->getTarget());
$risk[$herald_args['key']] = array(
'value' => $herald_args['value'],
'reason' => $herald_args['reason']);
$risk_key = $herald_args['key'];
// Set new value.
$adapter->queueTransaction(
id(new DifferentialTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
->setMetadataValue('customfield:key', $key)
->setOldValue($old_risk)
->setNewValue($risk));
return new HeraldApplyTranscript(
$effect,
true,
pht(
'Modifying automatic risk ratings (key: %s)!',
$risk_key));
}
}
```
Test Plan: Created a custom action for differential revisions, set up a Herald rule to match and trigger the custom action, did 'arc diff' and saw the action trigger in the transcripts.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: locutus, edutibau, ite-klass, epriestley, Korvin
Maniphest Tasks: T4884
Differential Revision: https://secure.phabricator.com/D8784
2014-07-02 06:29:46 +02:00
|
|
|
return array_merge(
|
|
|
|
array(
|
|
|
|
self::ACTION_ADD_CC,
|
|
|
|
self::ACTION_REMOVE_CC,
|
|
|
|
self::ACTION_EMAIL,
|
|
|
|
self::ACTION_ADD_REVIEWERS,
|
|
|
|
self::ACTION_ADD_BLOCKING_REVIEWERS,
|
|
|
|
self::ACTION_APPLY_BUILD_PLANS,
|
|
|
|
self::ACTION_REQUIRE_SIGNATURE,
|
|
|
|
self::ACTION_NOTHING,
|
|
|
|
),
|
|
|
|
parent::getActions($rule_type));
|
2013-08-02 20:32:50 +02:00
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
Support custom actions in Herald
Summary:
This was significantly easier than expected. Here's an example of what an extension class might look like:
```
<?php
final class AddRiskReviewHeraldCustomAction extends HeraldCustomAction {
public function appliesToAdapter(HeraldAdapter $adapter) {
return $adapter instanceof HeraldDifferentialRevisionAdapter;
}
public function appliesToRuleType($rule_type) {
return $rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL ||
$rule_type == HeraldRuleTypeConfig::RULE_TYPE_OBJECT;
}
public function getActionKey() {
return 'custom:add-risk';
}
public function getActionName() {
return 'Add risk rating (JSON)';
}
public function getActionType() {
return HeraldAdapter::VALUE_TEXT;
}
public function applyEffect(
HeraldAdapter $adapter,
$object,
HeraldEffect $effect) {
$key = "phragile:risk-rating";
// Read existing value.
$field_list = PhabricatorCustomField::getObjectFields(
$object,
PhabricatorCustomField::ROLE_VIEW);
$field_list->readFieldsFromStorage($object);
$field_list = mpull($field_list->getFields(), null, 'getFieldKey');
$field = $field_list[$key];
$field->setObject($object);
$field->setViewer(PhabricatorUser::getOmnipotentUser());
$risk = $field->getValue();
$old_risk = $risk; // PHP copies arrays by default!
// Add new value to array.
$herald_args = phutil_json_decode($effect->getTarget());
$risk[$herald_args['key']] = array(
'value' => $herald_args['value'],
'reason' => $herald_args['reason']);
$risk_key = $herald_args['key'];
// Set new value.
$adapter->queueTransaction(
id(new DifferentialTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
->setMetadataValue('customfield:key', $key)
->setOldValue($old_risk)
->setNewValue($risk));
return new HeraldApplyTranscript(
$effect,
true,
pht(
'Modifying automatic risk ratings (key: %s)!',
$risk_key));
}
}
```
Test Plan: Created a custom action for differential revisions, set up a Herald rule to match and trigger the custom action, did 'arc diff' and saw the action trigger in the transcripts.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: locutus, edutibau, ite-klass, epriestley, Korvin
Maniphest Tasks: T4884
Differential Revision: https://secure.phabricator.com/D8784
2014-07-02 06:29:46 +02:00
|
|
|
return array_merge(
|
|
|
|
array(
|
|
|
|
self::ACTION_ADD_CC,
|
|
|
|
self::ACTION_REMOVE_CC,
|
|
|
|
self::ACTION_EMAIL,
|
|
|
|
self::ACTION_FLAG,
|
|
|
|
self::ACTION_ADD_REVIEWERS,
|
|
|
|
self::ACTION_ADD_BLOCKING_REVIEWERS,
|
|
|
|
self::ACTION_NOTHING,
|
|
|
|
),
|
|
|
|
parent::getActions($rule_type));
|
2013-08-02 20:32:50 +02:00
|
|
|
}
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function applyHeraldEffects(array $effects) {
|
2012-03-30 22:51:54 +02:00
|
|
|
assert_instances_of($effects, 'HeraldEffect');
|
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
$result = array();
|
|
|
|
if ($this->explicitCCs) {
|
|
|
|
$effect = new HeraldEffect();
|
2013-08-06 20:23:01 +02:00
|
|
|
$effect->setAction(self::ACTION_ADD_CC);
|
2011-03-25 05:32:26 +01:00
|
|
|
$effect->setTarget(array_keys($this->explicitCCs));
|
|
|
|
$effect->setReason(
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('CCs provided explicitly by revision author or carried over '.
|
|
|
|
'from a previous version of the revision.'));
|
2011-03-25 05:32:26 +01:00
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('Added addresses to CC list.'));
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$forbidden_ccs = array_fill_keys(
|
|
|
|
nonempty($this->forbiddenCCs, array()),
|
|
|
|
true);
|
|
|
|
|
|
|
|
foreach ($effects as $effect) {
|
|
|
|
$action = $effect->getAction();
|
|
|
|
switch ($action) {
|
2013-08-06 20:23:01 +02:00
|
|
|
case self::ACTION_NOTHING:
|
2011-03-25 05:32:26 +01:00
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('OK, did nothing.'));
|
2011-03-25 05:32:26 +01:00
|
|
|
break;
|
2013-08-06 20:23:01 +02:00
|
|
|
case self::ACTION_FLAG:
|
2012-03-30 22:51:54 +02:00
|
|
|
$result[] = parent::applyFlagEffect(
|
|
|
|
$effect,
|
|
|
|
$this->revision->getPHID());
|
|
|
|
break;
|
2013-08-06 20:23:01 +02:00
|
|
|
case self::ACTION_EMAIL:
|
|
|
|
case self::ACTION_ADD_CC:
|
|
|
|
$op = ($action == self::ACTION_EMAIL) ? 'email' : 'CC';
|
2011-03-25 05:32:26 +01:00
|
|
|
$base_target = $effect->getTarget();
|
|
|
|
$forbidden = array();
|
|
|
|
foreach ($base_target as $key => $fbid) {
|
|
|
|
if (isset($forbidden_ccs[$fbid])) {
|
|
|
|
$forbidden[] = $fbid;
|
|
|
|
unset($base_target[$key]);
|
|
|
|
} else {
|
2013-08-06 20:23:01 +02:00
|
|
|
if ($action == self::ACTION_EMAIL) {
|
2011-05-28 00:52:26 +02:00
|
|
|
$this->emailPHIDs[$fbid] = true;
|
|
|
|
} else {
|
|
|
|
$this->newCCs[$fbid] = true;
|
|
|
|
}
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($forbidden) {
|
|
|
|
$failed = clone $effect;
|
|
|
|
$failed->setTarget($forbidden);
|
|
|
|
if ($base_target) {
|
|
|
|
$effect->setTarget($base_target);
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('Added these addresses to %s list. '.
|
|
|
|
'Others could not be added.', $op));
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$failed,
|
|
|
|
false,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('%s forbidden, these addresses have unsubscribed.', $op));
|
2011-03-25 05:32:26 +01:00
|
|
|
} else {
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('Added addresses to %s list.', $op));
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-08-06 20:23:01 +02:00
|
|
|
case self::ACTION_REMOVE_CC:
|
2011-03-25 05:32:26 +01:00
|
|
|
foreach ($effect->getTarget() as $fbid) {
|
|
|
|
$this->remCCs[$fbid] = true;
|
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('Removed addresses from CC list.'));
|
2011-03-25 05:32:26 +01:00
|
|
|
break;
|
2013-10-05 19:36:26 +02:00
|
|
|
case self::ACTION_ADD_REVIEWERS:
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
|
|
|
$this->addReviewerPHIDs[$phid] = true;
|
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Added reviewers.'));
|
|
|
|
break;
|
2013-10-07 02:09:24 +02:00
|
|
|
case self::ACTION_ADD_BLOCKING_REVIEWERS:
|
|
|
|
// This adds reviewers normally, it just also marks them blocking.
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
|
|
|
$this->addReviewerPHIDs[$phid] = true;
|
|
|
|
$this->blockingReviewerPHIDs[$phid] = true;
|
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Added blocking reviewers.'));
|
|
|
|
break;
|
2013-11-09 01:48:17 +01:00
|
|
|
case self::ACTION_APPLY_BUILD_PLANS:
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
|
|
|
$this->buildPlans[] = $phid;
|
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Applied build plans.'));
|
|
|
|
break;
|
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 16:53:53 +02:00
|
|
|
case self::ACTION_REQUIRE_SIGNATURE:
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
|
|
|
$this->requiredSignatureDocumentPHIDs[] = $phid;
|
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Required signatures.'));
|
|
|
|
break;
|
2011-03-25 05:32:26 +01:00
|
|
|
default:
|
Support custom actions in Herald
Summary:
This was significantly easier than expected. Here's an example of what an extension class might look like:
```
<?php
final class AddRiskReviewHeraldCustomAction extends HeraldCustomAction {
public function appliesToAdapter(HeraldAdapter $adapter) {
return $adapter instanceof HeraldDifferentialRevisionAdapter;
}
public function appliesToRuleType($rule_type) {
return $rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL ||
$rule_type == HeraldRuleTypeConfig::RULE_TYPE_OBJECT;
}
public function getActionKey() {
return 'custom:add-risk';
}
public function getActionName() {
return 'Add risk rating (JSON)';
}
public function getActionType() {
return HeraldAdapter::VALUE_TEXT;
}
public function applyEffect(
HeraldAdapter $adapter,
$object,
HeraldEffect $effect) {
$key = "phragile:risk-rating";
// Read existing value.
$field_list = PhabricatorCustomField::getObjectFields(
$object,
PhabricatorCustomField::ROLE_VIEW);
$field_list->readFieldsFromStorage($object);
$field_list = mpull($field_list->getFields(), null, 'getFieldKey');
$field = $field_list[$key];
$field->setObject($object);
$field->setViewer(PhabricatorUser::getOmnipotentUser());
$risk = $field->getValue();
$old_risk = $risk; // PHP copies arrays by default!
// Add new value to array.
$herald_args = phutil_json_decode($effect->getTarget());
$risk[$herald_args['key']] = array(
'value' => $herald_args['value'],
'reason' => $herald_args['reason']);
$risk_key = $herald_args['key'];
// Set new value.
$adapter->queueTransaction(
id(new DifferentialTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
->setMetadataValue('customfield:key', $key)
->setOldValue($old_risk)
->setNewValue($risk));
return new HeraldApplyTranscript(
$effect,
true,
pht(
'Modifying automatic risk ratings (key: %s)!',
$risk_key));
}
}
```
Test Plan: Created a custom action for differential revisions, set up a Herald rule to match and trigger the custom action, did 'arc diff' and saw the action trigger in the transcripts.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: locutus, edutibau, ite-klass, epriestley, Korvin
Maniphest Tasks: T4884
Differential Revision: https://secure.phabricator.com/D8784
2014-07-02 06:29:46 +02:00
|
|
|
$custom_result = parent::handleCustomHeraldEffect($effect);
|
|
|
|
if ($custom_result === null) {
|
|
|
|
throw new Exception("No rules to handle action '{$action}'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$result[] = $custom_result;
|
|
|
|
break;
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2014-07-23 02:03:09 +02:00
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
}
|