Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/provider/PhabricatorJIRAAuthProvider.php
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | final class PhabricatorJIRAAuthProvider extends PhabricatorOAuth1AuthProvider { | ||||
private function isSetup() { | private function isSetup() { | ||||
return !$this->getProviderConfig()->getID(); | return !$this->getProviderConfig()->getID(); | ||||
} | } | ||||
const PROPERTY_JIRA_NAME = 'oauth1:jira:name'; | const PROPERTY_JIRA_NAME = 'oauth1:jira:name'; | ||||
const PROPERTY_JIRA_URI = 'oauth1:jira:uri'; | const PROPERTY_JIRA_URI = 'oauth1:jira:uri'; | ||||
const PROPERTY_PUBLIC_KEY = 'oauth1:jira:key:public'; | const PROPERTY_PUBLIC_KEY = 'oauth1:jira:key:public'; | ||||
const PROPERTY_PRIVATE_KEY = 'oauth1:jira:key:private'; | const PROPERTY_PRIVATE_KEY = 'oauth1:jira:key:private'; | ||||
const PROPERTY_REPORT_LINK = 'oauth1:jira:report:link'; | |||||
const PROPERTY_REPORT_COMMENT = 'oauth1:jira:report:comment'; | |||||
public function readFormValuesFromProvider() { | public function readFormValuesFromProvider() { | ||||
$config = $this->getProviderConfig(); | $config = $this->getProviderConfig(); | ||||
$uri = $config->getProperty(self::PROPERTY_JIRA_URI); | $uri = $config->getProperty(self::PROPERTY_JIRA_URI); | ||||
return array( | return array( | ||||
self::PROPERTY_JIRA_NAME => $this->getProviderDomain(), | self::PROPERTY_JIRA_NAME => $this->getProviderDomain(), | ||||
self::PROPERTY_JIRA_URI => $uri, | self::PROPERTY_JIRA_URI => $uri, | ||||
); | ); | ||||
} | } | ||||
public function readFormValuesFromRequest(AphrontRequest $request) { | public function readFormValuesFromRequest(AphrontRequest $request) { | ||||
$is_setup = $this->isSetup(); | $is_setup = $this->isSetup(); | ||||
if ($is_setup) { | if ($is_setup) { | ||||
$name = $request->getStr(self::PROPERTY_JIRA_NAME); | $name = $request->getStr(self::PROPERTY_JIRA_NAME); | ||||
} else { | } else { | ||||
$name = $this->getProviderDomain(); | $name = $this->getProviderDomain(); | ||||
} | } | ||||
return array( | return array( | ||||
self::PROPERTY_JIRA_NAME => $name, | self::PROPERTY_JIRA_NAME => $name, | ||||
self::PROPERTY_JIRA_URI => $request->getStr(self::PROPERTY_JIRA_URI), | self::PROPERTY_JIRA_URI => $request->getStr(self::PROPERTY_JIRA_URI), | ||||
self::PROPERTY_REPORT_LINK => | |||||
$request->getInt(self::PROPERTY_REPORT_LINK, 0), | |||||
self::PROPERTY_REPORT_COMMENT => | |||||
$request->getInt(self::PROPERTY_REPORT_COMMENT, 0), | |||||
); | ); | ||||
} | } | ||||
public function processEditForm( | public function processEditForm( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
array $values) { | array $values) { | ||||
$errors = array(); | $errors = array(); | ||||
$issues = array(); | $issues = array(); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function extendEditForm( | ||||
} | } | ||||
$form->appendRemarkupInstructions( | $form->appendRemarkupInstructions( | ||||
pht( | pht( | ||||
'NOTE: This provider **only supports JIRA 6**. It will not work with '. | 'NOTE: This provider **only supports JIRA 6**. It will not work with '. | ||||
'JIRA 5 or earlier.')); | 'JIRA 5 or earlier.')); | ||||
$is_setup = $this->isSetup(); | $is_setup = $this->isSetup(); | ||||
$viewer = $request->getViewer(); | |||||
$e_required = $request->isFormPost() ? null : true; | $e_required = $request->isFormPost() ? null : true; | ||||
$v_name = $values[self::PROPERTY_JIRA_NAME]; | $v_name = $values[self::PROPERTY_JIRA_NAME]; | ||||
if ($is_setup) { | if ($is_setup) { | ||||
$e_name = idx($issues, self::PROPERTY_JIRA_NAME, $e_required); | $e_name = idx($issues, self::PROPERTY_JIRA_NAME, $e_required); | ||||
} else { | } else { | ||||
$e_name = null; | $e_name = null; | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (!$is_setup) { | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormStaticControl()) | id(new AphrontFormStaticControl()) | ||||
->setLabel(pht('Consumer Key')) | ->setLabel(pht('Consumer Key')) | ||||
->setValue($ckey)) | ->setValue($ckey)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormStaticControl()) | id(new AphrontFormStaticControl()) | ||||
->setLabel(pht('Public Key')) | ->setLabel(pht('Public Key')) | ||||
->setValue($pkey)); | ->setValue($pkey)); | ||||
} | |||||
$form | |||||
->appendRemarkupInstructions( | |||||
pht( | |||||
'= Integration Options = '."\n". | |||||
'Configure how to record Revisions on JIRA tasks.'."\n\n". | |||||
'Note you\'ll have to restart the daemons for this to take '. | |||||
'effect.')) | |||||
->appendChild( | |||||
id(new AphrontFormCheckboxControl()) | |||||
->addCheckbox( | |||||
self::PROPERTY_REPORT_LINK, | |||||
1, | |||||
new PHUIRemarkupView( | |||||
$viewer, | |||||
pht( | |||||
'Create **Issue Link** to the Revision, as an "implemented '. | |||||
'in" relationship.')), | |||||
$this->shouldCreateJIRALink())) | |||||
->appendChild( | |||||
id(new AphrontFormCheckboxControl()) | |||||
->addCheckbox( | |||||
self::PROPERTY_REPORT_COMMENT, | |||||
1, | |||||
new PHUIRemarkupView( | |||||
$viewer, | |||||
pht( | |||||
'**Post a comment** in the JIRA task, similar to the '. | |||||
'emails Phabricator sends.')), | |||||
$this->shouldCreateJIRAComment())); | |||||
} | } | ||||
} | |||||
/** | /** | ||||
* JIRA uses a setup step to generate public/private keys. | * JIRA uses a setup step to generate public/private keys. | ||||
*/ | */ | ||||
public function hasSetupStep() { | public function hasSetupStep() { | ||||
return true; | return true; | ||||
} | } | ||||
Show All 17 Lines | public function newJIRAFuture( | ||||
$adapter = clone $this->getAdapter(); | $adapter = clone $this->getAdapter(); | ||||
$adapter->setToken($account->getProperty('oauth1.token')); | $adapter->setToken($account->getProperty('oauth1.token')); | ||||
$adapter->setTokenSecret($account->getProperty('oauth1.token.secret')); | $adapter->setTokenSecret($account->getProperty('oauth1.token.secret')); | ||||
return $adapter->newJIRAFuture($path, $method, $params); | return $adapter->newJIRAFuture($path, $method, $params); | ||||
} | } | ||||
public function shouldCreateJIRALink() { | |||||
$config = $this->getProviderConfig(); | |||||
return $config->getProperty(self::PROPERTY_REPORT_LINK, true); | |||||
} | |||||
public function shouldCreateJIRAComment() { | |||||
$config = $this->getProviderConfig(); | |||||
return $config->getProperty(self::PROPERTY_REPORT_COMMENT, true); | |||||
} | |||||
} | } |