@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.

Add Maniphest Herald condition "Acting user's projects"

Summary:
Support performing a Herald action in Maniphest only when the acting user is a member of specific project(s) defined in the conditions of the Herald rule.
This can be useful when project membership is restricted (projects used as Access control lists (ACL)).

Example use case: Make Herald add a comment when the description of a newly created task is empty but do not add a comment when done by a user who is a member of the #Trusted-Folks ACL project.

This borrows/copies code from DiffusionPreCommitContentAuthorProjectsHeraldField.

Closes T16120

Test Plan:
* Go to http://phorge.localhost/herald/edit/?content_type=HeraldManiphestTaskAdapter&rule_type=global to create a global Herald rule for Maniphest tasks.
* Click the "New Condition" button and see under "Supporting Applications" a new option "Acting user's projects"
* Under "Conditions", set:
** When all of these conditions are met:
** Description | matches regexp | @^$@
** Is newly created | is true
** Acting user's projects | include any of | #someExistingProject
* Under "Actions", set:
** Take these actions every time this rule matches:
** Change status to Spite
* Add yourself as a member to #someExistingProject
* File a task with an empty description, see that Herald set its status to Spite
* File more tasks with empty descriptions after changing the Herald condition to the other available options "include none of", "include all of" (after joining another project), "exists", and "does not exist", still behaves as expected
* Under "Acting user's projects | include any of", try to enter or select a milestone, see that it's not available as milestones cannot have members

It's all pretty much the same game as the condition "Author's projects" in http://phorge.localhost/herald/edit/?content_type=differential.diff&rule_type=global (with additional milestone exclusion).

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16120

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

+48
+2
src/__phutil_library_map__.php
··· 1826 1826 'ManiphestStatusesConfigType' => 'applications/maniphest/config/ManiphestStatusesConfigType.php', 1827 1827 'ManiphestSubtypesConfigType' => 'applications/maniphest/config/ManiphestSubtypesConfigType.php', 1828 1828 'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php', 1829 + 'ManiphestTaskActingUsersProjectsHeraldField' => 'applications/maniphest/herald/ManiphestTaskActingUsersProjectsHeraldField.php', 1829 1830 'ManiphestTaskAssignHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignHeraldAction.php', 1830 1831 'ManiphestTaskAssignOtherHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignOtherHeraldAction.php', 1831 1832 'ManiphestTaskAssignSelfHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignSelfHeraldAction.php', ··· 8078 8079 'PhabricatorPolicyCodexInterface', 8079 8080 'PhabricatorUnlockableInterface', 8080 8081 ), 8082 + 'ManiphestTaskActingUsersProjectsHeraldField' => 'ManiphestTaskHeraldField', 8081 8083 'ManiphestTaskAssignHeraldAction' => 'HeraldAction', 8082 8084 'ManiphestTaskAssignOtherHeraldAction' => 'ManiphestTaskAssignHeraldAction', 8083 8085 'ManiphestTaskAssignSelfHeraldAction' => 'ManiphestTaskAssignHeraldAction',
+46
src/applications/maniphest/herald/ManiphestTaskActingUsersProjectsHeraldField.php
··· 1 + <?php 2 + 3 + final class ManiphestTaskActingUsersProjectsHeraldField 4 + extends ManiphestTaskHeraldField { 5 + 6 + const FIELDCONST = 'herald.acting-user.projects'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht("Acting user's projects"); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + $adapter = $this->getAdapter(); 14 + $viewer = $adapter->getViewer(); 15 + 16 + $actor_phid = $this->getAdapter()->getActingAsPHID(); 17 + if (!$actor_phid) { 18 + return array(); 19 + } 20 + 21 + $projects = id(new PhabricatorProjectQuery()) 22 + ->setViewer($viewer) 23 + ->withMemberPHIDs(array($actor_phid)) 24 + ->withIsMilestone(false) 25 + ->execute(); 26 + 27 + return mpull($projects, 'getPHID'); 28 + } 29 + 30 + protected function getHeraldFieldStandardType() { 31 + return self::STANDARD_PHID_LIST; 32 + } 33 + 34 + protected function getDatasource() { 35 + // Prevent selecting milestones as they cannot have members 36 + return id(new PhabricatorProjectDatasource())->setParameters( 37 + array( 38 + 'policy' => 1, 39 + )); 40 + } 41 + 42 + public function getFieldGroupKey() { 43 + return HeraldSupportFieldGroup::FIELDGROUPKEY; 44 + } 45 + 46 + }