diff --git a/src/applications/audit/application/PhabricatorAuditApplication.php b/src/applications/audit/application/PhabricatorAuditApplication.php --- a/src/applications/audit/application/PhabricatorAuditApplication.php +++ b/src/applications/audit/application/PhabricatorAuditApplication.php @@ -19,9 +19,7 @@ } public function canUninstall() { - // Audit was once a separate application, but has largely merged with - // Diffusion. - return false; + return true; } public function isPinnedByDefault(PhabricatorUser $viewer) { diff --git a/src/applications/audit/conduit/AuditConduitAPIMethod.php b/src/applications/audit/conduit/AuditConduitAPIMethod.php --- a/src/applications/audit/conduit/AuditConduitAPIMethod.php +++ b/src/applications/audit/conduit/AuditConduitAPIMethod.php @@ -4,7 +4,7 @@ final public function getApplication() { return PhabricatorApplication::getByClass( - 'PhabricatorDiffusionApplication'); + 'PhabricatorAuditApplication'); } } diff --git a/src/applications/audit/query/PhabricatorCommitSearchEngine.php b/src/applications/audit/query/PhabricatorCommitSearchEngine.php --- a/src/applications/audit/query/PhabricatorCommitSearchEngine.php +++ b/src/applications/audit/query/PhabricatorCommitSearchEngine.php @@ -70,6 +70,7 @@ } protected function buildCustomSearchFields() { + $hide_audit_fields = (!id(new PhabricatorAuditApplication())->isInstalled()); return array( id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Responsible Users')) @@ -93,6 +94,7 @@ ->setConduitKey('auditors') ->setAliases(array('auditor', 'auditors', 'auditorPHID')) ->setDatasource(new DiffusionAuditorFunctionDatasource()) + ->setIsHidden($hide_audit_fields) ->setDescription( pht( 'Find commits where given users, projects, or packages are '. @@ -104,6 +106,7 @@ ->setOptions(DiffusionCommitAuditStatus::newOptions()) ->setDeprecatedOptions( DiffusionCommitAuditStatus::newDeprecatedOptions()) + ->setIsHidden($hide_audit_fields) ->setDescription(pht('Find commits with given audit statuses.')), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Repositories')) @@ -169,9 +172,13 @@ $names = array(); if ($this->requireViewer()->isLoggedIn()) { - $names['active'] = pht('Active Audits'); + if (id(new PhabricatorAuditApplication())->isInstalled()) { + $names['active'] = pht('Active Audits'); + } $names['authored'] = pht('Authored'); - $names['audited'] = pht('Audited'); + if (id(new PhabricatorAuditApplication())->isInstalled()) { + $names['audited'] = pht('Audited'); + } } $names['all'] = pht('All Commits'); @@ -221,9 +228,14 @@ $bucket = $this->getResultBucket($query); + // hide "Auditors" on /diffusion/commit/query/all/ if Audit not installed + $show_auditors = true; + if (!id(new PhabricatorAuditApplication())->isInstalled()) { + $show_auditors = false; + } $template = id(new DiffusionCommitGraphView()) ->setViewer($viewer) - ->setShowAuditors(true); + ->setShowAuditors($show_auditors); $views = array(); if ($bucket) { diff --git a/src/applications/diffusion/editor/DiffusionCommitEditEngine.php b/src/applications/diffusion/editor/DiffusionCommitEditEngine.php --- a/src/applications/diffusion/editor/DiffusionCommitEditEngine.php +++ b/src/applications/diffusion/editor/DiffusionCommitEditEngine.php @@ -100,21 +100,36 @@ $data = $object->getCommitData(); $fields = array(); - - $fields[] = id(new PhabricatorDatasourceEditField()) - ->setKey('auditors') - ->setLabel(pht('Auditors')) - ->setDatasource(new DiffusionAuditorDatasource()) - ->setUseEdgeTransactions(true) - ->setTransactionType( - DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) - ->setCommentActionLabel(pht('Change Auditors')) - ->setDescription(pht('Auditors for this commit.')) - ->setConduitDescription(pht('Change the auditors for this commit.')) - ->setConduitTypeDescription(pht('New auditors.')) - ->setValue($object->getAuditorPHIDsForEdit()); + // remove "Change Auditors" from "Add Action" dropdown etc + // if Audit is not installed + if (id(new PhabricatorAuditApplication())->isInstalled()) { + $fields[] = id(new PhabricatorDatasourceEditField()) + ->setKey('auditors') + ->setLabel(pht('Auditors')) + ->setDatasource(new DiffusionAuditorDatasource()) + ->setUseEdgeTransactions(true) + ->setTransactionType( + DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) + ->setCommentActionLabel(pht('Change Auditors')) + ->setDescription(pht('Auditors for this commit.')) + ->setConduitDescription(pht('Change the auditors for this commit.')) + ->setConduitTypeDescription(pht('New auditors.')) + ->setValue($object->getAuditorPHIDsForEdit()); + } $actions = DiffusionCommitActionTransaction::loadAllActions(); + // remove "Audit Actions" from "Add Action" dropdown if Audit not installed + if (!id(new PhabricatorAuditApplication())->isInstalled()) { + // TODO There must be a PHP way to make this more performant? + foreach ($actions as $actionkey => $value) { + // TODO: Hardcoding sucks; how to check if it's a (non-)audit action? + if ($actionkey === 'accept' || $actionkey === 'concern') { + unset($actions[$actionkey]); + } + } + $actions = array_values($actions); + } + $actions = msortv($actions, 'getCommitActionOrderVector'); foreach ($actions as $key => $action) { diff --git a/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php b/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php --- a/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php +++ b/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php @@ -9,8 +9,13 @@ return pht('Add auditors'); } + // hide "Add auditors" Herald action if Audit not installed public function supportsRuleType($rule_type) { - return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); + if (id(new PhabricatorAuditApplication())->isInstalled()) { + return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); + } else { + return false; + } } public function applyEffect($object, HeraldEffect $effect) { diff --git a/src/applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php b/src/applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php --- a/src/applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php +++ b/src/applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php @@ -9,8 +9,13 @@ return pht('Add me as an auditor'); } + // hide "Add me as an auditor" Herald action if Audit not installed public function supportsRuleType($rule_type) { - return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); + if (id(new PhabricatorAuditApplication())->isInstalled()) { + return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); + } else { + return false; + } } public function applyEffect($object, HeraldEffect $effect) { diff --git a/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php --- a/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php @@ -5,6 +5,15 @@ const FIELDCONST = 'diffusion.commit.auditors'; + // hide "Auditors" Herald condition if Audit not installed + public function supportsObject($object) { + if (id(new PhabricatorAuditApplication())->isInstalled()) { + return ($object instanceof PhabricatorRepositoryCommit); + } else { + return false; + } + } + public function getHeraldFieldName() { return pht('Auditors'); } diff --git a/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php --- a/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php @@ -5,6 +5,16 @@ const FIELDCONST = 'diffusion.commit.package.audit'; + // hide "Affected packages that need audit" Herald condition + // if Audit not installed + public function supportsObject($object) { + if (id(new PhabricatorAuditApplication())->isInstalled()) { + return ($object instanceof PhabricatorRepositoryCommit); + } else { + return false; + } + } + public function getHeraldFieldName() { return pht('Affected packages that need audit'); } diff --git a/src/applications/diffusion/view/DiffusionCommitGraphView.php b/src/applications/diffusion/view/DiffusionCommitGraphView.php --- a/src/applications/diffusion/view/DiffusionCommitGraphView.php +++ b/src/applications/diffusion/view/DiffusionCommitGraphView.php @@ -169,7 +169,10 @@ $this->addBuildAction($item_view, $hash); } - $this->addAuditAction($item_view, $hash); + // hide Audit entry on /diffusion/commit/query/all if Audit not installed + if (id(new PhabricatorAuditApplication())->isInstalled()) { + $this->addAuditAction($item_view, $hash); + } if ($show_auditors) { $auditor_list = $item_view->newMapView();