mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
implementing usermanager settiings panel
This commit is contained in:
parent
f48186b1cc
commit
941fdf509e
@ -25,7 +25,6 @@ export class ConfigLoader {
|
|||||||
let argv = optimist.argv;
|
let argv = optimist.argv;
|
||||||
delete(argv._);
|
delete(argv._);
|
||||||
delete(argv.$0);
|
delete(argv.$0);
|
||||||
console.log(argv);
|
|
||||||
this.processHierarchyVar(configObject, argv);
|
this.processHierarchyVar(configObject, argv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import {Error, ErrorCodes} from "../../../common/entities/Error";
|
|||||||
import {ObjectManagerRepository} from "../../model/ObjectManagerRepository";
|
import {ObjectManagerRepository} from "../../model/ObjectManagerRepository";
|
||||||
import {User} from "../../../common/entities/User";
|
import {User} from "../../../common/entities/User";
|
||||||
import {Config} from "../../config/Config";
|
import {Config} from "../../config/Config";
|
||||||
|
import {Utils} from "../../../common/Utils";
|
||||||
|
|
||||||
export class UserMWs {
|
export class UserMWs {
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ export class UserMWs {
|
|||||||
if ((err) || (!result)) {
|
if ((err) || (!result)) {
|
||||||
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
||||||
}
|
}
|
||||||
|
result = Utils.clone(result);
|
||||||
for (let i = 0; i < result.length; i++) {
|
for (let i = 0; i < result.length; i++) {
|
||||||
result[i].password = "";
|
result[i].password = "";
|
||||||
}
|
}
|
||||||
|
@ -1,77 +1,5 @@
|
|||||||
<app-frame>
|
<app-frame>
|
||||||
<div body class="container">
|
<div body class="container">
|
||||||
<div class="panel panel-default" *ngIf="userManagementEnable">
|
<settings-usermanager *ngIf="userManagementEnable"></settings-usermanager>
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">User management</h3>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Role</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tr *ngFor="let user of users">
|
|
||||||
<td>{{user.name}}</td>
|
|
||||||
<td *ngIf="canModifyUser(user)">
|
|
||||||
<select class="form-control" [(ngModel)]="user.role" (ngModelChange)="updateRole(user)" required>
|
|
||||||
<option *ngFor="let repository of userRoles" [value]="repository.key">
|
|
||||||
{{repository.value}}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td *ngIf="!canModifyUser(user)">
|
|
||||||
{{user.role | stringifyRole}}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button *ngIf="canModifyUser(user)" (click)="deleteUser(user)"
|
|
||||||
class="btn btn-danger pull-right">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true" aria-label="Delete"></span>
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<button class="btn btn-default pull-right" data-toggle="modal" data-target="#myModal"
|
|
||||||
(click)="initNewUser()">+ Add
|
|
||||||
user
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Modal -->
|
|
||||||
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
|
||||||
aria-hidden="true">×</span></button>
|
|
||||||
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
|
|
||||||
</div>
|
|
||||||
<form (ngSubmit)="onSubmit()" #NewUserForm="ngForm">
|
|
||||||
<div class="modal-body">
|
|
||||||
<input type="text" class="form-control" placeholder="Username" autofocus
|
|
||||||
[(ngModel)]="newUser.name" ngControl="name" #name="ngForm" required>
|
|
||||||
<input type="password" class="form-control" placeholder="Password"
|
|
||||||
[(ngModel)]="newUser.password" ngControl="password" #name="ngForm" required>
|
|
||||||
<select class="form-control" [(ngModel)]="newUser.role" required>
|
|
||||||
<option *ngFor="let repository of userRoles" [value]="repository.key">{{repository.value}}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
||||||
<button type="button" class="btn btn-primary" data-dismiss="modal"
|
|
||||||
(click)="addNewUser()"
|
|
||||||
[disabled]="!NewUserForm.form.valid">Add User
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</app-frame>
|
</app-frame>
|
||||||
|
@ -4,31 +4,23 @@ import {Component, OnInit} from "@angular/core";
|
|||||||
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
||||||
import {Router} from "@angular/router-deprecated";
|
import {Router} from "@angular/router-deprecated";
|
||||||
import {FrameComponent} from "../frame/frame.component";
|
import {FrameComponent} from "../frame/frame.component";
|
||||||
import {User, UserRoles} from "../../../common/entities/User";
|
import {UserRoles} from "../../../common/entities/User";
|
||||||
import {FORM_DIRECTIVES} from "@angular/common";
|
import {FORM_DIRECTIVES} from "@angular/common";
|
||||||
import {Utils} from "../../../common/Utils";
|
|
||||||
import {AdminService} from "./admin.service";
|
|
||||||
import {Message} from "../../../common/entities/Message";
|
|
||||||
import {StringifyRole} from "./../pipes/StringifyRolePipe";
|
import {StringifyRole} from "./../pipes/StringifyRolePipe";
|
||||||
import {Config} from "../config/Config";
|
import {Config} from "../config/Config";
|
||||||
|
import {UserMangerSettingsComponent} from "../settings/usermanager/usermanager.settings.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'admin',
|
selector: 'admin',
|
||||||
templateUrl: 'app/admin/admin.component.html',
|
templateUrl: 'app/admin/admin.component.html',
|
||||||
styleUrls: ['app/admin/admin.component.css'],
|
styleUrls: ['app/admin/admin.component.css'],
|
||||||
directives: [FrameComponent, FORM_DIRECTIVES],
|
directives: [FrameComponent, FORM_DIRECTIVES, UserMangerSettingsComponent],
|
||||||
providers: [AdminService],
|
|
||||||
pipes: [StringifyRole]
|
pipes: [StringifyRole]
|
||||||
})
|
})
|
||||||
export class AdminComponent implements OnInit {
|
export class AdminComponent implements OnInit {
|
||||||
|
|
||||||
private newUser = new User();
|
|
||||||
private userRoles:Array<any> = [];
|
|
||||||
private users:Array<User> = [];
|
|
||||||
userManagementEnable:boolean = false;
|
userManagementEnable:boolean = false;
|
||||||
|
|
||||||
constructor(private _authService:AuthenticationService, private _router:Router, private _adminService:AdminService) {
|
constructor(private _authService:AuthenticationService, private _router:Router) {
|
||||||
|
|
||||||
this.userManagementEnable = Config.Client.authenticationRequired;
|
this.userManagementEnable = Config.Client.authenticationRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,50 +29,8 @@ export class AdminComponent implements OnInit {
|
|||||||
this._router.navigate(['Login']);
|
this._router.navigate(['Login']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Config.Client.authenticationRequired === true) {
|
|
||||||
this.userRoles = Utils.enumToArray(UserRoles).filter(r => r.key <= this._authService.getUser().role);
|
|
||||||
this.getUsersList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getUsersList() {
|
|
||||||
this._adminService.getUsers().then((result:Message<Array<User>>) => {
|
|
||||||
this.users = result.result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
canModifyUser(user:User):boolean {
|
|
||||||
let currentUser = this._authService.getUser();
|
|
||||||
if (!currentUser) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentUser.name != user.name && currentUser.role >= user.role;
|
|
||||||
}
|
|
||||||
|
|
||||||
initNewUser() {
|
|
||||||
this.newUser = new User();
|
|
||||||
this.newUser.role = UserRoles.User;
|
|
||||||
}
|
|
||||||
|
|
||||||
addNewUser() {
|
|
||||||
this._adminService.createUser(this.newUser).then(() => {
|
|
||||||
this.getUsersList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateRole(user:User) {
|
|
||||||
this._adminService.updateRole(user).then(() => {
|
|
||||||
this.getUsersList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteUser(user:User) {
|
|
||||||
this._adminService.deleteUser(user).then(() => {
|
|
||||||
this.getUsersList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit {
|
|||||||
if (this.isAfterViewInit === false) {
|
if (this.isAfterViewInit === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.updateContainerWidth();
|
||||||
this.sortPhotos();
|
this.sortPhotos();
|
||||||
this.mergeNewPhotos();
|
this.mergeNewPhotos();
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
|
@ -57,21 +57,16 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, AfterViewInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.loading.show = true;
|
||||||
//set up befoar adding task to thumbnail generator
|
//set up befoar adding task to thumbnail generator
|
||||||
if (this.gridPhoto.isThumbnailAvailable()) {
|
if (this.gridPhoto.isThumbnailAvailable()) {
|
||||||
this.image.src = this.gridPhoto.getThumbnailPath();
|
this.image.src = this.gridPhoto.getThumbnailPath();
|
||||||
this.image.show = true;
|
this.image.show = true;
|
||||||
// this.loading.show = false;
|
} else if (this.gridPhoto.isReplacementThumbnailAvailable()) {
|
||||||
|
this.image.src = this.gridPhoto.getReplacementThumbnailPath();
|
||||||
} else {
|
this.image.show = true;
|
||||||
if (this.gridPhoto.isReplacementThumbnailAvailable()) {
|
|
||||||
this.image.src = this.gridPhoto.getReplacementThumbnailPath();
|
|
||||||
this.image.show = true;
|
|
||||||
this.loading.show = false;
|
|
||||||
} else {
|
|
||||||
this.loading.show = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
<div class="col-sm-offset-3 col-sm-6 col-lg-4 col-lg-offset-4">
|
<div class="col-sm-offset-3 col-sm-6 col-lg-4 col-lg-offset-4">
|
||||||
<form class="form-signin" #LoginForm="ngForm">
|
<form class="form-signin" #LoginForm="ngForm">
|
||||||
<h2 class="form-signin-heading">Please sign in</h2>
|
<h2 class="form-signin-heading">Please sign in</h2>
|
||||||
|
<div *ngIf="loginError">
|
||||||
|
{{loginError}}
|
||||||
|
</div>
|
||||||
<input type="text" class="form-control" placeholder="Username" autofocus
|
<input type="text" class="form-control" placeholder="Username" autofocus
|
||||||
[(ngModel)]="loginCredential.username" ngControl="name" #name="ngForm" required>
|
[(ngModel)]="loginCredential.username" ngControl="name" #name="ngForm" required>
|
||||||
<input type="password" class="form-control" placeholder="Password"
|
<input type="password" class="form-control" placeholder="Password"
|
||||||
|
@ -5,6 +5,9 @@ import {LoginCredential} from "../../../common/entities/LoginCredential";
|
|||||||
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
||||||
import {Router} from "@angular/router-deprecated";
|
import {Router} from "@angular/router-deprecated";
|
||||||
import {FORM_DIRECTIVES} from "@angular/common";
|
import {FORM_DIRECTIVES} from "@angular/common";
|
||||||
|
import {Message} from "../../../common/entities/Message";
|
||||||
|
import {User} from "../../../common/entities/User";
|
||||||
|
import {ErrorCodes} from "../../../common/entities/Error";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'login',
|
selector: 'login',
|
||||||
@ -14,6 +17,7 @@ import {FORM_DIRECTIVES} from "@angular/common";
|
|||||||
})
|
})
|
||||||
export class LoginComponent implements OnInit {
|
export class LoginComponent implements OnInit {
|
||||||
loginCredential:LoginCredential;
|
loginCredential:LoginCredential;
|
||||||
|
loginError = null;
|
||||||
|
|
||||||
constructor(private _authService:AuthenticationService, private _router:Router) {
|
constructor(private _authService:AuthenticationService, private _router:Router) {
|
||||||
this.loginCredential = new LoginCredential();
|
this.loginCredential = new LoginCredential();
|
||||||
@ -26,7 +30,14 @@ export class LoginComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onLogin() {
|
onLogin() {
|
||||||
this._authService.login(this.loginCredential);
|
this.loginError = null;
|
||||||
|
this._authService.login(this.loginCredential).then((message:Message<User>) => {
|
||||||
|
if (message.error) {
|
||||||
|
if (message.error.code === ErrorCodes.CREDENTIAL_NOT_FOUND) {
|
||||||
|
this.loginError = "Wrong username or password";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ export class AuthenticationService {
|
|||||||
//picking up session..
|
//picking up session..
|
||||||
if (this.isAuthenticated() == false && Cookie.get('pigallery2-session') != null) {
|
if (this.isAuthenticated() == false && Cookie.get('pigallery2-session') != null) {
|
||||||
if (typeof ServerInject !== "undefined" && typeof ServerInject.user !== "undefined") {
|
if (typeof ServerInject !== "undefined" && typeof ServerInject.user !== "undefined") {
|
||||||
console.log("user found");
|
|
||||||
this.setUser(ServerInject.user);
|
this.setUser(ServerInject.user);
|
||||||
}
|
}
|
||||||
this.getSessionUser();
|
this.getSessionUser();
|
||||||
@ -51,12 +50,13 @@ export class AuthenticationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public login(credential:LoginCredential) {
|
public login(credential:LoginCredential) {
|
||||||
this._userService.login(credential).then((message:Message<User>) => {
|
return this._userService.login(credential).then((message:Message<User>) => {
|
||||||
if (message.error) {
|
if (message.error) {
|
||||||
console.log(ErrorCodes[message.error.code] + ", message: " + message.error.message);
|
console.log(ErrorCodes[message.error.code] + ", message: " + message.error.message);
|
||||||
} else {
|
} else {
|
||||||
this.setUser(message.result);
|
this.setUser(message.result);
|
||||||
}
|
}
|
||||||
|
return message;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
frontend/app/notification.service.ts
Normal file
29
frontend/app/notification.service.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
///<reference path="../browser.d.ts"/>
|
||||||
|
|
||||||
|
import {Injectable} from "@angular/core";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NotificationService {
|
||||||
|
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public showException(message:string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public showError(message:string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public showWarn(message:string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public showInfo(message:string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">User management</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Role</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tr *ngFor="let user of users">
|
||||||
|
<td>{{user.name}}</td>
|
||||||
|
<td *ngIf="canModifyUser(user)">
|
||||||
|
<select class="form-control" [(ngModel)]="user.role" (ngModelChange)="updateRole(user)" required>
|
||||||
|
<option *ngFor="let repository of userRoles" [value]="repository.key">
|
||||||
|
{{repository.value}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td *ngIf="!canModifyUser(user)">
|
||||||
|
{{user.role | stringifyRole}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button *ngIf="canModifyUser(user)" (click)="deleteUser(user)"
|
||||||
|
class="btn btn-danger pull-right">
|
||||||
|
<span class="glyphicon glyphicon-trash" aria-hidden="true" aria-label="Delete"></span>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<button class="btn btn-default pull-right" data-toggle="modal" data-target="#myModal"
|
||||||
|
(click)="initNewUser()">+ Add
|
||||||
|
user
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
||||||
|
aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
|
||||||
|
</div>
|
||||||
|
<form (ngSubmit)="onSubmit()" #NewUserForm="ngForm">
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="text" class="form-control" placeholder="Username" autofocus
|
||||||
|
[(ngModel)]="newUser.name" ngControl="name" #name="ngForm" required>
|
||||||
|
<input type="password" class="form-control" placeholder="Password"
|
||||||
|
[(ngModel)]="newUser.password" ngControl="password" #name="ngForm" required>
|
||||||
|
<select class="form-control" [(ngModel)]="newUser.role" required>
|
||||||
|
<option *ngFor="let repository of userRoles" [value]="repository.key">{{repository.value}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
|
<button type="button" class="btn btn-primary" data-dismiss="modal"
|
||||||
|
(click)="addNewUser()"
|
||||||
|
[disabled]="!NewUserForm.form.valid">Add User
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,81 @@
|
|||||||
|
///<reference path="../../../browser.d.ts"/>
|
||||||
|
|
||||||
|
import {Component, OnInit} from "@angular/core";
|
||||||
|
import {AuthenticationService} from "../../model/network/authentication.service.ts";
|
||||||
|
import {Router} from "@angular/router-deprecated";
|
||||||
|
import {FrameComponent} from "../../frame/frame.component";
|
||||||
|
import {User, UserRoles} from "../../../../common/entities/User";
|
||||||
|
import {FORM_DIRECTIVES} from "@angular/common";
|
||||||
|
import {Utils} from "../../../../common/Utils";
|
||||||
|
import {Message} from "../../../../common/entities/Message";
|
||||||
|
import {StringifyRole} from "./../../pipes/StringifyRolePipe";
|
||||||
|
import {UserManagerSettingsService} from "./usermanager.settings.service";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'settings-usermanager',
|
||||||
|
templateUrl: 'app/settings/usermanager/usermanager.settings.component.html',
|
||||||
|
styleUrls: ['app/settings/usermanager/usermanager.settings.component.css'],
|
||||||
|
directives: [FrameComponent, FORM_DIRECTIVES],
|
||||||
|
providers: [UserManagerSettingsService],
|
||||||
|
pipes: [StringifyRole]
|
||||||
|
})
|
||||||
|
export class UserMangerSettingsComponent implements OnInit {
|
||||||
|
|
||||||
|
private newUser = new User();
|
||||||
|
private userRoles:Array<any> = [];
|
||||||
|
private users:Array<User> = [];
|
||||||
|
|
||||||
|
constructor(private _authService:AuthenticationService, private _router:Router, private _userSettings:UserManagerSettingsService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
if (!this._authService.isAuthenticated() || this._authService.getUser().role < UserRoles.Admin) {
|
||||||
|
this._router.navigate(['Login']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.userRoles = Utils.enumToArray(UserRoles).filter(r => r.key <= this._authService.getUser().role);
|
||||||
|
this.getUsersList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getUsersList() {
|
||||||
|
this._userSettings.getUsers().then((result:Message<Array<User>>) => {
|
||||||
|
this.users = result.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
canModifyUser(user:User):boolean {
|
||||||
|
let currentUser = this._authService.getUser();
|
||||||
|
if (!currentUser) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUser.name != user.name && currentUser.role >= user.role;
|
||||||
|
}
|
||||||
|
|
||||||
|
initNewUser() {
|
||||||
|
this.newUser = new User();
|
||||||
|
this.newUser.role = UserRoles.User;
|
||||||
|
}
|
||||||
|
|
||||||
|
addNewUser() {
|
||||||
|
this._userSettings.createUser(this.newUser).then(() => {
|
||||||
|
this.getUsersList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRole(user:User) {
|
||||||
|
this._userSettings.updateRole(user).then(() => {
|
||||||
|
this.getUsersList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteUser(user:User) {
|
||||||
|
this._userSettings.deleteUser(user).then(() => {
|
||||||
|
this.getUsersList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -3,8 +3,8 @@ import {BaseRequestOptions, Http} from "@angular/http";
|
|||||||
import {MockBackend} from "@angular/http/testing";
|
import {MockBackend} from "@angular/http/testing";
|
||||||
import {provide} from "@angular/core";
|
import {provide} from "@angular/core";
|
||||||
import "rxjs/Rx";
|
import "rxjs/Rx";
|
||||||
import {NetworkService} from "../model/network/network.service";
|
import {NetworkService} from "../../model/network/network.service";
|
||||||
import {AdminService} from "./admin.service";
|
import {UserManagerSettingsService} from "./usermanager.settings.service";
|
||||||
|
|
||||||
|
|
||||||
describe('AdminService', () => {
|
describe('AdminService', () => {
|
||||||
@ -19,7 +19,7 @@ describe('AdminService', () => {
|
|||||||
}, deps: [MockBackend, BaseRequestOptions]
|
}, deps: [MockBackend, BaseRequestOptions]
|
||||||
}),
|
}),
|
||||||
NetworkService,
|
NetworkService,
|
||||||
AdminService
|
UserManagerSettingsService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
|||||||
///<reference path="../../browser.d.ts"/>
|
///<reference path="../../../browser.d.ts"/>
|
||||||
|
|
||||||
import {Injectable} from "@angular/core";
|
import {Injectable} from "@angular/core";
|
||||||
import {NetworkService} from "../model/network/network.service.ts";
|
import {User} from "../../../../common/entities/User";
|
||||||
import {Message} from "../../../common/entities/Message";
|
import {NetworkService} from "../../model/network/network.service";
|
||||||
import {User} from "../../../common/entities/User";
|
import {Message} from "../../../../common/entities/Message";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AdminService {
|
export class UserManagerSettingsService {
|
||||||
|
|
||||||
|
|
||||||
constructor(private _networkService:NetworkService) {
|
constructor(private _networkService:NetworkService) {
|
Loading…
x
Reference in New Issue
Block a user