From d16574f0702d7bafa35b27ed8961580ad0a671ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 24 Jan 2013 13:07:59 +0100 Subject: [PATCH 01/32] 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(-) diff --git a/lib/public/user.php b/lib/public/user.php index 204d8e4c0f..2d22bdd96c 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 fd0ed6ecd3..d6d47293cb 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 2a95db9369..47c92f5fe7 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; + } } From 2fee1208eff1911ffcdbba24ea1e8543ed6ec26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 24 Jan 2013 15:49:23 +0100 Subject: [PATCH 02/32] 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(-) diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index a16d2c9e55..fb63200123 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 d6d47293cb..f9c8f48568 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{ From 9bb8e0583995fff244432bc34820127ef8ff6ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 11:05:00 +0100 Subject: [PATCH 03/32] 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(-) diff --git a/lib/public/user.php b/lib/public/user.php index 2d22bdd96c..3a2f4d02f5 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 f9c8f48568..f84b4c01df 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 47c92f5fe7..5823e39040 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 668d974693..3706dc918c 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 ) { From 4271430e609be252d9b4a69fd7b3590571c14f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 11:48:03 +0100 Subject: [PATCH 04/32] 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(-) diff --git a/lib/group.php b/lib/group.php index ed9482418b..8ebb698692 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 9ff432d066..ceb2d9242d 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 3a2f4d02f5..a93e3a674a 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 f84b4c01df..4cdf07dc3f 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 5823e39040..ec43d7f187 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 3706dc918c..bf27e80441 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; } From 64e853394c120888a7555901a52c5868f33aef3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 12:46:32 +0100 Subject: [PATCH 05/32] compare the correct uids --- settings/templates/users.php | 2 +- settings/users.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/settings/templates/users.php b/settings/templates/users.php index 6cbbca2404..44e9b5bafe 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -157,7 +157,7 @@ var isadmin = ; - + diff --git a/settings/users.php b/settings/users.php index bf27e80441..c8f5ef5ff3 100644 --- a/settings/users.php +++ b/settings/users.php @@ -53,6 +53,7 @@ foreach($accessibleusers as $displayName => $uid) { $users[] = array( "name" => $name, + "uid" => $uid, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($uid)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/), 'quota'=>$quota, 'isQuotaUserDefined'=>$isQuotaUserDefined, From b4291f1e8e2326f5f1cbd97fa130d547f949b62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 13:00:17 +0100 Subject: [PATCH 06/32] 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(-) diff --git a/lib/public/user.php b/lib/public/user.php index a93e3a674a..411098ed5a 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 4cdf07dc3f..65f899aa27 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{ From 839f4bd94916d0673341528ffa8a2a7b3242bf46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 13:01:53 +0100 Subject: [PATCH 07/32] show display name instead of uid in the public shared files view --- apps/files_sharing/public.php | 1 + apps/files_sharing/templates/public.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index efd977a1b6..93f3b4da2b 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -207,6 +207,7 @@ if ($linkItem) { OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_sharing', 'public', 'base'); $tmpl->assign('uidOwner', $shareOwner); + $tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner)); $tmpl->assign('dir', $dir); $tmpl->assign('filename', $file); $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path)); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 647e1e08a3..13af528ce8 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -14,9 +14,9 @@ ownCloud
- t('%s shared the folder %s with you', array($_['uidOwner'], $_['filename'])) ?> + t('%s shared the folder %s with you', array($_['displayName'], $_['filename'])) ?> - t('%s shared the file %s with you', array($_['uidOwner'], $_['filename'])) ?> + t('%s shared the file %s with you', array($_['displayName'], $_['filename'])) ?> Download" />t('Download')?> From e9a57e28fc9b87c0fd84de39a0e4cb305165a9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 13:57:08 +0100 Subject: [PATCH 08/32] show display name instead of uid --- core/ajax/share.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 077baa8ba5..231cdc5e24 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -72,6 +72,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo case 'email': // read post variables $user = OCP\USER::getUser(); + $displayName = OCP\User::getDisplayName(); $type = $_POST['itemType']; $link = $_POST['link']; $file = $_POST['file']; @@ -81,13 +82,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $l = OC_L10N::get('core'); // setup the email - $subject = (string)$l->t('User %s shared a file with you', $user); + $subject = (string)$l->t('User %s shared a file with you', $displayName); if ($type === 'dir') - $subject = (string)$l->t('User %s shared a folder with you', $user); + $subject = (string)$l->t('User %s shared a folder with you', $displayName); - $text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($user, $file, $link)); + $text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($displayName, $file, $link)); if ($type === 'dir') - $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($user, $file, $link)); + $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($displayName, $file, $link)); $default_from = OCP\Util::getDefaultEmailAddress('sharing-noreply'); @@ -158,14 +159,14 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo while ($count < 4 && count($users) == $limit) { $limit = 4 - $count; if ($sharePolicy == 'groups_only') { - $users = OC_Group::usersInGroups($groups, $_GET['search'], $limit, $offset); + $users = OC_Group::DisplayNamesInGroups($groups, $_GET['search'], $limit, $offset); } else { - $users = OC_User::getUsers($_GET['search'], $limit, $offset); + $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset); } $offset += $limit; - foreach ($users as $user) { - if ((!isset($_GET['itemShares']) || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) || !in_array($user, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) && $user != OC_User::getUser()) { - $shareWith[] = array('label' => $user, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $user)); + foreach ($users as $displayName => $uid) { + 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++; } } From a606e8d944f7c2754f00e9c50804b8c2beedc986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 25 Jan 2013 17:40:23 +0100 Subject: [PATCH 09/32] 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(-) diff --git a/core/js/share.js b/core/js/share.js index bb3ec010ff..1486d7f177 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 d779cc782c..df7cf8ac1d 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, From e0f2ed2757b698448d49fa3e73340ce9ced25e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 14:09:11 +0100 Subject: [PATCH 13/32] 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(-) diff --git a/lib/user.php b/lib/user.php index 65f899aa27..b91abd71fe 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 fe37a64cc0..efea622e31 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 fa6f058d92..835f46f6ed 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 9b5bf80923..c9156f9a11 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 64dce38ba3..2ba57fb4a7 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -93,7 +93,7 @@ var isadmin = ; "> - change display name From 70c3ab3c53fa31331c19d3f1d74fce29efc047d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 14:23:15 +0100 Subject: [PATCH 14/32] update the display name for the database back-end --- lib/user/database.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/user/database.php b/lib/user/database.php index f33e338e2e..49c7654532 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 From 3e0d117d6078703b46e73c6f5642f1945857da17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 14:38:38 +0100 Subject: [PATCH 15/32] add display name to the database table oc_users --- db_structure.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db_structure.xml b/db_structure.xml index db43ef2114..e878eac769 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -679,6 +679,14 @@ 64 + + displayname + text + + true + 64 + + password text From e6cc0cd08a502fc426c868bd1981c80eb39a9062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 15:07:31 +0100 Subject: [PATCH 16/32] implement display names for the database back-end --- lib/user/database.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/user/database.php b/lib/user/database.php index 49c7654532..52f11a5e29 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 From c00b66fe5bb37403e4dec1ede9d509947b795df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 15:47:57 +0100 Subject: [PATCH 17/32] 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(-) diff --git a/lib/group.php b/lib/group.php index 8ebb698692..5afef76936 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 ceb2d9242d..4f6570c3be 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 6eca98ba01..c5dd402b21 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 b91abd71fe..399a3240c8 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 52f11a5e29..bed97f25fd 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; } From 590c4aa710077ae82a5af0ec4477a00eafe791dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 15:58:40 +0100 Subject: [PATCH 18/32] 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(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 231cdc5e24..6704a00c5a 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 bed97f25fd..7deeb0c469 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()) { From f3a99f4869ea238822793f89bef14b564c333aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 28 Jan 2013 17:01:37 +0100 Subject: [PATCH 19/32] show display name in input field --- settings/js/users.js | 3 ++- settings/templates/users.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/settings/js/users.js b/settings/js/users.js index 835f46f6ed..111e3040a3 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -305,7 +305,8 @@ $(document).ready(function () { event.stopPropagation(); var img = $(this); var uid = img.parent().parent().attr('data-uid'); - var input = $(''); + var displayName = img.parent().parent().attr('data-displayName'); + var input = $(''); img.css('display', 'none'); img.parent().children('span').replaceWith(input); input.focus(); diff --git a/settings/templates/users.php b/settings/templates/users.php index 2ba57fb4a7..6407b59883 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -91,7 +91,8 @@ var isadmin = ; - "> + " + data-displayName=""> Date: Mon, 28 Jan 2013 17:05:20 +0100 Subject: [PATCH 20/32] rename Name to Login Name --- settings/templates/users.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings/templates/users.php b/settings/templates/users.php index 6407b59883..fa06c9c72e 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -18,7 +18,7 @@ var isadmin = ;
- ').attr('data-username', username).attr('data-user-groups', groups); tr.find('td.groups').empty(); if (tr.find('td.subadmins').length > 0) {