Skip to content

Commit

Permalink
MDL-62965 core_user: Fix missing user profile fields on signup page
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jul 27, 2018
1 parent e8ebf0f commit e2cbb82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion user/profile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ public function is_visible() {
case PROFILE_VISIBLE_ALL:
return true;
case PROFILE_VISIBLE_PRIVATE:
if ($this->userid == $USER->id) {
if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
return true;
} else if ($this->userid == $USER->id) {
return true;
} else {
return has_capability('moodle/user:viewalldetails', $context);
Expand All @@ -448,6 +450,11 @@ public function is_editable() {
return false;
}

if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
// Allow editing the field on the signup page.
return true;
}

$systemcontext = context_system::instance();

if ($this->userid == $USER->id && has_capability('moodle/user:editownprofile', $systemcontext)) {
Expand Down
29 changes: 28 additions & 1 deletion user/tests/behat/custom_profile_fields.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@core @core_user
Feature: Custom profile fields should be visible and editable by those with the correct permissions.

Background: Attempting to self-register as a new user with empty names
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| userwithinformation | userwithinformation | 1 | userwithinformation@example.com |
Expand All @@ -12,26 +12,32 @@ Feature: Custom profile fields should be visible and editable by those with the
| user | course | role |
| userwithinformation | C1 | student |

And the following config values are set as admin:
| registerauth | email |

And I log in as "admin"
And I navigate to "User profile fields" node in "Site administration > Users > Accounts"
And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | notvisible_field |
| Name | notvisible_field |
| Display on signup page? | Yes |
| Who is this field visible to? | Not visible |
And I click on "Save changes" "button"

And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | uservisible_field |
| Name | uservisible_field |
| Display on signup page? | Yes |
| Who is this field visible to? | Visible to user |
And I click on "Save changes" "button"

And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | everyonevisible_field |
| Name | everyonevisible_field |
| Display on signup page? | No |
| Who is this field visible to? | Visible to everyone |
And I click on "Save changes" "button"

Expand All @@ -44,6 +50,27 @@ Feature: Custom profile fields should be visible and editable by those with the
And I click on "Update profile" "button"
And I log out

@javascript
Scenario: Visible custom profile fields can be part of the sign up form for anonymous users.
Given I am on site homepage
And I follow "Log in"
When I press "Create new account"
And I expand all fieldsets
Then I should not see "notvisible_field"
And I should see "uservisible_field"
And I should not see "everyonevisible_field"

@javascript
Scenario: Visible custom profile fields can be part of the sign up form for guest users.
Given I log in as "guest"
And I am on site homepage
And I follow "Log in"
When I press "Create new account"
And I expand all fieldsets
Then I should not see "notvisible_field"
And I should see "uservisible_field"
And I should not see "everyonevisible_field"

@javascript
Scenario: User with moodle/user:update but without moodle/user:viewalldetails can only update visible profile fields.
Given the following "roles" exist:
Expand Down

0 comments on commit e2cbb82

Please sign in to comment.