Merge pull request #21782 from owncloud/update-system-addressbook-on-user-change-2

Introduce IUser::setEMailAddress and add hook mechanism
This commit is contained in:
Thomas Müller 2016-01-21 00:07:46 +01:00
commit 2f7dcf1a2c
22 changed files with 207 additions and 138 deletions

View File

@ -54,6 +54,10 @@ class HookManager {
'post_deleteUser',
$this,
'postDeleteUser');
Util::connectHook('OC_User',
'changeUser',
$this,
'changeUser');
}
public function postCreateUser($params) {
@ -64,6 +68,7 @@ class HookManager {
public function preDeleteUser($params) {
$this->usersToDelete[$params['uid']] = $this->userManager->get($params['uid']);
}
public function postDeleteUser($params) {
$uid = $params['uid'];
if (isset($this->usersToDelete[$uid])){
@ -71,4 +76,8 @@ class HookManager {
}
}
public function changeUser($params) {
$user = $params['user'];
$this->syncService->updateUser($user);
}
}

View File

@ -285,7 +285,7 @@ class Users {
break;
case 'email':
if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) {
$this->config->setUserValue($targetUserId, 'settings', 'email', $parameters['_put']['value']);
$targetUser->setEMailAddress($parameters['_put']['value']);
} else {
return new OC_OCS_Result(null, 102);
}

View File

@ -932,10 +932,10 @@ class UsersTest extends OriginalTest {
->method('get')
->with('UserToEdit')
->will($this->returnValue($targetUser));
$this->config
$targetUser
->expects($this->once())
->method('setUserValue')
->with('UserToEdit', 'settings', 'email', 'demo@owncloud.org');
->method('setEMailAddress')
->with('demo@owncloud.org');
$expected = new \OC_OCS_Result(null, 100);
$this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit', '_put' => ['key' => 'email', 'value' => 'demo@owncloud.org']]));

View File

@ -54,7 +54,8 @@ $userManager = new \OCA\user_ldap\lib\user\Manager(
new \OCA\user_ldap\lib\LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
\OC::$server->getDatabaseConnection());
\OC::$server->getDatabaseConnection(),
\OC::$server->getUserManager());
$access = new \OCA\user_ldap\lib\Access($con, $ldapWrapper, $userManager);

View File

@ -37,7 +37,8 @@ if(count($configPrefixes) === 1) {
new OCA\user_ldap\lib\LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
$dbc
$dbc,
\OC::$server->getUserManager()
);
$connector = new OCA\user_ldap\lib\Connection($ldapWrapper, $configPrefixes[0]);
$ldapAccess = new OCA\user_ldap\lib\Access($connector, $ldapWrapper, $userManager);

View File

@ -175,7 +175,8 @@ class Jobs extends \OC\BackgroundJob\TimedJob {
new LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
$dbc);
$dbc,
\OC::$server->getUserManager());
$connector = new Connection($ldapWrapper, $configPrefixes[0]);
$ldapAccess = new Access($connector, $ldapWrapper, $userManager);
$groupMapper = new GroupMapping($dbc);

View File

@ -61,6 +61,7 @@ abstract class Proxy {
static $userMap;
static $groupMap;
static $db;
static $userManager;
if(is_null($fs)) {
$ocConfig = \OC::$server->getConfig();
$fs = new FilesystemHelper();
@ -69,9 +70,10 @@ abstract class Proxy {
$db = \OC::$server->getDatabaseConnection();
$userMap = new UserMapping($db);
$groupMap = new GroupMapping($db);
$userManager = \OC::$server->getUserManager();
}
$userManager =
new user\Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db);
new user\Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $userManager);
$connector = new Connection($this->ldap, $configPrefix);
$access = new Access($connector, $this->ldap, $userManager);
$access->setUserMapper($userMap);

View File

@ -29,6 +29,11 @@ use OCA\user_ldap\lib\user\User;
use OCA\user_ldap\lib\LogWrapper;
use OCA\user_ldap\lib\FilesystemHelper;
use OCA\user_ldap\lib\user\OfflineUser;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Image;
use OCP\IUserManager;
/**
* Manager
@ -40,10 +45,10 @@ class Manager {
/** @var IUserTools */
protected $access;
/** @var \OCP\IConfig */
/** @var IConfig */
protected $ocConfig;
/** @var \OCP\IDBConnection */
/** @var IDBConnection */
protected $db;
/** @var FilesystemHelper */
@ -52,7 +57,7 @@ class Manager {
/** @var LogWrapper */
protected $ocLog;
/** @var \OCP\Image */
/** @var Image */
protected $image;
/** @param \OCP\IAvatarManager */
@ -69,18 +74,19 @@ class Manager {
);
/**
* @param \OCP\IConfig $ocConfig
* @param IConfig $ocConfig
* @param \OCA\user_ldap\lib\FilesystemHelper $ocFilesystem object that
* gives access to necessary functions from the OC filesystem
* @param \OCA\user_ldap\lib\LogWrapper $ocLog
* @param \OCP\IAvatarManager $avatarManager
* @param \OCP\Image $image an empty image instance
* @param \OCP\IDBConnection $db
* @param IAvatarManager $avatarManager
* @param Image $image an empty image instance
* @param IDBConnection $db
* @throws \Exception when the methods mentioned above do not exist
*/
public function __construct(\OCP\IConfig $ocConfig,
FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
\OCP\IAvatarManager $avatarManager, \OCP\Image $image, \OCP\IDBConnection $db) {
public function __construct(IConfig $ocConfig,
FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
IAvatarManager $avatarManager, Image $image,
IDBConnection $db, IUserManager $userManager) {
$this->ocConfig = $ocConfig;
$this->ocFilesystem = $ocFilesystem;
@ -88,6 +94,7 @@ class Manager {
$this->avatarManager = $avatarManager;
$this->image = $image;
$this->db = $db;
$this->userManager = $userManager;
}
/**
@ -110,7 +117,7 @@ class Manager {
$this->checkAccess();
$user = new User($uid, $dn, $this->access, $this->ocConfig,
$this->ocFilesystem, clone $this->image, $this->ocLog,
$this->avatarManager);
$this->avatarManager, $this->userManager);
$this->users['byDN'][$dn] = $user;
$this->users['byUid'][$uid] = $user;
return $user;

View File

@ -27,6 +27,9 @@ use OCA\user_ldap\lib\user\IUserTools;
use OCA\user_ldap\lib\Connection;
use OCA\user_ldap\lib\FilesystemHelper;
use OCA\user_ldap\lib\LogWrapper;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IUserManager;
/**
* User
@ -43,7 +46,7 @@ class User {
*/
protected $connection;
/**
* @var \OCP\IConfig
* @var IConfig
*/
protected $config;
/**
@ -59,10 +62,13 @@ class User {
*/
protected $log;
/**
* @var \OCP\IAvatarManager
* @var IAvatarManager
*/
protected $avatarManager;
/**
* @var IUserManager
*/
protected $userManager;
/**
* @var string
*/
@ -92,15 +98,16 @@ class User {
* @param string $dn the LDAP DN
* @param IUserTools $access an instance that implements IUserTools for
* LDAP interaction
* @param \OCP\IConfig $config
* @param IConfig $config
* @param FilesystemHelper $fs
* @param \OCP\Image $image any empty instance
* @param LogWrapper $log
* @param \OCP\IAvatarManager $avatarManager
* @param IAvatarManager $avatarManager
* @param IUserManager $userManager
*/
public function __construct($username, $dn, IUserTools $access,
\OCP\IConfig $config, FilesystemHelper $fs, \OCP\Image $image,
LogWrapper $log, \OCP\IAvatarManager $avatarManager) {
IConfig $config, FilesystemHelper $fs, \OCP\Image $image,
LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager) {
$this->access = $access;
$this->connection = $access->getConnection();
@ -111,6 +118,7 @@ class User {
$this->image = $image;
$this->log = $log;
$this->avatarManager = $avatarManager;
$this->userManager = $userManager;
}
/**
@ -400,8 +408,8 @@ class User {
}
}
if(!is_null($email)) {
$this->config->setUserValue(
$this->uid, 'settings', 'email', $email);
$user = $this->userManager->get($this->uid);
$user->setEMailAddress($email);
}
}

View File

@ -58,7 +58,8 @@ class Test_Access extends \Test\TestCase {
$this->getMock('\OCA\user_ldap\lib\LogWrapper'),
$this->getMock('\OCP\IAvatarManager'),
$this->getMock('\OCP\Image'),
$this->getMock('\OCP\IDBConnection')));
$this->getMock('\OCP\IDBConnection'),
$this->getMock('\OCP\IUserManager')));
return array($lw, $connector, $um);
}

View File

@ -123,7 +123,8 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
new \OCA\user_ldap\lib\LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
\OC::$server->getDatabaseConnection()
\OC::$server->getDatabaseConnection(),
\OC::$server->getUserManager()
);
}

View File

@ -44,6 +44,7 @@ class Test_User_Manager extends \Test\TestCase {
$avaMgr = $this->getMock('\OCP\IAvatarManager');
$image = $this->getMock('\OCP\Image');
$dbc = $this->getMock('\OCP\IDBConnection');
$userMgr = $this->getMock('\OCP\IUserManager');
$connection = new \OCA\user_ldap\lib\Connection(
$lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper'),
@ -55,11 +56,11 @@ class Test_User_Manager extends \Test\TestCase {
->method('getConnection')
->will($this->returnValue($connection));
return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc);
return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr);
}
public function testGetByDNExisting() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$inputDN = 'cn=foo,dc=foobar,dc=bar';
@ -78,7 +79,7 @@ class Test_User_Manager extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@ -90,7 +91,7 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetByEDirectoryDN() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$inputDN = 'uid=foo,o=foobar,c=bar';
@ -109,7 +110,7 @@ class Test_User_Manager extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@ -117,7 +118,7 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetByExoticDN() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$inputDN = 'ab=cde,f=ghei,mno=pq';
@ -136,7 +137,7 @@ class Test_User_Manager extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@ -144,7 +145,7 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetByDNNotExisting() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$inputDN = 'cn=gone,dc=foobar,dc=bar';
@ -164,7 +165,7 @@ class Test_User_Manager extends \Test\TestCase {
->with($this->equalTo($inputDN))
->will($this->returnValue(false));
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@ -172,7 +173,7 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetByUidExisting() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$dn = 'cn=foo,dc=foobar,dc=bar';
@ -191,7 +192,7 @@ class Test_User_Manager extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue(false));
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($uid);
@ -203,7 +204,7 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetByUidNotExisting() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$dn = 'cn=foo,dc=foobar,dc=bar';
@ -217,7 +218,7 @@ class Test_User_Manager extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue(false));
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$user = $manager->get($uid);
@ -225,10 +226,10 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetAttributesAll() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$connection = $access->getConnection();
@ -243,10 +244,10 @@ class Test_User_Manager extends \Test\TestCase {
}
public function testGetAttributesMinimal() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
$manager->setLdapAccess($access);
$attributes = $manager->getAttributes(true);

View File

@ -25,6 +25,7 @@
namespace OCA\user_ldap\tests;
use OCA\user_ldap\lib\user\User;
use OCP\IUserManager;
/**
* Class Test_User_User
@ -43,11 +44,12 @@ class Test_User_User extends \Test\TestCase {
$avaMgr = $this->getMock('\OCP\IAvatarManager');
$image = $this->getMock('\OCP\Image');
$dbc = $this->getMock('\OCP\IDBConnection');
$userMgr = $this->getMock('\OCP\IUserManager');
return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc);
return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr);
}
private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc) {
private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc, $userMgr = null) {
static $conMethods;
static $accMethods;
static $umMethods;
@ -61,8 +63,11 @@ class Test_User_User extends \Test\TestCase {
}
$lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper');
$im = $this->getMock('\OCP\Image');
if (is_null($userMgr)) {
$userMgr = $this->getMock('\OCP\IUserManager');
}
$um = $this->getMock('\OCA\user_ldap\lib\user\Manager',
$umMethods, array($cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc));
$umMethods, array($cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc, $userMgr));
$connector = $this->getMock('\OCA\user_ldap\lib\Connection',
$conMethods, array($lw, null, null));
$access = $this->getMock('\OCA\user_ldap\lib\Access',
@ -72,25 +77,25 @@ class Test_User_User extends \Test\TestCase {
}
public function testGetDNandUsername() {
list($access, $config, $filesys, $image, $log, $avaMgr) =
list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
$this->getTestInstances();
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$this->assertSame($dn, $user->getDN());
$this->assertSame($uid, $user->getUsername());
}
public function testUpdateEmailProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
$this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
$this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr);
$connection->expects($this->once())
->method('__get')
@ -103,24 +108,27 @@ class Test_User_User extends \Test\TestCase {
$this->equalTo('email'))
->will($this->returnValue(array('alice@foo.bar')));
$config->expects($this->once())
->method('setUserValue')
->with($this->equalTo('alice'), $this->equalTo('settings'),
$this->equalTo('email'),
$this->equalTo('alice@foo.bar'))
->will($this->returnValue(true));
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$uuser = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()
->getMock();
$uuser->expects($this->once())
->method('setEMailAddress')
->with('alice@foo.bar');
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userMgr */
$userMgr->expects($this->any())
->method('get')
->willReturn($uuser);
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateEmail();
}
public function testUpdateEmailNotProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -144,13 +152,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateEmail();
}
public function testUpdateEmailNotConfigured() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -171,13 +179,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateEmail();
}
public function testUpdateQuotaAllProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -214,13 +222,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota();
}
public function testUpdateQuotaDefaultProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -257,13 +265,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota();
}
public function testUpdateQuotaIndividualProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -300,13 +308,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -338,13 +346,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneConfigured() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -373,13 +381,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota();
}
public function testUpdateQuotaFromValue() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -412,14 +420,14 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateQuota($readQuota);
}
//the testUpdateAvatar series also implicitely tests getAvatarImage
public function testUpdateAvatarJpegPhotoProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -462,13 +470,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateAvatar();
}
public function testUpdateAvatarThumbnailPhotoProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -520,13 +528,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateAvatar();
}
public function testUpdateAvatarNotProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -566,13 +574,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->updateAvatar();
}
public function testUpdateBeforeFirstLogin() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -602,13 +610,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->update();
}
public function testUpdateAfterFirstLogin() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -642,13 +650,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->update();
}
public function testUpdateNoRefresh() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -678,13 +686,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->update();
}
public function testMarkLogin() {
list($access, $config, $filesys, $image, $log, $avaMgr) =
list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
$this->getTestInstances();
$config->expects($this->once())
@ -699,13 +707,13 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->markLogin();
}
public function testGetAvatarImageProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr) =
list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
$this->getTestInstances();
$access->expects($this->once())
@ -718,7 +726,7 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$photo = $user->getAvatarImage();
$this->assertSame('this is a photo', $photo);
@ -728,7 +736,7 @@ class Test_User_User extends \Test\TestCase {
}
public function testProcessAttributes() {
list(, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -748,7 +756,7 @@ class Test_User_User extends \Test\TestCase {
);
$userMock = $this->getMockBuilder('OCA\user_ldap\lib\user\User')
->setConstructorArgs(array($uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr))
->setConstructorArgs(array($uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr))
->setMethods($requiredMethods)
->getMock();
@ -795,7 +803,7 @@ class Test_User_User extends \Test\TestCase {
* @dataProvider emptyHomeFolderAttributeValueProvider
*/
public function testGetHomePathNotConfigured($attributeValue) {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -816,14 +824,14 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$path = $user->getHomePath();
$this->assertSame($path, false);
}
public function testGetHomePathConfiguredNotAvailableAllowed() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
@ -847,7 +855,7 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$path = $user->getHomePath();
@ -858,11 +866,11 @@ class Test_User_User extends \Test\TestCase {
* @expectedException \Exception
*/
public function testGetHomePathConfiguredNotAvailableNotAllowed() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
list($access, $connection) =
$this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
$this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr);
$connection->expects($this->any())
->method('__get')
@ -882,7 +890,7 @@ class Test_User_User extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
$user->getHomePath();
}

View File

@ -84,7 +84,8 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
$this->getMock('\OCA\user_ldap\lib\LogWrapper'),
$this->getMock('\OCP\IAvatarManager'),
$this->getMock('\OCP\Image'),
$this->getMock('\OCP\IDBConnection')
$this->getMock('\OCP\IDBConnection'),
$this->getMock('\OCP\IUserManager')
])
->getMock();

