From d8fee28b3becfff155c73395c96d76a0315788a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= <schiessle@owncloud.com>
Date: Sun, 10 Feb 2013 14:43:31 +0100
Subject: [PATCH] add switch to enable/disable the possibility to change the
 display name by the user

---
 config/config.sample.php            |  3 +++
 lib/user.php                        | 10 ++++++----
 settings/ajax/changedisplayname.php |  4 ++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/config/config.sample.php b/config/config.sample.php
index cfef3d5117d..2f394c41a3b 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -114,6 +114,9 @@ $CONFIG = array(
 /* How long should ownCloud keep deleted files in the trash bin, default value:  180 days */
 'trashbin_retention_obligation' => 180,
 
+/* allow user to change his display name, if it is supported by the back-end */
+'allow_user_to_change_display_name' => true,
+
 /* Check 3rdparty apps for malicious code fragments */
 "appcodechecker" => "",
 
diff --git a/lib/user.php b/lib/user.php
index 9dc8cca97a6..37b46118889 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -445,10 +445,12 @@ class OC_User {
 	 * Check whether a specified user can change his display name
 	 */
 	public static function canUserChangeDisplayName($uid) {
-		foreach(self::$_usedBackends as $backend) {
-			if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
-				if($backend->userExists($uid)) {
-					return true;
+		if (OC_Config::getValue('allow_user_to_change_display_name', true)) {
+			foreach(self::$_usedBackends as $backend) {
+				if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
+					if($backend->userExists($uid)) {
+						return true;
+					}
 				}
 			}
 		}
diff --git a/settings/ajax/changedisplayname.php b/settings/ajax/changedisplayname.php
index 8f2ff865bd5..69462330765 100644
--- a/settings/ajax/changedisplayname.php
+++ b/settings/ajax/changedisplayname.php
@@ -15,6 +15,10 @@ if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
 	$userstatus = 'subadmin';
 }
 
+if ($username == OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
+	$userstatus = 'changeOwnDisplayName';
+}
+
 if(is_null($userstatus)) {
 	OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));
 	exit();
-- 
GitLab