@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow to uninstall (hide) Audit application

Summary:
While many Phorge applications can be uninstalled (such as Differential for pre-merge commit review), this has not been the case for Audit (post-merge commit review) since rP11861265fe94fa97e4d0563c5bdb7b8cac27282d.

In installations which do not use Audit in their workflows, exposing Audit related UI elements creates additional clutter and complexity.

Fixes T15129

Test Plan:
* Go to `/applications/view/PhabricatorAuditApplication/` and click "Uninstall"
* View an individual merged commit in Diffusion, click "Edit Commit" in the sidebar to go to `/diffusion/commit/edit/1/`, see that "Auditors" datasource is not displayed
* View an individual merged commit in Diffusion, click the "Add Action..." dropdown, see that the "Audit Action" section and its entries "Accept Commit" and "Raise Concern" are not displayed
* View an individual merged commit in Diffusion, click the "Add Action..." dropdown, see that the "Change Auditors" entry is not displayed
* Go to `/conduit/` and see that the API method "audit.query" and the entire section "audit" is not displayed
* Go to `/diffusion/commit/` and see no "Active Audits" and "Audited" searches in the left side bar
* Go to `/diffusion/commit/query/all/` and see that no "Auditors" entry is shown for each commit
* Go to `/diffusion/commit/query/all/` and see that no audit related entry is shown in the grey column on the right (if Harbormaster is not installed, there will be no grey column at all)
* Go to `/herald/edit/?content_type=commit&rule_type=global` and see that no Condition entry "Auditors" and no Condition entry "Affected packages that need audit" is displayed
* Go to `/herald/edit/?content_type=commit&rule_type=personal` and see that no "Add me as an auditor" Herald action and no "Added Auditors" Herald condition is displayed

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15129

Differential Revision: https://we.phorge.it/D25503

