Changeset View
Changeset View
Standalone View
Standalone View
src/applications/doorkeeper/worker/DoorkeeperAsanaFeedWorker.php
| Show First 20 Lines • Show All 519 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
| private function lookupAsanaUserIDs($all_phids) { | private function lookupAsanaUserIDs($all_phids) { | ||||
| $phid_map = array(); | $phid_map = array(); | ||||
| $all_phids = array_unique(array_filter($all_phids)); | $all_phids = array_unique(array_filter($all_phids)); | ||||
| if (!$all_phids) { | if (!$all_phids) { | ||||
| return $phid_map; | return $phid_map; | ||||
| } | } | ||||
| $provider = PhabricatorAsanaAuthProvider::getAsanaProvider(); | $accounts = $this->loadAsanaExternalAccounts($all_phids); | ||||
| $accounts = id(new PhabricatorExternalAccountQuery()) | |||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
| ->withUserPHIDs($all_phids) | |||||
| ->withAccountTypes(array($provider->getProviderType())) | |||||
| ->withAccountDomains(array($provider->getProviderDomain())) | |||||
| ->needAccountIdentifiers(true) | |||||
| ->requireCapabilities( | |||||
| array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| )) | |||||
| ->execute(); | |||||
| foreach ($accounts as $account) { | foreach ($accounts as $account) { | ||||
| $phid_map[$account->getUserPHID()] = $this->getAsanaAccountID($account); | $phid_map[$account->getUserPHID()] = $this->getAsanaAccountID($account); | ||||
| } | } | ||||
| // Put this back in input order. | // Put this back in input order. | ||||
| $phid_map = array_select_keys($phid_map, $all_phids); | $phid_map = array_select_keys($phid_map, $all_phids); | ||||
| return $phid_map; | return $phid_map; | ||||
| } | } | ||||
| private function findAnyValidAsanaAccessToken(array $user_phids) { | private function loadAsanaExternalAccounts(array $user_phids) { | ||||
| if (!$user_phids) { | |||||
| return array(null, null, null); | |||||
| } | |||||
| $provider = $this->getProvider(); | $provider = $this->getProvider(); | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| if (!$user_phids) { | |||||
| return array(); | |||||
| } | |||||
| $accounts = id(new PhabricatorExternalAccountQuery()) | $accounts = id(new PhabricatorExternalAccountQuery()) | ||||
| ->setViewer($viewer) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withUserPHIDs($user_phids) | ->withUserPHIDs($user_phids) | ||||
| ->withAccountTypes(array($provider->getProviderType())) | ->withProviderConfigPHIDs( | ||||
| ->withAccountDomains(array($provider->getProviderDomain())) | array( | ||||
| $provider->getProviderConfigPHID(), | |||||
| )) | |||||
| ->needAccountIdentifiers(true) | ->needAccountIdentifiers(true) | ||||
| ->requireCapabilities( | ->requireCapabilities( | ||||
| array( | array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| )) | )) | ||||
| ->execute(); | ->execute(); | ||||
| return $accounts; | |||||
| } | |||||
| private function findAnyValidAsanaAccessToken(array $user_phids) { | |||||
| $provider = $this->getProvider(); | |||||
| $viewer = $this->getViewer(); | |||||
| if (!$user_phids) { | |||||
| return array(null, null, null); | |||||
| } | |||||
| $accounts = $this->loadAsanaExternalAccounts($user_phids); | |||||
| // Reorder accounts in the original order. | // Reorder accounts in the original order. | ||||
| // TODO: This needs to be adjusted if/when we allow you to link multiple | // TODO: This needs to be adjusted if/when we allow you to link multiple | ||||
| // accounts. | // accounts. | ||||
| $accounts = mpull($accounts, null, 'getUserPHID'); | $accounts = mpull($accounts, null, 'getUserPHID'); | ||||
| $accounts = array_select_keys($accounts, $user_phids); | $accounts = array_select_keys($accounts, $user_phids); | ||||
| $workspace_id = $this->getWorkspaceID(); | $workspace_id = $this->getWorkspaceID(); | ||||
| ▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines | |||||