From 05b46f78281e5df49a5c6a0513a37eaf03c3c29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 8 Feb 2013 17:16:18 +0100 Subject: [PATCH 1/5] on creation only test for existing users if the backend supports user creation this solves the issue where no users can be created any more if backends are active which always return true on userExists() like WebDAV Auth --- lib/user.php | 15 ++++++++++++++- settings/ajax/createuser.php | 6 ------ settings/js/users.js | 6 ------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/user.php b/lib/user.php index 9dc8cca97a6..76c4c45ee30 100644 --- a/lib/user.php +++ b/lib/user.php @@ -172,7 +172,7 @@ class OC_User { } // Check if user already exists - if( self::userExists($uid) ) { + if( self::userExistsForCreation($uid) ) { throw new Exception('The username is already being used'); } @@ -551,6 +551,19 @@ class OC_User { return false; } + public static function userExistsForCreation($uid) { + foreach(self::$_usedBackends as $backend) { + if(!$backend->implementsActions(OC_USER_BACKEND_CREATE_USER)) + continue; + + $result=$backend->userExists($uid); + if($result===true) { + return true; + } + } + return false; + } + /** * disables a user * @param string $userid the user to disable diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index 09ef25d92fa..56653bed6bd 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -26,12 +26,6 @@ if(OC_User::isAdminUser(OC_User::getUser())) { $username = $_POST["username"]; $password = $_POST["password"]; -// Does the group exist? -if(OC_User::userExists($username)) { - OC_JSON::error(array("data" => array( "message" => "User already exists" ))); - exit(); -} - // Return Success story try { if (!OC_User::createUser($username, $password)) { diff --git a/settings/js/users.js b/settings/js/users.js index 094cddda294..3ab48675f29 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -400,12 +400,6 @@ $(document).ready(function () { event.preventDefault(); var username = $('#newusername').val(); var password = $('#newuserpassword').val(); - if ($('#content table tbody tr').filterAttr('data-uid', username).length > 0) { - OC.dialogs.alert( - t('settings', 'The username is already being used'), - t('settings', 'Error creating user')); - return; - } if ($.trim(username) == '') { OC.dialogs.alert( t('settings', 'A valid username must be provided'), From f58ed7a509da54fcd29e21dc6fc75528822157a4 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Sun, 10 Feb 2013 17:31:12 +0100 Subject: [PATCH 2/5] no need to implement createUser in web dav auth --- apps/user_webdavauth/user_webdavauth.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/user_webdavauth/user_webdavauth.php b/apps/user_webdavauth/user_webdavauth.php index 1459781a3b4..dd34e0ad2f1 100755 --- a/apps/user_webdavauth/user_webdavauth.php +++ b/apps/user_webdavauth/user_webdavauth.php @@ -28,12 +28,6 @@ class OC_USER_WEBDAVAUTH extends OC_User_Backend { $this->webdavauth_url = OC_Config::getValue( "user_webdavauth_url" ); } - public function createUser() { - // Can't create user - OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to create users from web frontend using WebDAV user backend', 3); - return false; - } - public function deleteUser($uid) { // Can't delete user OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to delete users from web frontend using WebDAV user backend', 3); From 5731a1b01cc5ba1a4f1226336a56761d967c8e88 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 11 Feb 2013 22:01:52 +0100 Subject: [PATCH 3/5] introduce new virtual method hasUserListings() to determine if a user backend can list it's users. --- apps/user_ldap/user_ldap.php | 6 ++ apps/user_ldap/user_proxy.php | 8 +++ apps/user_webdavauth/user_webdavauth.php | 6 ++ lib/user.php | 2 +- lib/user/backend.php | 24 ++++--- lib/user/database.php | 82 +++++++++++++----------- lib/user/dummy.php | 7 ++ lib/user/interface.php | 7 +- 8 files changed, 95 insertions(+), 47 deletions(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 0962756228c..7778c37c794 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -261,4 +261,10 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface { return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_HOME) & $actions); } + /** + * @return bool + */ + public function hasUserListings() { + return true; + } } \ No newline at end of file diff --git a/apps/user_ldap/user_proxy.php b/apps/user_ldap/user_proxy.php index a94be3354fc..b150e2f32c3 100644 --- a/apps/user_ldap/user_proxy.php +++ b/apps/user_ldap/user_proxy.php @@ -183,4 +183,12 @@ class User_Proxy extends lib\Proxy implements \OCP\UserInterface { public function deleteUser($uid) { return false; } + + /** + * @return bool + */ + public function hasUserListings() { + return true; + } + } \ No newline at end of file diff --git a/apps/user_webdavauth/user_webdavauth.php b/apps/user_webdavauth/user_webdavauth.php index dd34e0ad2f1..6417e45434d 100755 --- a/apps/user_webdavauth/user_webdavauth.php +++ b/apps/user_webdavauth/user_webdavauth.php @@ -65,6 +65,12 @@ class OC_USER_WEBDAVAUTH extends OC_User_Backend { return true; } + /** + * @return bool + */ + public function hasUserListings() { + return false; + } /* * we donĀ“t know the users so all we can do it return an empty array here diff --git a/lib/user.php b/lib/user.php index 0ab224bb15f..16680be4aa0 100644 --- a/lib/user.php +++ b/lib/user.php @@ -555,7 +555,7 @@ class OC_User { public static function userExistsForCreation($uid) { foreach(self::$_usedBackends as $backend) { - if(!$backend->implementsActions(OC_USER_BACKEND_CREATE_USER)) + if(!$backend->hasUserListings()) continue; $result=$backend->userExists($uid); diff --git a/lib/user/backend.php b/lib/user/backend.php index 56fa3195978..34de1e50698 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -134,18 +134,26 @@ abstract class OC_User_Backend implements OC_User_Interface { 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) { + /** + * @brief Get a list of all display names + * @returns array with all displayNames (value) and the corresponding 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; + return $displayNames; + } + + /** + * @brief Check if a user list is available or not + * @return boolean if users can be listed or not + */ + public function hasUserListings() { + return false; } } diff --git a/lib/user/database.php b/lib/user/database.php index 8dfd9534a96..1a6a22d7a16 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -111,30 +111,30 @@ class OC_User_Database extends OC_User_Backend { } } - /** - * @brief Set display name - * @param $uid The username - * @param $displayName The new display name - * @returns true/false - * - * Change the display name of a user + /** + * @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; - } + 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) { + /** + * @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(); @@ -144,36 +144,36 @@ class OC_User_Database extends OC_User_Backend { } 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. - */ + /** + * @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); + $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()) { - $displayNames[$row['uid']] = $row['displayname']; + $users = array(); + while ($row = $result->fetchRow()) { + $displayNames[$row['uid']] = $row['displayname']; } // let's see if we can also find some users who don't have a display name yet - $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(`uid`) LIKE LOWER(?)', $limit, $offset); $result = $query->execute(array($search.'%')); - while ($row = $result->fetchRow()) { + while ($row = $result->fetchRow()) { $displayName = trim($row['displayname'], ' '); - if ( empty($displayName) ) { + if ( empty($displayName) ) { $displayNames[$row['uid']] = $row['uid']; - } + } } - - return $displayNames; + + return $displayNames; } /** @@ -256,4 +256,12 @@ class OC_User_Database extends OC_User_Backend { return false; } } + + /** + * @return bool + */ + public function hasUserListings() { + return true; + } + } diff --git a/lib/user/dummy.php b/lib/user/dummy.php index 4dbbc02b888..d63f60efbeb 100644 --- a/lib/user/dummy.php +++ b/lib/user/dummy.php @@ -112,4 +112,11 @@ class OC_User_Dummy extends OC_User_Backend { public function userExists($uid) { return isset($this->users[$uid]); } + + /** + * @return bool + */ + public function hasUserListings() { + return true; + } } diff --git a/lib/user/interface.php b/lib/user/interface.php index b4667633b50..b1e19aea7fb 100644 --- a/lib/user/interface.php +++ b/lib/user/interface.php @@ -66,10 +66,15 @@ interface OC_User_Interface { /** * @brief Get a list of all display names - * @returns array with all displayNames (value) and the correspondig uids (key) + * @returns array with all displayNames (value) and the corresponding uids (key) * * Get a list of all display names and user ids. */ public function getDisplayNames($search = '', $limit = null, $offset = null); + /** + * @brief Check if a user list is available or not + * @return boolean if users can be listed or not + */ + public function hasUserListings(); } \ No newline at end of file From 14e3d77d64a83704d224ca91b5736ec2e94ee01b Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Tue, 12 Feb 2013 13:10:26 +0100 Subject: [PATCH 4/5] https://github.com/owncloud/core/pull/1598#discussion_r2976684 --- apps/user_ldap/user_proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user_ldap/user_proxy.php b/apps/user_ldap/user_proxy.php index b150e2f32c3..6a75bae3815 100644 --- a/apps/user_ldap/user_proxy.php +++ b/apps/user_ldap/user_proxy.php @@ -188,7 +188,7 @@ class User_Proxy extends lib\Proxy implements \OCP\UserInterface { * @return bool */ public function hasUserListings() { - return true; + return $this->refBackend->hasUserListings(); } } \ No newline at end of file From 9d6f74c65eb51b88e6d93c85a725fbaac2ed8e4a Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Wed, 13 Feb 2013 10:59:41 +0100 Subject: [PATCH 5/5] missing piece after merge --- settings/js/users.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/settings/js/users.js b/settings/js/users.js index 8b1e32163df..a70cf18ead3 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -346,12 +346,6 @@ $(document).ready(function () { event.preventDefault(); var username = $('#newusername').val(); var password = $('#newuserpassword').val(); - if ($('#content table tbody tr').filterAttr('data-uid', username).length > 0) { - OC.dialogs.alert( - t('settings', 'The username is already being used'), - t('settings', 'Error creating user')); - return; - } if ($.trim(username) == '') { OC.dialogs.alert( t('settings', 'A valid username must be provided'),