[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAsanaConfigOptions 4 extends PhabricatorApplicationConfigOptions { 5 6 public function getName() { 7 return pht('Integration with Asana'); 8 } 9 10 public function getDescription() { 11 return pht('Asana integration options.'); 12 } 13 14 public function getOptions() { 15 return array( 16 $this->newOption('asana.workspace-id', 'string', null) 17 ->setSummary(pht('Asana Workspace ID to publish into.')) 18 ->setDescription( 19 pht( 20 'To enable synchronization into Asana, enter an Asana Workspace '. 21 'ID here.'. 22 "\n\n". 23 "NOTE: This feature is new and experimental.")), 24 $this->newOption('asana.project-ids', 'wild', null) 25 ->setSummary(pht('Optional Asana projects to use as application tags.')) 26 ->setDescription( 27 pht( 28 'When Phabricator creates tasks in Asana, it can add the tasks '. 29 'to Asana projects based on which application the corresponding '. 30 'object in Phabricator comes from. For example, you can add code '. 31 'reviews in Asana to a "Differential" project.'. 32 "\n\n". 33 'NOTE: This feature is new and experimental.')), 34 ); 35 } 36 37 public function renderContextualDescription( 38 PhabricatorConfigOption $option, 39 AphrontRequest $request) { 40 41 switch ($option->getKey()) { 42 case 'asana.workspace-id': 43 break; 44 case 'asana.project-ids': 45 return $this->renderContextualProjectDescription($option, $request); 46 default: 47 return parent::renderContextualDescription($option, $request); 48 } 49 50 $viewer = $request->getUser(); 51 52 $provider = PhabricatorAsanaAuthProvider::getAsanaProvider(); 53 if (!$provider) { 54 return null; 55 } 56 57 $account = id(new PhabricatorExternalAccountQuery()) 58 ->setViewer($viewer) 59 ->withUserPHIDs(array($viewer->getPHID())) 60 ->withAccountTypes(array($provider->getProviderType())) 61 ->withAccountDomains(array($provider->getProviderDomain())) 62 ->requireCapabilities( 63 array( 64 PhabricatorPolicyCapability::CAN_VIEW, 65 PhabricatorPolicyCapability::CAN_EDIT, 66 )) 67 ->executeOne(); 68 if (!$account) { 69 return null; 70 } 71 72 $token = $provider->getOAuthAccessToken($account); 73 if (!$token) { 74 return null; 75 } 76 77 try { 78 $workspaces = id(new PhutilAsanaFuture()) 79 ->setAccessToken($token) 80 ->setRawAsanaQuery('workspaces') 81 ->resolve(); 82 } catch (Exception $ex) { 83 return null; 84 } 85 86 if (!$workspaces) { 87 return null; 88 } 89 90 $out = array(); 91 $out[] = pht('| Workspace ID | Workspace Name |'); 92 $out[] = '| ------------ | -------------- |'; 93 foreach ($workspaces as $workspace) { 94 $out[] = sprintf('| `%s` | `%s` |', $workspace['id'], $workspace['name']); 95 } 96 97 $out = implode("\n", $out); 98 99 $out = pht( 100 "The Asana Workspaces your linked account has access to are:\n\n%s", 101 $out); 102 103 return PhabricatorMarkupEngine::renderOneObject( 104 id(new PhabricatorMarkupOneOff())->setContent($out), 105 'default', 106 $viewer); 107 } 108 109 private function renderContextualProjectDescription( 110 PhabricatorConfigOption $option, 111 AphrontRequest $request) { 112 113 $viewer = $request->getUser(); 114 115 $publishers = id(new PhutilSymbolLoader()) 116 ->setAncestorClass('DoorkeeperFeedStoryPublisher') 117 ->loadObjects(); 118 119 $out = array(); 120 $out[] = pht( 121 'To specify projects to add tasks to, enter a JSON map with publisher '. 122 'class names as keys and a list of project IDs as values. For example, '. 123 'to put Differential tasks into Asana projects with IDs `123` and '. 124 '`456`, enter:'. 125 "\n\n". 126 " lang=txt\n". 127 " {\n". 128 " \"DifferentialDoorkeeperRevisionFeedStoryPublisher\" : [123, 456]\n". 129 " }\n"); 130 131 $out[] = pht('Available publishers class names are:'); 132 foreach ($publishers as $publisher) { 133 $out[] = ' - `'.get_class($publisher).'`'; 134 } 135 136 $out[] = pht( 137 'You can find an Asana project ID by clicking the project in Asana and '. 138 'then examining the URL:'. 139 "\n\n". 140 " lang=txt\n". 141 " https://app.asana.com/0/12345678901234567890/111111111111111111\n". 142 " ^^^^^^^^^^^^^^^^^^^^\n". 143 " This is the ID to use.\n"); 144 145 $out = implode("\n", $out); 146 147 return PhabricatorMarkupEngine::renderOneObject( 148 id(new PhabricatorMarkupOneOff())->setContent($out), 149 'default', 150 $viewer); 151 } 152 153 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |