MDL-29857 google apis: OAuth 2.0 portfolio plugins upgrade
We are disabling the plugins if not configured. As part of this upgrade we will emailing admins about this change if they have a plugin configured. This is required because OAuth 2 credentials are now required in the plugin configuration. NOTE: These strings are temporary and need to be improved.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @param int $oldversion the version we are upgrading from
|
||||
* @return bool result
|
||||
*/
|
||||
function xmldb_portfolio_googledocs_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2012053000) {
|
||||
// Delete old user preferences containing authsub tokens.
|
||||
$DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey'));
|
||||
upgrade_plugin_savepoint(true, 2012053000, 'portfolio', 'googledocs');
|
||||
}
|
||||
|
||||
if ($oldversion < 2012053001) {
|
||||
$existing = $DB->get_record('portfolio_instance', array('plugin' => 'googledocs'), '*', IGNORE_MULTIPLE);
|
||||
|
||||
if ($existing) {
|
||||
portfolio_googledocs_admin_upgrade_notification();
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'googledocs');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function portfolio_googledocs_admin_upgrade_notification() {
|
||||
$admins = get_admins();
|
||||
|
||||
if (empty($admins)) {
|
||||
return;
|
||||
}
|
||||
$mainadmin = reset($admins);
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$message = new stdClass();
|
||||
$message->component = 'moodle';
|
||||
$message->name = 'notices';
|
||||
$message->userfrom = $mainadmin;
|
||||
$message->userto = $admin;
|
||||
$message->smallmessage = get_string('oauth2upgrade_message_small', 'portfolio_googledocs');
|
||||
$message->subject = get_string('oauth2upgrade_message_subject', 'portfolio_googledocs');
|
||||
$message->fullmessage = get_string('oauth2upgrade_message_content', 'portfolio_googledocs');
|
||||
$message->fullmessagehtml = get_string('oauth2upgrade_message_content', 'portfolio_googledocs');
|
||||
$message->fullmessageformat = FORMAT_PLAIN;
|
||||
$message->notification = 1;
|
||||
message_send($message);
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,14 @@
|
||||
*/
|
||||
|
||||
$string['clientid'] = 'Client ID';
|
||||
$string['oauthinfo'] = '<p>To use the google docs portfolio you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
|
||||
$string['noauthtoken'] = 'An authentication token has not been recieved from google. Please ensure you are allowing moodle to access your google account';
|
||||
$string['nooauthcredentials'] = 'OAuth credentials required.';
|
||||
$string['nooauthcredentials_help'] = 'To use the Google Docs portfolio plugin you must configure OAuth credentials in the portfolio settings.';
|
||||
$string['nosessiontoken'] = 'A session token does not exist preventing export to google.';
|
||||
$string['oauthinfo'] = '<p>To use the google docs portfolio you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
|
||||
$string['oauth2upgrade_message_subject'] = 'Important information regarding Google Docs portfolio plugin';
|
||||
$string['oauth2upgrade_message_content'] = 'As part of the upgrade to Moodle 2.3, the Google Docs portfolio plugin has been disabled due to changes in Googles API. To re-enable your plugin, you must configure oauth credentials in this plugin.';
|
||||
$string['oauth2upgrade_message_small'] = 'The Google Docs portfolio plugin has been disabled until configured with OAuth2';
|
||||
$string['pluginname'] = 'Google Docs';
|
||||
$string['sendfailed'] = 'The file {$a} failed to transfer to google';
|
||||
$string['secret'] = 'Secret';
|
||||
|
||||
@@ -126,4 +126,16 @@ class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
|
||||
|
||||
$this->googleoauth = new google_oauth($clientid, $secret, $returnurl->out(false), google_docs::REALM);
|
||||
}
|
||||
|
||||
public function instance_sanity_check() {
|
||||
$clientid = $this->get_config('clientid');
|
||||
$secret = $this->get_config('secret');
|
||||
|
||||
// If there is no oauth config (e.g. plugins upgraded from < 2.3 then
|
||||
// there will be no config and this plugin should be disabled.
|
||||
if (empty($clientid) or empty($secret)) {
|
||||
return 'nooauthcredentials';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012051400; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2012053001; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2012051100; // Requires this Moodle version.
|
||||
$plugin->component = 'portfolio_googledocs'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->cron = 0;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @param int $oldversion the version we are upgrading from
|
||||
* @return bool result
|
||||
*/
|
||||
function xmldb_portfolio_picasa_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2012053000) {
|
||||
// Delete old user preferences containing authsub tokens.
|
||||
$DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey_picasa'));
|
||||
upgrade_plugin_savepoint(true, 2012053000, 'portfolio', 'picasa');
|
||||
}
|
||||
|
||||
if ($oldversion < 2012053001) {
|
||||
$existing = $DB->get_record('portfolio_instance', array('plugin' => 'picasa'), '*', IGNORE_MISSING);
|
||||
|
||||
if ($existing) {
|
||||
portfolio_picasa_admin_upgrade_notification();
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'picasa');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function portfolio_picasa_admin_upgrade_notification() {
|
||||
$admins = get_admins();
|
||||
|
||||
if (empty($admins)) {
|
||||
return;
|
||||
}
|
||||
$mainadmin = reset($admins);
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$message = new stdClass();
|
||||
$message->component = 'moodle';
|
||||
$message->name = 'notices';
|
||||
$message->userfrom = $mainadmin;
|
||||
$message->userto = $admin;
|
||||
$message->smallmessage = get_string('oauth2upgrade_message_small', 'portfolio_picasa');
|
||||
$message->subject = get_string('oauth2upgrade_message_subject', 'portfolio_picasa');
|
||||
$message->fullmessage = get_string('oauth2upgrade_message_content', 'portfolio_picasa');
|
||||
$message->fullmessagehtml = get_string('oauth2upgrade_message_content', 'portfolio_picasa');
|
||||
$message->fullmessageformat = FORMAT_PLAIN;
|
||||
$message->notification = 1;
|
||||
message_send($message);
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,13 @@
|
||||
*/
|
||||
|
||||
$string['clientid'] = 'Client ID';
|
||||
$string['oauthinfo'] = '<p>To use the Picasa portfolio you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
|
||||
$string['noauthtoken'] = 'An authentication token has not been recieved from google. Please ensure you are allowing moodle to access your google account';
|
||||
$string['nooauthcredentials'] = 'OAuth credentials required.';
|
||||
$string['nooauthcredentials_help'] = 'To use the Picasa portfolio plugin you must configure OAuth credentials in the portfolio settings.';
|
||||
$string['oauthinfo'] = '<p>To use the Picasa portfolio you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
|
||||
$string['oauth2upgrade_message_subject'] = 'Important information regarding Picasa portfolio plugin';
|
||||
$string['oauth2upgrade_message_content'] = 'As part of the upgrade to Moodle 2.3, the Picasa portfolio plugin has been disabled due to changes in Googles API. To re-enable your plugin, you must configure oauth credentials in this plugin.';
|
||||
$string['oauth2upgrade_message_small'] = 'The Picasa portfolio plugin has been disabled until configured with OAuth2';
|
||||
$string['pluginname'] = 'Picasa';
|
||||
$string['sendfailed'] = 'The file {$a} failed to transfer to picasa';
|
||||
$string['secret'] = 'Secret';
|
||||
|
||||
@@ -126,4 +126,16 @@ class portfolio_plugin_picasa extends portfolio_plugin_push_base {
|
||||
|
||||
$this->googleoauth = new google_oauth($clientid, $secret, $returnurl->out(false), google_picasa::REALM);
|
||||
}
|
||||
|
||||
public function instance_sanity_check() {
|
||||
$clientid = $this->get_config('clientid');
|
||||
$secret = $this->get_config('secret');
|
||||
|
||||
// If there is no oauth config (e.g. plugins upgraded from < 2.3 then
|
||||
// there will be no config and this plugin should be disabled.
|
||||
if (empty($clientid) or empty($secret)) {
|
||||
return 'nooauthcredentials';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012051400; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2012053001; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2012051100; // Requires this Moodle version.
|
||||
$plugin->component = 'portfolio_picasa'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->cron = 0;
|
||||
|
||||
Reference in New Issue
Block a user