protected static function queryByAffiliatedUser($owner)
 {
     $is_valid_phid = phid_get_type($owner) == PhabricatorPHIDConstants::PHID_TYPE_USER;
     if (!$is_valid_phid) {
         throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription('Expected user PHID for affiliation, got ' . $owner);
     }
     $owners = PhabricatorOwnersOwner::loadAffiliatedPackages($owner);
     $package_ids = mpull($owners, 'getPackageID');
     $packages = array();
     foreach ($package_ids as $id) {
         $packages[] = id(new PhabricatorOwnersPackage())->load($id);
     }
     return $packages;
 }
 /**
  * Load the PHIDs for all objects the user has the authority to act as an
  * audit for. This includes themselves, and any packages they are an owner
  * of.
  */
 public static function loadAuditPHIDsForUser(PhabricatorUser $user)
 {
     $phids = array();
     // The user can audit on their own behalf.
     $phids[$user->getPHID()] = true;
     // The user can audit on behalf of all packages they own.
     $owned_packages = PhabricatorOwnersOwner::loadAffiliatedPackages($user->getPHID());
     if ($owned_packages) {
         $packages = id(new PhabricatorOwnersPackage())->loadAllWhere('id IN (%Ld)', mpull($owned_packages, 'getPackageID'));
         foreach (mpull($packages, 'getPHID') as $phid) {
             $phids[$phid] = true;
         }
     }
     // The user can audit on behalf of all projects they are a member of.
     $query = new PhabricatorProjectQuery();
     $query->setMembers(array($user->getPHID()));
     $projects = $query->execute();
     foreach ($projects as $project) {
         $phids[$project->getPHID()] = true;
     }
     return array_keys($phids);
 }