Commit 0818d906 authored by Daniel Stone's avatar Daniel Stone 🌴 Committed by Ana Rute Mendes
Browse files

LOCAL/POLICY: Project: Make project field required for Maniphest

Enforce a local policy that all tasks must have an associated project.
parent 349cdac6
......@@ -316,6 +316,48 @@ final class ManiphestTransactionEditor
$errors[] = $error;
}
if (!$this->getIsNewObject()) {
$projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
$object->getPHID(),
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
$projects = array_fuse($projects);
} else {
$projects = array();
}
foreach ($xactions as $xaction) {
$xaction_type = $xaction->getTransactionType();
$edge_type = $xaction->getMetadataValue('edge:type');
if ($xaction_type != PhabricatorTransactions::TYPE_EDGE ||
$edge_type != PhabricatorProjectObjectHasProjectEdgeType::EDGECONST) {
continue;
}
$new = $xaction->getNewValue();
$new_add = idx($new, '+', array());
$new_rem = idx($new, '-', array());
$new_set = idx($new, '=', null);
foreach ($new_add as $phid => $edge) {
$projects[$phid] = $phid;
}
foreach ($new_rem as $phid => $edge) {
unset($projects[$phid]);
}
if ($new_set) {
$projects = $new_set;
}
}
if (empty($projects)) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
PhabricatorTransactions::TYPE_EDGE,
pht('Required'),
pht('You must specify at least one project tag for a task.'),
null
);
}
return $errors;
}
......
......@@ -63,6 +63,10 @@ final class PhabricatorProjectsEditEngineExtension
->setValue($project_phids)
->setViewer($viewer);
if ($object instanceof ManiphestTask) {
$projects_field->setIsRequired(true);
}
$projects_datasource = id(new PhabricatorProjectDatasource())
->setViewer($viewer);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment