1
0
Fork 0
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:
Mumshad Mannambeth 2017-06-11 21:24:27 -04:00
parent c21aebbf49
commit a71d1109a8
4 changed files with 58 additions and 9 deletions

View file

@ -7,7 +7,7 @@ import routes from './project.routes';
export class ProjectComponent { export class ProjectComponent {
/*@ngInject*/ /*@ngInject*/
constructor($scope, Projects) { constructor($scope, Projects, Auth) {
'ngInject'; 'ngInject';
var default_project_folder = '/opt/ehc-ansible-projects/'; var default_project_folder = '/opt/ehc-ansible-projects/';
@ -104,8 +104,11 @@ export class ProjectComponent {
$scope.$watch('newProject.name', function(newValue, oldValue){ $scope.$watch('newProject.name', function(newValue, oldValue){
console.log("Changed"); console.log("Changed");
$scope.newProject.ansibleEngine.projectFolder = '/opt/ansible-projects/' + newValue; // Project folders cannot be edited once created
$scope.newProject.ansibleEngine.customModules = '/opt/ansible-projects/' + newValue + '/library'; var user_id = Auth.getCurrentUserSync()._id;
if($scope.editProjectFlag)return;
$scope.newProject.ansibleEngine.projectFolder = '/opt/ansible-projects/' + user_id + '_' + newValue;
$scope.newProject.ansibleEngine.customModules = '/opt/ansible-projects/' + user_id + '_' + newValue + '/library';
}); });
} }

View file

@ -28,14 +28,14 @@
<p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost"> <p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost">
<label>Project Folder</label> <label>Project Folder</label>
<input ng-model="newProject.ansibleEngine.projectFolder" class="form-control"> <input ng-readonly="editProjectFlag" ng-model="newProject.ansibleEngine.projectFolder" class="form-control">
<div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path to store files of this project </div> <div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path on the Ansible Host to store files of this project </div>
</p> </p>
<p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost"> <p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost">
<label>Custom Modules Location</label> <label>Custom Modules Location</label>
<input ng-model="newProject.ansibleEngine.customModules" class="form-control"> <input ng-readonly="editProjectFlag" ng-model="newProject.ansibleEngine.customModules" class="form-control">
<div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path to store custom modules for this project </div> <div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path on the Ansible Host to store custom modules for this project </div>
</p> </p>
<button class="btn btn-success" ng-disabled="!newProject.name" ng-click="createProject()"> Save <span class="fa {{saveButtonIcon}}"></span></button> <button class="btn btn-success" ng-disabled="!newProject.name" ng-click="createProject()"> Save <span class="fa {{saveButtonIcon}}"></span></button>
@ -57,6 +57,7 @@
<th>Name</th> <th>Name</th>
<th>Ansible Host</th> <th>Ansible Host</th>
<th>Ansible Version</th> <th>Ansible Version</th>
<th>Owner</th>
<th>Time</th> <th>Time</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
@ -66,6 +67,7 @@
<td>{{project.name}}</td> <td>{{project.name}}</td>
<td>{{project.ansibleEngine.ansibleHost}}</td> <td>{{project.ansibleEngine.ansibleHost}}</td>
<td>{{project.ansibleVersion}}</td> <td>{{project.ansibleVersion}}</td>
<td>{{project.owner_name}}</td>
<td>{{project.creationTime | date : 'medium'}}</td> <td>{{project.creationTime | date : 'medium'}}</td>
<td> <td>
<div class="btn-group"> <div class="btn-group">

View file

@ -12,6 +12,7 @@
import jsonpatch from 'fast-json-patch'; import jsonpatch from 'fast-json-patch';
import Project from './project.model'; import Project from './project.model';
import config from '../../config/environment';
var ansibleTool = require('../../components/ansible/ansible_tool'); var ansibleTool = require('../../components/ansible/ansible_tool');
function respondWithResult(res, statusCode) { function respondWithResult(res, statusCode) {
@ -68,7 +69,17 @@ function handleError(res, statusCode) {
// Gets a list of Projects // Gets a list of Projects
export function index(req, res) { export function index(req, res) {
console.log("Getting projects list"); 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)) .then(respondWithResult(res))
.catch(handleError(res)); .catch(handleError(res));
} }
@ -89,6 +100,36 @@ export function create(req, res) {
console.log("Ansible Engine " + JSON.stringify(ansibleEngine)); 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){ if(ansibleEngine.ansibleHost){
ansibleTool.getAnsibleVersion( ansibleTool.getAnsibleVersion(
function(version){ function(version){

View file

@ -15,7 +15,10 @@ var ProjectSchema = new mongoose.Schema({
inventory_data: String, //YAML Format inventory_data: String, //YAML Format
inventory_data_json: {}, //JSON Format inventory_data_json: {}, //JSON Format
roles_data: String, //YAML Format roles_data: String, //YAML Format
roles_data_json: {} //JSON Format roles_data_json: {}, //JSON Format
owner_id: String,
owner_name: String,
members: []
}); });
registerEvents(ProjectSchema); registerEvents(ProjectSchema);