1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +01:00

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
This commit is contained in:
epriestley 2013-07-12 13:10:03 -07:00
parent 014fba2831
commit 2b37911097
3 changed files with 103 additions and 2 deletions

View file

@ -150,7 +150,20 @@ final class PhabricatorConfigEditController
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel(pht('Description'))
->setValue($description))
->setValue($description));
if ($group) {
$extra = $group->renderContextualDescription(
$option,
$request);
if ($extra !== null) {
$form->appendChild(
id(new AphrontFormMarkupControl())
->setValue($extra));
}
}
$form
->appendChild($control);
$submit_control = id(new AphrontFormSubmitControl())

View file

@ -119,6 +119,22 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
return;
}
/**
* Hook to render additional hints based on, e.g., the viewing user, request,
* or other context. For example, this is used to show workspace IDs when
* configuring `asana.workspace-id`.
*
* @param PhabricatorConfigOption Option being rendered.
* @param AphrontRequest Active request.
* @return wild Additional contextual description
* information.
*/
public function renderContextualDescription(
PhabricatorConfigOption $option,
AphrontRequest $request) {
return null;
}
public function getKey() {
$class = get_class($this);
$matches = null;

View file

@ -14,8 +14,80 @@ final class PhabricatorAsanaConfigOptions
public function getOptions() {
return array(
$this->newOption('asana.workspace-id', 'string', null)
->setSummary(pht("Workspace ID to publish into.")),
->setSummary(pht("Asana Workspace ID to publish into."))
->setDescription(
pht(
'To enable synchronization into Asana, enter an Asana Workspace '.
'ID here.'.
"\n\n".
"NOTE: This feature is new and experimental.")),
);
}
public function renderContextualDescription(
PhabricatorConfigOption $option,
AphrontRequest $request) {
switch ($option->getKey()) {
case 'asana.workspace-id':
break;
default:
return parent::renderContextualDescription($option, $request);
}
$viewer = $request->getUser();
$provider = PhabricatorAuthProviderOAuthAsana::getAsanaProvider();
if (!$provider) {
return null;
}
$account = id(new PhabricatorExternalAccountQuery())
->setViewer($viewer)
->withUserPHIDs(array($viewer->getPHID()))
->withAccountTypes(array($provider->getProviderType()))
->withAccountDomains(array($provider->getProviderDomain()))
->executeOne();
if (!$account) {
return null;
}
$token = $provider->getOAuthAccessToken($account);
if (!$token) {
return null;
}
try {
$workspaces = id(new PhutilAsanaFuture())
->setAccessToken($token)
->setRawAsanaQuery('workspaces')
->resolve();
} catch (Exception $ex) {
return null;
}
if (!$workspaces) {
return null;
}
$out = array();
$out[] = pht("| Workspace ID | Workspace Name |");
$out[] = "| ------------ | -------------- |";
foreach ($workspaces as $workspace) {
$out[] = sprintf('| `%s` | `%s` |', $workspace['id'], $workspace['name']);
}
$out = implode("\n", $out);
$out = pht(
"The Asana Workspaces your linked account has access to are:\n\n%s",
$out);
return PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($out),
'default',
$viewer);
}
}