Merge pull request #6513 from owncloud/user-no-change-displayname
Re-add the config options to remove the ability for users to change their displayname
This commit is contained in:
commit
14e0b1b6d1
|
@ -69,10 +69,18 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
return new Root($manager, $view, $user);
|
return new Root($manager, $view, $user);
|
||||||
});
|
});
|
||||||
$this->registerService('UserManager', function($c) {
|
$this->registerService('UserManager', function($c) {
|
||||||
return new \OC\User\Manager();
|
/**
|
||||||
|
* @var SimpleContainer $c
|
||||||
|
* @var \OC\AllConfig $config
|
||||||
|
*/
|
||||||
|
$config = $c->query('AllConfig');
|
||||||
|
return new \OC\User\Manager($config);
|
||||||
});
|
});
|
||||||
$this->registerService('UserSession', function($c) {
|
$this->registerService('UserSession', function($c) {
|
||||||
/** @var $c SimpleContainer */
|
/**
|
||||||
|
* @var SimpleContainer $c
|
||||||
|
* @var \OC\User\Manager $manager
|
||||||
|
*/
|
||||||
$manager = $c->query('UserManager');
|
$manager = $c->query('UserManager');
|
||||||
$userSession = new \OC\User\Session($manager, \OC::$session);
|
$userSession = new \OC\User\Session($manager, \OC::$session);
|
||||||
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
|
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
|
||||||
|
|
|
@ -35,7 +35,16 @@ class Manager extends PublicEmitter {
|
||||||
*/
|
*/
|
||||||
private $cachedUsers = array();
|
private $cachedUsers = array();
|
||||||
|
|
||||||
public function __construct() {
|
/**
|
||||||
|
* @var \OC\AllConfig $config
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OC\AllConfig $config
|
||||||
|
*/
|
||||||
|
public function __construct($config = null) {
|
||||||
|
$this->config = $config;
|
||||||
$cachedUsers = $this->cachedUsers;
|
$cachedUsers = $this->cachedUsers;
|
||||||
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
|
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
|
||||||
$i = array_search($user, $cachedUsers);
|
$i = array_search($user, $cachedUsers);
|
||||||
|
@ -103,7 +112,7 @@ class Manager extends PublicEmitter {
|
||||||
if (isset($this->cachedUsers[$uid])) {
|
if (isset($this->cachedUsers[$uid])) {
|
||||||
return $this->cachedUsers[$uid];
|
return $this->cachedUsers[$uid];
|
||||||
}
|
}
|
||||||
$this->cachedUsers[$uid] = new User($uid, $backend, $this);
|
$this->cachedUsers[$uid] = new User($uid, $backend, $this, $this->config);
|
||||||
return $this->cachedUsers[$uid];
|
return $this->cachedUsers[$uid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,18 @@ class User {
|
||||||
*/
|
*/
|
||||||
private $home;
|
private $home;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OC\AllConfig $config
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
* @param \OC_User_Backend $backend
|
* @param \OC_User_Backend $backend
|
||||||
* @param Emitter $emitter
|
* @param \OC\Hooks\Emitter $emitter
|
||||||
|
* @param \OC\AllConfig $config
|
||||||
*/
|
*/
|
||||||
public function __construct($uid, $backend, $emitter = null) {
|
public function __construct($uid, $backend, $emitter = null, $config = null) {
|
||||||
$this->uid = $uid;
|
$this->uid = $uid;
|
||||||
if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
|
if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
|
||||||
$this->displayName = $backend->getDisplayName($uid);
|
$this->displayName = $backend->getDisplayName($uid);
|
||||||
|
@ -56,8 +62,13 @@ class User {
|
||||||
}
|
}
|
||||||
$this->backend = $backend;
|
$this->backend = $backend;
|
||||||
$this->emitter = $emitter;
|
$this->emitter = $emitter;
|
||||||
$enabled = \OC_Preferences::getValue($uid, 'core', 'enabled', 'true'); //TODO: DI for OC_Preferences
|
$this->config = $config;
|
||||||
|
if ($this->config) {
|
||||||
|
$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
|
||||||
$this->enabled = ($enabled === 'true');
|
$this->enabled = ($enabled === 'true');
|
||||||
|
} else {
|
||||||
|
$this->enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,8 +152,10 @@ class User {
|
||||||
if (!$this->home) {
|
if (!$this->home) {
|
||||||
if ($this->backend->implementsActions(\OC_USER_BACKEND_GET_HOME) and $home = $this->backend->getHome($this->uid)) {
|
if ($this->backend->implementsActions(\OC_USER_BACKEND_GET_HOME) and $home = $this->backend->getHome($this->uid)) {
|
||||||
$this->home = $home;
|
$this->home = $home;
|
||||||
|
} elseif ($this->config) {
|
||||||
|
$this->home = $this->config->getSystemValue('datadirectory') . '/' . $this->uid;
|
||||||
} else {
|
} else {
|
||||||
$this->home = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data") . '/' . $this->uid; //TODO switch to Config object once implemented
|
$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->home;
|
return $this->home;
|
||||||
|
@ -175,8 +188,12 @@ class User {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canChangeDisplayName() {
|
public function canChangeDisplayName() {
|
||||||
|
if ($this->config and $this->config->getSystemValue('allow_user_to_change_display_name') === false) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
|
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the user is enabled
|
* check if the user is enabled
|
||||||
|
@ -194,7 +211,9 @@ class User {
|
||||||
*/
|
*/
|
||||||
public function setEnabled($enabled) {
|
public function setEnabled($enabled) {
|
||||||
$this->enabled = $enabled;
|
$this->enabled = $enabled;
|
||||||
|
if ($this->config) {
|
||||||
$enabled = ($enabled) ? 'true' : 'false';
|
$enabled = ($enabled) ? 'true' : 'false';
|
||||||
\OC_Preferences::setValue($this->uid, 'core', 'enabled', $enabled);
|
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
namespace Test\User;
|
namespace Test\User;
|
||||||
|
|
||||||
|
use OC\AllConfig;
|
||||||
use OC\Hooks\PublicEmitter;
|
use OC\Hooks\PublicEmitter;
|
||||||
|
|
||||||
class User extends \PHPUnit_Framework_TestCase {
|
class User extends \PHPUnit_Framework_TestCase {
|
||||||
|
@ -205,7 +206,9 @@ class User extends \PHPUnit_Framework_TestCase {
|
||||||
->method('implementsActions')
|
->method('implementsActions')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
|
|
||||||
$user = new \OC\User\User('foo', $backend);
|
$allConfig = new AllConfig();
|
||||||
|
|
||||||
|
$user = new \OC\User\User('foo', $backend, null, $allConfig);
|
||||||
$this->assertEquals(\OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data") . '/foo', $user->getHome());
|
$this->assertEquals(\OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data") . '/foo', $user->getHome());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue