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

Make it easier to configure an Asana workspace ID

Summary:
Ref T2852. It's a little tricky to figure out Asana workspace IDs right now. If the viewer has a linked account, just pull their workspaces and show them which IDs are available.

(In theory, we could use a `<select>`, but it would have more edge cases; this seems like a pretty solid fix.)

Test Plan: {F49938}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

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

+103 -2
+14 -1
src/applications/config/controller/PhabricatorConfigEditController.php
··· 150 150 ->appendChild( 151 151 id(new AphrontFormMarkupControl()) 152 152 ->setLabel(pht('Description')) 153 - ->setValue($description)) 153 + ->setValue($description)); 154 + 155 + if ($group) { 156 + $extra = $group->renderContextualDescription( 157 + $option, 158 + $request); 159 + if ($extra !== null) { 160 + $form->appendChild( 161 + id(new AphrontFormMarkupControl()) 162 + ->setValue($extra)); 163 + } 164 + } 165 + 166 + $form 154 167 ->appendChild($control); 155 168 156 169 $submit_control = id(new AphrontFormSubmitControl())
+16
src/applications/config/option/PhabricatorApplicationConfigOptions.php
··· 119 119 return; 120 120 } 121 121 122 + /** 123 + * Hook to render additional hints based on, e.g., the viewing user, request, 124 + * or other context. For example, this is used to show workspace IDs when 125 + * configuring `asana.workspace-id`. 126 + * 127 + * @param PhabricatorConfigOption Option being rendered. 128 + * @param AphrontRequest Active request. 129 + * @return wild Additional contextual description 130 + * information. 131 + */ 132 + public function renderContextualDescription( 133 + PhabricatorConfigOption $option, 134 + AphrontRequest $request) { 135 + return null; 136 + } 137 + 122 138 public function getKey() { 123 139 $class = get_class($this); 124 140 $matches = null;
+73 -1
src/applications/doorkeeper/option/PhabricatorAsanaConfigOptions.php
··· 14 14 public function getOptions() { 15 15 return array( 16 16 $this->newOption('asana.workspace-id', 'string', null) 17 - ->setSummary(pht("Workspace ID to publish into.")), 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.")), 18 24 ); 19 25 } 26 + 27 + public function renderContextualDescription( 28 + PhabricatorConfigOption $option, 29 + AphrontRequest $request) { 30 + 31 + switch ($option->getKey()) { 32 + case 'asana.workspace-id': 33 + break; 34 + default: 35 + return parent::renderContextualDescription($option, $request); 36 + } 37 + 38 + $viewer = $request->getUser(); 39 + 40 + $provider = PhabricatorAuthProviderOAuthAsana::getAsanaProvider(); 41 + if (!$provider) { 42 + return null; 43 + } 44 + 45 + $account = id(new PhabricatorExternalAccountQuery()) 46 + ->setViewer($viewer) 47 + ->withUserPHIDs(array($viewer->getPHID())) 48 + ->withAccountTypes(array($provider->getProviderType())) 49 + ->withAccountDomains(array($provider->getProviderDomain())) 50 + ->executeOne(); 51 + if (!$account) { 52 + return null; 53 + } 54 + 55 + $token = $provider->getOAuthAccessToken($account); 56 + if (!$token) { 57 + return null; 58 + } 59 + 60 + try { 61 + $workspaces = id(new PhutilAsanaFuture()) 62 + ->setAccessToken($token) 63 + ->setRawAsanaQuery('workspaces') 64 + ->resolve(); 65 + } catch (Exception $ex) { 66 + return null; 67 + } 68 + 69 + if (!$workspaces) { 70 + return null; 71 + } 72 + 73 + $out = array(); 74 + $out[] = pht("| Workspace ID | Workspace Name |"); 75 + $out[] = "| ------------ | -------------- |"; 76 + foreach ($workspaces as $workspace) { 77 + $out[] = sprintf('| `%s` | `%s` |', $workspace['id'], $workspace['name']); 78 + } 79 + 80 + $out = implode("\n", $out); 81 + 82 + $out = pht( 83 + "The Asana Workspaces your linked account has access to are:\n\n%s", 84 + $out); 85 + 86 + return PhabricatorMarkupEngine::renderOneObject( 87 + id(new PhabricatorMarkupOneOff())->setContent($out), 88 + 'default', 89 + $viewer); 90 + } 91 + 20 92 21 93 }