Skip to content

Commit

Permalink
MDL-71051 core_user: fix issues and address review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin authored and marinaglancy committed Apr 28, 2021
1 parent 8974874 commit 3bf770c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
6 changes: 3 additions & 3 deletions admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ function() {

// Custom profile fields.
$profilefields = profile_get_custom_fields();
foreach ($profilefields as $key => $field) {
// Only reasonable-length fields can be used as identity fields.
if ($field->param2 > 255) {
foreach ($profilefields as $field) {
// Only reasonable-length text fields can be used as identity fields.
if ($field->param2 > 255 || $field->datatype != 'text') {
continue;
}
$fields['profile_field_' . $field->shortname] = $field->name . ' *';
Expand Down
11 changes: 7 additions & 4 deletions badges/criteria/award_criteria_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class award_criteria_profile extends award_criteria {
*
*/
public function get_options(&$mform) {
global $CFG;
global $CFG, $DB;
require_once($CFG->dirroot . '/user/profile/lib.php');

$none = true;
Expand Down Expand Up @@ -93,13 +93,14 @@ public function get_options(&$mform) {
foreach ($cfields as $field) {
if (!isset($currentcat) || $currentcat != $field->categoryid) {
$currentcat = $field->categoryid;
$mform->addElement('header', 'category_' . $currentcat, format_string($field->categoryname));
$categoryname = $DB->get_field('user_info_category', 'name', ['id' => $field->categoryid]);
$mform->addElement('header', 'category_' . $currentcat, format_string($categoryname));
}
$checked = false;
if (in_array($field->id, $existing)) {
$checked = true;
}
$this->config_options($mform, array('id' => $field->fieldid, 'checked' => $checked, 'name' => $field->name, 'error' => false));
$this->config_options($mform, array('id' => $field->id, 'checked' => $checked, 'name' => $field->name, 'error' => false));
$none = false;
}
}
Expand Down Expand Up @@ -135,7 +136,9 @@ public function get_details($short = '') {
foreach ($this->params as $p) {
if (is_numeric($p['field'])) {
$fields = profile_get_custom_fields();
$str = $fields[$p['field']]->name ?? $p['field'];
// Get formatted field name if such field exists.
$str = isset($fields[$p['field']]->name) ?
format_string($fields[$p['field']]->name) : null;
} else {
$str = \core_user\fields::get_display_name($p['field']);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/behat/showuseridentity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Select user identity fields
| user1 | C1 | manager |
| user2 | C1 | manager |

Scenario: The admin settings screen should show text custom fields (and let you choose them)
Scenario: The admin settings screen should show text custom fields of certain length (and let you choose them)
When I log in as "admin"
And I navigate to "Users > Permissions > User policies" in site administration
Then I should see "Speciality" in the "#admin-showuseridentity" "css_element"
Expand Down
8 changes: 4 additions & 4 deletions user/classes/form/profile_field_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ public function set_data_for_dynamic_submission(): void {
$field = $this->get_field_record();

// Clean and prepare description for the editor.
$field->description = clean_text($field->description, $field->descriptionformat);
$field->description = array('text' => $field->description, 'format' => $field->descriptionformat, 'itemid' => 0);
$description = clean_text($field->description, $field->descriptionformat);
$field->description = ['text' => $description, 'format' => $field->descriptionformat, 'itemid' => 0];
// Convert the data format for.
if (is_array($this->editors())) {
foreach ($this->editors() as $editor) {
if (isset($field->$editor)) {
$field->$editor = clean_text($field->$editor, $field->{$editor.'format'});
$field->$editor = array('text' => $field->$editor, 'format' => $field->{$editor.'format'}, 'itemid' => 0);
$editordesc = clean_text($field->$editor, $field->{$editor.'format'});
$field->$editor = ['text' => $editordesc, 'format' => $field->{$editor.'format'}, 'itemid' => 0];
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions user/profile/definelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,8 @@ function profile_list_categories() {
* Create or update a profile category
*
* @param stdClass $data
* @throws coding_exception
* @throws dml_exception
*/
function profile_save_category(stdClass $data) {
function profile_save_category(stdClass $data): void {
global $DB;

if (empty($data->id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ Feature: Social profile fields can not have a duplicate shortname.
Scenario: Verify you can edit social profile fields.
Given I log in as "admin"
When I navigate to "Users > Accounts > User profile fields" in site administration
And I set the field "datatype" to "Social"
And I click on "Create a new profile field" "link"
And I click on "Social" "link"
And I set the following fields to these values:
| Short name | yahoo |
| Networktype | Yahoo ID |
| Short name | yahoo |
And I click on "Save changes" "button"
And I set the field "datatype" to "Social"
And I click on "Create a new profile field" "link"
And I click on "Social" "link"
And I set the following fields to these values:
| Short name | yahoo |
| Networktype | Yahoo ID |
| Short name | yahoo |
And I click on "Save changes" "button"
Then I should see "This short name is already in use"
2 changes: 1 addition & 1 deletion user/profile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function profile_save_custom_fields($userid, $profilefields) {
* current request for all fields so that it can be used quickly.
*
* @param string $shortname Shortname of custom profile field
* @return stdClass Object with properties id, shortname, name, visible, datatype, categoryid, etc
* @return stdClass|null Object with properties id, shortname, name, visible, datatype, categoryid, etc
*/
function profile_get_custom_field_data_by_shortname(string $shortname): ?stdClass {
$cache = \cache::make_from_params(cache_store::MODE_REQUEST, 'core_profile', 'customfields',
Expand Down

0 comments on commit 3bf770c

Please sign in to comment.