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
|
@ -7,7 +7,7 @@ import routes from './project.routes';
|
|||
|
||||
export class ProjectComponent {
|
||||
/*@ngInject*/
|
||||
constructor($scope, Projects) {
|
||||
constructor($scope, Projects, Auth) {
|
||||
'ngInject';
|
||||
var default_project_folder = '/opt/ehc-ansible-projects/';
|
||||
|
||||
|
@ -104,8 +104,11 @@ export class ProjectComponent {
|
|||
|
||||
$scope.$watch('newProject.name', function(newValue, oldValue){
|
||||
console.log("Changed");
|
||||
$scope.newProject.ansibleEngine.projectFolder = '/opt/ansible-projects/' + newValue;
|
||||
$scope.newProject.ansibleEngine.customModules = '/opt/ansible-projects/' + newValue + '/library';
|
||||
// Project folders cannot be edited once created
|
||||
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';
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
|
||||
<p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost">
|
||||
<label>Project Folder</label>
|
||||
<input 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>
|
||||
<input ng-readonly="editProjectFlag" ng-model="newProject.ansibleEngine.projectFolder" class="form-control">
|
||||
<div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path on the Ansible Host to store files of this project </div>
|
||||
</p>
|
||||
|
||||
<p class="form-group" ng-if="newProject.ansibleEngine.ansibleHost">
|
||||
<label>Custom Modules Location</label>
|
||||
<input 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>
|
||||
<input ng-readonly="editProjectFlag" ng-model="newProject.ansibleEngine.customModules" class="form-control">
|
||||
<div ng-if="newProject.ansibleEngine.ansibleHost" class="hint">A directory path on the Ansible Host to store custom modules for this project </div>
|
||||
</p>
|
||||
|
||||
<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>Ansible Host</th>
|
||||
<th>Ansible Version</th>
|
||||
<th>Owner</th>
|
||||
<th>Time</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
|
@ -66,6 +67,7 @@
|
|||
<td>{{project.name}}</td>
|
||||
<td>{{project.ansibleEngine.ansibleHost}}</td>
|
||||
<td>{{project.ansibleVersion}}</td>
|
||||
<td>{{project.owner_name}}</td>
|
||||
<td>{{project.creationTime | date : 'medium'}}</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -15,7 +15,10 @@ var ProjectSchema = new mongoose.Schema({
|
|||
inventory_data: String, //YAML Format
|
||||
inventory_data_json: {}, //JSON 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue