Skip to content

Commit

Permalink
MDL-59511 oauth2: Allow empty email in system account
Browse files Browse the repository at this point in the history
  • Loading branch information
Dagefoerde committed Jul 28, 2017
1 parent d509f80 commit 3fa588c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/classes/oauth2/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public static function connect_system_account($issuer, $returnurl) {
$record->issuerid = $issuer->get('id');
$record->refreshtoken = $refreshtoken;
$record->grantedscopes = $scopes;
$record->email = $userinfo['email'];
$record->email = isset($userinfo['email']) ? $userinfo['email'] : '';
$record->username = $userinfo['username'];

$systemaccount = new system_account(0, $record);
Expand Down
2 changes: 1 addition & 1 deletion lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,7 @@
<FIELD NAME="issuerid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The id of the oauth 2 identity issuer"/>
<FIELD NAME="refreshtoken" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The refresh token used to request access tokens."/>
<FIELD NAME="grantedscopes" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The scopes that this system account has been granted access to."/>
<FIELD NAME="email" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The email that was connected to this issuer."/>
<FIELD NAME="email" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The email that was connected to this issuer."/>
<FIELD NAME="username" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The username that was connected as a system account to this issue."/>
</FIELDS>
<KEYS>
Expand Down
12 changes: 12 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2214,5 +2214,17 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017072000.02);
}

if ($oldversion < 2017072700.01) {
// Changing nullability of field email on table oauth2_system_account to null.
$table = new xmldb_table('oauth2_system_account');
$field = new xmldb_field('email', XMLDB_TYPE_TEXT, null, null, null, null, null, 'grantedscopes');

// Launch change of nullability for field email.
$dbman->change_field_notnull($table, $field);

// Main savepoint reached.
upgrade_main_savepoint(true, 2017072700.01);
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2017072700.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017072700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit 3fa588c

Please sign in to comment.