More stuff
This commit is contained in:
27
dist/qmi-cloud/main.js
vendored
27
dist/qmi-cloud/main.js
vendored
@@ -30,7 +30,7 @@ webpackEmptyAsyncContext.id = "./src/$$_lazy_route_resource lazy recursive";
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = "<app-logs *ngIf=\"logShow\" (onClose)=\"onLogsClose()\" [type]=\"logstype\" [selectedprov]=\"selectedprov\"></app-logs>\n<div class=\"jumbotron\">\n <h1>Users</h1>\n <table class=\"table table-sm\">\n <thead class=\"thead-light\">\n <tr>\n <th>Name</th>\n <th>Email</th>\n <th>User ID</th>\n <th>Role</th>\n <th></th>\n </tr>\n </thead>\n <tr *ngFor=\"let user of users; let i = index\">\n <td>{{user.displayName}}</td>\n <td>{{user.upn}}</td> \n <td>{{user._id}}</td>\n <td><span *ngIf=\"user.role\">{{user.role}}</span></td>\n <td>\n <button class=\"lui-button\" (click)=\"setAdmin(user)\">Set Admin</button>\n <button class=\"lui-button\" (click)=\"removeAdmin(user)\">Remove Admin</button>\n </td>\n </tr>\n </table>\n</div>\n\n<table class=\"table table-sm\" style=\"margin-bottom: 100px;\">\n <thead class=\"thead-light\">\n <tr>\n <th colspan=\"5\">Scenario Provision</th>\n <th colspan=\"4\" style=\"border-left:2px solid #ccc;\">Scenario Destroy</th>\n <td style=\"border-left:2px solid #ccc;\"></td>\n </tr>\n </thead>\n <tr>\n <th>ProvisionID</th>\n <th>Prov. Date</th>\n <th>User</th>\n <th>Scenario</th>\n <th style=\"width: 150px;\">Status</th>\n <th style=\"border-left:2px solid #ccc;\">DestroyID</th>\n <th>Dest. Date</th>\n <th>Status</th>\n <th style=\"border-right:2px solid #ccc;\">Destroyed?</th>\n <th></th>\n </tr>\n <tr *ngFor=\"let provision of provisions; let i = index\">\n <td><a href (click)=\"showLogs($event, provision, 'provision')\" class=\"lui-text-info\">{{ provision._id }}</a></td>\n <td>{{provision.created | date: 'MMM dd, yyyy - H:mm'}}</td>\n <td class=\"ell\" title=\"{{provision.path}}\" >{{provision.user}}</td>\n <td>{{ provision.scenario }}</td>\n <td>\n <span style=\"text-transform: capitalize;\" class=\"badge badge-secondary\" [ngClass]=\"{'badge-warning': provision.status === 'provisioning' || provision.status === 'initializing', 'badge-success': provision.status === 'provisioned', 'badge-danger': provision.status === 'error' }\">{{provision.status}}</span>\n <span *ngIf=\"provision.status === 'provisioning' || provision.status === 'initializing'\" class=\"spinner-border spinner-border-sm text-warning\" role=\"status\">\n <span class=\"sr-only\"></span>\n </span>\n </td>\n <td style=\"border-left:2px solid #ccc;\"><a *ngIf=\"provision.destroyId\" href (click)=\"showLogs($event, provision, 'destroy')\" class=\"lui-text-info\">{{provision.destroyId}}</a></td>\n <td>{{provision.dateDestroy | date: 'MMM dd, yyyy - H:mm'}}</td>\n <td>\n <span style=\"text-transform: capitalize;\" class=\"badge badge-secondary\" [ngClass]=\"{'badge-warning': provision.statusDestroy === 'destroying', 'badge-success': provision.statusDestroy === 'destroyed', 'badge-danger': provision.statusDestroy === 'error'}\">{{provision.statusDestroy}}</span>\n <span *ngIf=\"provision.statusDestroy === 'destroying'\" class=\"spinner-border spinner-border-sm text-warning\" role=\"status\">\n <span class=\"sr-only\"></span>\n </span>\n </td>\n \n <td style=\"border-right:2px solid #ccc;\"><span *ngIf=\"provision.isDestroyed\" class=\"lui-icon lui-icon--tick lui-text-success\"></span></td>\n <td>\n <button title=\"Destroy provision\" *ngIf=\"!provision.isDestroyed && provision.statusDestroy !== 'destroying' && provision.status !== 'provisioning'\" (click)=\"destroy(provision)\" class=\"lui-button lui-text-danger\"><span class=\"lui-icon lui-icon--remove\" aria-hidden=\"true\"></span></button>\n <button title=\"Remove entry\" *ngIf=\"provision.isDestroyed && provision.statusDestroy === 'destroyed'\" (click)=\"del(provision)\" class=\"lui-button lui-text-danger\"><span class=\"lui-icon lui-icon--bin\" aria-hidden=\"true\"></span></button>\n </td>\n </tr>\n</table>\n"
|
||||
module.exports = "<app-logs *ngIf=\"logShow\" (onClose)=\"onLogsClose()\" [type]=\"logstype\" [selectedprov]=\"selectedprov\"></app-logs>\n<h1>Users</h1>\n<table class=\"table table-sm\" style=\"margin-bottom: 50px;\">\n <thead class=\"thead-light\">\n <tr>\n <th>Name</th>\n <th>Email</th>\n <th>User ID</th>\n <th>Role</th>\n <th></th>\n </tr>\n </thead>\n <tr *ngFor=\"let user of users; let i = index\">\n <td>{{user.displayName}}</td>\n <td>{{user.upn}}</td> \n <td>{{user._id}}</td>\n <td><span *ngIf=\"user.role\">{{user.role}}</span></td>\n <td>\n <button *ngIf=\"user.role !== 'admin' && user.role !== 'superadmin'\" class=\"lui-button\" (click)=\"setAdmin(user)\">Set Admin</button>\n <button *ngIf=\"user.role === 'admin'\" class=\"lui-button\" (click)=\"removeAdmin(user)\">Remove Admin</button>\n </td>\n </tr>\n</table>\n<h1>Provisions</h1>\n<table class=\"table table-sm\" style=\"margin-bottom: 100px;\">\n <thead class=\"thead-light\">\n <tr>\n <th colspan=\"5\">Scenario Provision</th>\n <th colspan=\"4\" style=\"border-left:2px solid #ccc;\">Scenario Destroy</th>\n <td style=\"border-left:2px solid #ccc;\"></td>\n </tr>\n </thead>\n <tr>\n <th>ProvisionID</th>\n <th>Prov. Date</th>\n <th>User</th>\n <th>Scenario</th>\n <th style=\"width: 150px;\">Status</th>\n <th style=\"border-left:2px solid #ccc;\">DestroyID</th>\n <th>Dest. Date</th>\n <th>Status</th>\n <th style=\"border-right:2px solid #ccc;\">Destroyed?</th>\n <th></th>\n </tr>\n <tr *ngFor=\"let provision of provisions; let i = index\">\n <td><a href (click)=\"showLogs($event, provision, 'provision')\" class=\"lui-text-info\">{{ provision._id }}</a></td>\n <td>{{provision.created | date: 'MMM dd, yyyy - H:mm'}}</td>\n <td class=\"ell\" title=\"{{provision.path}}\" >{{provision.user}}</td>\n <td>{{ provision.scenario }}</td>\n <td>\n <span style=\"text-transform: capitalize;\" class=\"badge badge-secondary\" [ngClass]=\"{'badge-warning': provision.status === 'provisioning' || provision.status === 'initializing', 'badge-success': provision.status === 'provisioned', 'badge-danger': provision.status === 'error' }\">{{provision.status}}</span>\n <span *ngIf=\"provision.status === 'provisioning' || provision.status === 'initializing'\" class=\"spinner-border spinner-border-sm text-warning\" role=\"status\">\n <span class=\"sr-only\"></span>\n </span>\n </td>\n <td style=\"border-left:2px solid #ccc;\"><a *ngIf=\"provision.destroyId\" href (click)=\"showLogs($event, provision, 'destroy')\" class=\"lui-text-info\">{{provision.destroyId}}</a></td>\n <td>{{provision.dateDestroy | date: 'MMM dd, yyyy - H:mm'}}</td>\n <td>\n <span style=\"text-transform: capitalize;\" class=\"badge badge-secondary\" [ngClass]=\"{'badge-warning': provision.statusDestroy === 'destroying', 'badge-success': provision.statusDestroy === 'destroyed', 'badge-danger': provision.statusDestroy === 'error'}\">{{provision.statusDestroy}}</span>\n <span *ngIf=\"provision.statusDestroy === 'destroying'\" class=\"spinner-border spinner-border-sm text-warning\" role=\"status\">\n <span class=\"sr-only\"></span>\n </span>\n </td>\n \n <td style=\"border-right:2px solid #ccc;\"><span *ngIf=\"provision.isDestroyed\" class=\"lui-icon lui-icon--tick lui-text-success\"></span></td>\n <td>\n <button title=\"Destroy provision\" *ngIf=\"!provision.isDestroyed && provision.statusDestroy !== 'destroying' && provision.status !== 'provisioning'\" (click)=\"destroy(provision)\" class=\"lui-button lui-text-danger\"><span class=\"lui-icon lui-icon--remove\" aria-hidden=\"true\"></span></button>\n <button title=\"Remove entry\" *ngIf=\"provision.isDestroyed && provision.statusDestroy === 'destroyed'\" (click)=\"del(provision)\" class=\"lui-button lui-text-danger\"><span class=\"lui-icon lui-icon--bin\" aria-hidden=\"true\"></span></button>\n </td>\n </tr>\n</table>\n"
|
||||
|
||||
/***/ }),
|
||||
|
||||
@@ -93,6 +93,8 @@ var AdminComponent = /** @class */ (function () {
|
||||
}
|
||||
});
|
||||
};
|
||||
AdminComponent.prototype._getUsers = function () {
|
||||
};
|
||||
AdminComponent.prototype.ngOnInit = function () {
|
||||
var _this = this;
|
||||
this._usersService.getUsers().subscribe(function (res) {
|
||||
@@ -151,6 +153,24 @@ var AdminComponent = /** @class */ (function () {
|
||||
console.log("onStartProvision");
|
||||
this._refresh();
|
||||
};
|
||||
AdminComponent.prototype.setAdmin = function (user) {
|
||||
var _this = this;
|
||||
this._usersService.updateUser(user._id, { "role": "admin" }).subscribe(function (res1) {
|
||||
console.log("Updated", res1);
|
||||
_this._usersService.getUsers().subscribe(function (res) {
|
||||
_this.users = res;
|
||||
});
|
||||
});
|
||||
};
|
||||
AdminComponent.prototype.removeAdmin = function (user) {
|
||||
var _this = this;
|
||||
this._usersService.updateUser(user._id, { "role": null }).subscribe(function (res1) {
|
||||
console.log("Updated", res1);
|
||||
_this._usersService.getUsers().subscribe(function (res) {
|
||||
_this.users = res;
|
||||
});
|
||||
});
|
||||
};
|
||||
AdminComponent = __decorate([
|
||||
Object(_angular_core__WEBPACK_IMPORTED_MODULE_0__["Component"])({
|
||||
selector: 'app-admin',
|
||||
@@ -1003,6 +1023,9 @@ var UsersService = /** @class */ (function () {
|
||||
UsersService.prototype.getUsers = function () {
|
||||
return this.httpClient.get("/api/users");
|
||||
};
|
||||
UsersService.prototype.updateUser = function (userId, patchData) {
|
||||
return this.httpClient.put("/api/users/" + userId, patchData);
|
||||
};
|
||||
UsersService = __decorate([
|
||||
Object(_angular_core__WEBPACK_IMPORTED_MODULE_0__["Injectable"])({
|
||||
providedIn: 'root'
|
||||
@@ -1086,7 +1109,7 @@ var FooterComponent = /** @class */ (function () {
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = "<nav class=\"navbar navbar-dark bg-dark mb-5\">\n <a class=\"navbar-brand\" href=\"/\">QMI Cloud</a>\n <div class=\"navbar-expand mr-auto\">\n <div class=\"navbar-nav\">\n <a class=\"nav-item nav-link\" routerLink=\"/home\" routerLinkActive=\"active\">Home</a>\n <a *ngIf=\"user\" class=\"nav-item nav-link\" routerLink=\"/provisions\" routerLinkActive=\"active\">Provisions</a>\n </div>\n </div>\n <div class=\"navbar-expand ml-auto navbar-nav\">\n <div class=\"navbar-nav\">\n <!--<a class=\"nav-item nav-link\" href=\"https://github.com/beeman\" target=\"_blank\">\n <i class=\"fa fa-github\"></i>\n </a>\n <a class=\"nav-item nav-link\" href=\"https://twitter.com/beeman_nl\" target=\"_blank\">\n <i class=\"fa fa-twitter\"></i>\n </a>\n <a class=\"nav-item nav-link\" href=\"https://medium.com/@beeman\" target=\"_blank\">\n <i class=\"fa fa-medium\"></i>\n </a>-->\n <a *ngIf=\"user && user.role === 'admin'\" class=\"nav-item nav-link\" routerLink=\"/admin\" routerLinkActive=\"active\">Admin</a>\n <a *ngIf=\"user\" class=\"nav-item nav-link \">Hello {{user.displayName}}</a>\n <a *ngIf=\"!user\" class=\"btn btn-primary\" href=\"/login\">Login <i class=\"fa fa-sign-in\"></i></a>\n <a *ngIf=\"user\" class=\"btn btn-primary\" href=\"/logout\">Logout <i class=\"fa fa-sign-out\"></i></a>\n </div>\n </div>\n</nav>"
|
||||
module.exports = "<nav class=\"navbar navbar-dark bg-dark mb-5\">\n <a class=\"navbar-brand\" href=\"/\">QMI Cloud</a>\n <div class=\"navbar-expand mr-auto\">\n <div class=\"navbar-nav\">\n <a class=\"nav-item nav-link\" routerLink=\"/home\" routerLinkActive=\"active\">Home</a>\n <a *ngIf=\"user\" class=\"nav-item nav-link\" routerLink=\"/provisions\" routerLinkActive=\"active\">Provisions</a>\n </div>\n </div>\n <div class=\"navbar-expand ml-auto navbar-nav\">\n <div class=\"navbar-nav\">\n <!--<a class=\"nav-item nav-link\" href=\"https://github.com/beeman\" target=\"_blank\">\n <i class=\"fa fa-github\"></i>\n </a>\n <a class=\"nav-item nav-link\" href=\"https://twitter.com/beeman_nl\" target=\"_blank\">\n <i class=\"fa fa-twitter\"></i>\n </a>\n <a class=\"nav-item nav-link\" href=\"https://medium.com/@beeman\" target=\"_blank\">\n <i class=\"fa fa-medium\"></i>\n </a>-->\n <a *ngIf=\"user && (user.role === 'admin' || user.role === 'superadmin')\" class=\"nav-item nav-link\" routerLink=\"/admin\" routerLinkActive=\"active\">Admin</a>\n <a *ngIf=\"user\" class=\"nav-item nav-link \">Hello {{user.displayName}}</a>\n <a *ngIf=\"!user\" class=\"btn btn-primary\" href=\"/login\">Login <i class=\"fa fa-sign-in\"></i></a>\n <a *ngIf=\"user\" class=\"btn btn-primary\" href=\"/logout\">Logout <i class=\"fa fa-sign-out\"></i></a>\n </div>\n </div>\n</nav>"
|
||||
|
||||
/***/ }),
|
||||
|
||||
|
||||
2
dist/qmi-cloud/main.js.map
vendored
2
dist/qmi-cloud/main.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -69,11 +69,9 @@ const add = async (model, data, reply) => {
|
||||
}
|
||||
};
|
||||
|
||||
const update = async (model, req, reply) => {
|
||||
const update = async (model, id, body, reply) => {
|
||||
try {
|
||||
const id = req.id
|
||||
const entity = req.body
|
||||
const { ...updateData } = entity;
|
||||
const { ...updateData } = body;
|
||||
updateData.updated = new Date();
|
||||
const update = await model.findByIdAndUpdate(id, updateData, { new: true });
|
||||
return update;
|
||||
@@ -102,8 +100,8 @@ function _m(model) {
|
||||
add: async (data, reply) => {
|
||||
return add(model, data, reply);
|
||||
},
|
||||
update: async (data, reply) => {
|
||||
return update(model, data, reply);
|
||||
update: async (id, data, reply) => {
|
||||
return update(model, id, data, reply);
|
||||
},
|
||||
del: async (id, reply) => {
|
||||
return del(model, id, reply);
|
||||
|
||||
@@ -205,7 +205,7 @@ module.exports.ensureAuthenticated = function(req, res, next) {
|
||||
};
|
||||
|
||||
module.exports.ensureAuthenticatedAndAdmin = function(req, res, next) {
|
||||
if ( req.isAuthenticated() && req.user.role === 'admin' ) {
|
||||
if ( req.isAuthenticated() && (req.user.role === 'admin' || req.user.role === 'superadmin') ) {
|
||||
return next();
|
||||
}
|
||||
res.status(401).send({"error": "Unauthorized"});
|
||||
@@ -213,7 +213,7 @@ module.exports.ensureAuthenticatedAndAdmin = function(req, res, next) {
|
||||
|
||||
module.exports.ensureAuthenticatedAndIsMe = function (req, res, next) {
|
||||
if ( req.isAuthenticated() ) {
|
||||
if ( req.user._id == req.params.userId || req.user.role === 'admin' ) {
|
||||
if ( req.user._id == req.params.userId || req.user.role === 'admin' || req.user.role === 'superadmin' ) {
|
||||
return next();
|
||||
} else {
|
||||
return res.status(401).send("Error: Unauthorized");
|
||||
|
||||
@@ -19,10 +19,6 @@ const passport = require('../passport');
|
||||
*/
|
||||
router.get('/', passport.ensureAuthenticatedAndAdmin, async (req, res, next) => {
|
||||
|
||||
if ( req.user.role !== 'admin' ) {
|
||||
return res.status(403).json({"msg": "forbidden"});
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.destroy.get();
|
||||
return res.json(result);
|
||||
|
||||
@@ -73,6 +73,37 @@ router.get('/:userId', passport.ensureAuthenticatedAndIsMe, async (req, res, nex
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /users/{userId}:
|
||||
* put:
|
||||
* description: Update profile for an user
|
||||
* summary: Update profile for an user
|
||||
* parameters:
|
||||
* - name: userId
|
||||
* in: path
|
||||
* type: string
|
||||
* required: true
|
||||
* - in: body
|
||||
* name: body
|
||||
* description: User object
|
||||
* required: true
|
||||
* produces:
|
||||
* - application/json
|
||||
* responses:
|
||||
* 200:
|
||||
* description: User
|
||||
*/
|
||||
router.put('/:userId', passport.ensureAuthenticatedAndAdmin, async (req, res, next) => {
|
||||
|
||||
try {
|
||||
const result = await db.user.update(req.params.userId, req.body);
|
||||
return res.json(result);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
<app-logs *ngIf="logShow" (onClose)="onLogsClose()" [type]="logstype" [selectedprov]="selectedprov"></app-logs>
|
||||
<div class="jumbotron">
|
||||
<h1>Users</h1>
|
||||
<table class="table table-sm">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>User ID</th>
|
||||
<th>Role</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr *ngFor="let user of users; let i = index">
|
||||
<td>{{user.displayName}}</td>
|
||||
<td>{{user.upn}}</td>
|
||||
<td>{{user._id}}</td>
|
||||
<td><span *ngIf="user.role">{{user.role}}</span></td>
|
||||
<td>
|
||||
<button class="lui-button" (click)="setAdmin(user)">Set Admin</button>
|
||||
<button class="lui-button" (click)="removeAdmin(user)">Remove Admin</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h1>Users</h1>
|
||||
<table class="table table-sm" style="margin-bottom: 50px;">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>User ID</th>
|
||||
<th>Role</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr *ngFor="let user of users; let i = index">
|
||||
<td>{{user.displayName}}</td>
|
||||
<td>{{user.upn}}</td>
|
||||
<td>{{user._id}}</td>
|
||||
<td><span *ngIf="user.role">{{user.role}}</span></td>
|
||||
<td>
|
||||
<button *ngIf="user.role !== 'admin' && user.role !== 'superadmin'" class="lui-button" (click)="setAdmin(user)">Set Admin</button>
|
||||
<button *ngIf="user.role === 'admin'" class="lui-button" (click)="removeAdmin(user)">Remove Admin</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h1>Provisions</h1>
|
||||
<table class="table table-sm" style="margin-bottom: 100px;">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
|
||||
@@ -34,9 +34,15 @@ export class AdminComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private _getUsers() {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this._usersService.getUsers().subscribe( res => {
|
||||
|
||||
this.users = res;
|
||||
|
||||
this.subscription = timer(0, 5000).pipe( switchMap(() => this._provisionsService.getCombinedProvisionsAdmin() ) ).subscribe(pair => {
|
||||
this._provisionsService.composePair(pair);
|
||||
this._fillUser(pair);
|
||||
@@ -96,4 +102,21 @@ export class AdminComponent implements OnInit {
|
||||
this._refresh();
|
||||
}
|
||||
|
||||
setAdmin(user) : void {
|
||||
this._usersService.updateUser(user._id, {"role": "admin"}).subscribe( res1 => {
|
||||
console.log("Updated", res1);
|
||||
this._usersService.getUsers().subscribe( res => {
|
||||
this.users = res;
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
removeAdmin(user) : void {
|
||||
this._usersService.updateUser(user._id, {"role": null}).subscribe( res1 => {
|
||||
console.log("Updated", res1);
|
||||
this._usersService.getUsers().subscribe( res => {
|
||||
this.users = res;
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,8 @@ export class UsersService {
|
||||
getUsers() : Observable<any> {
|
||||
return this.httpClient.get(`/api/users`);
|
||||
}
|
||||
|
||||
updateUser(userId, patchData): Observable<any> {
|
||||
return this.httpClient.put(`/api/users/${userId}`, patchData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<a class="nav-item nav-link" href="https://medium.com/@beeman" target="_blank">
|
||||
<i class="fa fa-medium"></i>
|
||||
</a>-->
|
||||
<a *ngIf="user && user.role === 'admin'" class="nav-item nav-link" routerLink="/admin" routerLinkActive="active">Admin</a>
|
||||
<a *ngIf="user && (user.role === 'admin' || user.role === 'superadmin')" class="nav-item nav-link" routerLink="/admin" routerLinkActive="active">Admin</a>
|
||||
<a *ngIf="user" class="nav-item nav-link ">Hello {{user.displayName}}</a>
|
||||
<a *ngIf="!user" class="btn btn-primary" href="/login">Login <i class="fa fa-sign-in"></i></a>
|
||||
<a *ngIf="user" class="btn btn-primary" href="/logout">Logout <i class="fa fa-sign-out"></i></a>
|
||||
|
||||
Reference in New Issue
Block a user