From d16574f0702d7bafa35b27ed8961580ad0a671ae Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 24 Jan 2013 13:07:59 +0100 Subject: new branch which introduces display names first commit with some infrastructure code --- lib/public/user.php | 10 +++++++++- lib/user.php | 41 ++++++++++++++++++++++++++++++++++++++++- lib/user/backend.php | 11 +++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/public/user.php b/lib/public/user.php index 204d8e4c0f1..2d22bdd96c8 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -51,7 +51,15 @@ class User { public static function getUsers($search = '', $limit = null, $offset = null) { return \OC_USER::getUsers(); } - + + /** + * @brief get the user display name of the user currently logged in. + * @return string display name + */ + public static function getDisplayName() { + return \OC_USER::getDisplayName(); + } + /** * @brief Check if the user is logged in * @returns true/false diff --git a/lib/user.php b/lib/user.php index fd0ed6ecd3a..d6d47293cbb 100644 --- a/lib/user.php +++ b/lib/user.php @@ -251,6 +251,7 @@ class OC_User { if($uid && $enabled) { session_regenerate_id(true); self::setUserId($uid); + self::setDisplayName($uid); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password )); return true; } @@ -264,6 +265,31 @@ class OC_User { public static function setUserId($uid) { $_SESSION['user_id'] = $uid; } + + /** + * @brief Sets user display name for session + */ + private static function setDisplayName($uid) { + $_SESSION['display_name'] = self::determineDisplayName($uid); + } + + /** + * @brief get display name + * @param $uid The username + * @returns string display name or uid if no display name is defined + * + */ + private static function determineDisplayName( $uid ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { + $result=$backend->getDisplayName( $uid ); + if($result) { + return $result; + } + } + } + return $uid; + } /** * @brief Logs the current user out and kills all the session data @@ -319,7 +345,20 @@ class OC_User { return false; } } - + + /** + * @brief get the display name of the user currently logged in. + * @return string uid or false + */ + public static function getDisplayName() { + if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { + return $_SESSION['display_name']; + } + else{ + return false; + } + } + /** * @brief Autogenerate a password * @returns string diff --git a/lib/user/backend.php b/lib/user/backend.php index 2a95db93690..47c92f5fe7b 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -35,6 +35,7 @@ define('OC_USER_BACKEND_CREATE_USER', 0x000001); define('OC_USER_BACKEND_SET_PASSWORD', 0x000010); define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100); define('OC_USER_BACKEND_GET_HOME', 0x001000); +define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000); /** @@ -50,6 +51,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_SET_PASSWORD => 'setPassword', OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword', OC_USER_BACKEND_GET_HOME => 'getHome', + OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', ); /** @@ -120,4 +122,13 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getHome($uid) { return false; } + + /** + * @brief get display name of the user + * @param $uid user ID of the user + * @return display name + */ + public function getDisplayName($uid) { + return $uid; + } } -- cgit v1.2.3 From 2fee1208eff1911ffcdbba24ea1e8543ed6ec26b Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 24 Jan 2013 15:49:23 +0100 Subject: add display name to title instead if login-ID --- core/templates/layout.user.php | 2 +- lib/user.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index a16d2c9e55d..fb63200123e 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -1,7 +1,7 @@ - <?php echo isset($_['application']) && !empty($_['application'])?$_['application'].' | ':'' ?>ownCloud <?php echo OC_User::getUser()?' ('.OC_User::getUser().') ':'' ?> + <?php echo isset($_['application']) && !empty($_['application'])?$_['application'].' | ':'' ?>ownCloud <?php echo OC_User::getDisplayName()?' ('.OC_User::getDisplayName().') ':'' ?> diff --git a/lib/user.php b/lib/user.php index d6d47293cbb..f9c8f48568e 100644 --- a/lib/user.php +++ b/lib/user.php @@ -351,7 +351,7 @@ class OC_User { * @return string uid or false */ public static function getDisplayName() { - if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { + if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { return $_SESSION['display_name']; } else{ -- cgit v1.2.3 From 9bb8e0583995fff244432bc34820127ef8ff6ac6 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 25 Jan 2013 11:05:00 +0100 Subject: get all display names --- lib/public/user.php | 10 ++++++++++ lib/user.php | 18 ++++++++++++++++++ lib/user/backend.php | 15 +++++++++++++++ settings/users.php | 15 ++++++++++----- 4 files changed, 53 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/public/user.php b/lib/public/user.php index 2d22bdd96c8..3a2f4d02f5c 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -60,6 +60,16 @@ class User { return \OC_USER::getDisplayName(); } + /** + * @brief Get a list of all display names + * @returns array with all display names and the correspondig uids + * + * Get a list of all display names. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + return \OC_USER::getDisplayNames($search, $limit, $offset); + } + /** * @brief Check if the user is logged in * @returns true/false diff --git a/lib/user.php b/lib/user.php index f9c8f48568e..f84b4c01df7 100644 --- a/lib/user.php +++ b/lib/user.php @@ -457,6 +457,24 @@ class OC_User { asort($users); return $users; } + + /** + * @brief Get a list of all users display name + * @returns associative array with all display names and corresponding uids + * + * Get a list of all users. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + $displayNames = array(); + foreach (self::$_usedBackends as $backend) { + $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset); + if (is_array($backendDisplayNames)) { + $displayNames = array_merge($displayNames, $backendDisplayNames); + } + } + ksort($displayNames); + return $displayNames; + } /** * @brief check if a user exists diff --git a/lib/user/backend.php b/lib/user/backend.php index 47c92f5fe7b..5823e390406 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -131,4 +131,19 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getDisplayName($uid) { return $uid; } + + /** + * @brief Get a list of all display names + * @returns array with all displayNames and the correspondig uids + * + * Get a list of all display names. + */ + public function getDisplayNames($search = '', $limit = null, $offset = null) { + $displayNames = array(); + $users = $this->getUsers($search, $limit, $offset); + foreach ( $users as $user) { + $displayNames[$user] = $user; + } + return $displayNames; + } } diff --git a/settings/users.php b/settings/users.php index 668d974693a..3706dc918c0 100644 --- a/settings/users.php +++ b/settings/users.php @@ -22,7 +22,7 @@ $isadmin = OC_User::isAdminUser(OC_User::getUser()); if($isadmin) { $accessiblegroups = OC_Group::getGroups(); - $accessibleusers = OC_User::getUsers('', 30); + $accessibleusers = OC_User::getDisplayNames('', 30); $subadmins = OC_SubAdmin::getAllSubAdmins(); }else{ $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); @@ -42,16 +42,21 @@ $defaultQuota=OC_Appconfig::getValue('files', 'default_quota', 'none'); $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false && array_search($defaultQuota, array('none', 'default'))===false; // load users and quota -foreach($accessibleusers as $i) { +foreach($accessibleusers as $displayName => $uid) { $quota=OC_Preferences::getValue($i, 'files', 'quota', 'default'); $isQuotaUserDefined=array_search($quota, $quotaPreset)===false && array_search($quota, array('none', 'default'))===false; + $name = $displayName; + if ( $displayName != $uid ) { + $name = $name . ' ('.$uid.')'; + } + $users[] = array( - "name" => $i, - "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($i)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/), + "name" => $name, + "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($uid)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/), 'quota'=>$quota, 'isQuotaUserDefined'=>$isQuotaUserDefined, - 'subadmin'=>implode(', ', OC_SubAdmin::getSubAdminsGroups($i))); + 'subadmin'=>implode(', ', OC_SubAdmin::getSubAdminsGroups($iuid))); } foreach( $accessiblegroups as $i ) { -- cgit v1.2.3 From 4271430e609be252d9b4a69fd7b3590571c14f7c Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 25 Jan 2013 11:48:03 +0100 Subject: get all display names from users in a given group --- lib/group.php | 29 +++++++++++++++++++++++++++++ lib/group/backend.php | 18 ++++++++++++++++++ lib/public/user.php | 4 ++-- lib/user.php | 4 ++-- lib/user/backend.php | 4 ++-- settings/users.php | 2 +- 6 files changed, 54 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/group.php b/lib/group.php index ed9482418bd..8ebb698692b 100644 --- a/lib/group.php +++ b/lib/group.php @@ -286,4 +286,33 @@ class OC_Group { } return $users; } + + /** + * @brief get a list of all display names in a group + * @returns array with display names (key) and user ids(value) + */ + public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames=array(); + foreach(self::$_usedBackends as $backend) { + $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames); + } + return $displayNames; + } + + /** + * @brief get a list of all display names in several groups + * @param array $gids + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (Key) user ids (value) + */ + public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) { + $displayNames = array(); + foreach ($gids as $gid) { + // TODO Need to apply limits to groups as total + $displayNames = array_merge(array_diff(self::displayNamesInGroup($gid, $search, $limit, $offset), $displayNames), $displayNames); + } + return $displayNames; + } } diff --git a/lib/group/backend.php b/lib/group/backend.php index 9ff432d0663..ceb2d9242dd 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -133,5 +133,23 @@ abstract class OC_Group_Backend implements OC_Group_Interface { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); } + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (key) and user ids (value) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames = ''; + $users = $this->usersInGroup($gid, $search, $limit, $offset); + foreach ( $users as $user ) { + $DisplayNames[$user] = $user; + } + + return $DisplayNames; + } } diff --git a/lib/public/user.php b/lib/public/user.php index 3a2f4d02f5c..a93e3a674a8 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -62,9 +62,9 @@ class User { /** * @brief Get a list of all display names - * @returns array with all display names and the correspondig uids + * @returns array with all display names (key) and the correspondig uids (value) * - * Get a list of all display names. + * Get a list of all display names and user ids. */ public static function getDisplayNames($search = '', $limit = null, $offset = null) { return \OC_USER::getDisplayNames($search, $limit, $offset); diff --git a/lib/user.php b/lib/user.php index f84b4c01df7..4cdf07dc3ff 100644 --- a/lib/user.php +++ b/lib/user.php @@ -460,9 +460,9 @@ class OC_User { /** * @brief Get a list of all users display name - * @returns associative array with all display names and corresponding uids + * @returns associative array with all display names (key) and corresponding uids (value) * - * Get a list of all users. + * Get a list of all display names and user ids. */ public static function getDisplayNames($search = '', $limit = null, $offset = null) { $displayNames = array(); diff --git a/lib/user/backend.php b/lib/user/backend.php index 5823e390406..ec43d7f1872 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -134,9 +134,9 @@ abstract class OC_User_Backend implements OC_User_Interface { /** * @brief Get a list of all display names - * @returns array with all displayNames and the correspondig uids + * @returns array with all displayNames (key) and the correspondig uids (value) * - * Get a list of all display names. + * Get a list of all display names and user ids. */ public function getDisplayNames($search = '', $limit = null, $offset = null) { $displayNames = array(); diff --git a/settings/users.php b/settings/users.php index 3706dc918c0..bf27e804411 100644 --- a/settings/users.php +++ b/settings/users.php @@ -26,7 +26,7 @@ if($isadmin) { $subadmins = OC_SubAdmin::getAllSubAdmins(); }else{ $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); - $accessibleusers = OC_Group::usersInGroups($accessiblegroups, '', 30); + $accessibleusers = OC_Group::displayNamesInGroups($accessiblegroups, '', 30); $subadmins = false; } -- cgit v1.2.3 From b4291f1e8e2326f5f1cbd97fa130d547f949b62d Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 25 Jan 2013 13:00:17 +0100 Subject: allow to get the display name from an abitrary user --- lib/public/user.php | 4 ++-- lib/user.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/public/user.php b/lib/public/user.php index a93e3a674a8..411098ed5aa 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -56,8 +56,8 @@ class User { * @brief get the user display name of the user currently logged in. * @return string display name */ - public static function getDisplayName() { - return \OC_USER::getDisplayName(); + public static function getDisplayName($user=null) { + return \OC_USER::getDisplayName($user); } /** diff --git a/lib/user.php b/lib/user.php index 4cdf07dc3ff..65f899aa27c 100644 --- a/lib/user.php +++ b/lib/user.php @@ -350,8 +350,10 @@ class OC_User { * @brief get the display name of the user currently logged in. * @return string uid or false */ - public static function getDisplayName() { - if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { + public static function getDisplayName($user=null) { + if ( $user ) { + return self::determineDisplayName($user); + } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { return $_SESSION['display_name']; } else{ -- cgit v1.2.3 From a606e8d944f7c2754f00e9c50804b8c2beedc986 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 25 Jan 2013 17:40:23 +0100 Subject: use display name to show share_width and owner information --- core/js/share.js | 18 +++++++++--------- lib/public/share.php | 9 +++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/core/js/share.js b/core/js/share.js index bb3ec010ff5..1486d7f1773 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -148,9 +148,9 @@ OC.Share={ var html = ' - + diff --git a/settings/users.php b/settings/users.php index d779cc782ce..df7cf8ac1d5 100644 --- a/settings/users.php +++ b/settings/users.php @@ -42,7 +42,7 @@ $defaultQuota=OC_Appconfig::getValue('files', 'default_quota', 'none'); $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false && array_search($defaultQuota, array('none', 'default'))===false; // load users and quota -foreach($accessibleusers as $displayName => $uid) { +foreach($accessibleusers as $uid => $displayName) { $quota=OC_Preferences::getValue($i, 'files', 'quota', 'default'); $isQuotaUserDefined=array_search($quota, $quotaPreset)===false && array_search($quota, array('none', 'default'))===false; @@ -52,8 +52,8 @@ foreach($accessibleusers as $displayName => $uid) { } $users[] = array( - "name" => $name, - "uid" => $uid, + "name" => $uid, + "displayName" => $displayName, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($uid)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/), 'quota'=>$quota, 'isQuotaUserDefined'=>$isQuotaUserDefined, -- cgit v1.2.3 From e0f2ed2757b698448d49fa3e73340ce9ced25e7a Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 28 Jan 2013 14:09:11 +0100 Subject: interface and API to change display names --- lib/user.php | 19 +++++++++++++++++-- lib/user/backend.php | 2 ++ settings/js/users.js | 37 +++++++++++++++++++++++++++++++++++++ settings/routes.php | 2 ++ settings/templates/users.php | 2 +- 5 files changed, 59 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/user.php b/lib/user.php index 65f899aa27c..b91abd71fe6 100644 --- a/lib/user.php +++ b/lib/user.php @@ -269,10 +269,25 @@ class OC_User { /** * @brief Sets user display name for session */ - private static function setDisplayName($uid) { - $_SESSION['display_name'] = self::determineDisplayName($uid); + public static function setDisplayName($uid, $displayName = null) { + $result = false; + if ($displayName ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) { + if($backend->userExists($uid)) { + $success |= $backend->setDisplayName($uid, $displayName); + } + } + } + } else { + $displayName = self::determineDisplayName($uid); + $result = true; + } + $_SESSION['display_name'] = $displayName; + return result; } + /** * @brief get display name * @param $uid The username diff --git a/lib/user/backend.php b/lib/user/backend.php index fe37a64cc03..efea622e312 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -36,6 +36,7 @@ define('OC_USER_BACKEND_SET_PASSWORD', 0x000010); define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100); define('OC_USER_BACKEND_GET_HOME', 0x001000); define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000); +define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x010000); /** @@ -52,6 +53,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword', OC_USER_BACKEND_GET_HOME => 'getHome', OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', + OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName', ); /** diff --git a/settings/js/users.js b/settings/js/users.js index fa6f058d923..835f46f6ed3 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -300,6 +300,43 @@ $(document).ready(function () { $('td.password').live('click', function (event) { $(this).children('img').click(); }); + + $('td.displayName>img').live('click', function (event) { + event.stopPropagation(); + var img = $(this); + var uid = img.parent().parent().attr('data-uid'); + var input = $(''); + img.css('display', 'none'); + img.parent().children('span').replaceWith(input); + input.focus(); + input.keypress(function (event) { + console.log("event!"); + if (event.keyCode == 13) { + console.log("13"); + if ($(this).val().length > 0) { + console.log("post"); + $.post( + OC.filePath('settings', 'ajax', 'changedisplayname.php'), + {username:uid, displayName:$(this).val()}, + function (result) { + console.log("come back!"); + } + ); + input.blur(); + } else { + input.blur(); + } + } + }); + input.blur(function () { + $(this).replaceWith($(this).val()); + img.css('display', ''); + }); + }); + $('td.displayName').live('click', function (event) { + $(this).children('img').click(); + }); + $('select.quota, select.quota-user').live('change', function () { var select = $(this); diff --git a/settings/routes.php b/settings/routes.php index 9b5bf809230..c9156f9a115 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -39,6 +39,8 @@ $this->create('settings_ajax_removegroup', '/settings/ajax/removegroup.php') ->actionInclude('settings/ajax/removegroup.php'); $this->create('settings_ajax_changepassword', '/settings/ajax/changepassword.php') ->actionInclude('settings/ajax/changepassword.php'); +$this->create('settings_ajax_changedisplayname', '/settings/ajax/changedisplayname.php') +->actionInclude('settings/ajax/changedisplayname.php'); // personel $this->create('settings_ajax_lostpassword', '/settings/ajax/lostpassword.php') ->actionInclude('settings/ajax/lostpassword.php'); diff --git a/settings/templates/users.php b/settings/templates/users.php index 64dce38ba31..2ba57fb4a7c 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -93,7 +93,7 @@ var isadmin = ; "> - change display name -- cgit v1.2.3 From 70c3ab3c53fa31331c19d3f1d74fce29efc047d4 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 28 Jan 2013 14:23:15 +0100 Subject: update the display name for the database back-end --- lib/user/database.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/user/database.php b/lib/user/database.php index f33e338e2e4..49c76545327 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -110,6 +110,24 @@ class OC_User_Database extends OC_User_Backend { return false; } } + + /** + * @brief Set display name + * @param $uid The username + * @param $displayName The new display name + * @returns true/false + * + * Change the display name of a user + */ + public function setDisplayName( $uid, $displayName ) { + if( $this->userExists($uid) ) { + $query = OC_DB::prepare( 'UPDATE `*PREFIX*users` SET `displayname` = ? WHERE `uid` = ?' ); + $query->execute( array( $displayName, $uid )); + return true; + }else{ + return false; + } + } /** * @brief Check if the password is correct -- cgit v1.2.3 From e6cc0cd08a502fc426c868bd1981c80eb39a9062 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 28 Jan 2013 15:07:31 +0100 Subject: implement display names for the database back-end --- lib/user/database.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib') diff --git a/lib/user/database.php b/lib/user/database.php index 49c76545327..52f11a5e29d 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -129,6 +129,40 @@ class OC_User_Database extends OC_User_Backend { } } + /** + * @brief get display name of the user + * @param $uid user ID of the user + * @return display name + */ + public function getDisplayName($uid) { + if( $this->userExists($uid) ) { + $query = OC_DB::prepare( 'SELECT displayname FROM `*PREFIX*users` WHERE `uid` = ?' ); + $result = $query->execute( array( $uid ))->fetchAll(); + if (!empty($result[0]['displayname'])) { + return $result[0]['displayname']; + } else { + return $uid; + } + } + } + + /** + * @brief Get a list of all display names + * @returns array with all displayNames (value) and the correspondig uids (key) + * + * Get a list of all display names and user ids. + */ + public function getDisplayNames($search = '', $limit = null, $offset = null) { + $displayNames = array(); + $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); + $result = $query->execute(array($search.'%')); + $users = array(); + while ($row = $result->fetchRow()) { + $displayNames[$row['uid']] = $row['displayname']; + } + return $displayNames; + } + /** * @brief Check if the password is correct * @param $uid The username -- cgit v1.2.3 From c00b66fe5bb37403e4dec1ede9d509947b795df0 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 28 Jan 2013 15:47:57 +0100 Subject: implement DisplayNamesInGroup for database back-end --- lib/group.php | 2 +- lib/group/backend.php | 2 +- lib/group/database.php | 28 ++++++++++++++++++++++++++++ lib/user.php | 2 +- lib/user/database.php | 10 ++++++---- 5 files changed, 37 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/group.php b/lib/group.php index 8ebb698692b..5afef769361 100644 --- a/lib/group.php +++ b/lib/group.php @@ -289,7 +289,7 @@ class OC_Group { /** * @brief get a list of all display names in a group - * @returns array with display names (key) and user ids(value) + * @returns array with display names (value) and user ids(key) */ public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $displayNames=array(); diff --git a/lib/group/backend.php b/lib/group/backend.php index ceb2d9242dd..4f6570c3be3 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -140,7 +140,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface { * @param string $search * @param int $limit * @param int $offset - * @return array with display names (key) and user ids (value) + * @return array with display names (value) and user ids (key) */ public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $displayNames = ''; diff --git a/lib/group/database.php b/lib/group/database.php index 6eca98ba019..c5dd402b212 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -208,4 +208,32 @@ class OC_Group_Database extends OC_Group_Backend { } return $users; } + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames = ''; + /* + + SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo + FROM Persons + INNER JOIN Orders + ON Persons.P_Id=Orders.P_Id + ORDER BY Persons.LastName + */ + $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname` FROM `*PREFIX*users` INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid` WHERE `gid` = ? AND `*PREFIX*group_user.uid` LIKE ?', $limit, $offset); + $result = $stmt->execute(array($gid, $search.'%')); + $users = array(); + while ($row = $result->fetchRow()) { + $displayName = trim($row['displayname'], ' '); + $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; + } + return $displayNames; + } } diff --git a/lib/user.php b/lib/user.php index b91abd71fe6..399a3240c8c 100644 --- a/lib/user.php +++ b/lib/user.php @@ -477,7 +477,7 @@ class OC_User { /** * @brief Get a list of all users display name - * @returns associative array with all display names (key) and corresponding uids (value) + * @returns associative array with all display names (value) and corresponding uids (key) * * Get a list of all display names and user ids. */ diff --git a/lib/user/database.php b/lib/user/database.php index 52f11a5e29d..bed97f25fdb 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -138,8 +138,9 @@ class OC_User_Database extends OC_User_Backend { if( $this->userExists($uid) ) { $query = OC_DB::prepare( 'SELECT displayname FROM `*PREFIX*users` WHERE `uid` = ?' ); $result = $query->execute( array( $uid ))->fetchAll(); - if (!empty($result[0]['displayname'])) { - return $result[0]['displayname']; + $displayName = trim($result[0]['displayname'], ' '); + if ( !empty($displayName) ) { + return $displayName; } else { return $uid; } @@ -157,8 +158,9 @@ class OC_User_Database extends OC_User_Backend { $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); $result = $query->execute(array($search.'%')); $users = array(); - while ($row = $result->fetchRow()) { - $displayNames[$row['uid']] = $row['displayname']; + while ($row = $result->fetchRow()) { + $displayName = trim($row['displayname'], ' '); + $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; } return $displayNames; } -- cgit v1.2.3 From 590c4aa710077ae82a5af0ec4477a00eafe791dc Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 28 Jan 2013 15:58:40 +0100 Subject: search display name instead of uid; fix key/value order for array access --- core/ajax/share.php | 2 +- lib/user/database.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/core/ajax/share.php b/core/ajax/share.php index 231cdc5e242..6704a00c5a2 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -164,7 +164,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset); } $offset += $limit; - foreach ($users as $displayName => $uid) { + foreach ($users as $uid => $displayName) { if ((!isset($_GET['itemShares']) || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) || !in_array($uid, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) && $uid != OC_User::getUser()) { $shareWith[] = array('label' => $displayName, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $uid)); $count++; diff --git a/lib/user/database.php b/lib/user/database.php index bed97f25fdb..7deeb0c4697 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -155,7 +155,7 @@ class OC_User_Database extends OC_User_Backend { */ public function getDisplayNames($search = '', $limit = null, $offset = null) { $displayNames = array(); - $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); + $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`displayname`) LIKE LOWER(?)', $limit, $offset); $result = $query->execute(array($search.'%')); $users = array(); while ($row = $result->fetchRow()) { -- cgit v1.2.3 From 59bb9931dff564c4db238293c6a75b7a999d67bc Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 29 Jan 2013 20:09:41 +0100 Subject: Adjust user interface to additions around displayName Handling --- lib/user/interface.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/user/interface.php b/lib/user/interface.php index 3d9f4691f24..b4667633b50 100644 --- a/lib/user/interface.php +++ b/lib/user/interface.php @@ -57,4 +57,19 @@ interface OC_User_Interface { */ public function userExists($uid); + /** + * @brief get display name of the user + * @param $uid user ID of the user + * @return display name + */ + public function getDisplayName($uid); + + /** + * @brief Get a list of all display names + * @returns array with all displayNames (value) and the correspondig uids (key) + * + * Get a list of all display names and user ids. + */ + public function getDisplayNames($search = '', $limit = null, $offset = null); + } \ No newline at end of file -- cgit v1.2.3 From 79c309da83ce399eef1448e941293d34917cb25b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 29 Jan 2013 20:42:21 +0100 Subject: Typo --- lib/user.php | 116 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'lib') diff --git a/lib/user.php b/lib/user.php index 399a3240c8c..3a35069fd62 100644 --- a/lib/user.php +++ b/lib/user.php @@ -265,45 +265,45 @@ class OC_User { public static function setUserId($uid) { $_SESSION['user_id'] = $uid; } - - /** - * @brief Sets user display name for session - */ + + /** + * @brief Sets user display name for session + */ public static function setDisplayName($uid, $displayName = null) { $result = false; - if ($displayName ) { - foreach(self::$_usedBackends as $backend) { - if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) { - if($backend->userExists($uid)) { - $success |= $backend->setDisplayName($uid, $displayName); - } - } + if ($displayName ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) { + if($backend->userExists($uid)) { + $success |= $backend->setDisplayName($uid, $displayName); + } + } } } else { $displayName = self::determineDisplayName($uid); $result = true; } $_SESSION['display_name'] = $displayName; - return result; + return $result; } - - - /** - * @brief get display name - * @param $uid The username - * @returns string display name or uid if no display name is defined - * - */ - private static function determineDisplayName( $uid ) { - foreach(self::$_usedBackends as $backend) { - if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { - $result=$backend->getDisplayName( $uid ); - if($result) { - return $result; - } - } + + + /** + * @brief get display name + * @param $uid The username + * @returns string display name or uid if no display name is defined + * + */ + private static function determineDisplayName( $uid ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { + $result=$backend->getDisplayName( $uid ); + if($result) { + return $result; + } + } } - return $uid; + return $uid; } /** @@ -360,22 +360,22 @@ class OC_User { return false; } } - - /** - * @brief get the display name of the user currently logged in. - * @return string uid or false - */ + + /** + * @brief get the display name of the user currently logged in. + * @return string uid or false + */ public static function getDisplayName($user=null) { if ( $user ) { return self::determineDisplayName($user); - } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { - return $_SESSION['display_name']; - } - else{ - return false; - } + } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { + return $_SESSION['display_name']; + } + else{ + return false; + } } - + /** * @brief Autogenerate a password * @returns string @@ -474,23 +474,23 @@ class OC_User { asort($users); return $users; } - - /** - * @brief Get a list of all users display name - * @returns associative array with all display names (value) and corresponding uids (key) - * - * Get a list of all display names and user ids. - */ - public static function getDisplayNames($search = '', $limit = null, $offset = null) { - $displayNames = array(); - foreach (self::$_usedBackends as $backend) { - $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset); - if (is_array($backendDisplayNames)) { - $displayNames = array_merge($displayNames, $backendDisplayNames); - } - } - ksort($displayNames); - return $displayNames; + + /** + * @brief Get a list of all users display name + * @returns associative array with all display names (value) and corresponding uids (key) + * + * Get a list of all display names and user ids. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + $displayNames = array(); + foreach (self::$_usedBackends as $backend) { + $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset); + if (is_array($backendDisplayNames)) { + $displayNames = array_merge($displayNames, $backendDisplayNames); + } + } + ksort($displayNames); + return $displayNames; } /** -- cgit v1.2.3 From ebc3d1b2d7dadb543e132990434face1e3ff0fc9 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 29 Jan 2013 21:01:59 +0100 Subject: remove dubug value --- lib/user/backend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/user/backend.php b/lib/user/backend.php index efea622e312..56fa3195978 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -144,7 +144,7 @@ abstract class OC_User_Backend implements OC_User_Interface { $displayNames = array(); $users = $this->getUsers($search, $limit, $offset); foreach ( $users as $user) { - $displayNames[$user] = "foo"; + $displayNames[$user] = $user; } return $displayNames; } -- cgit v1.2.3 From 007bddceba7c9b5ca00710d6b1b23a49976e7a22 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 29 Jan 2013 21:04:28 +0100 Subject: version dump to trigger db update --- lib/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 374baa43dbe..0543df979d3 100755 --- a/lib/util.php +++ b/lib/util.php @@ -95,7 +95,7 @@ class OC_Util { */ public static function getVersion() { // hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4.90.0. This is not visible to the user - return array(4, 91, 02); + return array(4, 91, 03); } /** -- cgit v1.2.3 From 665979819766bd23cddc18a3e1666f303ac25932 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 29 Jan 2013 22:33:46 +0100 Subject: only change display name if the display name from the current user was changed; add correct display name to new user --- lib/user.php | 4 +++- settings/js/users.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/user.php b/lib/user.php index 3a35069fd62..6452f80602c 100644 --- a/lib/user.php +++ b/lib/user.php @@ -283,7 +283,9 @@ class OC_User { $displayName = self::determineDisplayName($uid); $result = true; } - $_SESSION['display_name'] = $displayName; + if (OC_User::getUser() === $uid) { + $_SESSION['display_name'] = $displayName; + } return $result; } diff --git a/settings/js/users.js b/settings/js/users.js index a50fac03727..524a57e0776 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -70,7 +70,9 @@ var UserList = { add:function (username, groups, subadmin, quota, sort) { var tr = $('tbody tr').first().clone(); tr.attr('data-uid', username); + tr.attr('data-displayName', username); tr.find('td.name').text(username); + tr.find('td.displayName').text(username); var groupsSelect = $('').attr('data-username', username).attr('data-user-groups', groups); tr.find('td.groups').empty(); if (tr.find('td.subadmins').length > 0) { -- cgit v1.2.3