diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index 21aa73babd..035b3e43dd 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -798,6 +798,10 @@ bool ApplicationV8::prepareV8Instance (const size_t i) { if (vocbase != 0) { // special check script to be run just once in first thread (not in all) // but for all databases + v8::HandleScope scope; + + context->_context->Global()->Set(v8::String::New("UPGRADE_ARGS"), v8::Object::New()); + bool ok = TRI_V8RunVersionCheck(vocbase, &_startupLoader, context->_context); if (! ok) { diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 7bcfd0ce98..5bf88d9b27 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -7915,7 +7915,7 @@ static v8::Handle JS_ListDatabases (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// /// @brief create a new database /// -/// @FUN{@FA{db}._createDatabase(@FA{name})} +/// @FUN{@FA{db}._createDatabase(@FA{name}, @FA{options})} /// /// Creates a new database with the name specified by @FA{name}. /// There are restrictions for database names (see @ref DatabaseNames}. @@ -7931,8 +7931,8 @@ static v8::Handle JS_ListDatabases (v8::Arguments const& argv) { static v8::Handle JS_CreateDatabase (v8::Arguments const& argv) { v8::HandleScope scope; - if (argv.Length() < 1) { - TRI_V8_EXCEPTION_USAGE(scope, "db._createDatabase(, )"); + if (argv.Length() < 1 || argv.Length() > 3) { + TRI_V8_EXCEPTION_USAGE(scope, "db._createDatabase(, , )"); } TRI_vocbase_t* vocbase = GetContextVocBase(); @@ -8008,6 +8008,17 @@ static v8::Handle JS_CreateDatabase (v8::Arguments const& argv) { assert(database != 0); + // copy users into context + if (argv.Length() >= 3 && argv[2]->IsArray()) { + v8::Handle users = v8::Object::New(); + users->Set(v8::String::New("users"), argv[2]); + + v8::Context::GetCurrent()->Global()->Set(v8::String::New("UPGRADE_ARGS"), users); + } + else { + v8::Context::GetCurrent()->Global()->Set(v8::String::New("UPGRADE_ARGS"), v8::Object::New()); + } + if (TRI_V8RunVersionCheck(database, (JSLoader*) v8g->_loader, v8::Context::GetCurrent())) { // version check ok TRI_V8InitialiseFoxx(database, v8::Context::GetCurrent()); diff --git a/js/actions/api-database.js b/js/actions/api-database.js index 031b01ed48..98b0b22e15 100644 --- a/js/actions/api-database.js +++ b/js/actions/api-database.js @@ -277,7 +277,25 @@ function post_api_database (req, res) { return; } - var result = arangodb.db._createDatabase(json.name || "", options); + var users = json.users; + + if (users === undefined) { + users = [ ]; + } + else if (! Array.isArray(users)) { + actions.resultBad(req, res, arangodb.ERROR_HTTP_BAD_PARAMETER); + return; + } + + var i; + for (i = 0; i < users.length; ++i) { + if (typeof users[i] !== 'object' || ! users[i].hasOwnProperty('username')) { + actions.resultBad(req, res, arangodb.ERROR_HTTP_BAD_PARAMETER); + return; + } + } + + var result = arangodb.db._createDatabase(json.name || "", options, users); actions.resultOk(req, res, actions.HTTP_OK, { result : result }); } diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoDatabase.js b/js/apps/system/aardvark/frontend/js/collections/arangoDatabase.js index bd295a98de..83740bb485 100644 --- a/js/apps/system/aardvark/frontend/js/collections/arangoDatabase.js +++ b/js/apps/system/aardvark/frontend/js/collections/arangoDatabase.js @@ -65,7 +65,6 @@ if (hash) { url += hash; } - console.log(url); return url; }, diff --git a/js/apps/system/aardvark/frontend/js/templates/foxxActiveView.ejs b/js/apps/system/aardvark/frontend/js/templates/foxxActiveView.ejs index 30be51f9a3..38be092ab6 100644 --- a/js/apps/system/aardvark/frontend/js/templates/foxxActiveView.ejs +++ b/js/apps/system/aardvark/frontend/js/templates/foxxActiveView.ejs @@ -5,7 +5,7 @@
- icon + icon

Mount: <%=attributes.mount %>
diff --git a/js/apps/system/aardvark/frontend/js/templates/foxxInstalledView.ejs b/js/apps/system/aardvark/frontend/js/templates/foxxInstalledView.ejs index 04e620d3b8..597d60c03d 100644 --- a/js/apps/system/aardvark/frontend/js/templates/foxxInstalledView.ejs +++ b/js/apps/system/aardvark/frontend/js/templates/foxxInstalledView.ejs @@ -1,7 +1,7 @@

<%= attributes.name %><%= attributes.isSystem ? " (system)" : "" %>
- icon + icon

Path: <%=attributes.path %>
diff --git a/js/apps/system/aardvark/frontend/js/views/footerView.js b/js/apps/system/aardvark/frontend/js/views/footerView.js index 9ded85e3b7..053f086dc2 100644 --- a/js/apps/system/aardvark/frontend/js/views/footerView.js +++ b/js/apps/system/aardvark/frontend/js/views/footerView.js @@ -5,6 +5,7 @@ var footerView = Backbone.View.extend({ el: '.footer', system: {}, isOffline: true, + dbSelectionView: null, initialize: function () { //also server online check @@ -12,11 +13,11 @@ var footerView = Backbone.View.extend({ window.setInterval(function(){ self.getVersion(); }, 15000); - self.getVersion(); this.dbSelectionView = new window.DBSelectionView({ collection: arangoDatabase }); + self.getVersion(); }, template: templateEngine.createTemplate("footerView.ejs"), diff --git a/js/server/version-check.js b/js/server/version-check.js index c81c212969..6e078fcb46 100644 --- a/js/server/version-check.js +++ b/js/server/version-check.js @@ -1,5 +1,5 @@ /*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true, stupid: true, continue: true, regexp: true */ -/*global require, exports, module */ +/*global require, exports, module, UPGRADE_ARGS */ //////////////////////////////////////////////////////////////////////////////// /// @brief version check at the start of the server, will optionally perform @@ -42,7 +42,7 @@ /// @brief updates the database //////////////////////////////////////////////////////////////////////////////// -(function() { +(function(args) { var internal = require("internal"); var fs = require("fs"); var console = require("console"); @@ -285,9 +285,16 @@ return false; } - if (users.count() === 0) { - // only add account if user has not created his/her own accounts already - userManager.save("root", "", true); + if (args && args.users) { + args.users.forEach(function(user) { + userManager.save(user.username, user.password, user.active || true, user.extra || { }); + }); + } + else { + if (users.count() === 0) { + // only add account if user has not created his/her own accounts already + userManager.save("root", "", true); + } } return true; @@ -668,7 +675,7 @@ // we should never get here return true; -}()); +}(UPGRADE_ARGS)); //////////////////////////////////////////////////////////////////////////////// /// @}