mirror of https://gitee.com/bigwinds/arangodb
fixed user permission bug in ui
This commit is contained in:
parent
1b8fe39348
commit
433c636c51
|
@ -9,6 +9,7 @@
|
||||||
el2: '.header',
|
el2: '.header',
|
||||||
el3: '.footer',
|
el3: '.footer',
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
|
loginCounter: 0,
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
"keyPress #loginForm input" : "keyPress",
|
"keyPress #loginForm input" : "keyPress",
|
||||||
|
@ -43,18 +44,19 @@
|
||||||
$('#loginForm').hide();
|
$('#loginForm').hide();
|
||||||
$('.login-window #databases').show();
|
$('.login-window #databases').show();
|
||||||
|
|
||||||
$.ajax(url).success(function(data) {
|
$.ajax(url).success(function(permissions) {
|
||||||
//enable db select and login button
|
//enable db select and login button
|
||||||
$('#loginDatabase').html('');
|
$('#loginDatabase').html('');
|
||||||
//fill select with allowed dbs
|
//fill select with allowed dbs
|
||||||
_.each(data.result, function(db) {
|
|
||||||
|
_.each(permissions.result, function(db) {
|
||||||
$('#loginDatabase').append(
|
$('#loginDatabase').append(
|
||||||
'<option>' + db + '</option>'
|
'<option>' + db + '</option>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.renderDBS();
|
self.renderDBS();
|
||||||
}).error(function(data) {
|
}).error(function() {
|
||||||
console.log("could not fetch user db data");
|
console.log("could not fetch user db data");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -92,57 +94,82 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var callback = function(error) {
|
this.collection.login(username, password, this.loginCallback.bind(this, username, password));
|
||||||
var self = this;
|
},
|
||||||
if (error) {
|
|
||||||
$('.wrong-credentials').show();
|
loginCallback: function(username, password, error) {
|
||||||
$('#loginDatabase').html('');
|
|
||||||
$('#loginDatabase').append(
|
var self = this;
|
||||||
'<option>_system</option>'
|
|
||||||
);
|
if (error) {
|
||||||
|
if (self.loginCounter === 0) {
|
||||||
|
self.loginCounter++;
|
||||||
|
self.collection.login(username, password, this.loginCallback.bind(this, username));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
self.loginCounter = 0;
|
||||||
// TODO
|
$('.wrong-credentials').show();
|
||||||
//var url = arangoHelper.databaseUrl("/_api/database/user", '_system');
|
$('#loginDatabase').html('');
|
||||||
var url = arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(username) + "/database", '_system');
|
$('#loginDatabase').append(
|
||||||
|
'<option>_system</option>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var url = arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(username) + "/database", '_system');
|
||||||
|
|
||||||
if (frontendConfig.authenticationEnabled === false) {
|
if (frontendConfig.authenticationEnabled === false) {
|
||||||
url = arangoHelper.databaseUrl("/_api/database/user");
|
url = arangoHelper.databaseUrl("/_api/database/user");
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.wrong-credentials').hide();
|
$('.wrong-credentials').hide();
|
||||||
self.loggedIn = true;
|
self.loggedIn = true;
|
||||||
//get list of allowed dbs
|
|
||||||
$.ajax(url).success(function(data) {
|
|
||||||
|
|
||||||
$('#loginForm').hide();
|
//get list of allowed dbs
|
||||||
$('#databases').show();
|
$.ajax(url).success(function(permissions) {
|
||||||
|
|
||||||
//enable db select and login button
|
//HANDLE PERMISSIONS
|
||||||
$('#loginDatabase').html('');
|
_.each(permissions.result, function(value, key) {
|
||||||
//fill select with allowed dbs
|
if (value !== 'rw') {
|
||||||
_.each(data.result, function(db, key) {
|
delete permissions.result[key];
|
||||||
$('#loginDatabase').append(
|
}
|
||||||
'<option>' + key + '</option>'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.renderDBS();
|
|
||||||
}).error(function(data) {
|
|
||||||
$('.wrong-credentials').show();
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
this.collection.login(username, password, callback);
|
$('#loginForm').hide();
|
||||||
|
$('#databases').show();
|
||||||
|
|
||||||
|
//enable db select and login button
|
||||||
|
$('#loginDatabase').html('');
|
||||||
|
|
||||||
|
|
||||||
|
//fill select with allowed dbs
|
||||||
|
_.each(permissions.result, function(db, key) {
|
||||||
|
$('#loginDatabase').append(
|
||||||
|
'<option>' + key + '</option>'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.renderDBS();
|
||||||
|
}).error(function() {
|
||||||
|
$('.wrong-credentials').show();
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderDBS: function() {
|
renderDBS: function() {
|
||||||
var db = $('#loginDatabase').val();
|
|
||||||
$('#goToDatabase').html("Select: " + db);
|
if ($('#loginDatabase').children().length === 0) {
|
||||||
window.setTimeout(function() {
|
$('#dbForm').remove();
|
||||||
$('#goToDatabase').focus();
|
$('#databases').prepend(
|
||||||
}, 300);
|
'<div class="no-database">You do not have permission to a database.</div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var db = $('#loginDatabase').val();
|
||||||
|
$('#goToDatabase').html("Select DB: " + db);
|
||||||
|
window.setTimeout(function() {
|
||||||
|
$('#goToDatabase').focus();
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
logout: function() {
|
logout: function() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*jshint browser: true */
|
/*jshint browser: true */
|
||||||
/*jshint unused: false */
|
/*jshint unused: false */
|
||||||
/*global CryptoJS, _, arangoHelper, Backbone, window, templateEngine, $ */
|
/*global CryptoJS, _, frontendConfig, arangoHelper, Backbone, window, templateEngine, $ */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -57,16 +57,13 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
url: arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(user) + "/database/" + encodeURIComponent(db)),
|
url: arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(user) + "/database/" + encodeURIComponent(db)),
|
||||||
contentType: "application/json",
|
contentType: "application/json"
|
||||||
data: JSON.stringify({
|
|
||||||
grant: ''
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
continueRender: function() {
|
continueRender: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.currentUser = this.collection.findWhere({
|
this.currentUser = this.collection.findWhere({
|
||||||
user: this.username
|
user: this.username
|
||||||
});
|
});
|
||||||
|
@ -75,11 +72,16 @@
|
||||||
|
|
||||||
arangoHelper.buildUserSubNav(this.currentUser.get("user"), 'Permissions');
|
arangoHelper.buildUserSubNav(this.currentUser.get("user"), 'Permissions');
|
||||||
|
|
||||||
|
|
||||||
|
var url = arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(self.currentUser.get("user")) + "/database");
|
||||||
|
if (frontendConfig.db === '_system') {
|
||||||
|
url = arangoHelper.databaseUrl("/_api/user/root/database");
|
||||||
|
}
|
||||||
|
|
||||||
//FETCH COMPLETE DB LIST
|
//FETCH COMPLETE DB LIST
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
//url: arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(this.currentUser.get("user")) + "/config"),
|
url: url,
|
||||||
url: arangoHelper.databaseUrl("/_api/database/user"),
|
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var allDBs = data.result;
|
var allDBs = data.result;
|
||||||
|
@ -92,6 +94,13 @@
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var permissions = data.result;
|
var permissions = data.result;
|
||||||
|
if (allDBs._system) {
|
||||||
|
var arr = [];
|
||||||
|
_.each(allDBs, function(db, name) {
|
||||||
|
arr.push(name);
|
||||||
|
});
|
||||||
|
allDBs = arr;
|
||||||
|
}
|
||||||
self.finishRender(allDBs, permissions);
|
self.finishRender(allDBs, permissions);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -101,6 +110,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
finishRender: function(allDBs, permissions) {
|
finishRender: function(allDBs, permissions) {
|
||||||
|
_.each(permissions, function(value, key) {
|
||||||
|
if (value !== 'rw') {
|
||||||
|
delete permissions[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(this.el).html(this.template.render({
|
$(this.el).html(this.template.render({
|
||||||
allDBs: allDBs,
|
allDBs: allDBs,
|
||||||
|
|
|
@ -328,12 +328,12 @@
|
||||||
}
|
}
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
display: none;
|
display: none;
|
||||||
|
left: initial;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 5px 0 0;
|
margin: 5px 0 0;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
left: initial;
|
|
||||||
top: 80%;
|
top: 80%;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,13 @@
|
||||||
#databases {
|
#databases {
|
||||||
height: 140px;
|
height: 140px;
|
||||||
|
|
||||||
|
.no-database {
|
||||||
|
background: $c-white;
|
||||||
|
border-radius: 2px;
|
||||||
|
padding: 40px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
#logout {
|
#logout {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue