Merge pull request #16064 from owncloud/fix-empty-mail-address

Allow user to set an empty email address
This commit is contained in:
Jan-Christoph Borchardt 2015-05-05 14:51:53 +02:00
commit 2aaafc134c
3 changed files with 81 additions and 5 deletions

View file

@ -504,7 +504,12 @@ class UsersController extends Controller {
);
}
$this->config->setUserValue($id, 'settings', 'email', $mailAddress);
// delete user value if email address is empty
if($mailAddress === '') {
$this->config->deleteUserValue($id, 'settings', 'email');
} else {
$this->config->setUserValue($id, 'settings', 'email', $mailAddress);
}
return new DataResponse(
array(

View file

@ -12,8 +12,9 @@
* user or 1 second after the last data entry
*
* @param callback
* @param allowEmptyValue if this is set to true the callback is also called when the value is empty
*/
jQuery.fn.keyUpDelayedOrEnter = function (callback) {
jQuery.fn.keyUpDelayedOrEnter = function (callback, allowEmptyValue) {
var cb = callback;
var that = this;
this.keyup(_.debounce(function (event) {
@ -21,13 +22,13 @@ jQuery.fn.keyUpDelayedOrEnter = function (callback) {
if (event.keyCode === 13) {
return;
}
if (that.val() !== '') {
if (allowEmptyValue || that.val() !== '') {
cb();
}
}, 1000));
this.keypress(function (event) {
if (event.keyCode === 13 && that.val() !== '') {
if (event.keyCode === 13 && (allowEmptyValue || that.val() !== '')) {
event.preventDefault();
cb();
}
@ -213,7 +214,7 @@ $(document).ready(function () {
});
$('#displayName').keyUpDelayedOrEnter(changeDisplayName);
$('#email').keyUpDelayedOrEnter(changeEmailAddress);
$('#email').keyUpDelayedOrEnter(changeEmailAddress, true);
$("#languageinput").change(function () {
// Serialize the data

View file

@ -1388,4 +1388,74 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertEquals($expectedResult, $result);
}
public function setEmailAddressData() {
return [
['', true, false, true],
['foobar@localhost', true, true, false],
['foo@bar@localhost', false, false, false],
];
}
/**
* @dataProvider setEmailAddressData
*
* @param string $mailAddress
* @param bool $isValid
* @param bool $expectsUpdate
* @param bool $expectsDelete
*/
public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $expectsDelete) {
$this->container['IsAdmin'] = true;
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
->expects($this->any())
->method('getUID')
->will($this->returnValue('foo'));
$this->container['UserSession']
->expects($this->atLeastOnce())
->method('getUser')
->will($this->returnValue($user));
$this->container['Mailer']
->expects($this->any())
->method('validateMailAddress')
->with($mailAddress)
->willReturn($isValid);
if ($isValid) {
$user->expects($this->atLeastOnce())
->method('canChangeDisplayName')
->willReturn(true);
$this->container['UserManager']
->expects($this->atLeastOnce())
->method('get')
->with('foo')
->will($this->returnValue($user));
}
$this->container['Config']
->expects(($expectsUpdate) ? $this->once() : $this->never())
->method('setUserValue')
->with(
$this->equalTo($user->getUID()),
$this->equalTo('settings'),
$this->equalTo('email'),
$this->equalTo($mailAddress)
);
$this->container['Config']
->expects(($expectsDelete) ? $this->once() : $this->never())
->method('deleteUserValue')
->with(
$this->equalTo($user->getUID()),
$this->equalTo('settings'),
$this->equalTo('email')
);
$this->container['UsersController']->setMailAddress($user->getUID(), $mailAddress);
}
}