@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 projects to own packages

Summary:
- The UI is pretty straightforward, since Handle just works (tm)
- Added two methods to the owners object to handle the new layer of
indirection. Then ran git grep PhabricatorOwnersOwner and changed
callsites as appropriate.

Sending this to get a round of feedback before I test the non-trivial
changes in this diff.

Test Plan:
- owners tool: edit, view, list for basic functionality.
- phlog for the two new methods I added

Reviewers: epriestley, blair, jungejason

CC: aran

Differential Revision: https://secure.phabricator.com/D2079

mkedia 591d5000 8813c7be

+66 -11
+5
src/__phutil_library_map__.php
··· 929 929 ), 930 930 'function' => 931 931 array( 932 + '__phabricator_date_format' => 'view/utils', 932 933 '__phabricator_format_local_time' => 'view/utils', 933 934 '_qsprintf_check_scalar_type' => 'storage/qsprintf', 934 935 '_qsprintf_check_type' => 'storage/qsprintf', ··· 939 940 'phabricator_datetime' => 'view/utils', 940 941 'phabricator_format_relative_time' => 'view/utils', 941 942 'phabricator_format_units_generic' => 'view/utils', 943 + 'phabricator_on_relative_date' => 'view/utils', 944 + 'phabricator_relative_date' => 'view/utils', 942 945 'phabricator_render_form' => 'infrastructure/javelin/markup', 943 946 'phabricator_time' => 'view/utils', 947 + 'phid_get_type' => 'applications/phid/utils', 948 + 'phid_group_by_type' => 'applications/phid/utils', 944 949 'qsprintf' => 'storage/qsprintf', 945 950 'queryfx' => 'storage/queryfx', 946 951 'queryfx_all' => 'storage/queryfx',
+2 -2
src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php
··· 202 202 $phids[$user->getPHID()] = true; 203 203 204 204 // The user can audit on behalf of all packages they own. 205 - $owned_packages = id(new PhabricatorOwnersOwner())->loadAllWhere( 206 - 'userPHID = %s', 205 + $owned_packages = PhabricatorOwnersOwner::loadAffiliatedPackages( 207 206 $user->getPHID()); 207 + 208 208 if ($owned_packages) { 209 209 $packages = id(new PhabricatorOwnersPackage())->loadAllWhere( 210 210 'id IN (%Ld)',
+2 -2
src/applications/herald/adapter/differential/HeraldDifferentialRevisionAdapter.php
··· 217 217 return mpull($packages, 'getPHID'); 218 218 case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: 219 219 $packages = $this->loadAffectedPackages(); 220 - $owners = PhabricatorOwnersOwner::loadAllForPackages($packages); 221 - return mpull($owners, 'getUserPHID'); 220 + return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( 221 + mpull($packages, 'getID')); 222 222 default: 223 223 throw new Exception("Invalid field '{$field}'."); 224 224 }
+2 -2
src/applications/owners/controller/edit/PhabricatorOwnersEditController.php
··· 203 203 ->setError($e_name)) 204 204 ->appendChild( 205 205 id(new AphrontFormTokenizerControl()) 206 - ->setDatasource('/typeahead/common/users/') 206 + ->setDatasource('/typeahead/common/usersorprojects/') 207 207 ->setLabel('Primary Owner') 208 208 ->setName('primary') 209 209 ->setLimit(1) ··· 211 211 ->setError($e_primary)) 212 212 ->appendChild( 213 213 id(new AphrontFormTokenizerControl()) 214 - ->setDatasource('/typeahead/common/users/') 214 + ->setDatasource('/typeahead/common/usersorprojects/') 215 215 ->setLabel('Owners') 216 216 ->setName('owners') 217 217 ->setValue($token_all_owners)
+1 -1
src/applications/owners/controller/list/PhabricatorOwnersListController.php
··· 171 171 ->setValue($request->getStr('name'))) 172 172 ->appendChild( 173 173 id(new AphrontFormTokenizerControl()) 174 - ->setDatasource('/typeahead/common/users/') 174 + ->setDatasource('/typeahead/common/usersorprojects/') 175 175 ->setLimit(1) 176 176 ->setName('owner') 177 177 ->setLabel('Owner')
+43
src/applications/owners/storage/owner/PhabricatorOwnersOwner.php
··· 19 19 final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO { 20 20 21 21 protected $packageID; 22 + 23 + // this can be a project or a user. We assume that all members of a project 24 + // owner also own the package; use the loadAffiliatedUserPHIDs method if 25 + // you want to recursively grab all user ids that own a package 22 26 protected $userPHID; 23 27 24 28 public function getConfiguration() { ··· 37 41 mpull($packages, 'getID')); 38 42 } 39 43 44 + // Loads all user phids affiliated with a set of packages. This includes both 45 + // user owners and all members of any project owners 46 + public static function loadAffiliatedUserPHIDs(array $package_ids) { 47 + $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 48 + 'packageID IN (%Ls)', 49 + $package_ids); 50 + 51 + $all_phids = phid_group_by_type(mpull($owners, 'getUserPHID')); 52 + 53 + $user_phids = idx($all_phids, 54 + PhabricatorPHIDConstants::PHID_TYPE_USER, 55 + array()); 56 + 57 + $users_in_project_phids = array(); 58 + if (idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ)) { 59 + $users_in_project_phids = mpull( 60 + id(new PhabricatorProjectAffiliation())->loadAllWhere( 61 + 'projectPHID IN (%Ls)', 62 + idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ, array())), 63 + 'getUserPHID'); 64 + } 65 + 66 + return array_unique(array_merge($users_in_project_phids, $user_phids)); 67 + } 68 + 69 + // Loads all affiliated packages for a user. This includes packages owned by 70 + // any project the user is a member of. 71 + public static function loadAffiliatedPackages($user_phid) { 72 + $query = new PhabricatorProjectQuery(); 73 + $query->setMembers(array($user_phid)); 74 + $query->withStatus(PhabricatorProjectQuery::STATUS_ACTIVE); 75 + $projects = $query->execute(); 76 + 77 + $phids = mpull($projects, 'getPHID') + array($user_phid); 78 + return 79 + id(new PhabricatorOwnersOwner())->loadAllWhere( 80 + 'userPHID in (%Ls)', 81 + $phids); 82 + } 40 83 }
+4
src/applications/owners/storage/owner/__init__.php
··· 7 7 8 8 9 9 phutil_require_module('phabricator', 'applications/owners/storage/base'); 10 + phutil_require_module('phabricator', 'applications/phid/constants'); 11 + phutil_require_module('phabricator', 'applications/phid/utils'); 12 + phutil_require_module('phabricator', 'applications/project/query/project'); 13 + phutil_require_module('phabricator', 'applications/project/storage/affiliation'); 10 14 11 15 phutil_require_module('phutil', 'utils'); 12 16
+2 -4
src/applications/repository/worker/owner/PhabricatorRepositoryCommitOwnersWorker.php
··· 126 126 $reasons[] = "No Revision Specified"; 127 127 } 128 128 129 - $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 130 - 'packageID = %d', 131 - $package->getID()); 132 - $owners_phids = mpull($owners, 'getUserPHID'); 129 + $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( 130 + array($package->getID())); 133 131 134 132 if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || 135 133 $commit_reviewedby_phid && in_array($commit_reviewedby_phid,
+4
src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php
··· 61 61 case 'projects': 62 62 $need_projs = true; 63 63 break; 64 + case 'usersorprojects': 65 + $need_users = true; 66 + $need_projs = true; 67 + break; 64 68 case 'repositories': 65 69 $need_repos = true; 66 70 break;
+1
src/view/form/control/tokenizer/AphrontFormTokenizerControl.php
··· 105 105 106 106 $map = array( 107 107 'users' => 'Type a user name...', 108 + 'usersorprojects' => 'Type a user or project name...', 108 109 'searchowner' => 'Type a user name...', 109 110 'accounts' => 'Type a user name...', 110 111 'mailable' => 'Type a user or mailing list...',