+79 -32
+1 -3
src/applications/audit/application/PhabricatorAuditApplication.php
··· 19 19 } 20 20 21 21 public function canUninstall() { 22 - // Audit was once a separate application, but has largely merged with 23 - // Diffusion. 24 - return false; 22 + return true; 25 23 } 26 24 27 25 public function isPinnedByDefault(PhabricatorUser $viewer) {
+1 -1
src/applications/audit/conduit/AuditConduitAPIMethod.php
··· 4 4 5 5 final public function getApplication() { 6 6 return PhabricatorApplication::getByClass( 7 - 'PhabricatorDiffusionApplication'); 7 + 'PhabricatorAuditApplication'); 8 8 } 9 9 10 10 }
+12 -3
src/applications/audit/query/PhabricatorCommitSearchEngine.php
··· 70 70 } 71 71 72 72 protected function buildCustomSearchFields() { 73 + $show_audit_fields = (id(new PhabricatorAuditApplication())->isInstalled()); 73 74 $show_packages = PhabricatorApplication::isClassInstalled( 74 75 'PhabricatorPackagesApplication'); 75 76 return array( ··· 95 96 ->setConduitKey('auditors') 96 97 ->setAliases(array('auditor', 'auditors', 'auditorPHID')) 97 98 ->setDatasource(new DiffusionAuditorFunctionDatasource()) 99 + ->setIsHidden(!$show_audit_fields) 98 100 ->setDescription( 99 101 pht( 100 102 'Find commits where given users, projects, or packages are '. ··· 106 108 ->setOptions(DiffusionCommitAuditStatus::newOptions()) 107 109 ->setDeprecatedOptions( 108 110 DiffusionCommitAuditStatus::newDeprecatedOptions()) 111 + ->setIsHidden(!$show_audit_fields) 109 112 ->setDescription(pht('Find commits with given audit statuses.')), 110 113 id(new PhabricatorSearchDatasourceField()) 111 114 ->setLabel(pht('Repositories')) ··· 172 175 $names = array(); 173 176 174 177 if ($this->requireViewer()->isLoggedIn()) { 175 - $names['active'] = pht('Active Audits'); 178 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 179 + $names['active'] = pht('Active Audits'); 180 + } 176 181 $names['authored'] = pht('Authored'); 177 - $names['audited'] = pht('Audited'); 182 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 183 + $names['audited'] = pht('Audited'); 184 + } 178 185 } 179 186 180 187 $names['all'] = pht('All Commits'); ··· 224 231 225 232 $bucket = $this->getResultBucket($query); 226 233 234 + // hide "Auditors" on /diffusion/commit/query/all/ if Audit not installed 235 + $show_auditors = id(new PhabricatorAuditApplication())->isInstalled(); 227 236 $template = id(new DiffusionCommitGraphView()) 228 237 ->setViewer($viewer) 229 - ->setShowAuditors(true); 238 + ->setShowAuditors($show_auditors); 230 239 231 240 $views = array(); 232 241 if ($bucket) {
+16 -13
src/applications/diffusion/editor/DiffusionCommitEditEngine.php
··· 100 100 $data = $object->getCommitData(); 101 101 102 102 $fields = array(); 103 - 104 - $fields[] = id(new PhabricatorDatasourceEditField()) 105 - ->setKey('auditors') 106 - ->setLabel(pht('Auditors')) 107 - ->setDatasource(new DiffusionAuditorDatasource()) 108 - ->setUseEdgeTransactions(true) 109 - ->setTransactionType( 110 - DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) 111 - ->setCommentActionLabel(pht('Change Auditors')) 112 - ->setDescription(pht('Auditors for this commit.')) 113 - ->setConduitDescription(pht('Change the auditors for this commit.')) 114 - ->setConduitTypeDescription(pht('New auditors.')) 115 - ->setValue($object->getAuditorPHIDsForEdit()); 103 + // remove "Change Auditors" from "Add Action" dropdown etc 104 + // if Audit is not installed 105 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 106 + $fields[] = id(new PhabricatorDatasourceEditField()) 107 + ->setKey('auditors') 108 + ->setLabel(pht('Auditors')) 109 + ->setDatasource(new DiffusionAuditorDatasource()) 110 + ->setUseEdgeTransactions(true) 111 + ->setTransactionType( 112 + DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) 113 + ->setCommentActionLabel(pht('Change Auditors')) 114 + ->setDescription(pht('Auditors for this commit.')) 115 + ->setConduitDescription(pht('Change the auditors for this commit.')) 116 + ->setConduitTypeDescription(pht('New auditors.')) 117 + ->setValue($object->getAuditorPHIDsForEdit()); 118 + } 116 119 117 120 $actions = DiffusionCommitActionTransaction::loadAllActions(); 118 121 $actions = msortv($actions, 'getCommitActionOrderVector');
+6 -1
src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php
··· 9 9 return pht('Add auditors'); 10 10 } 11 11 12 + // hide "Add auditors" Herald action if Audit not installed 12 13 public function supportsRuleType($rule_type) { 13 - return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 14 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 15 + return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 16 + } else { 17 + return false; 18 + } 14 19 } 15 20 16 21 public function applyEffect($object, HeraldEffect $effect) {
+6 -1
src/applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php
··· 9 9 return pht('Add me as an auditor'); 10 10 } 11 11 12 + // hide "Add me as an auditor" Herald action if Audit not installed 12 13 public function supportsRuleType($rule_type) { 13 - return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 14 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 15 + return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 16 + } else { 17 + return false; 18 + } 14 19 } 15 20 16 21 public function applyEffect($object, HeraldEffect $effect) {
+9
src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php
··· 5 5 6 6 const FIELDCONST = 'diffusion.commit.auditors'; 7 7 8 + // hide "Auditors" Herald condition if Audit not installed 9 + public function supportsObject($object) { 10 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 11 + return ($object instanceof PhabricatorRepositoryCommit); 12 + } else { 13 + return false; 14 + } 15 + } 16 + 8 17 public function getHeraldFieldName() { 9 18 return pht('Auditors'); 10 19 }
+10
src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php
··· 5 5 6 6 const FIELDCONST = 'diffusion.commit.package.audit'; 7 7 8 + // hide "Affected packages that need audit" Herald condition 9 + // if Audit not installed 10 + public function supportsObject($object) { 11 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 12 + return ($object instanceof PhabricatorRepositoryCommit); 13 + } else { 14 + return false; 15 + } 16 + } 17 + 8 18 public function getHeraldFieldName() { 9 19 return pht('Affected packages that need audit'); 10 20 }
+4 -1
src/applications/diffusion/view/DiffusionCommitGraphView.php
··· 169 169 $this->addBuildAction($item_view, $hash); 170 170 } 171 171 172 - $this->addAuditAction($item_view, $hash); 172 + // hide Audit entry on /diffusion/commit/query/all if Audit not installed 173 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 174 + $this->addAuditAction($item_view, $hash); 175 + } 173 176 174 177 if ($show_auditors) { 175 178 $auditor_list = $item_view->newMapView();
+3
src/applications/diffusion/xaction/DiffusionCommitActionTransaction.php
··· 8 8 } 9 9 10 10 public function isActionAvailable($object, PhabricatorUser $viewer) { 11 + if (!id(new PhabricatorAuditApplication())->isInstalled()) { 12 + return false; 13 + } 11 14 try { 12 15 $this->validateAction($object, $viewer); 13 16 return true;
+11 -9
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 275 275 ->setOptions($orders); 276 276 } 277 277 278 - $buckets = $this->newResultBuckets(); 279 - if ($query && $buckets) { 280 - $bucket_options = array( 281 - self::BUCKET_NONE => pht('No Bucketing'), 282 - ) + mpull($buckets, 'getResultBucketName'); 278 + if (id(new PhabricatorAuditApplication())->isInstalled()) { 279 + $buckets = $this->newResultBuckets(); 280 + if ($query && $buckets) { 281 + $bucket_options = array( 282 + self::BUCKET_NONE => pht('No Bucketing'), 283 + ) + mpull($buckets, 'getResultBucketName'); 283 284 284 - $fields[] = id(new PhabricatorSearchSelectField()) 285 - ->setLabel(pht('Bucket')) 286 - ->setKey('bucket') 287 - ->setOptions($bucket_options); 285 + $fields[] = id(new PhabricatorSearchSelectField()) 286 + ->setLabel(pht('Bucket')) 287 + ->setKey('bucket') 288 + ->setOptions($bucket_options); 289 + } 288 290 } 289 291 290 292 $field_map = array();