From d9fbe3146cfc2efff8d41ad78e28a877e1f5a43e Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 28 Mar 2017 11:58:45 +0800 Subject: [PATCH] MDL-58220 oauth2: Use the same list of user fields Authentication has a hard coded list of valid internal user fields - but they are in a class variable. We need them in oauth user_field_mapping so we need to move them to a central place and call them from oauth2 and auth. --- lib/authlib.php | 21 +----------------- lib/classes/oauth2/user_field_mapping.php | 27 +++++++++-------------- lib/classes/user.php | 25 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/lib/authlib.php b/lib/authlib.php index 09aa59d0584..0fea5319156 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -102,26 +102,7 @@ class auth_plugin_base { * The fields we can lock and update from/to external authentication backends * @var array */ - var $userfields = array( - 'firstname', - 'lastname', - 'email', - 'city', - 'country', - 'lang', - 'description', - 'url', - 'idnumber', - 'institution', - 'department', - 'phone1', - 'phone2', - 'address', - 'firstnamephonetic', - 'lastnamephonetic', - 'middlename', - 'alternatename' - ); + var $userfields = \core_user::AUTHSYNCFIELDS; /** * Moodle custom fields to sync with. diff --git a/lib/classes/oauth2/user_field_mapping.php b/lib/classes/oauth2/user_field_mapping.php index 9751bc9009a..8586edc061d 100644 --- a/lib/classes/oauth2/user_field_mapping.php +++ b/lib/classes/oauth2/user_field_mapping.php @@ -37,21 +37,14 @@ class user_field_mapping extends persistent { const TABLE = 'oauth2_user_field_mapping'; - /** @var array $userfields - List of standard Moodle userfields. */ - private static $userfields = [ - 'firstname', - 'middlename', - 'lastname', - 'email', - 'username', - 'idnumber', - 'url', - 'alternatename', - 'picture', - 'address', - 'phone', - 'lang' - ]; + /** + * Return the list of valid internal user fields. + * + * @return array + */ + private static function get_user_fields() { + return array_merge(\core_user::AUTHSYNCFIELDS, ['picture']); + } /** * Return the definition of the properties of this model. @@ -68,7 +61,7 @@ class user_field_mapping extends persistent { ), 'internalfield' => array( 'type' => PARAM_ALPHANUMEXT, - 'choices' => self::$userfields, + 'choices' => self::get_user_fields() ) ); } @@ -79,6 +72,6 @@ class user_field_mapping extends persistent { * @return array */ public function get_internalfield_list() { - return array_combine(self::$userfields, self::$userfields); + return array_combine(self::get_user_fields(), self::get_user_fields()); } } diff --git a/lib/classes/user.php b/lib/classes/user.php index 26cb195df67..9c95cc2132c 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -58,6 +58,30 @@ class core_user { */ const MAILDISPLAY_COURSE_MEMBERS_ONLY = 2; + /** + * List of fields that can be synched/locked during authentication. + */ + const AUTHSYNCFIELDS = [ + 'firstname', + 'lastname', + 'email', + 'city', + 'country', + 'lang', + 'description', + 'url', + 'idnumber', + 'institution', + 'department', + 'phone1', + 'phone2', + 'address', + 'firstnamephonetic', + 'lastnamephonetic', + 'middlename', + 'alternatename' + ]; + /** @var stdClass keep record of noreply user */ public static $noreplyuser = false; @@ -887,4 +911,5 @@ class core_user { return $value; } } + }