Commit 8d444326 authored by mechtelm's avatar mechtelm
Browse files

Show staff list

parent f3be6095
......@@ -5,6 +5,8 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/personaldb/dist" />
<excludeFolder url="file://$MODULE_DIR$/personaldb/tmp" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
......
......@@ -12,7 +12,7 @@ export class IsAdminGuard implements CanActivate {
) {
const req = context.switchToHttp().getRequest();
const userId = req.user.id;
const isAdmin = await this.authService.isAdminUser(userId);
const isAdmin = await this.authService.isAppAdminUser(userId);
if (!isAdmin) {
throw new UnauthorizedException();
}
......
......@@ -37,12 +37,8 @@ export class AppController {
type: AuthDataDto,
})
@ApiTags('auth')
async findCanDos(@UserId() userId: number, @UserName() userName: string): Promise<AuthDataDto> {
return <AuthDataDto>{
userId: userId,
userName: userName,
isAppAdmin: await this.authService.isAdminUser(userId)
}
async findCanDos(@UserId() userId: number): Promise<AuthDataDto> {
return await this.authService.getCanDos(userId)
}
@Patch('password')
......
import { Injectable } from '@nestjs/common';
import {JwtService} from "@nestjs/jwt";
import {UsersService} from "../../database/services/users.service";
import {AuthDataDto} from "../../../../../../libs/dto/src";
@Injectable()
export class AuthService {
......@@ -18,9 +19,23 @@ export class AuthService {
return this.jwtService.sign(payload);
}
async isAdminUser(userId: number): Promise<boolean> {
const isAdmin = await this.usersService.getUserIsAppAdmin(userId);
return isAdmin ? isAdmin : false;
async isAppAdminUser(userId: number): Promise<boolean> {
const canDos = await this.usersService.getCanDos(userId);
return canDos ? canDos.isAppAdmin : false;
}
async isPersonalAdminUser(userId: number): Promise<boolean> {
const canDos = await this.usersService.getCanDos(userId);
return canDos ? canDos.isPersonalAdmin : false;
}
async isCmsAdminUser(userId: number): Promise<boolean> {
const canDos = await this.usersService.getCanDos(userId);
return canDos ? canDos.isCmsAdmin : false;
}
async getCanDos(userId: number): Promise<AuthDataDto> {
return await this.usersService.getCanDos(userId);
}
async getMyName(id: number): Promise<string> {
......
......@@ -4,7 +4,7 @@ import {InjectRepository} from "@nestjs/typeorm";
import User from "../entities/user.entity";
import * as bcrypt from 'bcrypt';
import {passwordHash} from "../../auth/auth.constants";
import {CreateUserDto, UserFullDto, UserInListDto} from "../../../../../../libs/dto/src";
import {AuthDataDto, CreateUserDto, UserFullDto, UserInListDto} from "../../../../../../libs/dto/src";
@Injectable()
export class UsersService {
......@@ -61,7 +61,7 @@ export class UsersService {
return null
}
async getUserIsAppAdmin(userId: number): Promise<boolean | null> {
async getCanDos(userId: number): Promise<AuthDataDto | null> {
const user = await getConnection()
.getRepository(User)
.createQueryBuilder("user")
......@@ -69,7 +69,13 @@ export class UsersService {
{id: userId})
.getOne();
if (user) {
return user.isAppAdmin
return <AuthDataDto>{
userId: userId,
userName: user.name,
isAppAdmin: user.isAppAdmin,
isPersonalAdmin: user.isPersonalAdmin,
isCmsAdmin: user.isCmsAdmin
}
}
return null
}
......
......@@ -86,4 +86,4 @@ import {IqbComponentsModule} from "../../../../../libs/iqb-components/src";
EditUserComponent
]
})
export class AdminModule { }
export class AppAdminModule { }
export { AdminComponent } from './admin.component';
export { AdminModule } from './admin.module';
export { AppAdminModule } from './app-admin.module';
......@@ -149,8 +149,8 @@ export class UsersComponent implements OnInit {
if (newDescription !== selectedRows[0].description) changedData.description = newDescription;
if (newPassword) changedData.password = newPassword;
if (newIsAppAdmin !== selectedRows[0].isAppAdmin) changedData.isAppAdmin = newIsAppAdmin;
if (newIsPersonalAdmin !== selectedRows[0].isAppAdmin) changedData.isPersonalAdmin = newIsPersonalAdmin;
if (newIsCmsAdmin !== selectedRows[0].isAppAdmin) changedData.isCmsAdmin = newIsCmsAdmin;
if (newIsPersonalAdmin !== selectedRows[0].isPersonalAdmin) changedData.isPersonalAdmin = newIsPersonalAdmin;
if (newIsCmsAdmin !== selectedRows[0].isCmsAdmin) changedData.isCmsAdmin = newIsCmsAdmin;
this.backendService.changeUserData(changedData).subscribe(
respOk => {
this.updateUserList();
......
......@@ -8,8 +8,16 @@ const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{
path: 'admin',
loadChildren: () => import('./app-admin/admin.module').then(module => module.AdminModule)
path: 'app-admin',
loadChildren: () => import('./app-admin/app-admin.module').then(module => module.AppAdminModule)
},
{
path: 'personal-admin',
loadChildren: () => import('./personal-admin/personal-admin.module').then(module => module.PersonalAdminModule)
},
{
path: 'staff',
loadChildren: () => import('./staff-list/staff-list.module').then(module => module.StaffListModule)
}
];
......
......@@ -10,6 +10,7 @@
.box-right, .box-left {
padding: 20px;
margin: 10px;
min-height: 300px;
}
.box-right {
......
<div class="home-body" fxLayout="row" fxLayoutAlign="center stretch">
<div fxFlex="0 0 500px" fxLayout="column" *ngIf="appService.authData.userId === 0" class="box-left">
<!-- - - - - - - - - - - - - - - - - -->
<div class="home-body">
<div fxLayout="row" fxLayoutAlign="center stretch">
<mat-card fxFlex="0 0 400px" *ngIf="appService.authData.userId === 0" class="box-left">
<form [formGroup]="loginForm" (ngSubmit)="login()">
<h1>Anmelden</h1>
<h2 *ngIf="appService.globalWarning" class="warning">{{appService.globalWarning}}</h2>
<div fxLayout="column">
<mat-form-field class="full-width">
<input matInput formControlName="name" placeholder="Anmeldename" (keyup.enter)="pw.focus()">
</mat-form-field>
<mat-form-field class="full-width">
<input matInput #pw type="password" formControlName="pw" placeholder="Kennwort" (keyup.enter)="login()">
</mat-form-field>
</div>
<p *ngIf="errorMessage" class="error-message">{{errorMessage}}</p>
<button mat-raised-button type="submit" [disabled]="loginForm.invalid" color="primary">Weiter</button>
<mat-card-title>Anmelden</mat-card-title>
<mat-card-content>
<h2 *ngIf="appService.globalWarning" class="warning">{{appService.globalWarning}}</h2>
<div fxLayout="column">
<mat-form-field class="full-width">
<input matInput formControlName="name" placeholder="Anmeldename" (keyup.enter)="pw.focus()">
</mat-form-field>
<mat-form-field class="full-width">
<input matInput #pw type="password" formControlName="pw" placeholder="Kennwort" (keyup.enter)="login()">
</mat-form-field>
</div>
<p *ngIf="errorMessage" class="error-message">{{errorMessage}}</p>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button type="submit" [disabled]="loginForm.invalid" color="primary">Weiter</button>
</mat-card-actions>
</form>
</div>
</mat-card>
<div fxFlex="0 0 500px" fxLayout="column" class="box-left" *ngIf="appService.authData.userId > 0">
<h1 fxLayout="row" fxLayoutAlign="space-between center">
Arbeitsbereich wählen
<button mat-button *ngIf="appService.authData.isAppAdmin" [routerLink]="['/admin']"
matTooltip="Nutzer/Arbeitsbereiche">
<mat-card fxFlex="0 0 400px" fxLayout="column" class="box-left" *ngIf="appService.authData.userId > 0">
<mat-card-title fxLayout="row" fxLayoutAlign="space-between center">
Bitte wählen
<button mat-button *ngIf="appService.authData.isAppAdmin" [routerLink]="['/app-admin']"
matTooltip="Systemeinstellungen">
<mat-icon>settings</mat-icon>
</button>
<button mat-button *ngIf="appService.authData.isPersonalAdmin" [routerLink]="['/personal-admin']"
matTooltip="Einstellungen Personal">
<mat-icon>settings</mat-icon>
</button>
</h1>
<h2 *ngIf="appService.globalWarning" class="warning">{{appService.globalWarning}}</h2>
</mat-card-title>
<mat-card-content>
<h2 *ngIf="appService.globalWarning" class="warning">{{appService.globalWarning}}</h2>
<button mat-raised-button color="primary" [routerLink]="['/staff']">Personal-Daten</button>
</mat-card-content>
<div fxLayout="row" fxLayoutAlign="space-between center">
<button mat-raised-button color="foreground" (click)="changePassword()" matTooltip="Kennwort ändern">
<mat-card-actions fxLayout="row" fxLayoutAlign="space-between center">
<button mat-raised-button (click)="changePassword()" matTooltip="Kennwort ändern">
<mat-icon>account_box</mat-icon>Kennwort ändern
</button>
<button mat-raised-button color="foreground" (click)="logout()" matTooltip="Abmelden/Neu anmelden">
<button mat-raised-button (click)="logout()" matTooltip="Abmelden/Neu anmelden">
<mat-icon>logout</mat-icon>Abmelden
</button>
</div>
</div>
</mat-card-actions>
</mat-card>
<div fxFlex="0 2 500px" fxLayout="column" class="box-right">
<h1>{{appService.appConfig?.appTitle}}</h1>
<div [innerHTML]="appService.appConfig?.introHtml" class="scroll-area"></div>
<div *ngIf="appService.authData.userId === 0">
<ul>
<li>Kennung der Anwendung: {{appName}}</li>
<li>Version: {{appVersion}}</li>
<li>angemeldet als: {{ appService.authData.userName }}</li>
<li *ngIf="appService.authData.isAppAdmin">Berechtigung zum Ändern von Nutzerrechten und Arbeitsbereichen</li>
</ul>
</div>
<button mat-raised-button color="foreground" [routerLink]="['/about']">Impressum/Datenschutz</button>
</div>
<mat-card fxFlex="0 2 400px" fxLayout="column" class="box-right">
<mat-card-title>{{appService.appConfig?.appTitle}}</mat-card-title>
<mat-card-content>
<div [innerHTML]="appService.appConfig?.introHtml" class="scroll-area"></div>
<div *ngIf="appService.authData.userId === 0">
<ul>
<li>Kennung der Anwendung: {{appName}}</li>
<li>Version: {{appVersion}}</li>
<li>angemeldet als: {{ appService.authData.userName }}</li>
<li *ngIf="appService.authData.isAppAdmin">Berechtigung zum Ändern von Nutzerrechten und Arbeitsbereichen</li>
<li *ngIf="appService.authData.isPersonalAdmin">Berechtigung zum Ändern von Einstellungen für Personaldaten</li>
<li *ngIf="appService.authData.isCmsAdmin">Berechtigung zur Übernahme in das IDM der HU</li>
</ul>
</div>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" [routerLink]="['/about']">Impressum/Datenschutz</button>
</mat-card-actions>
</mat-card>
</div>
</div>
......@@ -63,6 +63,10 @@ export class HomeComponent implements OnInit, OnDestroy {
console.log(this.redirectTo);
if (this.redirectTo) {
this.router.navigate([this.redirectTo]);
} else {
if (this.appService.authData.isAppAdmin || this.appService.authData.isPersonalAdmin || this.appService.authData.isCmsAdmin) {
this.router.navigate(['/staff']);
}
}
},
err => {
......
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PersonalAdminComponent } from './personal-admin.component';
describe('PersonalAdminComponent', () => {
let component: PersonalAdminComponent;
let fixture: ComponentFixture<PersonalAdminComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PersonalAdminComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PersonalAdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'studio-lite-personal-admin',
templateUrl: './personal-admin.component.html',
styleUrls: ['./personal-admin.component.scss']
})
export class PersonalAdminComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PersonalAdminComponent } from './personal-admin.component';
@NgModule({
declarations: [
PersonalAdminComponent
],
imports: [
CommonModule
]
})
export class PersonalAdminModule { }
import { catchError } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Injectable, Inject } from '@angular/core';
import {StaffMemberInListDto} from "../../../../../libs/dto/src";
@Injectable({
providedIn: 'root'
})
export class BackendService {
constructor(
@Inject('SERVER_URL') private readonly serverUrl: string,
private http: HttpClient
) {}
getStaffList(): Observable <StaffMemberInListDto[]> {
return this.http
.get<StaffMemberInListDto[]>(`${this.serverUrl}staff`)
.pipe(
catchError(() => [])
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment