mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Better auth handling in projects
This commit is contained in:
@@ -28,8 +28,8 @@ module.exports = {
|
||||
|
||||
// Projects
|
||||
|
||||
// List all projects
|
||||
app.get("/", function(req,res) {
|
||||
// List projects
|
||||
runtime.storage.projects.listProjects().then(function(list) {
|
||||
var active = runtime.storage.projects.getActiveProject();
|
||||
var response = {
|
||||
@@ -47,8 +47,8 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Create project
|
||||
app.post("/", function(req,res) {
|
||||
// Create project
|
||||
runtime.storage.projects.createProject(req.body).then(function(data) {
|
||||
res.json(data);
|
||||
}).catch(function(err) {
|
||||
@@ -61,8 +61,8 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Update a project
|
||||
app.put("/:id", function(req,res) {
|
||||
// Update a project
|
||||
//TODO: validate the payload properly
|
||||
if (req.body.active) {
|
||||
var currentProject = runtime.storage.projects.getActiveProject();
|
||||
@@ -83,7 +83,8 @@ module.exports = {
|
||||
req.body.hasOwnProperty('description') ||
|
||||
req.body.hasOwnProperty('dependencies')||
|
||||
req.body.hasOwnProperty('summary') ||
|
||||
req.body.hasOwnProperty('files')) {
|
||||
req.body.hasOwnProperty('files') ||
|
||||
req.body.hasOwnProperty('remote')) {
|
||||
runtime.storage.projects.updateProject(req.params.id, req.body).then(function() {
|
||||
res.redirect(303,req.baseUrl + '/'+ req.params.id);
|
||||
}).catch(function(err) {
|
||||
@@ -96,11 +97,10 @@ module.exports = {
|
||||
} else {
|
||||
res.status(400).json({error:"unexpected_error", message:"invalid_request"});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Get project metadata
|
||||
app.get("/:id", function(req,res) {
|
||||
// Get project metadata
|
||||
runtime.storage.projects.getProject(req.params.id).then(function(data) {
|
||||
if (data) {
|
||||
res.json(data);
|
||||
@@ -113,13 +113,13 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
app.delete("/:id",function(req,res) {
|
||||
// Delete project
|
||||
// Delete project - tbd
|
||||
app.delete("/:id", function(req,res) {
|
||||
});
|
||||
|
||||
|
||||
// Get project status - files, commit counts, branch info
|
||||
app.get("/:id/status", function(req,res) {
|
||||
// Get project metadata
|
||||
runtime.storage.projects.getStatus(req.params.id).then(function(data) {
|
||||
if (data) {
|
||||
res.json(data);
|
||||
@@ -133,8 +133,7 @@ module.exports = {
|
||||
});
|
||||
|
||||
|
||||
// Project Files
|
||||
|
||||
// Project file listing
|
||||
app.get("/:id/files", function(req,res) {
|
||||
runtime.storage.projects.getFiles(req.params.id).then(function(data) {
|
||||
console.log("TODO: REMOVE /:id/files as /:id/status is better!")
|
||||
@@ -146,7 +145,8 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// /:project/files/:treeish/file-path
|
||||
|
||||
// Get file content in a given tree (index/stage)
|
||||
app.get("/:id/files/:treeish/*", function(req,res) {
|
||||
var projectId = req.params.id;
|
||||
var treeish = req.params.treeish;
|
||||
@@ -161,6 +161,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Stage a file
|
||||
app.post("/:id/stage/*", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var file = req.params[0];
|
||||
@@ -173,6 +174,8 @@ module.exports = {
|
||||
res.status(400).json({error:"unexpected_error", message:err.toString()});
|
||||
})
|
||||
});
|
||||
|
||||
// Stage multiple files
|
||||
app.post("/:id/stage", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var files = req.body.files;
|
||||
@@ -186,6 +189,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Commit changes
|
||||
app.post("/:id/commit", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
|
||||
@@ -198,6 +202,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Unstage a file
|
||||
app.delete("/:id/stage/*", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var file = req.params[0];
|
||||
@@ -210,6 +215,8 @@ module.exports = {
|
||||
res.status(400).json({error:"unexpected_error", message:err.toString()});
|
||||
})
|
||||
});
|
||||
|
||||
// Unstage multiple files
|
||||
app.delete("/:id/stage", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
runtime.storage.projects.unstageFile(projectName).then(function(data) {
|
||||
@@ -221,6 +228,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Get a file diff
|
||||
app.get("/:id/diff/:type/*", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var type = req.params.type;
|
||||
@@ -236,6 +244,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Get a list of commits
|
||||
app.get("/:id/commits", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
var options = {
|
||||
@@ -255,6 +264,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Get an individual commit details
|
||||
app.get("/:id/commits/:sha", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
var sha = req.params.sha;
|
||||
@@ -268,6 +278,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Push local commits to remote
|
||||
app.post("/:id/push/?*", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var remoteBranchName = req.params[0]
|
||||
@@ -284,6 +295,8 @@ module.exports = {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Pull remote commits
|
||||
app.get("/:id/pull/?*", function(req,res) {
|
||||
var projectName = req.params.id;
|
||||
var remoteBranchName = req.params[0];
|
||||
@@ -301,6 +314,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Abort an ongoing merge
|
||||
app.delete("/:id/merge", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
runtime.storage.projects.abortMerge(projectName).then(function(data) {
|
||||
@@ -316,6 +330,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Resolve a merge
|
||||
app.post("/:id/resolve/*", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
var file = req.params[0];
|
||||
@@ -333,6 +348,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Get a list of local branches
|
||||
app.get("/:id/branches", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
runtime.storage.projects.getBranches(projectName,false).then(function(data) {
|
||||
@@ -347,6 +363,8 @@ module.exports = {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Get a list of remote branches
|
||||
app.get("/:id/branches/remote", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
runtime.storage.projects.getBranches(projectName,true).then(function(data) {
|
||||
@@ -362,6 +380,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
// Get branch status - commit counts/ahead/behind
|
||||
app.get("/:id/branches/remote/*/status", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
var branch = req.params[0];
|
||||
@@ -378,7 +397,7 @@ module.exports = {
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
// Set the active local branch
|
||||
app.post("/:id/branches", function(req, res) {
|
||||
var projectName = req.params.id;
|
||||
var branchName = req.body.name;
|
||||
|
Reference in New Issue
Block a user