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

Implement readProjectsFromRequest() helper for SearchEngines

Summary:
Ref T4100. This just makes the "specify stuff in query parameters" workflow a little better:

- You can now do `?projects=differential,diffusion`.
- You can now do `?projects=projects(alincoln)`.

Test Plan: Did that stuff ^^^^

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4100

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

+107 -7
+2 -3
src/applications/differential/query/DifferentialRevisionSearchEngine.php
··· 40 40 41 41 $saved->setParameter( 42 42 'subscriberPHIDs', 43 - $this->readUsersFromRequest($request, 'subscribers')); 43 + $this->readSubscribersFromRequest($request, 'subscribers')); 44 44 45 45 $saved->setParameter( 46 46 'repositoryPHIDs', 47 47 $request->getArr('repositories')); 48 48 49 - // TODO: Implement "readProjectsFromRequest(...)" to improve this. 50 49 $saved->setParameter( 51 50 'projects', 52 - $this->readListFromRequest($request, 'projects')); 51 + $this->readProjectsFromRequest($request, 'projects')); 53 52 54 53 $saved->setParameter( 55 54 'draft',
-1
src/applications/phid/PhabricatorPHIDConstants.php
··· 2 2 3 3 final class PhabricatorPHIDConstants { 4 4 5 - const PHID_TYPE_USER = 'USER'; 6 5 const PHID_TYPE_UNKNOWN = '????'; 7 6 const PHID_TYPE_MAGIC = '!!!!'; 8 7 const PHID_TYPE_STRY = 'STRY';
+38
src/applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php
··· 44 44 $phids[] = head($argv); 45 45 } 46 46 47 + $phids = $this->resolvePHIDs($phids); 48 + 47 49 $projects = id(new PhabricatorProjectQuery()) 48 50 ->setViewer($this->getViewer()) 49 51 ->withMemberPHIDs($phids) ··· 65 67 $phids[] = head($argv); 66 68 } 67 69 70 + $phids = $this->resolvePHIDs($phids); 71 + 68 72 $tokens = $this->renderTokens($phids); 69 73 foreach ($tokens as $token) { 70 74 if ($token->isInvalid()) { ··· 80 84 } 81 85 82 86 return $tokens; 87 + } 88 + 89 + private function resolvePHIDs(array $phids) { 90 + // If we have a function like `projects(alincoln)`, try to resolve the 91 + // username first. This won't happen normally, but can be passed in from 92 + // the query string. 93 + 94 + // The user might also give us an invalid username. In this case, we 95 + // preserve it and return it in-place so we get an "invalid" token rendered 96 + // in the UI. This shows the user where the issue is and best represents 97 + // the user's input. 98 + 99 + $usernames = array(); 100 + foreach ($phids as $key => $phid) { 101 + if (phid_get_type($phid) != PhabricatorPeopleUserPHIDType::TYPECONST) { 102 + $usernames[$key] = $phid; 103 + } 104 + } 105 + 106 + if ($usernames) { 107 + $users = id(new PhabricatorPeopleQuery()) 108 + ->setViewer($this->getViewer()) 109 + ->withUsernames($usernames) 110 + ->execute(); 111 + $users = mpull($users, null, 'getUsername'); 112 + foreach ($usernames as $key => $username) { 113 + $user = idx($users, $username); 114 + if ($user) { 115 + $phids[$key] = $user->getPHID(); 116 + } 117 + } 118 + } 119 + 120 + return $phids; 83 121 } 84 122 85 123 }
+67 -3
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 378 378 * @param AphrontRequest Request to read user PHIDs from. 379 379 * @param string Key to read in the request. 380 380 * @param list<const> Other permitted PHID types. 381 - * @return list<phid> List of user PHIDs. 382 - * 381 + * @return list<phid> List of user PHIDs and selector functions. 383 382 * @task read 384 383 */ 385 384 protected function readUsersFromRequest( ··· 392 391 $phids = array(); 393 392 $names = array(); 394 393 $allow_types = array_fuse($allow_types); 395 - $user_type = PhabricatorPHIDConstants::PHID_TYPE_USER; 394 + $user_type = PhabricatorPeopleUserPHIDType::TYPECONST; 396 395 foreach ($list as $item) { 397 396 $type = phid_get_type($item); 398 397 if ($type == $user_type) { ··· 422 421 } 423 422 424 423 return $phids; 424 + } 425 + 426 + 427 + /** 428 + * Read a list of project PHIDs from a request in a flexible way. 429 + * 430 + * @param AphrontRequest Request to read user PHIDs from. 431 + * @param string Key to read in the request. 432 + * @return list<phid> List of projet PHIDs and selector functions. 433 + * @task read 434 + */ 435 + protected function readProjectsFromRequest(AphrontRequest $request, $key) { 436 + $list = $this->readListFromRequest($request, $key); 437 + 438 + $phids = array(); 439 + $slugs = array(); 440 + $project_type = PhabricatorProjectProjectPHIDType::TYPECONST; 441 + foreach ($list as $item) { 442 + $type = phid_get_type($item); 443 + if ($type == $project_type) { 444 + $phids[] = $item; 445 + } else { 446 + if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) { 447 + // If this is a function, pass it through unchanged; we'll evaluate 448 + // it later. 449 + $phids[] = $item; 450 + } else { 451 + $slugs[] = $item; 452 + } 453 + } 454 + } 455 + 456 + if ($slugs) { 457 + $projects = id(new PhabricatorProjectQuery()) 458 + ->setViewer($this->requireViewer()) 459 + ->withSlugs($slugs) 460 + ->execute(); 461 + foreach ($projects as $project) { 462 + $phids[] = $project->getPHID(); 463 + } 464 + $phids = array_unique($phids); 465 + } 466 + 467 + return $phids; 468 + } 469 + 470 + 471 + /** 472 + * Read a list of subscribers from a request in a flexible way. 473 + * 474 + * @param AphrontRequest Request to read PHIDs from. 475 + * @param string Key to read in the request. 476 + * @return list<phid> List of object PHIDs. 477 + * @task read 478 + */ 479 + protected function readSubscribersFromRequest( 480 + AphrontRequest $request, 481 + $key) { 482 + return $this->readUsersFromRequest( 483 + $request, 484 + $key, 485 + array( 486 + PhabricatorProjectProjectPHIDType::TYPECONST, 487 + PhabricatorMailingListListPHIDType::TYPECONST, 488 + )); 425 489 } 426 490 427 491