1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Permit login with blank scope

Required for the editor, which doesn't know the appropriate scope
for the user logging in. The user will adopt their default permission
scope once logged in.
This commit is contained in:
Nick O'Leary 2015-07-15 10:11:16 +01:00
parent 10ad7fbf6e
commit 9fb81b2814
7 changed files with 21 additions and 8 deletions

View File

@ -237,7 +237,7 @@ RED.deploy = (function() {
}).fail(function(xhr,textStatus,err) { }).fail(function(xhr,textStatus,err) {
RED.nodes.dirty(true); RED.nodes.dirty(true);
if (xhr.responseText) { if (xhr.responseText) {
RED.notify(RED._("notification.error",{message:xhr.responseJSON.message}),"error"); RED.notify(RED._("notification.error",{message:xhr.responseText}),"error");
} else { } else {
RED.notify(RED._("notification.error",{message:RED._("deploy.errors.noResponse")}),"error"); RED.notify(RED._("notification.error",{message:RED._("deploy.errors.noResponse")}),"error");
} }

View File

@ -287,6 +287,8 @@ RED.editor = (function() {
}).done(function() { }).done(function() {
RED.library.loadFlowLibrary(); RED.library.loadFlowLibrary();
RED.notify(RED._("library.savedNodes"),"success"); RED.notify(RED._("library.savedNodes"),"success");
}).fail(function(xhr,textStatus,err) {
RED.notify(RED._("library.saveFailed",{message:xhr.responseText}),"error");
}); });
} }
} }

View File

@ -329,7 +329,7 @@ RED.library = (function() {
}).done(function(data,textStatus,xhr) { }).done(function(data,textStatus,xhr) {
RED.notify(RED._("library.savedType", {type:options.type}),"success"); RED.notify(RED._("library.savedType", {type:options.type}),"success");
}).fail(function(xhr,textStatus,err) { }).fail(function(xhr,textStatus,err) {
RED.notify(RED._("library.saveFailed",{message:xhr.responseJSON.message}),"error"); RED.notify(RED._("library.saveFailed",{message:xhr.responseText}),"error");
}); });
} }
$( "#node-dialog-library-save-confirm" ).dialog({ $( "#node-dialog-library-save-confirm" ).dialog({

View File

@ -86,7 +86,7 @@ RED.user = (function() {
var body = { var body = {
client_id: "node-red-editor", client_id: "node-red-editor",
grant_type: "password", grant_type: "password",
scope:"*" scope:""
} }
for (var i=0;i<data.prompts.length;i++) { for (var i=0;i<data.prompts.length;i++) {
var field = data.prompts[i]; var field = data.prompts[i];

View File

@ -33,7 +33,11 @@ function hasPermission(userScope,permission) {
return true; return true;
} }
if (userScope == "*") { if (permission === "") {
return true;
}
if (userScope === "*") {
return true; return true;
} }
@ -46,7 +50,7 @@ function hasPermission(userScope,permission) {
return true; return true;
} }
if (userScope == "read") { if (userScope === "read") {
return readRE.test(permission); return readRE.test(permission);
} else { } else {
return false; // anything not allowed is disallowed return false; // anything not allowed is disallowed

View File

@ -85,6 +85,9 @@ var passwordTokenExchange = function(client, username, password, scope, done) {
Users.authenticate(username,password).then(function(user) { Users.authenticate(username,password).then(function(user) {
if (user) { if (user) {
if (scope === "") {
scope = user.permissions;
}
if (permissions.hasPermission(user.permissions,scope)) { if (permissions.hasPermission(user.permissions,scope)) {
loginAttempts = loginAttempts.filter(function(logEntry) { loginAttempts = loginAttempts.filter(function(logEntry) {
return logEntry.user !== username; return logEntry.user !== username;

View File

@ -40,5 +40,9 @@ describe("Auth permissions", function() {
permissions.hasPermission("read",["foo.read","foo.write"]).should.be.false; permissions.hasPermission("read",["foo.read","foo.write"]).should.be.false;
permissions.hasPermission("read",["foo.read","bar.read"]).should.be.true; permissions.hasPermission("read",["foo.read","bar.read"]).should.be.true;
}); });
it('permits an empty permission', function() {
permissions.hasPermission("*","").should.be.true;
permissions.hasPermission("read",[""]).should.be.true;
});
}); });
}); });