Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'MDL-42097-master' of git://github.com/ankitagarwal/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Dec 3, 2013
2 parents 53741d3 + 963cdce commit 8761a4f
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 4 deletions.
2 changes: 1 addition & 1 deletion auth/db/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ function can_change_password() {
* @return moodle_url
*/
function change_password_url() {
if ($this->is_internal()) {
if ($this->is_internal() || empty($this->config->changepasswordurl)) {
// Standard form.
return null;
} else {
Expand Down
6 changes: 5 additions & 1 deletion auth/imap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ function can_change_password() {
* @return moodle_url
*/
function change_password_url() {
return new moodle_url($this->config->changepasswordurl);
if (!empty($this->config->changepasswordurl)) {
return new moodle_url($this->config->changepasswordurl);
} else {
return null;
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,11 @@ function can_change_password() {
*/
function change_password_url() {
if (empty($this->config->stdchangepassword)) {
return new moodle_url($this->config->changepasswordurl);
if (!empty($this->config->changepasswordurl)) {
return new moodle_url($this->config->changepasswordurl);
} else {
return null;
}
} else {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion auth/pop3/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ function can_change_password() {
* @return moodle_url
*/
function change_password_url() {
return new moodle_url($this->config->changepasswordurl);
if (!empty($this->config->changepasswordurl)) {
return new moodle_url($this->config->changepasswordurl);
} else {
return null;
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions auth/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
This files describes API changes in /auth/* - plugins,
information provided here is intended especially for developers.

=== 2.7 ===

* If you are returning a url in method change_password_url() from config, please make sure it is set before trying to use it.

=== 2.6 ===

* can_be_manually_set() - This function was introduced in the base class and returns false by default. If overriden by
Expand Down
2 changes: 2 additions & 0 deletions lib/authlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function can_change_password() {
*
* This method is used if can_change_password() returns true.
* This method is called only when user is logged in, it may use global $USER.
* If you are using a plugin config variable in this method, please make sure it is set before using it,
* as this method can be called even if the plugin is disabled, in which case the config values won't be set.
*
* @return moodle_url url of the profile page or null if standard used
*/
Expand Down
66 changes: 66 additions & 0 deletions lib/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,72 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
hide : false
}
},
/**
* Lock the given field if the field value is in the given set of values.
*
* @param elements
* @param values
* @returns {{lock: boolean, hide: boolean}}
* @private
*/
_dependency_in : function(elements, values) {
// A pipe (|) is used as a value separator
// when multiple values have to be passed on at the same time.
values = values.split('|');
var lock = false;
var hidden_val = false;
var options, v, selected, value;
elements.each(function(){
if (this.getAttribute('type').toLowerCase()=='radio' && !Y.Node.getDOMNode(this).checked) {
return;
} else if (this.getAttribute('type').toLowerCase() == 'hidden' && !this.siblings('input[type=checkbox][name="' + this.get('name') + '"]').isEmpty()) {
// This is the hidden input that is part of an advcheckbox.
hidden_val = (values.indexOf(this.get('value')) > -1);
return;
} else if (this.getAttribute('type').toLowerCase() == 'checkbox' && !Y.Node.getDOMNode(this).checked) {
lock = lock || hidden_val;
return;
}
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
// Check for filepicker status.
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
lock = false;
} else {
lock = true;
}
} else if (this.get('nodeName').toUpperCase() === 'SELECT' && this.get('multiple') === true) {
// Multiple selects can have one or more value assigned.
selected = [];
options = this.get('options');
options.each(function() {
if (this.get('selected')) {
selected[selected.length] = this.get('value');
}
});
if (selected.length > 0 && selected.length === values.length) {
for (var i in selected) {
v = selected[i];
if (values.indexOf(v) > -1) {
lock = true;
} else {
lock = false;
return;
}
}
} else {
lock = false;
}
} else {
value = this.get('value');
lock = lock || (values.indexOf(value) > -1);
}
});
return {
lock : lock,
hide : false
}
},
_dependency_hide : function(elements, value) {
return {
lock : false,
Expand Down
8 changes: 8 additions & 0 deletions user/editadvanced_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ function definition() {
$enabled = get_string('pluginenabled', 'core_plugin');
$disabled = get_string('plugindisabled', 'core_plugin');
$auth_options = array($enabled=>array(), $disabled=>array());
$cannotchangepass = array();
foreach ($auths as $auth => $unused) {
$authinst = get_auth_plugin($auth);
$passwordurl = $authinst->change_password_url();
if (!($authinst->can_change_password() && empty($passwordurl))) {
$cannotchangepass[] = $auth;
}
if (is_enabled_auth($auth)) {
$auth_options[$enabled][$auth] = get_string('pluginname', "auth_{$auth}");
} else {
Expand All @@ -73,6 +79,8 @@ function definition() {
$mform->setType('newpassword', PARAM_RAW);
$mform->disabledIf('newpassword', 'createpassword', 'checked');

$mform->disabledIf('newpassword', 'auth', 'in', $cannotchangepass);

$mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
$mform->addHelpButton('preference_auth_forcepasswordchange', 'forcepasswordchange');
$mform->disabledIf('preference_auth_forcepasswordchange', 'createpassword', 'checked');
Expand Down
19 changes: 19 additions & 0 deletions user/tests/behat/edituserpassword.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@core @core_user
Feature: Enable/disable password field based on authentication selected.
In order edit a user password properly
As an admin
I need to be able to notice if the change in password is allowed by athuentication plugin or not

@javascript
Scenario: Verify the password field is enabled/disabled based on authentication selected, in user edit advanced page.
Given I log in as "admin"
And I follow "My home"
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
When I follow "Add a new user"
Then the "newpassword" "field" should be enabled
And I select "Web services authentication" from "auth"
And the "newpassword" "field" should be disabled
And I select "Email-based self-registration" from "auth"
And the "newpassword" "field" should be enabled

0 comments on commit 8761a4f

Please sign in to comment.