1
0
Fork 0

add users when creating a database

This commit is contained in:
Jan Steemann 2013-11-06 16:48:18 +01:00
parent 7bcb02f3eb
commit c46d6b99f4
8 changed files with 54 additions and 14 deletions

View File

@ -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) {

View File

@ -7915,7 +7915,7 @@ static v8::Handle<v8::Value> 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<v8::Value> JS_ListDatabases (v8::Arguments const& argv) {
static v8::Handle<v8::Value> JS_CreateDatabase (v8::Arguments const& argv) {
v8::HandleScope scope;
if (argv.Length() < 1) {
TRI_V8_EXCEPTION_USAGE(scope, "db._createDatabase(<name>, <options>)");
if (argv.Length() < 1 || argv.Length() > 3) {
TRI_V8_EXCEPTION_USAGE(scope, "db._createDatabase(<name>, <options>, <users>)");
}
TRI_vocbase_t* vocbase = GetContextVocBase();
@ -8008,6 +8008,17 @@ static v8::Handle<v8::Value> JS_CreateDatabase (v8::Arguments const& argv) {
assert(database != 0);
// copy users into context
if (argv.Length() >= 3 && argv[2]->IsArray()) {
v8::Handle<v8::Object> 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());

View File

@ -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 });
}

View File

@ -65,7 +65,6 @@
if (hash) {
url += hash;
}
console.log(url);
return url;
},

View File

@ -5,7 +5,7 @@
<div class="pull-right">
<span class="glyphicon glyphicon-info-sign" title="Show API documentation"></span>
</div>
<img src="/_admin/aardvark/foxxes/thumbnail/<%=attributes.app %>" alt="icon" class="foxxIcon"/>
<img src="foxxes/thumbnail/<%=attributes.app %>" alt="icon" class="foxxIcon"/>
<p class="foxxDescription">
<!--Description: <%=attributes.description %><br /> -->
<strong>Mount:</strong>&nbsp;<%=attributes.mount %><br />

View File

@ -1,7 +1,7 @@
<small>
<div class="plain">
<h5 class="applicationName"><%= attributes.name %><%= attributes.isSystem ? " (system)" : "" %></h5>
<img src="/_admin/aardvark/foxxes/thumbnail/<%=attributes.app %>" alt="icon" class="foxxIcon"/>
<img src="foxxes/thumbnail/<%=attributes.app %>" alt="icon" class="foxxIcon"/>
<p class="foxxDescription">
<!--Description: <%=attributes.description %><br />-->
<strong>Path:</strong>&nbsp;<%=attributes.path %><br />

View File

@ -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"),

View File

@ -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));
////////////////////////////////////////////////////////////////////////////////
/// @}