mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add req back to audit log events and extend to Projects api
This commit is contained in:
@@ -27,11 +27,12 @@ var api = module.exports = {
|
||||
available: function(opts) {
|
||||
return Promise.resolve(!!runtime.storage.projects);
|
||||
},
|
||||
|
||||
/**
|
||||
* List projects known to the runtime
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -56,10 +57,12 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {Object} opts.project - the project information
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
createProject: function(opts) {
|
||||
runtime.log.audit({event: "projects.create",name:opts.project.name}, opts.req);
|
||||
return runtime.storage.projects.createProject(opts.user, opts.project)
|
||||
},
|
||||
|
||||
@@ -69,11 +72,13 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project to initialise
|
||||
* @param {Object} opts.project - the project information
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
initialiseProject: function(opts) {
|
||||
// Initialised set when creating default files for an empty repo
|
||||
runtime.log.audit({event: "projects.initialise",id:opts.id}, opts.req);
|
||||
return runtime.storage.projects.initialiseProject(opts.user, opts.id, opts.project)
|
||||
},
|
||||
|
||||
@@ -81,6 +86,7 @@ var api = module.exports = {
|
||||
* Gets the active project
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the active project
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -93,11 +99,13 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project to activate
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
setActiveProject: function(opts) {
|
||||
var currentProject = runtime.storage.projects.getActiveProject(opts.user);
|
||||
runtime.log.audit({event: "projects.set",id:opts.id}, opts.req);
|
||||
if (!currentProject || opts.id !== currentProject.name) {
|
||||
return runtime.storage.projects.setActiveProject(opts.user, opts.id);
|
||||
} else {
|
||||
@@ -110,6 +118,7 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project to get
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the project metadata
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -123,10 +132,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project to update
|
||||
* @param {Object} opts.project - the project information
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
updateProject: function(opts) {
|
||||
runtime.log.audit({event: "projects.update",id:opts.id}, opts.req);
|
||||
return runtime.storage.projects.updateProject(opts.user, opts.id, opts.project);
|
||||
},
|
||||
|
||||
@@ -135,10 +146,12 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project to update
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
deleteProject: function(opts) {
|
||||
runtime.log.audit({event: "projects.delete",id:opts.id}, opts.req);
|
||||
return runtime.storage.projects.deleteProject(opts.user, opts.id);
|
||||
},
|
||||
|
||||
@@ -148,6 +161,7 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Boolean} opts.remote - whether to include status of remote repos
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the project status
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -161,6 +175,7 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Boolean} opts.remote - whether to return remote branches (true) or local (false)
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - a list of the local branches
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -174,6 +189,7 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.branch - the name of the branch
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the status of the branch
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -188,10 +204,12 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.branch - the name of the branch
|
||||
* @param {Boolean} opts.create - whether to create the branch if it doesn't exist
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
setBranch: function(opts) {
|
||||
runtime.log.audit({event: "projects.branch.set",id:opts.id, branch: opts.branch, create:opts.create}, opts.req);
|
||||
return runtime.storage.projects.setBranch(opts.user, opts.id, opts.branch, opts.create)
|
||||
},
|
||||
|
||||
@@ -202,10 +220,12 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.branch - the name of the branch
|
||||
* @param {Boolean} opts.force - whether to force delete
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
deleteBranch: function(opts) {
|
||||
runtime.log.audit({event: "projects.branch.delete",id:opts.id, branch: opts.branch, force:opts.force}, opts.req);
|
||||
return runtime.storage.projects.deleteBranch(opts.user, opts.id, opts.branch, false, opts.force);
|
||||
},
|
||||
|
||||
@@ -215,10 +235,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.message - the message to associate with the commit
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
commit: function(opts) {
|
||||
runtime.log.audit({event: "projects.commit",id:opts.id}, opts.req);
|
||||
return runtime.storage.projects.commit(opts.user, opts.id,{message: opts.message});
|
||||
},
|
||||
|
||||
@@ -228,6 +250,7 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.sha - the sha of the commit to return
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the commit details
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -242,6 +265,7 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.limit - limit how many to return
|
||||
* @param {String} opts.before - id of the commit to work back from
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Array>} - an array of commits
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -257,10 +281,12 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
abortMerge: function(opts) {
|
||||
runtime.log.audit({event: "projects.merge.abort",id:opts.id}, opts.req);
|
||||
return runtime.storage.projects.abortMerge(opts.user, opts.id);
|
||||
},
|
||||
|
||||
@@ -271,10 +297,12 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.path - the path of the file being merged
|
||||
* @param {String} opts.resolutions - how to resolve the merge conflict
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
resolveMerge: function(opts) {
|
||||
runtime.log.audit({event: "projects.merge.resolve",id:opts.id, file:opts.path}, opts.req);
|
||||
return runtime.storage.projects.resolveMerge(opts.user, opts.id, opts.path, opts.resolution);
|
||||
},
|
||||
|
||||
@@ -283,6 +311,7 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the file listing
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -297,6 +326,7 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.path - the path of the file
|
||||
* @param {String} opts.tree - the version control tree to use
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<String>} - the content of the file
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -310,10 +340,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String|Array} opts.path - the path of the file, or an array of paths
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
stageFile: function(opts) {
|
||||
runtime.log.audit({event: "projects.file.stage",id:opts.id, file:opts.path}, opts.req);
|
||||
return runtime.storage.projects.stageFile(opts.user, opts.id, opts.path);
|
||||
},
|
||||
|
||||
@@ -323,10 +355,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.path - the path of the file. If not set, all staged files are unstaged
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
unstageFile: function(opts) {
|
||||
runtime.log.audit({event: "projects.file.unstage",id:opts.id, file:opts.path}, opts.req);
|
||||
return runtime.storage.projects.unstageFile(opts.user, opts.id, opts.path);
|
||||
},
|
||||
|
||||
@@ -336,10 +370,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.path - the path of the file
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
revertFile: function(opts) {
|
||||
runtime.log.audit({event: "projects.file.revert",id:opts.id, file:opts.path}, opts.req);
|
||||
return runtime.storage.projects.revertFile(opts.user, opts.id,opts.path)
|
||||
},
|
||||
|
||||
@@ -350,6 +386,7 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.path - the path of the file
|
||||
* @param {String} opts.type - the type of diff
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the requested diff
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -362,6 +399,7 @@ var api = module.exports = {
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - a list of project remotes
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
@@ -378,10 +416,12 @@ var api = module.exports = {
|
||||
* @param {Object} opts.remote - the remote metadata
|
||||
* @param {String} opts.remote.name - the name of the remote
|
||||
* @param {String} opts.remote.url - the url of the remote
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
addRemote: function(opts) {
|
||||
runtime.log.audit({event: "projects.remote.add",id:opts.id, remote:opts.remote.name}, opts.req);
|
||||
return runtime.storage.projects.addRemote(opts.user, opts.id, opts.remote)
|
||||
},
|
||||
|
||||
@@ -391,10 +431,12 @@ var api = module.exports = {
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.remote - the name of the remote
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
removeRemote: function(opts) {
|
||||
runtime.log.audit({event: "projects.remote.delete",id:opts.id, remote:opts.remote}, opts.req);
|
||||
return runtime.storage.projects.removeRemote(opts.user, opts.id, opts.remote);
|
||||
},
|
||||
|
||||
@@ -405,10 +447,12 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {Object} opts.remote - the remote metadata
|
||||
* @param {String} opts.remote.name - the name of the remote
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
updateRemote: function(opts) {
|
||||
runtime.log.audit({event: "projects.remote.update",id:opts.id, remote:opts.remote.name}, opts.req);
|
||||
return runtime.storage.projects.updateRemote(opts.user, opts.id, opts.remote.name, opts.remote)
|
||||
},
|
||||
|
||||
@@ -416,10 +460,15 @@ var api = module.exports = {
|
||||
* Pull changes from the remote
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.remote - the remote to pull
|
||||
* @param {Boolean} opts.track - whether to track this remote
|
||||
* @param {Boolean} opts.allowUnrelatedHistories -
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
pull: function(opts) {
|
||||
runtime.log.audit({event: "projects.pull",id:opts.id, remote: opts.remote, track:opts.track}, opts.req);
|
||||
return runtime.storage.projects.pull(opts.user, opts.id, opts.remote, opts.track, opts.allowUnrelatedHistories);
|
||||
},
|
||||
|
||||
@@ -430,10 +479,12 @@ var api = module.exports = {
|
||||
* @param {String} opts.id - the id of the project
|
||||
* @param {String} opts.remote - the name of the remote
|
||||
* @param {String} opts.track - whether to set the remote as the upstream
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_projects
|
||||
*/
|
||||
push: function(opts) {
|
||||
runtime.log.audit({event: "projects.push",id:opts.id, remote: opts.remote, track:opts.track}, opts.req);
|
||||
return runtime.storage.projects.push(opts.user, opts.id, opts.remote, opts.track);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user