[Pkg-owncloud-commits] [owncloud] 35/104: fix the config option to remove the ability for users to set their displayname

David Prévot taffit at moszumanska.debian.org
Sat Jan 18 13:33:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 62887c67ab7cee8403925f80005bf72c017a9db3
Author: Robin Appelman <icewind at owncloud.com>
Date:   Mon Dec 16 14:22:25 2013 +0100

    fix the config option to remove the ability for users to set their displayname
---
 lib/private/server.php       | 12 ++++++++++--
 lib/private/user/manager.php | 17 +++++++++++++----
 lib/private/user/user.php    | 17 ++++++++++++++---
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/lib/private/server.php b/lib/private/server.php
index 77c3732..bee70de 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -69,10 +69,18 @@ class Server extends SimpleContainer implements IServerContainer {
 			return new Root($manager, $view, $user);
 		});
 		$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) {
-			/** @var $c SimpleContainer */
+			/**
+			 * @var SimpleContainer $c
+			 * @var \OC\User\Manager $manager
+			 */
 			$manager = $c->query('UserManager');
 			$userSession = new \OC\User\Session($manager, \OC::$session);
 			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 703c8cd..cf83a75 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -35,7 +35,16 @@ class Manager extends PublicEmitter {
 	 */
 	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;
 		$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
 			$i = array_search($user, $cachedUsers);
@@ -103,7 +112,7 @@ class Manager extends PublicEmitter {
 		if (isset($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];
 	}
 
@@ -141,7 +150,7 @@ class Manager extends PublicEmitter {
 	 */
 	public function checkPassword($loginname, $password) {
 		foreach ($this->backends as $backend) {
-			if($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
+			if ($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
 				$uid = $backend->checkPassword($loginname, $password);
 				if ($uid !== false) {
 					return $this->getUserObject($uid, $backend);
@@ -234,7 +243,7 @@ class Manager extends PublicEmitter {
 		// Allowed are: "a-z", "A-Z", "0-9" and "_. at -"
 		if (preg_match('/[^a-zA-Z0-9 _\.@\-]/', $uid)) {
 			throw new \Exception('Only the following characters are allowed in a username:'
-			. ' "a-z", "A-Z", "0-9", and "_. at -"');
+				. ' "a-z", "A-Z", "0-9", and "_. at -"');
 		}
 		// No empty username
 		if (trim($uid) == '') {
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index b4f33fa..b0b4657 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -43,11 +43,17 @@ class User {
 	private $home;
 
 	/**
+	 * @var \OC\AllConfig $config
+	 */
+	private $config;
+
+	/**
 	 * @param string $uid
 	 * @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;
 		if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
 			$this->displayName = $backend->getDisplayName($uid);
@@ -58,6 +64,7 @@ class User {
 		$this->emitter = $emitter;
 		$enabled = \OC_Preferences::getValue($uid, 'core', 'enabled', 'true'); //TODO: DI for OC_Preferences
 		$this->enabled = ($enabled === 'true');
+		$this->config = $config;
 	}
 
 	/**
@@ -175,7 +182,11 @@ class User {
 	 * @return bool
 	 */
 	public function canChangeDisplayName() {
-		return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
+		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);
+		}
 	}
 
 	/**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list