From 85209a0a001081c4b82007aea06807922754a059 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 14 Nov 2012 21:23:27 +0100 Subject: [PATCH 01/12] Cleanup user settings js --- settings/js/users.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/settings/js/users.js b/settings/js/users.js index 249d529df4f..cad3667c50e 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -29,7 +29,6 @@ var UserList={ $('#notification').html(t('users', 'deleted')+' '+uid+''+t('users', 'undo')+''); $('#notification').data('deleteuser',true); $('#notification').fadeIn(); - }, /** @@ -57,7 +56,6 @@ var UserList={ $('#notification').fadeOut(); $('tr').filterAttr('data-uid', UserList.deleteUid).remove(); UserList.deleteCanceled = true; - UserList.deleteFiles = null; if (ready) { ready(); } @@ -401,13 +399,8 @@ $(document).ready(function(){ $('#notification').hide(); $('#notification .undo').live('click', function() { if($('#notification').data('deleteuser')) { - $('tbody tr').each(function(index, row) { - if ($(row).data('uid') == UserList.deleteUid) { - $(row).show(); - } - }); + $('tbody tr').filterAttr('data-uid', UserList.deleteUid).show(); UserList.deleteCanceled=true; - UserList.deleteFiles=null; } $('#notification').fadeOut(); }); From 4eff27ed421205d6627e96203e03516666125b70 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 14 Nov 2012 21:28:23 +0100 Subject: [PATCH 02/12] Always have the username as string in user admin --- settings/js/users.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/settings/js/users.js b/settings/js/users.js index cad3667c50e..91be1a44385 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -67,7 +67,7 @@ var UserList={ add:function(username, groups, subadmin, quota, sort) { var tr = $('tbody tr').first().clone(); - tr.data('uid', username); + tr.attr('data-uid', username); tr.find('td.name').text(username); var groupsSelect = $(''); img.css('display','none'); img.parent().children('span').replaceWith(input); @@ -304,7 +304,7 @@ $(document).ready(function(){ $('select.quota, select.quota-user').live('change',function(){ var select=$(this); - var uid=$(this).parent().parent().parent().data('uid'); + var uid=$(this).parent().parent().parent().attr('data-uid'); var quota=$(this).val(); var other=$(this).next(); if(quota!='other'){ @@ -322,7 +322,7 @@ $(document).ready(function(){ }) $('input.quota-other').live('change',function(){ - var uid=$(this).parent().parent().parent().data('uid'); + var uid=$(this).parent().parent().parent().attr('data-uid'); var quota=$(this).val(); var select=$(this).prev(); var other=$(this); From 59627367ae4ba41c84f14e55ef4fe57c2924b7ab Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 14 Nov 2012 21:44:44 +0100 Subject: [PATCH 03/12] Better check and handling of user creation --- lib/user.php | 2 +- settings/ajax/createuser.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/user.php b/lib/user.php index 801ab7f608d..872fff9b2d9 100644 --- a/lib/user.php +++ b/lib/user.php @@ -182,7 +182,7 @@ class OC_User { $backend->createUser($uid, $password); OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => $uid, "password" => $password )); - return true; + return self::userExists($uid); } } return false; diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index 16b48c8a9ca..addae78517a 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -29,14 +29,17 @@ $username = $_POST["username"]; $password = $_POST["password"]; // Does the group exist? -if( in_array( $username, OC_User::getUsers())) { +if(OC_User::userExists($username)) { OC_JSON::error(array("data" => array( "message" => "User already exists" ))); exit(); } // Return Success story try { - OC_User::createUser($username, $password); + if (!OC_User::createUser($username, $password)) { + OC_JSON::error(array('data' => array( 'message' => 'User creation failed for '.$username ))); + exit(); + } foreach( $groups as $i ) { if(!OC_Group::groupExists($i)) { OC_Group::createGroup($i); From 343e9d86213edb832455338816527e9cbab0d6e0 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 14 Nov 2012 21:45:03 +0100 Subject: [PATCH 04/12] Better check and handing of user deletion --- lib/user.php | 2 +- settings/js/users.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/user.php b/lib/user.php index 872fff9b2d9..a60ebbe4423 100644 --- a/lib/user.php +++ b/lib/user.php @@ -216,7 +216,7 @@ class OC_User { // Emit and exit OC_Hook::emit( "OC_User", "post_deleteUser", array( "uid" => $uid )); - return true; + return !self::userExists($uid); } else{ return false; diff --git a/settings/js/users.js b/settings/js/users.js index 91be1a44385..517984f9247 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -59,6 +59,8 @@ var UserList={ if (ready) { ready(); } + } else { + oc.dialogs.alert(result.data.message, t('settings', 'Unable to remove user')); } } }); From ad87bc464524ee99e2f19eae8c2f8adf570456d9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Nov 2012 22:37:21 +0100 Subject: [PATCH 05/12] Prevent ajax race conditions when using routes by offering a callback that is run after the the routes have finished loading --- core/js/router.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/js/router.js b/core/js/router.js index 8b66f5a05c5..02c8d11e695 100644 --- a/core/js/router.js +++ b/core/js/router.js @@ -1,17 +1,30 @@ OC.router_base_url = OC.webroot + '/index.php/', OC.Router = { + loadedCallback: null, + // register your ajax requests to load after the loading of the routes + // has finished. otherwise you face problems with race conditions + registerLoadedCallback: function(callback){ + if(this.routes_request.state() === 'resolved'){ + callback(); + } else { + this.loadedCallback = callback; + } + }, routes_request: $.ajax(OC.router_base_url + 'core/routes.json', { dataType: 'json', success: function(jsondata) { - if (jsondata.status == 'success') { + if (jsondata.status === 'success') { OC.Router.routes = jsondata.data; + if(OC.Router.loadedCallback !== null){ + OC.Router.loadedCallback(); + } } } }), generate:function(name, opt_params) { if (!('routes' in this)) { if(this.routes_request.state() != 'resolved') { - alert('wait');// wait + alert('To avoid race conditions, please register a callback');// wait } } if (!(name in this.routes)) { From bf20021b628e5e00f825203ac37f4878f97a4a2e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Nov 2012 23:55:37 +0100 Subject: [PATCH 06/12] instead of warning via popup, write to console.warn --- core/js/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/js/router.js b/core/js/router.js index 02c8d11e695..406f1912fed 100644 --- a/core/js/router.js +++ b/core/js/router.js @@ -24,7 +24,7 @@ OC.Router = { generate:function(name, opt_params) { if (!('routes' in this)) { if(this.routes_request.state() != 'resolved') { - alert('To avoid race conditions, please register a callback');// wait + console.warn('To avoid race conditions, please register a callback');// wait } } if (!(name in this.routes)) { From e642d18e26f3a6448ac33b2f34341d9b3ee6baae Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 15 Nov 2012 14:48:06 +0100 Subject: [PATCH 07/12] When using routing in apps, no apps are loaded in the left navigation tree. To fix this: load apps for matching a request --- lib/base.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/base.php b/lib/base.php index c97700b3dbf..66d2d400285 100644 --- a/lib/base.php +++ b/lib/base.php @@ -488,6 +488,7 @@ class OC{ return; } try { + OC_App::loadApps(); OC::getRouter()->match(OC_Request::getPathInfo()); return; } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { From 25e4a071ef3f89a5573f1d67b0c3cb60ccf7c858 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 15 Nov 2012 15:01:21 +0100 Subject: [PATCH 08/12] fixed: this.routes_request is a deferred/promise --- core/js/router.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/js/router.js b/core/js/router.js index 406f1912fed..77168e33025 100644 --- a/core/js/router.js +++ b/core/js/router.js @@ -4,11 +4,7 @@ OC.Router = { // register your ajax requests to load after the loading of the routes // has finished. otherwise you face problems with race conditions registerLoadedCallback: function(callback){ - if(this.routes_request.state() === 'resolved'){ - callback(); - } else { - this.loadedCallback = callback; - } + this.routes_request.done(callback); }, routes_request: $.ajax(OC.router_base_url + 'core/routes.json', { dataType: 'json', From defdbe3c1036d4eb7b7793d2143a30bc9ce8d778 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 15 Nov 2012 15:07:01 +0100 Subject: [PATCH 09/12] removed unneeded callback checks in routes_request that could potentially fail --- core/js/router.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/js/router.js b/core/js/router.js index 77168e33025..3562785b342 100644 --- a/core/js/router.js +++ b/core/js/router.js @@ -1,6 +1,5 @@ OC.router_base_url = OC.webroot + '/index.php/', OC.Router = { - loadedCallback: null, // register your ajax requests to load after the loading of the routes // has finished. otherwise you face problems with race conditions registerLoadedCallback: function(callback){ @@ -11,9 +10,6 @@ OC.Router = { success: function(jsondata) { if (jsondata.status === 'success') { OC.Router.routes = jsondata.data; - if(OC.Router.loadedCallback !== null){ - OC.Router.loadedCallback(); - } } } }), From 9419913c06bc0fc7795243d9a9f8800f5e2a7ac4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 15 Nov 2012 18:10:40 +0100 Subject: [PATCH 10/12] Better place to check for user removal --- lib/user.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/user.php b/lib/user.php index a60ebbe4423..31c93740d77 100644 --- a/lib/user.php +++ b/lib/user.php @@ -204,6 +204,9 @@ class OC_User { foreach(self::$_usedBackends as $backend) { $backend->deleteUser($uid); } + if (self::userExists($uid)) { + return false; + } // We have to delete the user from all groups foreach( OC_Group::getUserGroups( $uid ) as $i ) { OC_Group::removeFromGroup( $uid, $i ); @@ -216,7 +219,7 @@ class OC_User { // Emit and exit OC_Hook::emit( "OC_User", "post_deleteUser", array( "uid" => $uid )); - return !self::userExists($uid); + return true; } else{ return false; From b51b9539d074222d01bd4a9836be6fe2f191a31e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 15 Nov 2012 19:43:10 +0100 Subject: [PATCH 11/12] Very simple js console switcher. --- core/js/js.js | 16 ++++++++++++++++ core/templates/layout.base.php | 1 + core/templates/layout.guest.php | 1 + core/templates/layout.user.php | 1 + 4 files changed, 19 insertions(+) diff --git a/core/js/js.js b/core/js/js.js index 164fab80ed4..3b4cabe710b 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1,3 +1,19 @@ +/** + * Disable console output unless DEBUG mode is enabled. + * Add + * define('DEBUG', true); + * To the end of config/config.php to enable debug mode. + */ +if (oc_debug !== true) { + if (!window.console) { + window.console = {}; + } + var methods = ['log', 'debug', 'warn', 'info', 'error', 'assert']; + for (var i = 0; i < methods.length; i++) { + console[methods[i]] = function () { }; + } +} + /** * translate a string * @param app the id of the app for which to translate the string diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php index d8f83058775..47f4b423b3e 100644 --- a/core/templates/layout.base.php +++ b/core/templates/layout.base.php @@ -8,6 +8,7 @@