diff --git a/red/api/editor/index.js b/red/api/editor/index.js index 20621bc6a..21cc29b9e 100644 --- a/red/api/editor/index.js +++ b/red/api/editor/index.js @@ -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"); diff --git a/red/api/editor/projects/index.js b/red/api/editor/projects/index.js index cd9d1b935..eba738938 100644 --- a/red/api/editor/projects/index.js +++ b/red/api/editor/projects/index.js @@ -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 diff --git a/red/runtime/storage/index.js b/red/runtime/storage/index.js index 5bdcc240c..fe03da254 100644 --- a/red/runtime/storage/index.js +++ b/red/runtime/storage/index.js @@ -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; } } diff --git a/red/runtime/storage/localfilesystem/projects/index.js b/red/runtime/storage/localfilesystem/projects/index.js index a1df95e26..9e19ef656 100644 --- a/red/runtime/storage/localfilesystem/projects/index.js +++ b/red/runtime/storage/localfilesystem/projects/index.js @@ -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] && projectSettings[name].git && projectSettings[name].git.user[username]) { - result.git.user = projectSettings[name].git.user[username]; - } - return result; + return project.toJSON(); }); }