mirror of
				https://github.com/mmumshad/ansible-playable.git
				synced 2025-03-09 23:38:54 +00:00 
			
		
		
		
	Append project owner id to project folder names
This commit is contained in:
		
							parent
							
								
									c21aebbf49
								
							
						
					
					
						commit
						a71d1109a8
					
				
					 4 changed files with 58 additions and 9 deletions
				
			
		|  | @ -12,6 +12,7 @@ | |||
| 
 | ||||
| import jsonpatch from 'fast-json-patch'; | ||||
| import Project from './project.model'; | ||||
| import config from '../../config/environment'; | ||||
| var ansibleTool = require('../../components/ansible/ansible_tool'); | ||||
| 
 | ||||
| function respondWithResult(res, statusCode) { | ||||
|  | @ -68,7 +69,17 @@ function handleError(res, statusCode) { | |||
| // Gets a list of Projects
 | ||||
| export function index(req, res) { | ||||
|   console.log("Getting projects list"); | ||||
|   return Project.find().exec() | ||||
| 
 | ||||
|   let filter ={owner_id: req.user._id}; | ||||
| 
 | ||||
|   if(config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf('admin')){ | ||||
|     console.log("User is admin"); | ||||
|     filter = {} | ||||
|   } | ||||
| 
 | ||||
|   console.log("Filter =" + JSON.stringify(filter)); | ||||
| 
 | ||||
|   return Project.find(filter).exec() | ||||
|     .then(respondWithResult(res)) | ||||
|     .catch(handleError(res)); | ||||
| } | ||||
|  | @ -89,6 +100,36 @@ export function create(req, res) { | |||
| 
 | ||||
|   console.log("Ansible Engine " + JSON.stringify(ansibleEngine)); | ||||
| 
 | ||||
|   req.body.owner_id = req.user._id; | ||||
|   req.body.owner_name = req.user.name; | ||||
| 
 | ||||
|   // Set default values
 | ||||
|   if(!ansibleEngine.ansibleHost){ | ||||
|     ansibleEngine = { | ||||
|       ansibleHost: config.scriptEngine.host, | ||||
|       ansibleHostUser: config.scriptEngine.user, | ||||
|       ansibleHostPassword: config.scriptEngine.password | ||||
|     }; | ||||
| 
 | ||||
|     // Update project request body to save in db, without password
 | ||||
|     req.body.ansibleEngine = { | ||||
|       ansibleHost: config.scriptEngine.host, | ||||
|       ansibleHostUser: config.scriptEngine.user | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   if(!ansibleEngine.projectFolder){ | ||||
|     ansibleEngine.projectFolder = '/opt/ansible-projects/' + req.user._id + '_' + req.body.name; | ||||
|     ansibleEngine.customModules = '/opt/ansible-projects/' + req.user._id + '_' + req.body.name + '/library'; | ||||
| 
 | ||||
|     // Update project request body to save in db
 | ||||
|     req.body.ansibleEngine.projectFolder = ansibleEngine.projectFolder; | ||||
|     req.body.ansibleEngine.customModules = ansibleEngine.customModules; | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   if(ansibleEngine.ansibleHost){ | ||||
|     ansibleTool.getAnsibleVersion( | ||||
|       function(version){ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue