summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2013-01-29 14:05:54 -0800
committerLukas Reschke <lukas@statuscode.ch>2013-01-29 14:05:54 -0800
commit250c565d2be9ebd7033c43c3362a44c58964c79b (patch)
treef8354bf6b5d6a8a37b46d4685f09342d41dd2695
parent472491955ae7e8172b113bd564ec242cc8bc4577 (diff)
parent665979819766bd23cddc18a3e1666f303ac25932 (diff)
downloadnextcloud-server-250c565d2be9ebd7033c43c3362a44c58964c79b.tar.gz
nextcloud-server-250c565d2be9ebd7033c43c3362a44c58964c79b.zip
Merge pull request #1360 from owncloud/display_name
introduction of display names
-rw-r--r--apps/files_sharing/public.php1
-rw-r--r--apps/files_sharing/templates/public.php4
-rw-r--r--apps/user_ldap/user_ldap.php44
-rw-r--r--core/ajax/share.php19
-rw-r--r--core/js/share.js18
-rw-r--r--core/templates/layout.user.php2
-rw-r--r--db_structure.xml8
-rw-r--r--lib/group.php29
-rw-r--r--lib/group/backend.php18
-rw-r--r--lib/group/database.php28
-rw-r--r--lib/public/share.php9
-rw-r--r--lib/public/user.php20
-rw-r--r--lib/user.php76
-rw-r--r--lib/user/backend.php28
-rw-r--r--lib/user/database.php54
-rw-r--r--lib/user/interface.php15
-rwxr-xr-xlib/util.php2
-rw-r--r--settings/ajax/changedisplayname.php28
-rw-r--r--settings/js/users.js36
-rw-r--r--settings/routes.php2
-rw-r--r--settings/templates/users.php12
-rw-r--r--settings/users.php20
22 files changed, 440 insertions, 33 deletions
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index acd5353faff..5672c78dc33 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 35cca7c42dc..71fca09ed6d 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -6,9 +6,9 @@
<a href="<?php echo link_to('', 'index.php'); ?>" title="" id="owncloud"><img class="svg" src="<?php echo image_path('', 'logo-wide.svg'); ?>" alt="ownCloud" /></a>
<div class="header-right">
<?php if (isset($_['folder'])): ?>
- <span id="details"><?php echo $l->t('%s shared the folder %s with you', array($_['uidOwner'], $_['filename'])) ?></span>
+ <span id="details"><?php echo $l->t('%s shared the folder %s with you', array($_['displayName'], $_['filename'])) ?></span>
<?php else: ?>
- <span id="details"><?php echo $l->t('%s shared the file %s with you', array($_['uidOwner'], $_['filename'])) ?></span>
+ <span id="details"><?php echo $l->t('%s shared the file %s with you', array($_['displayName'], $_['filename'])) ?></span>
<?php endif; ?>
<?php if (!isset($_['folder']) || $_['allowZipDownload']): ?>
<a href="<?php echo $_['downloadURL']; ?>" class="button" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a>
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index 6591d1d5fee..4928ad2e27f 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -208,6 +208,50 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
return false;
}
+ /**
+ * @brief get display name of the user
+ * @param $uid user ID of the user
+ * @return display name
+ */
+ public function getDisplayName($uid) {
+ $cacheKey = 'getDisplayName'.$uid;
+ if(!is_null($displayName = $this->connection->getFromCache($cacheKey))) {
+ return $displayName;
+ }
+
+ $displayName = $this->readAttribute(
+ $this->username2dn($uid),
+ $this->connection->ldapUserDisplayName);
+
+ if($displayName && (count($displayName) > 0)) {
+ $this->connection->writeToCache($cacheKey, $displayName);
+ return $displayName[0];
+ }
+
+ return null;
+ }
+
+ /**
+ * @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) {
+ $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
+ if(!is_null($displayNames = $this->connection->getFromCache($cacheKey))) {
+ return $displayNames;
+ }
+
+ $displayNames = array();
+ $users = $this->getUsers($search, $limit, $offset);
+ foreach ($users as $user) {
+ $displayNames[$user] = $this->getDisplayName($user);
+ }
+ $this->connection->writeToCache($cacheKey, $displayNames);
+ return $displayNames;
+ }
+
/**
* @brief Check if backend implements actions
* @param $actions bitwise-or'ed actions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 077baa8ba56..6704a00c5a2 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 $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/core/js/share.js b/core/js/share.js
index b9b7201dd8b..0c45765bd8b 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -165,9 +165,9 @@ OC.Share={
var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
- html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.uid_owner})+'</span>';
+ html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner})+'</span>';
} else {
- html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.uid_owner})+'</span>';
+ html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner})+'</span>';
}
html += '<br />';
}
@@ -203,9 +203,9 @@ OC.Share={
OC.Share.showLink(share.token, share.share_with, itemSource);
} else {
if (share.collection) {
- OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, share.collection);
+ OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection);
} else {
- OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, false);
+ OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false);
}
}
if (share.expiration != null) {
@@ -245,7 +245,7 @@ OC.Share={
// Default permissions are Read and Share
var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE;
OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
- OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
+ OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions);
$('#shareWith').val('');
OC.Share.updateIcon(itemType, itemSource);
});
@@ -274,7 +274,7 @@ OC.Share={
}
});
},
- addShareWith:function(shareType, shareWith, permissions, possiblePermissions, collection) {
+ addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) {
if (!OC.Share.itemShares[shareType]) {
OC.Share.itemShares[shareType] = [];
}
@@ -289,7 +289,7 @@ OC.Share={
if (collectionList.length > 0) {
$(collectionList).append(', '+shareWith);
} else {
- var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWith})+'</li>';
+ var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWithDisplayName})+'</li>';
$('#shareWithList').prepend(html);
}
} else {
@@ -312,9 +312,9 @@ OC.Share={
var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'" title="' + shareWith + '">';
html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
if(shareWith.length > 14){
- html += shareWith.substr(0,11) + '...';
+ html += shareWithDisplayName.substr(0,11) + '...';
}else{
- html += shareWith;
+ html += shareWithDisplayName;
}
if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
if (editChecked == '') {
diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php
index 18291e0f84e..2886c3c5a2e 100644
--- a/core/templates/layout.user.php
+++ b/core/templates/layout.user.php
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title><?php echo isset($_['application']) && !empty($_['application'])?$_['application'].' | ':'' ?>ownCloud <?php echo OC_User::getUser()?' ('.OC_User::getUser().') ':'' ?></title>
+ <title><?php echo isset($_['application']) && !empty($_['application'])?$_['application'].' | ':'' ?>ownCloud <?php echo OC_User::getDisplayName()?' ('.OC_Util::sanitizeHTML(OC_User::getDisplayName()).') ':'' ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-itunes-app" content="app-id=543672169">
<link rel="shortcut icon" href="<?php echo image_path('', 'favicon.png'); ?>" /><link rel="apple-touch-icon-precomposed" href="<?php echo image_path('', 'favicon-touch.png'); ?>" />
diff --git a/db_structure.xml b/db_structure.xml
index db43ef21140..e878eac7690 100644
--- a/db_structure.xml
+++ b/db_structure.xml
@@ -680,6 +680,14 @@
</field>
<field>
+ <name>displayname</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>64</length>
+ </field>
+
+ <field>
<name>password</name>
<type>text</type>
<default></default>
diff --git a/lib/group.php b/lib/group.php
index ed9482418bd..5afef769361 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 (value) and user ids(key)
+ */
+ 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..4f6570c3be3 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 (value) and user ids (key)
+ */
+ 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/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/public/share.php b/lib/public/share.php
index cda583aa073..e1d77e652d5 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -946,6 +946,15 @@ class Share {
continue;
}
}
+
+ // Add display names to result
+ if ( isset($row['share_with']) && $row['share_with'] != '') {
+ $row['share_with_displayname'] = \OCP\User::getDisplayName($row['share_with']);
+ }
+ if ( isset($row['uid_owner']) && $row['uid_owner'] != '') {
+ $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']);
+ }
+
$items[$row['id']] = $row;
}
if (!empty($items)) {
diff --git a/lib/public/user.php b/lib/public/user.php
index 204d8e4c0f1..de52055a4c5 100644
--- a/lib/public/user.php
+++ b/lib/public/user.php
@@ -51,7 +51,25 @@ 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($user=null) {
+ return \OC_USER::getDisplayName($user);
+ }
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all display names (value) and the correspondig uids (key)
+ *
+ * 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);
+ }
+
/**
* @brief Check if the user is logged in
* @returns true/false
diff --git a/lib/user.php b/lib/user.php
index 85240ce6b68..38259bceea5 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;
}
@@ -266,6 +267,48 @@ class OC_User {
}
/**
+ * @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);
+ }
+ }
+ }
+ } else {
+ $displayName = self::determineDisplayName($uid);
+ $result = true;
+ }
+ if (OC_User::getUser() === $uid) {
+ $_SESSION['display_name'] = $displayName;
+ }
+ 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;
+ }
+
+ /**
* @brief Logs the current user out and kills all the session data
*
* Logout, destroys session
@@ -321,6 +364,21 @@ class OC_User {
}
/**
+ * @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;
+ }
+ }
+
+ /**
* @brief Autogenerate a password
* @returns string
*
@@ -420,6 +478,24 @@ class OC_User {
}
/**
+ * @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 check if a user exists
* @param string $uid the username
* @param string $excludingBackend (default none)
diff --git a/lib/user/backend.php b/lib/user/backend.php
index 2a95db93690..56fa3195978 100644
--- a/lib/user/backend.php
+++ b/lib/user/backend.php
@@ -35,6 +35,8 @@ 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);
+define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x010000);
/**
@@ -50,6 +52,8 @@ 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',
+ OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
);
/**
@@ -120,4 +124,28 @@ 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;
+ }
+
+ /**
+ * @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();
+ $users = $this->getUsers($search, $limit, $offset);
+ foreach ( $users as $user) {
+ $displayNames[$user] = $user;
+ }
+ return $displayNames;
+ }
}
diff --git a/lib/user/database.php b/lib/user/database.php
index f33e338e2e4..7deeb0c4697 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -110,7 +110,61 @@ 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 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();
+ $displayName = trim($result[0]['displayname'], ' ');
+ if ( !empty($displayName) ) {
+ return $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(`displayname`) LIKE LOWER(?)', $limit, $offset);
+ $result = $query->execute(array($search.'%'));
+ $users = array();
+ while ($row = $result->fetchRow()) {
+ $displayName = trim($row['displayname'], ' ');
+ $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
+ }
+ return $displayNames;
+ }
+
/**
* @brief Check if the password is correct
* @param $uid The username
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
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);
}
/**
diff --git a/settings/ajax/changedisplayname.php b/settings/ajax/changedisplayname.php
new file mode 100644
index 00000000000..f80ecb7a0c9
--- /dev/null
+++ b/settings/ajax/changedisplayname.php
@@ -0,0 +1,28 @@
+<?php
+// Check if we are a user
+OCP\JSON::callCheck();
+OC_JSON::checkLoggedIn();
+
+$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
+$displayName = $_POST["displayName"];
+
+$userstatus = null;
+if(OC_User::isAdminUser(OC_User::getUser())) {
+ $userstatus = 'admin';
+}
+if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
+ $userstatus = 'subadmin';
+}
+
+if(is_null($userstatus)) {
+ OC_JSON::error( array( "data" => array( "message" => "Authentication error" )));
+ exit();
+}
+
+// Return Success story
+if( OC_User::setDisplayName( $username, $displayName )) {
+ OC_JSON::success(array("data" => array( "username" => $username )));
+}
+else{
+ OC_JSON::error(array("data" => array( "message" => "Unable to change display name" )));
+} \ No newline at end of file
diff --git a/settings/js/users.js b/settings/js/users.js
index 9f0c1ffd111..424d00b51a7 100644
--- a/settings/js/users.js
+++ b/settings/js/users.js
@@ -69,7 +69,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 = $('<select multiple="multiple" class="groupsselect" data-placehoder="Groups" title="' + t('settings', 'Groups') + '"></select>').attr('data-username', username).attr('data-user-groups', groups);
tr.find('td.groups').empty();
if (tr.find('td.subadmins').length > 0) {
@@ -299,6 +301,40 @@ $(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 displayName = img.parent().parent().attr('data-displayName');
+ var input = $('<input type="text" value="'+displayName+'">');
+ img.css('display', 'none');
+ img.parent().children('span').replaceWith(input);
+ input.focus();
+ input.keypress(function (event) {
+ if (event.keyCode == 13) {
+ if ($(this).val().length > 0) {
+ $.post(
+ OC.filePath('settings', 'ajax', 'changedisplayname.php'),
+ {username:uid, displayName:$(this).val()},
+ function (result) {
+ }
+ );
+ 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 1c766837dd1..0a5b2fbfd38 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 c88966f7137..f30c21efaef 100644
--- a/settings/templates/users.php
+++ b/settings/templates/users.php
@@ -18,7 +18,7 @@ $_['subadmingroups'] = array_flip($items);
<div id="controls">
<form id="newuser" autocomplete="off">
- <input id="newusername" type="text" placeholder="<?php echo $l->t('Name')?>" /> <input
+ <input id="newusername" type="text" placeholder="<?php echo $l->t('Login Name')?>" /> <input
type="password" id="newuserpassword"
placeholder="<?php echo $l->t('Password')?>" /> <select
class="groupsselect"
@@ -76,7 +76,8 @@ $_['subadmingroups'] = array_flip($items);
<table data-groups="<?php echo implode(', ', $allGroups);?>">
<thead>
<tr>
- <th id='headerName'><?php echo $l->t('Name')?></th>
+ <th id='headerName'><?php echo $l->t('Login Name')?></th>
+ <th id="headerDisplayName"><?php echo $l->t( 'Display Name' ); ?></th>
<th id="headerPassword"><?php echo $l->t( 'Password' ); ?></th>
<th id="headerGroups"><?php echo $l->t( 'Groups' ); ?></th>
<?php if(is_array($_['subadmins']) || $_['subadmins']): ?>
@@ -88,8 +89,13 @@ $_['subadmingroups'] = array_flip($items);
</thead>
<tbody>
<?php foreach($_["users"] as $user): ?>
- <tr data-uid="<?php echo $user["name"] ?>">
+ <tr data-uid="<?php echo $user["name"] ?>"
+ data-displayName="<?php echo $user["displayName"] ?>">
<td class="name"><?php echo $user["name"]; ?></td>
+ <td class="displayName"><span><?php echo $user["displayName"]; ?></span> <img class="svg action"
+ src="<?php echo image_path('core', 'actions/rename.svg')?>"
+ alt="change display name" title="change display name"/>
+ </td>
<td class="password"><span>●●●●●●●</span> <img class="svg action"
src="<?php echo image_path('core', 'actions/rename.svg')?>"
alt="set new password" title="set new password"/>
diff --git a/settings/users.php b/settings/users.php
index 668d974693a..ab7a7aed734 100644
--- a/settings/users.php
+++ b/settings/users.php
@@ -22,11 +22,11 @@ $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());
- $accessibleusers = OC_Group::usersInGroups($accessiblegroups, '', 30);
+ $accessibleusers = OC_Group::displayNamesInGroups($accessiblegroups, '', 30);
$subadmins = false;
}
@@ -42,16 +42,22 @@ $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) {
- $quota=OC_Preferences::getValue($i, 'files', 'quota', 'default');
+foreach($accessibleusers as $uid => $displayName) {
+ $quota=OC_Preferences::getValue($uid, '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" => $uid,
+ "displayName" => $displayName,
+ "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($uid)));
}
foreach( $accessiblegroups as $i ) {