View File

@ -229,6 +229,10 @@ class Server extends ServerContainer implements IServerContainer {
$userSession->listen('\OC\User', 'logout', function () {
\OC_Hook::emit('OC_User', 'logout', array());
});
$userSession->listen('\OC\User', 'changeUser', function ($user) {
/** @var $user \OC\User\User */
\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user));
});
return $userSession;
});
$this->registerService('NavigationManager', function ($c) {

View File

@ -44,6 +44,7 @@ use OCP\IConfig;
* - postDelete(\OC\User\User $user)
* - preCreateUser(string $uid, string $password)
* - postCreateUser(\OC\User\User $user, string $password)
* - change(\OC\User\User $user)
*
* @package OC\User
*/

View File

@ -137,14 +137,37 @@ class User implements IUser {
public function setDisplayName($displayName) {
$displayName = trim($displayName);
if ($this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME) && !empty($displayName)) {
$this->displayName = $displayName;
$result = $this->backend->setDisplayName($this->uid, $displayName);
if ($result) {
$this->displayName = $displayName;
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'changeUser', array($this));
}
}
return $result !== false;
} else {
return false;
}
}
/**
* set the email address of the user
*
* @param string|null $mailAddress
* @return void
* @since 9.0.0
*/
public function setEMailAddress($mailAddress) {
if($mailAddress === '') {
$this->config->deleteUserValue($this->uid, 'settings', 'email');
} else {
$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
}
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'changeUser', array($this));
}
}
/**
* returns the timestamp of the user's last login or 0 if the user did never
* login
@ -365,4 +388,5 @@ class User implements IUser {
return $url;
}
}

View File

@ -169,4 +169,13 @@ interface IUser {
* @since 9.0.0
*/
public function getCloudId();
/**
* set the email address of the user
*
* @param string|null $mailAddress
* @return void
* @since 9.0.0
*/
public function setEMailAddress($mailAddress);
}

