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

Fix conditional initialisation of projects

This commit is contained in:
Nick O'Leary 2017-12-16 23:43:08 +00:00
parent a3a1bba5ef
commit 474f4572f2
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 27 additions and 18 deletions

View File

@ -68,11 +68,9 @@ module.exports = {
editorApp.use("/",ui.editorResources);
//Projects
if (runtime.storage.projects) {
var projects = require("./projects");
projects.init(runtime);
editorApp.use("/projects",projects.app());
}
var projects = require("./projects");
projects.init(runtime);
editorApp.use("/projects",projects.app());
// Locales
var locales = require("./locales");

View File

@ -27,6 +27,14 @@ module.exports = {
app: function() {
var app = express();
app.use(function(req,res,next) {
if (!runtime.storage.projects) {
res.status(404).end();
} else {
next();
}
});
// Projects
// List all projects

View File

@ -54,8 +54,12 @@ var storageModuleInterface = {
} catch (e) {
return when.reject(e);
}
if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
if (storageModule.projects) {
if (!!storageModule.projects) {
var projectsEnabled = true;
if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
projectsEnabled = runtime.settings.editorTheme.projects.enabled !== false;
}
if (projectsEnabled) {
storageModuleInterface.projects = storageModule.projects;
}
}

View File

@ -29,7 +29,7 @@ var Projects = require("./Project");
var settings;
var runtime;
var projectsEnabled;
var projectsEnabled = true;
var projectLogMessages = [];
var projectsDir;
@ -96,17 +96,21 @@ function init(_settings, _runtime) {
// has not yet been initialised. That isn't ideal - can this be deferred?
.then(storageSettings.getSettings)
.then(function(globalSettings) {
var saveSettings = false;
if (!globalSettings.projects) {
// TODO: Migration Case
console.log("TODO: Migration from single file to project");
globalSettings.projects = {
activeProject: "",
projects: {}
}
return storageSettings.saveSettings(globalSettings);
saveSettings = true;
} else {
activeProject = globalSettings.projects.activeProject;
}
if (!activeProject) {
projectLogMessages.push(log._("storage.localfilesystem.no-active-project"))
}
if (saveSettings) {
return storageSettings.saveSettings(globalSettings);
}
});
}
}
@ -151,12 +155,7 @@ function getProject(user, name) {
username = user.username;
}
return Projects.get(name).then(function(project) {
var result = project.toJSON();
var projectSettings = settings.get("projects").projects;
if (projectSettings[name].git && projectSettings[name].git.user[username]) {
result.git.user = projectSettings[name].git.user[username];
}
return result;
return project.toJSON();
});
}