From 474f4572f2d1033e87faf648b2e190a65b9a0952 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 16 Dec 2017 23:43:08 +0000 Subject: [PATCH] Fix conditional initialisation of projects --- red/api/editor/index.js | 8 +++---- red/api/editor/projects/index.js | 8 +++++++ red/runtime/storage/index.js | 8 +++++-- .../storage/localfilesystem/projects/index.js | 21 +++++++++---------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/red/api/editor/index.js b/red/api/editor/index.js index 4e26ef82f..b9f4d539a 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 65b2f8bbf..9373b4b21 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 2c24a48af..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].git && projectSettings[name].git.user[username]) { - result.git.user = projectSettings[name].git.user[username]; - } - return result; + return project.toJSON(); }); }