From: Brion Vibber Date: Mon, 27 Sep 2010 23:56:48 +0000 (-0700) Subject: Yammer import API keys can now be overridden by the admin. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=61fde6c8fff5201393db4496918fe193fe960c01;p=quix0rs-gnu-social.git Yammer import API keys can now be overridden by the admin. --- diff --git a/plugins/YammerImport/YammerImportPlugin.php b/plugins/YammerImport/YammerImportPlugin.php index 547870936b..98c6ecd0ab 100644 --- a/plugins/YammerImport/YammerImportPlugin.php +++ b/plugins/YammerImport/YammerImportPlugin.php @@ -119,6 +119,7 @@ class YammerImportPlugin extends Plugin case 'sn_yammerclient': case 'yammerimporter': case 'yammerrunner': + case 'yammerapikeyform': case 'yammerauthinitform': case 'yammerauthverifyform': case 'yammerprogressform': diff --git a/plugins/YammerImport/actions/yammeradminpanel.php b/plugins/YammerImport/actions/yammeradminpanel.php index 04ef26d512..13960d9051 100644 --- a/plugins/YammerImport/actions/yammeradminpanel.php +++ b/plugins/YammerImport/actions/yammeradminpanel.php @@ -52,15 +52,18 @@ class YammeradminpanelAction extends AdminPanelAction */ function getInstructions() { - return _m('Yammer import tool'); + return _m('This Yammer import tool is still undergoing testing, ' . + 'and is incomplete in some areas. ' . + 'Currently user subscriptions and group memberships are not ' . + 'transferred; in the future this may be supported for ' . + 'imports done by verified administrators on the Yammer side.'); } function prepare($args) { $ok = parent::prepare($args); - $this->init_auth = $this->trimmed('init_auth'); - $this->verify_token = $this->trimmed('verify_token'); + $this->subaction = $this->trimmed('subaction'); $this->runner = YammerRunner::init(); return $ok; @@ -68,26 +71,48 @@ class YammeradminpanelAction extends AdminPanelAction function handle($args) { + // @fixme move this to saveSettings and friends? if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->checkSessionToken(); - if ($this->init_auth) { - $url = $this->runner->requestAuth(); - $form = new YammerAuthVerifyForm($this, $this->runner); - return $this->showAjaxForm($form); - } else if ($this->verify_token) { - $this->runner->saveAuthToken($this->verify_token); - + if ($this->subaction == 'change-apikey') { + $form = new YammerApiKeyForm($this); + } else if ($this->subaction == 'apikey') { + if ($this->saveKeys()) { + $form = new YammerAuthInitForm($this, $this->runner); + } else { + $form = new YammerApiKeyForm($this); + } + } else if ($this->subaction == 'authinit') { + // hack + if ($this->arg('change-apikey')) { + $form = new YammerApiKeyForm($this); + } else { + $url = $this->runner->requestAuth(); + $form = new YammerAuthVerifyForm($this, $this->runner); + } + } else if ($this->subaction == 'authverify') { + $this->runner->saveAuthToken($this->trimmed('verify_token')); + // Haho! Now we can make THE FUN HAPPEN $this->runner->startBackgroundImport(); - + $form = new YammerProgressForm($this, $this->runner); - return $this->showAjaxForm($form); } else { throw new ClientException('Invalid POST'); } - } else { - return parent::handle($args); + return $this->showAjaxForm($form); } + return parent::handle($args); + } + + function saveKeys() + { + $key = $this->trimmed('consumer_key'); + $secret = $this->trimmed('consumer_secret'); + Config::save('yammer', 'consumer_key', $key); + Config::save('yammer', 'consumer_secret', $secret); + + return !empty($key) && !empty($secret); } function showAjaxForm($form) @@ -103,27 +128,35 @@ class YammeradminpanelAction extends AdminPanelAction } /** - * Show the Yammer admin panel form - * - * @return void + * Fetch the appropriate form for our current state. + * @return Form */ - function showForm() + function statusForm() { - $this->elementStart('fieldset'); - + if (!(common_config('yammer', 'consumer_key')) + || !(common_config('yammer', 'consumer_secret'))) { + return new YammerApiKeyForm($this); + } switch($this->runner->state()) { case 'init': - $form = new YammerAuthInitForm($this, $this->runner); - break; + return new YammerAuthInitForm($this, $this->runner); case 'requesting-auth': - $form = new YammerAuthVerifyForm($this, $this->runner); - break; + return new YammerAuthVerifyForm($this, $this->runner); default: - $form = new YammerProgressForm($this, $this->runner); + return new YammerProgressForm($this, $this->runner); } - $form->show(); + } + /** + * Show the Yammer admin panel form + * + * @return void + */ + function showForm() + { + $this->elementStart('fieldset'); + $this->statusForm()->show(); $this->elementEnd('fieldset'); } diff --git a/plugins/YammerImport/css/admin.css b/plugins/YammerImport/css/admin.css index 4c1aaacd64..9c99a0b880 100644 --- a/plugins/YammerImport/css/admin.css +++ b/plugins/YammerImport/css/admin.css @@ -49,3 +49,7 @@ /* override */ background: none !important; } + +.magiclink { + margin-left: 40px; +} \ No newline at end of file diff --git a/plugins/YammerImport/lib/yammerapikeyform.php b/plugins/YammerImport/lib/yammerapikeyform.php new file mode 100644 index 0000000000..b2acec4ede --- /dev/null +++ b/plugins/YammerImport/lib/yammerapikeyform.php @@ -0,0 +1,112 @@ +runner = $runner; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'yammer-apikey-form'; + } + + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_yammer_apikey form_settings'; + } + + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('yammeradminpanel'); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _m('Yammer API registration')); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->hidden('subaction', 'apikey'); + + $this->out->elementStart('fieldset'); + + $this->out->elementStart('p'); + $this->out->text(_m('Before we can connect to your Yammer network, ' . + 'you will need to register the importer as an ' . + 'application authorized to pull data on your behalf. ' . + 'This registration will work only for your own network. ' . + 'Follow this link to register the app at Yammer; ' . + 'you will be prompted to log in if necessary:')); + $this->out->elementEnd('p'); + + $this->out->elementStart('p', array('class' => 'magiclink')); + $this->out->element('a', + array('href' => 'https://www.yammer.com/client_applications/new', + 'target' => '_blank'), + _m('Open Yammer application registration form')); + $this->out->elementEnd('p'); + + $this->out->element('p', array(), _m('Copy the consumer key and secret you are given into the form below:')); + + $this->out->elementStart('ul', array('class' => 'form_data')); + $this->out->elementStart('li'); + $this->out->input('consumer_key', _m('Consumer key:'), common_config('yammer', 'consumer_key')); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->input('consumer_secret', _m('Consumer secret:'), common_config('yammer', 'consumer_secret')); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + + $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save these consumer keys')); + + $this->out->elementEnd('fieldset'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + } +} diff --git a/plugins/YammerImport/lib/yammerauthinitform.php b/plugins/YammerImport/lib/yammerauthinitform.php index 5a83a06c21..9f48fd82a5 100644 --- a/plugins/YammerImport/lib/yammerauthinitform.php +++ b/plugins/YammerImport/lib/yammerauthinitform.php @@ -22,7 +22,7 @@ class YammerAuthInitForm extends Form function formClass() { - return 'form_yammer_auth_init'; + return 'form_yammer_auth_init form_settings'; } @@ -56,7 +56,12 @@ class YammerAuthInitForm extends Form function formData() { - $this->out->hidden('init_auth', '1'); + $this->out->hidden('subaction', 'authinit'); + + $this->out->elementStart('fieldset'); + $this->out->submit('submit', _m('Start authentication'), 'submit', null, _m('Request authorization to connect to Yammer account')); + $this->out->submit('change-apikey', _m('Change API key')); + $this->out->elementEnd('fieldset'); } /** @@ -67,6 +72,5 @@ class YammerAuthInitForm extends Form function formActions() { - $this->out->submit('submit', _m('Connect to Yammer'), 'submit', null, _m('Request authorization to connect to Yammer account')); } } diff --git a/plugins/YammerImport/lib/yammerauthverifyform.php b/plugins/YammerImport/lib/yammerauthverifyform.php index 2b3efbcb1a..e119be96f7 100644 --- a/plugins/YammerImport/lib/yammerauthverifyform.php +++ b/plugins/YammerImport/lib/yammerauthverifyform.php @@ -30,7 +30,7 @@ class YammerAuthVerifyForm extends Form function formClass() { - return 'form_yammer_auth_verify'; + return 'form_yammer_auth_verify form_settings'; } @@ -64,27 +64,39 @@ class YammerAuthVerifyForm extends Form function formData() { + $this->out->hidden('subaction', 'authverify'); + + $this->out->elementStart('fieldset'); + $this->out->elementStart('p'); $this->out->text(_m('Follow this link to confirm authorization at Yammer; you will be prompted to log in if necessary:')); $this->out->elementEnd('p'); - $this->out->elementStart('blockquote'); + // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O + /* + $this->out->element('iframe', array('id' => 'yammer-oauth', + 'src' => $this->runner->getAuthUrl())); + */ + // yeah, it ignores the callback_url + // soo... crappy link. :( + + $this->out->elementStart('p', array('class' => 'magiclink')); $this->out->element('a', array('href' => $this->runner->getAuthUrl(), 'target' => '_blank'), _m('Open Yammer authentication window')); - $this->out->elementEnd('blockquote'); + $this->out->elementEnd('p'); - $this->out->element('p', array(), _m('Copy the verification code you are given into the form below:')); + $this->out->element('p', array(), _m('Copy the verification code you are given below:')); + $this->out->elementStart('ul', array('class' => 'form_data')); + $this->out->elementStart('li'); $this->out->input('verify_token', _m('Verification code:')); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); - // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O - /* - $this->out->element('iframe', array('id' => 'yammer-oauth', - 'src' => $this->runner->getAuthUrl())); - */ - // yeah, it ignores the callback_url + $this->out->submit('submit', _m('Continue'), 'submit', null, _m('Save code and begin import')); + $this->out->elementEnd('fieldset'); } /** @@ -95,6 +107,5 @@ class YammerAuthVerifyForm extends Form function formActions() { - $this->out->submit('submit', _m('Verify code'), 'submit', null, _m('Verification code')); } } diff --git a/plugins/YammerImport/scripts/yamdump.php b/plugins/YammerImport/scripts/yamdump.php deleted file mode 100644 index 944ee2e499..0000000000 --- a/plugins/YammerImport/scripts/yamdump.php +++ /dev/null @@ -1,34 +0,0 @@ -users(); -var_dump($data); -// @fixme follow paging -foreach ($data as $item) { - $user = $imp->prepUser($item); - var_dump($user); -} -*/ - -$data = $yam->messages(array('newer_than' => 1)); -var_dump($data); -// @fixme follow paging -$messages = $data['messages']; -$messages = array_reverse($messages); -foreach ($messages as $message) { - $notice = $imp->prepNotice($message); - var_dump($notice); -}