View File

@ -373,7 +373,7 @@ class UsersController extends Controller {
* Send new user mail only if a mail is set
*/
if($email !== '') {
$this->config->setUserValue($username, 'settings', 'email', $email);
$user->setEMailAddress($email);
// data for the mail template
$mailData = array(
@ -545,11 +545,7 @@ class UsersController extends Controller {
}
// delete user value if email address is empty
if($mailAddress === '') {
$this->config->deleteUserValue($id, 'settings', 'email');
} else {
$this->config->setUserValue($id, 'settings', 'email', $mailAddress);
}
$user->setEMailAddress($mailAddress);
return new DataResponse(
array(

View File

@ -47,6 +47,9 @@ class Test_LocalAddressBook extends \Test\TestCase
class SimpleUserForTesting implements IUser {
private $uid;
private $displayName;
public function __construct($uid, $displayName) {
$this->uid = $uid;
@ -105,4 +108,7 @@ class SimpleUserForTesting implements IUser {
public function getCloudId() {
}
public function setEMailAddress($mailAddress) {
}
}

View File

@ -342,7 +342,8 @@ class User extends \Test\TestCase {
$backend->expects($this->once())
->method('setDisplayName')
->with('foo','Foo');
->with('foo','Foo')
->willReturn(true);
$user = new \OC\User\User('foo', $backend);
$this->assertTrue($user->setDisplayName('Foo'));

View File

@ -1679,11 +1679,11 @@ class UsersControllerTest extends \Test\TestCase {
*/
public function setEmailAddressData() {
return [
/* mailAddress, isValid, expectsUpdate, expectsDelete, canChangeDisplayName, responseCode */
[ '', true, false, true, true, Http::STATUS_OK ],
[ 'foo@local', true, true, false, true, Http::STATUS_OK],
[ 'foo@bar@local', false, false, false, true, Http::STATUS_UNPROCESSABLE_ENTITY],
[ 'foo@local', true, false, false, false, Http::STATUS_FORBIDDEN],
/* mailAddress, isValid, expectsUpdate, canChangeDisplayName, responseCode */
[ '', true, true, true, Http::STATUS_OK ],
[ 'foo@local', true, true, true, Http::STATUS_OK],
[ 'foo@bar@local', false, false, true, Http::STATUS_UNPROCESSABLE_ENTITY],
[ 'foo@local', true, false, false, Http::STATUS_FORBIDDEN],
];
}
@ -1695,7 +1695,7 @@ class UsersControllerTest extends \Test\TestCase {
* @param bool $expectsUpdate
* @param bool $expectsDelete
*/
public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $expectsDelete, $canChangeDisplayName, $responseCode) {
public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
$this->container['IsAdmin'] = true;
$user = $this->getMockBuilder('\OC\User\User')
@ -1708,6 +1708,13 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->any())
->method('canChangeDisplayName')
->will($this->returnValue($canChangeDisplayName));
$user
->expects($expectsUpdate ? $this->once() : $this->never())
->method('setEMailAddress')
->with(
$this->equalTo($mailAddress)
);
$this->container['UserSession']
->expects($this->atLeastOnce())
->method('getUser')
@ -1730,26 +1737,6 @@ class UsersControllerTest extends \Test\TestCase {
->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')
);
$response = $this->container['UsersController']->setMailAddress($user->getUID(), $mailAddress);
$this->assertSame($responseCode, $response->getStatus());