Compare commits

...

4 Commits

33 changed files with 231 additions and 278 deletions

View File

@@ -37,7 +37,7 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
return Ok(new AuthCheckDto(IsAuthenticated: User.Identity?.IsAuthenticated ?? false));
return Ok(User.Identity?.IsAuthenticated ?? false);
}
catch(Exception ex)
{

View File

@@ -117,8 +117,11 @@ namespace DigitalData.UserManager.API.Controllers
if (dirEntryUsername is null)
return Unauthorized();
var result = _dirSearchService.FindAllByUserCache(dirEntryUsername, filter, properties: propName);
return Ok(result);
return _dirSearchService.FindAllByUserCache(dirEntryUsername, filter, properties: propName).Then(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status424FailedDependency);
});
}
catch (Exception ex)
{
@@ -142,9 +145,11 @@ namespace DigitalData.UserManager.API.Controllers
if (filter is null)
return NotFound($"The filter named {filterName} does not exist.");
var result = _dirSearchService.FindAllByUserCache(dirEntryUsername, filter, properties: propName);
return Ok(result);
return _dirSearchService.FindAllByUserCache(dirEntryUsername, filter, properties: propName).Then(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status424FailedDependency);
});
}
catch (Exception ex)
{
@@ -168,9 +173,11 @@ namespace DigitalData.UserManager.API.Controllers
if (filter is null)
throw new InvalidOperationException("The LDAP Group Search filter configuration is missing in your appsettings. Please ensure it's added under DirectorySearch:CustomSearchFilters:Group to enable group searches.");
var result = _dirSearchService.FindAllByUserCache(username: dirEntryUsername, filter, properties: propName);
return Ok(result);
return _dirSearchService.FindAllByUserCache(username: dirEntryUsername, filter, properties: propName).Then(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status424FailedDependency);
});
}
catch (Exception ex)
{
@@ -195,15 +202,21 @@ namespace DigitalData.UserManager.API.Controllers
if (filter is null)
throw new InvalidOperationException("The LDAP User Search filter configuration is missing in your appsettings. Please ensure it's added under DirectorySearch:CustomSearchFilters:User to enable group searches.");
var result = _dirSearchService.FindAllByUserCache(username: dirEntryUsername, filter, properties: propName);
if (groupName is not null && result.IsSuccess && result.Data is not null)
result.Data = result.Data
.Where(rp => rp.PropertyNames.Cast<string>().Contains("memberof") &&
rp["memberof"].Cast<string>().Any(ldapDir => ldapDir.Contains(groupName)))
.ToList();
return Ok(result);
return _dirSearchService.FindAllByUserCache(username: dirEntryUsername, filter, properties: propName).Then(
Success: data =>
{
if (groupName is not null)
data = data
.Where(rp => rp.PropertyNames.Cast<string>().Contains("memberof") &&
rp["memberof"].Cast<string>().Any(ldapDir => ldapDir.Contains(groupName)))
.ToList();
return Ok(data);
},
Fail: IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status424FailedDependency);
});
}
catch (Exception ex)
{

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Group;
using DigitalData.UserManager.Domain.Entities;
@@ -19,15 +20,19 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.CreateAsync(adGroup);
if (result.IsSuccess)
{
var createdResource = new { Id = result.Data };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
}
return BadRequest(result);
return await _service.CreateAsync(adGroup).ThenAsync(
Success: id =>
{
var createdResource = new { Id = id };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
},
Fail: IActionResult (m, n) =>
{
_logger.LogNotice(n);
return BadRequest();
});
}
catch (Exception ex)
{

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.GroupOfUser;
using DigitalData.UserManager.Domain.Entities;
@@ -19,13 +20,11 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.DeleteAsyncByGroupUserId(groupId, userId);
if (result.IsSuccess)
return await _service.DeleteAsyncByGroupUserId(groupId, userId).ThenAsync(Ok, IActionResult (m, n) =>
{
return Ok(result);
}
return BadRequest(result);
_logger.LogNotice(n);
return BadRequest();
});
}
catch (Exception ex)
{
@@ -42,13 +41,11 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.ReadAllAsyncWith(withUser, withGroup);
if (result.IsSuccess)
return await _service.ReadAllAsyncWith(withUser, withGroup).ThenAsync(Ok, IActionResult (m, n) =>
{
return Ok(result);
}
return NotFound(result);
_logger.LogNotice(n);
return NotFound();
});
}
catch(Exception ex)
{
@@ -62,7 +59,11 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
return Ok(await _service.HasGroup(username, groupname));
return await _service.HasGroup(username, groupname).ThenAsync(Ok, (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch(Exception ex)
{

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.ModuleOfUser;
using DigitalData.UserManager.Domain.Entities;
@@ -19,13 +20,11 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.DeleteAsyncByModuleUserId(moduleId, userId);
if (result.IsSuccess)
return await _service.DeleteAsyncByModuleUserId(moduleId, userId).ThenAsync(Ok, IActionResult (m, n) =>
{
return Ok(result);
}
return BadRequest(result);
_logger.LogNotice(n);
return BadRequest();
});
}
catch(Exception ex)
{

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
@@ -19,8 +20,12 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = assigned ? await _service.ReadByModuleIdAsync(moduleId) : await _service.ReadUnassignedByModuleIdAsync(moduleId);
return Ok(result);
return await (assigned ? _service.ReadByModuleIdAsync(moduleId) : _service.ReadUnassignedByModuleIdAsync(moduleId))
.ThenAsync(Ok, IActionResult(m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch(Exception ex)
{
@@ -34,8 +39,12 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = assigned ? await _service.ReadByGroupIdAsync(groupId) : await _service.ReadUnassignedByGroupIdAsync(groupId); ;
return Ok(result);
return await (assigned ? _service.ReadByGroupIdAsync(groupId) : _service.ReadUnassignedByGroupIdAsync(groupId))
.ThenAsync(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch(Exception ex)
{
@@ -49,15 +58,19 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.CreateAsync(upDto);
if (result.IsSuccess)
{
var createdResource = new { Id = result.Data };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
}
return BadRequest(result);
return await _service.CreateAsync(upDto).ThenAsync(
Success: id =>
{
var createdResource = new { Id = id };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
},
Fail: IActionResult (m, n) =>
{
_logger.LogNotice(n);
return BadRequest();
});
}
catch(Exception ex)
{
@@ -71,12 +84,11 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.ReadByUsernameAsync(username);
if (result.IsSuccess)
return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) =>
{
return Ok(result);
}
return NotFound(result);
_logger.LogNotice(n);
return NotFound();
});
}
catch(Exception ex)
{

View File

@@ -1,4 +1,5 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.UserRep;
using DigitalData.UserManager.Domain.Entities;
@@ -26,14 +27,12 @@ namespace DigitalData.UserManager.API.Controllers
{
try
{
var result = await _service.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId);
if (result.IsSuccess)
return await _service.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId).ThenAsync(Ok, IActionResult (m, n) =>
{
return Ok(result);
}
return NotFound(result);
_logger.LogNotice(n);
return NotFound();
});
}
catch (Exception ex)
{

View File

@@ -4,7 +4,6 @@ import { Observable, of } from 'rxjs';
import { AuthenticationService } from '../services/authentication.service'; // Adjust the path as necessary
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { LoginComponent } from '../login/login.component';
import Swal from 'sweetalert2';
@Injectable({
providedIn: 'root',
@@ -47,4 +46,4 @@ export class AuthGuard implements CanActivate {
});
return dialogRef;
}
}
}

View File

@@ -1,10 +1,12 @@
import { AfterViewInit, Component, Inject, OnInit, ViewChild } from '@angular/core';
import { GuiRowSelection, GuiRowSelectionMode, GuiRowSelectionType } from '@generic-ui/ngx-grid';
import Swal from 'sweetalert2';
import { GroupService } from 'src/app/services/group.service';
import { forkJoin, of } from 'rxjs';
import { GroupService } from '../../services/group.service';
import { Observable, forkJoin, of } from 'rxjs';
import { catchError, finalize } from 'rxjs/operators';
import { DirGroupTableComponent } from '../tables/dir-group-table/dir-group-table.component';
import { DirGroupService } from '../../services/dir-group.service';
import { DirGroup } from '../../models/user-management.api.models';
@Component({
selector: 'app-group-dir-import',
@@ -40,15 +42,12 @@ export class GroupDirImportComponent implements OnInit, AfterViewInit {
}
addSelectedGroups() {
let requests = [];
let requests = new Array<Observable<DirGroup | null>>();
let numAdded: number = 0;
for (let row of this.dirGroups.selectedRows) {
// Create an Observable for each request and add it to the requests array
requests.push(
this.gService.createByDir({ samaccountname: row?.source?.samaccountname }).pipe(
catchError((err) => {
console.log(err);
// In case of error, return a 'null' observable for this request, so it doesn't affect other requests
return of(null);
})
)
@@ -72,13 +71,9 @@ export class GroupDirImportComponent implements OnInit, AfterViewInit {
})
).subscribe({
next: (results) => {
// Increment numAdded for each successful request
// You can increment numAdded for each result that is not null
numAdded += results.filter(result => result !== null).length;
},
error: (err) => {
// You may need to handle any potential errors here
console.log('An error occurred', err);
}
});
}

View File

@@ -2,17 +2,17 @@ import { AfterViewInit, Component, Inject, Input, OnDestroy, OnInit, ViewChild,
import { ApiService } from '../../../services/user-management.api.service';
import { GuiColumn, GuiColumnMenu, GuiSorting, GuiRowDetail, GuiPaging, GuiPagingDisplay, GuiSearching, GuiCellEdit, GuiInfoPanel, GuiTitlePanel, GuiRowSelection, GuiSelectedRow, GuiGridComponent, GuiGridApi, GuiTheme } from '@generic-ui/ngx-grid';
import { Subscription } from 'rxjs/internal/Subscription';
import { ColorModeService, Theme } from 'src/app/services/color-mode.service';
import { ColorModeService, Theme } from '../../../services/color-mode.service';
@Component({
selector: 'app-base-table',
templateUrl: './base-table.component.html',
styleUrl: './base-table.component.css'
})
export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>> implements OnInit, AfterViewInit, OnDestroy {
export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>> implements OnInit, AfterViewInit, OnDestroy {
service: TApiService;
columnMenu: GuiColumnMenu = {
enabled: true,
sort: true,
@@ -26,7 +26,7 @@ export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>>
loading: boolean = true;
autoResizeWidth: boolean = true;
rowDetail: GuiRowDetail = {
enabled : true,
enabled: true,
template: (item: TModel) => {
return `
<div></div>`;
@@ -59,25 +59,25 @@ export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>>
<div class='title-panel-example' >List of contract workers</div>
`;
}
};
};
theme: GuiTheme = localStorage.getItem('theme') === 'dark'? GuiTheme.DARK : GuiTheme.FABRIC;
theme: GuiTheme = localStorage.getItem('theme') === 'dark' ? GuiTheme.DARK : GuiTheme.FABRIC;
private themeSubscription: Subscription = new Subscription();
constructor(@Inject(ApiService<TModel>) service: TApiService, columns: Array<GuiColumn>, private cModeService: ColorModeService) {
this.service = service;
if(this.columns.length == 0)
if (this.columns.length == 0)
this.columns = columns;
//assign row details
if(this.rowDetailTemplate === null || this.rowDetailTemplate === undefined)
if (this.rowDetailTemplate === null || this.rowDetailTemplate === undefined)
this.rowDetail = {
enabled : false,
enabled: false,
};
else
this.rowDetail = {
enabled : true,
enabled: true,
template: (this.rowDetailTemplate)
};
}
@@ -101,40 +101,40 @@ export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>>
@Input() rowSelection: boolean | GuiRowSelection = true;
@Input() onSelectedRows: (rows: Array<GuiSelectedRow>) => void = (rows) => {};
@Input() initData : () => void = this.fetchData;
@Input() onSelectedRows: (rows: Array<GuiSelectedRow>) => void = (rows) => { };
@Input() initData: () => void = this.fetchData;
@Input() columns: Array<GuiColumn> = [];
selected: boolean = false;
safelyUnselectAll() {
this.selected = true
if(this.api?.getSelectedRows() != undefined)
if((this.api?.getSelectedRows().length ?? 0 > 0) && this.selected) {
this.api?.unselectAll()
this.selected = false
}
if (this.api?.getSelectedRows() != undefined)
if ((this.api?.getSelectedRows().length ?? 0 > 0) && this.selected) {
this.api?.unselectAll()
this.selected = false
}
}
@ViewChild('grid', { static: true }) mainGrid!: GuiGridComponent;
private get api() : GuiGridApi {
private get api(): GuiGridApi {
return this.mainGrid.api;
}
set source(data : TModel[]) {
set source(data: TModel[]) {
this.api.setSource(data)
}
get selectedRows(): Array<GuiSelectedRow> {
return this.api.getSelectedRows();
}
ngOnInit(): void {
const subscription = this.cModeService.themeChanges$.subscribe((theme: Theme) => {
this.theme = theme === 'dark'? GuiTheme.DARK : GuiTheme.FABRIC;
this.theme = theme === 'dark' ? GuiTheme.DARK : GuiTheme.FABRIC;
});
this.themeSubscription.add(subscription);
@@ -147,20 +147,14 @@ export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>>
ngAfterViewInit(): void {
}
fetchData(): void {
this.service.getAll().subscribe({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
this.loading = false;
} else {
// Handle response failure
console.error('Failed to fetch users');
}
this.source = response;
this.loading = false;
},
error: (error) => console.error('Error fetching users:', error)
error: (error) => {}
});
}
}
}

View File

@@ -1,9 +1,9 @@
import { Component, Inject } from '@angular/core';
import { BaseTableComponent } from '../base-table/base-table.component';
import { DirGroupService } from 'src/app/services/dir-group.service';
import { DirGroup } from 'src/app/models/user-management.api.models';
import { DirGroupService } from '../../../services/dir-group.service';
import { DirGroup } from '../../../models/user-management.api.models';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-dir-group-table',

View File

@@ -1,9 +1,9 @@
import { Component, Inject } from '@angular/core';
import { DirUser } from 'src/app/models/user-management.api.models';
import { DirUserService } from 'src/app/services/dir-user.service';
import { DirUser } from '../../../models/user-management.api.models';
import { DirUserService } from '../../../services/dir-user.service';
import { BaseTableComponent } from '../base-table/base-table.component';
import { GuiColumn } from '@generic-ui/ngx-grid/gui/grid/src/core/api/gui.grid.public-api';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-dir-user-table',
@@ -17,17 +17,11 @@ export class DirUserTableComponent extends BaseTableComponent<DirUser, DirUserSe
fetchDataByGroupName(groupName: string): void {
this.service.getAll(groupName).subscribe({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
this.loading = false;
} else {
// Handle response failure
this.loading = false;
console.error('Failed to fetch users');
}
next: (response: any) => {
this.source = response;
this.loading = false;
},
error: (error) => console.error('Error fetching users:', error)
error: (error: any) => {}
})
}
}

View File

@@ -3,7 +3,7 @@ import { GroupService } from '../../../services/group.service';
import { Group } from '../../../models/user-management.api.models';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-group-table',

View File

@@ -3,7 +3,7 @@ import { GroupOfUserService } from '../../../services/group-of-user.service';
import { GroupOfUser } from '../../../models/user-management.api.models';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-group-user-table',
@@ -20,14 +20,9 @@ export class GroupUserTableComponent extends BaseTableComponent<GroupOfUser, Gro
fetchDataWith(withUser: boolean, withGroup: boolean){
this.service.getAll(withUser, withGroup).subscribe ({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
} else {
// Handle response failure
console.error('Failed to fetch users');
}
this.source = response;
},
error: (error) => console.error('Error fetching users:', error)
error: (error) => {}
});
}
}

View File

@@ -3,7 +3,7 @@ import { Module } from '../../../models/user-management.api.models';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ModuleService } from '../../../services/module.service'
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-module-table',

View File

@@ -1,9 +1,9 @@
import { Component, Inject } from '@angular/core';
import { UserRep } from 'src/app/models/user-management.api.models';
import { UserRepService } from 'src/app/services/user-representation.service';
import { UserRep } from '../../../models/user-management.api.models';
import { UserRepService } from '../../../services/user-representation.service';
import { BaseTableComponent } from '../base-table/base-table.component';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service';
@Component({
selector: 'app-user-rep-table',
@@ -19,16 +19,11 @@ export class UserRepTableComponent extends BaseTableComponent<UserRep, UserRepSe
override fetchData(userId?: number): void {
this.service.getAll(false, true, true, true, userId).subscribe({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
this.loading = false;
} else {
// Handle response failure
console.error('Failed to fetch users');
}
next: (response: UserRep[]) => {
this.source = response;
this.loading = false;
},
error: (error) => console.error('Error fetching users:', error)
error: (error: any) => {}
});
}
}

View File

@@ -5,7 +5,7 @@ import { GroupOfUserService } from '../../../services/group-of-user.service';
import { User } from '../../../models/user-management.api.models';
import { GuiColumn } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ColorModeService } from 'src/app/services/color-mode.service';
import { ColorModeService } from '../../../services/color-mode.service'
@Component({
selector: 'app-user-table',
@@ -17,7 +17,11 @@ export class UserTableComponent extends BaseTableComponent<User, UserService> {
mosService: ModuleOfUserService;
gosService: GroupOfUserService;
constructor(mosService: ModuleOfUserService, gosService: GroupOfUserService, service: UserService, @Inject('USER_TABLE_COLUMNS') columns: Array<GuiColumn>, cModeService: ColorModeService) {
constructor(mosService: ModuleOfUserService,
gosService: GroupOfUserService,
service: UserService,
@Inject('USER_TABLE_COLUMNS') columns: Array<GuiColumn>,
cModeService: ColorModeService) {
super(service, columns, cModeService)
this.mosService = mosService;
this.gosService = gosService;
@@ -25,80 +29,57 @@ export class UserTableComponent extends BaseTableComponent<User, UserService> {
fetchDataByModuleId(moduleId: number, assigned: boolean = true): void {
this.service.getByModuleId(moduleId, assigned).subscribe({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
} else {
// Handle response failure
console.error('Failed to fetch users');
}
next: (users) => {
this.source = users;
},
error: (error) => console.error('Error fetching users:', error)
error: (error) => {}
});
}
fetchDataByGroupId(groupId: number, assigned: boolean = true): void {
this.service.getByGroupId(groupId, assigned).subscribe({
next: (response) => {
if (response.isSuccess && response.data) {
this.source = response.data;
} else {
// Handle response failure
console.error('Failed to fetch users');
}
next: (users) => {
this.source = users;
},
error: (error) => console.error('Error fetching users:', error)
error: (error) => {}
});
}
async createModuleOfUsers(moduleId: number, users: User[]): Promise<any[]> {
const creationPromises = users
.filter(user => user.guid && user.guid != null)
.map(user => this.mosService.create({ moduleId: moduleId, userId: user.guid??-1, addedWho:"DEFAULT" }).toPromise());
.map(user => this.mosService.create({ moduleId: moduleId, userId: user.guid ?? -1, addedWho: "DEFAULT" }).toPromise());
return Promise.all(creationPromises);
}
}
async createGroupOfUsers(groupId: number, users: User[]): Promise<any[]> {
const creationPromises = users
.filter(user => user.guid && user.guid != null)
.map(user => this.gosService.create({ groupId: groupId, userId: user.guid??-1, addedWho:"DEFAULT" }).toPromise());
.map(user => this.gosService.create({ groupId: groupId, userId: user.guid ?? -1, addedWho: "DEFAULT" }).toPromise());
return Promise.all(creationPromises);
}
}
async deleteModuleOfUsers(moduleId: number, users: User[]): Promise<void> {
const deletionPromises = users
.filter(user => user.guid)
.map(user => this.mosService.deleteByModuleGroupId(moduleId, user.guid??-1).toPromise());
.map(user => this.mosService.deleteByModuleGroupId(moduleId, user.guid ?? -1).toPromise());
try {
const responses = await Promise.all(deletionPromises);
responses.forEach(response => {
if (!response?.isSuccess) {
console.error(response?.messages);
}
});
} catch (error) {
console.error('Error deleting module of users:', error);
}
}
async deleteGroupOfUsers(groupId: number, users: User[]): Promise<void> {
const deletionPromises = users
.filter(user => user.guid)
.map(user => this.gosService.deleteByGroupUserId(groupId, user.guid??-1).toPromise());
.map(user => this.gosService.deleteByGroupUserId(groupId, user.guid ?? -1).toPromise());
try {
const responses = await Promise.all(deletionPromises);
responses.forEach(response => {
if (!response?.isSuccess) {
console.error(response?.messages);
}
});
} catch (error) {
console.error('Error deleting group of users:', error);
}
}
}
}

View File

@@ -1,12 +1,13 @@
import { AfterViewInit, Component, Inject, OnInit, ViewChild } from '@angular/core';
import { GuiRowSelection, GuiRowSelectionMode, GuiRowSelectionType, GuiSelectedRow } from '@generic-ui/ngx-grid';
import Swal from 'sweetalert2';
import { GroupService } from 'src/app/services/group.service';
import { forkJoin, of } from 'rxjs';
import { GroupService } from '../../services/group.service';
import { Observable, forkJoin, of } from 'rxjs';
import { catchError, finalize } from 'rxjs/operators';
import { DirGroupTableComponent } from '../tables/dir-group-table/dir-group-table.component';
import { DirUserTableComponent } from '../tables/dir-user-table/dir-user-table.component';
import { UserService } from 'src/app/services/user.service';
import { UserService } from '../../services/user.service';
import {User} from '../../models/user-management.api.models'
@Component({
selector: 'app-user-group-dir-import',
@@ -43,10 +44,9 @@ export class UserGroupDirImportComponent implements OnInit, AfterViewInit {
}
addSelectedUsers() {
let requests = [];
let requests = new Array<Observable<User | null>>();
let numAdded: number = 0;
for (let row of this.dirUsers.selectedRows) {
console.log(row)
// Create an Observable for each request and add it to the requests array
requests.push(
this.uService.create({
@@ -56,8 +56,6 @@ export class UserGroupDirImportComponent implements OnInit, AfterViewInit {
name: row.source?.sn?.[0],
}).pipe(
catchError((err) => {
console.log('An error occurred', err);
// In case of error, return a 'null' observable for this request, so it doesn't affect other requests
return of(null);
})
)
@@ -81,13 +79,9 @@ export class UserGroupDirImportComponent implements OnInit, AfterViewInit {
})
).subscribe({
next: (results) => {
// Increment numAdded for each successful request
// You can increment numAdded for each result that is not null
numAdded += results.filter(result => result !== null).length;
},
error: (err) => {
// You may need to handle any potential errors here
console.log('An error occurred', err);
}
});
}

View File

@@ -3,7 +3,7 @@ import { GuiColumn, GuiSelectedRow } from '@generic-ui/ngx-grid/gui/grid/src/cor
import { UserTableComponent } from '../tables/user-table/user-table.component';
import { UserRepTableComponent } from '../tables/user-rep-table/user-rep-table.component';
import { GroupTableComponent } from '../tables/group-table/group-table.component';
import { UserRepService } from 'src/app/services/user-representation.service';
import { UserRepService } from '../../services/user-representation.service';
import Swal from 'sweetalert2';
@Component({

View File

@@ -12,12 +12,9 @@ export class UserComponent {
cellEditing: GuiCellEdit = {
enabled: true,
rowEdit: (value: any, item: any, index: number) => {
console.log("rowEdit", value, item, index)
console.log(this.userTable.selectedRows)
return Boolean(index % 2);
},
cellEdit: (value: any, item: any, index: number) => {
console.log("cellEdit", value, item, index)
return Boolean(index % 5);
}
}

View File

@@ -1,8 +0,0 @@
export interface ApiMessage {
isSuccess: boolean;
messages: string[];
}
export interface ApiResult<T> extends ApiMessage {
data?: T;
}

View File

@@ -76,8 +76,4 @@ export interface DirUser {
sn?: Array<string>;
mail?: string;
addedWho?: string;
}
export interface AuthCheckDto {
isAuthenticated: boolean;
}

View File

@@ -60,7 +60,6 @@ export class NavMenuComponent {
}
},
error: (err) => {
console.error("unexpected err happend", err)
}
})
}

View File

@@ -1,8 +1,6 @@
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { ApiMessage, ApiResult } from '../models/api.response.model';
import { AuthCheckDto } from '../models/user-management.api.models';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';
import Swal from 'sweetalert2';
@@ -10,15 +8,20 @@ import Swal from 'sweetalert2';
providedIn: 'root',
})
export class AuthenticationService {
constructor(private router: Router, private http: HttpClient, @Inject('LOGIN_URL') private loginUrl: string, @Inject('LOGOUT_URL') private logoutUrl: string, @Inject('LOGIN_CHECK_URL') private checkUrl: string) { }
constructor(
private router: Router,
private http: HttpClient,
@Inject('LOGIN_URL') private loginUrl: string,
@Inject('LOGOUT_URL') private logoutUrl: string,
@Inject('LOGIN_CHECK_URL') private checkUrl: string) { }
isAuthenticated(): Observable<boolean> {
return new Observable(observer => {
this.http.get<AuthCheckDto>(this.checkUrl, { withCredentials: true })
this.http.get<boolean>(this.checkUrl, { withCredentials: true })
.subscribe({
next: (response) => {
_isLogedIn = response.isAuthenticated;
observer.next(response.isAuthenticated)
_isLogedIn = response;
observer.next(response)
},
error: (error) => {
this.showErrorAlert()
@@ -50,9 +53,9 @@ export class AuthenticationService {
});
}
logout(): Observable<ApiMessage> {
logout(): Observable<any> {
return new Observable(observer => {
this.http.post<ApiMessage>(this.logoutUrl, {}, { withCredentials: true })
this.http.post<any>(this.logoutUrl, {}, { withCredentials: true })
.subscribe({
next: (response) => {
this.router.navigate(['/']);

View File

@@ -1,8 +1,7 @@
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DirGroup, DirUser } from '../models/user-management.api.models';
import { DirGroup, } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { ApiResult } from '../models/api.response.model';
import { Observable } from 'rxjs/internal/Observable';
import Swal from 'sweetalert2';
@@ -14,21 +13,20 @@ export class DirGroupService extends ApiService<DirGroup> {
super(http, userUri);
}
override getAll(): Observable<ApiResult<DirGroup[]>> {
return new Observable(observer => {
//TODO: Swal.fire
override getAll(): Observable<DirGroup[]> {
return new Observable<DirGroup[]>(observer => {
super.getAll()
.subscribe({
next: (response) => {
if(!response.isSuccess || !response.data) {
Swal.fire({
icon: "error",
title: "Oops...",
text: `Active Directory-Verbindung verloren. Bitte melden Sie sich erneut an`,
});
}
observer.next(response)
},
error: (error) => {
Swal.fire({
icon: "error",
title: "Oops...",
text: `Active Directory-Verbindung verloren. Bitte melden Sie sich erneut an`,
});
observer.error(error)
},
complete: () => observer.complete()

View File

@@ -3,7 +3,6 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { DirUser } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { Observable } from 'rxjs/internal/Observable';
import { ApiResult } from '../models/api.response.model';
@Injectable({
providedIn: 'root'
@@ -13,12 +12,12 @@ export class DirUserService extends ApiService<DirUser> {
super(http, userUri);
}
override getAll(groupName?: string): Observable<ApiResult<DirUser[]>> {
override getAll(groupName?: string): Observable<DirUser[]> {
let params = new HttpParams();
if (groupName) {
params = params.set('groupName', groupName);
}
return this.http.get<ApiResult<DirUser[]>>(this.baseUrl, { params, withCredentials: true });
return this.http.get<DirUser[]>(this.baseUrl, { params, withCredentials: true });
}
}

View File

@@ -1,6 +1,5 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApiResult } from '../models/api.response.model';
import { Inject, Injectable } from '@angular/core';
import { DirUser } from '../models/user-management.api.models';
@@ -12,12 +11,12 @@ export class DirService {
this.http = http;
}
getUser(groupName: string): Observable<ApiResult<DirUser[]>> {
getUser(groupName: string): Observable<DirUser[]> {
let params = new HttpParams();
if (groupName) {
params = params.set('groupName', groupName);
}
return this.http.get<ApiResult<DirUser[]>>(this.baseUrl, { params, withCredentials: true });
return this.http.get<DirUser[]>(this.baseUrl, { params, withCredentials: true });
}
}

View File

@@ -2,7 +2,6 @@ import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { GroupOfUser } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { ApiResult } from '../models/api.response.model';
import { Observable } from 'rxjs';
@Injectable({
@@ -13,12 +12,12 @@ export class GroupOfUserService extends ApiService<GroupOfUser> {
super(http, userUri);
}
deleteByGroupUserId(groupId: number, userId: number): Observable<ApiResult<any>> {
deleteByGroupUserId(groupId: number, userId: number): Observable<any> {
const url = `${this.baseUrl}?groupId=${groupId}&userId=${userId}`;
return this.http.delete<ApiResult<any>>(url, { withCredentials: true });
return this.http.delete<any>(url, { withCredentials: true });
}
override getAll(withUser: boolean = false, withGroup: boolean = false): Observable<ApiResult<GroupOfUser[]>> {
override getAll(withUser: boolean = false, withGroup: boolean = false): Observable<GroupOfUser[]> {
let params = new HttpParams();
if (withUser) {
params = params.set('withUser', withUser);
@@ -27,6 +26,6 @@ export class GroupOfUserService extends ApiService<GroupOfUser> {
params = params.set('withGroup', withGroup);
}
return this.http.get<ApiResult<GroupOfUser[]>>(this.baseUrl, { params, withCredentials: true });
return this.http.get<GroupOfUser[]>(this.baseUrl, { params, withCredentials: true });
}
}

View File

@@ -2,7 +2,6 @@ import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ModuleOfUser } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { ApiResult } from '../models/api.response.model';
import { Observable } from 'rxjs';
@Injectable({
@@ -13,8 +12,8 @@ export class ModuleOfUserService extends ApiService<ModuleOfUser> {
super(http, userUri);
}
deleteByModuleGroupId(moduleId: number, userId: number): Observable<ApiResult<any>> {
deleteByModuleGroupId(moduleId: number, userId: number): Observable<any> {
const url = `${this.baseUrl}?moduleId=${moduleId}&userId=${userId}`;
return this.http.delete<ApiResult<any>>(url, { withCredentials: true });
return this.http.delete<any>(url, { withCredentials: true });
}
}

View File

@@ -1,6 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApiResult } from '../models/api.response.model';
import { Inject, Injectable } from '@angular/core';
@Injectable({
@@ -15,26 +14,26 @@ export class ApiService<Model> {
http: HttpClient;
baseUrl: string;
getAll(): Observable<ApiResult<Model[]>> {
return this.http.get<ApiResult<Model[]>>(this.baseUrl, { withCredentials: true });
getAll(): Observable<Model[]> {
return this.http.get<Model[]>(this.baseUrl, { withCredentials: true });
}
getById(id: number): Observable<ApiResult<Model>> {
getById(id: number): Observable<Model> {
const url = `${this.baseUrl}/${id}`;
return this.http.get<ApiResult<Model>>(url, { withCredentials: true });
return this.http.get<Model>(url, { withCredentials: true });
}
create(createModel: Model): Observable<Model> {
return this.http.post<Model>(this.baseUrl, createModel, { withCredentials: true });
}
update(updateModel: Model): Observable<ApiResult<Model>> {
update(updateModel: Model): Observable<Model> {
const url = `${this.baseUrl}`;
return this.http.put<ApiResult<Model>>(url, updateModel, { withCredentials: true });
return this.http.put<Model>(url, updateModel, { withCredentials: true });
}
delete(id: number): Observable<ApiResult<any>> {
delete(id: number): Observable<any> {
const url = `${this.baseUrl}/${id}`;
return this.http.delete<ApiResult<any>>(url, { withCredentials: true });
return this.http.delete<any>(url, { withCredentials: true });
}
}

View File

@@ -2,7 +2,6 @@ import { Inject, Injectable } from "@angular/core";
import { UserRep } from "../models/user-management.api.models";
import { ApiService } from "./user-management.api.service";
import { HttpClient, HttpParams } from "@angular/common/http";
import { ApiResult } from "../models/api.response.model";
import { Observable } from "rxjs";
@Injectable({
@@ -13,7 +12,7 @@ export class UserRepService extends ApiService<UserRep> {
super(http, userRepUri)
}
override getAll(withUser: boolean = false, withRepGroup: boolean = false, withRightGroup: boolean = false, withRepUser: boolean = false, userId?: number): Observable<ApiResult<UserRep[]>> {
override getAll(withUser: boolean = false, withRepGroup: boolean = false, withRightGroup: boolean = false, withRepUser: boolean = false, userId?: number): Observable<UserRep[]> {
let params = new HttpParams();
if (withUser) {
params = params.set('withUser', withUser);
@@ -31,6 +30,6 @@ export class UserRepService extends ApiService<UserRep> {
params = params.set('userId', userId)
}
return this.http.get<ApiResult<UserRep[]>>(`${this.baseUrl}`, { params: params, withCredentials: true });
return this.http.get<UserRep[]>(`${this.baseUrl}`, { params: params, withCredentials: true });
}
}

View File

@@ -3,7 +3,6 @@ import { HttpClient } from '@angular/common/http';
import { DirUser, User } from '../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { Observable } from 'rxjs';
import { ApiResult } from '../models/api.response.model';
@Injectable({
providedIn: 'root'
@@ -13,18 +12,17 @@ export class UserService extends ApiService<User> {
super(http, userUri);
}
getByModuleId(moduleId: number, assigned: boolean = true): Observable<ApiResult<User[]>> {
getByModuleId(moduleId: number, assigned: boolean = true): Observable<User[]> {
const url = `${this.baseUrl}/ByModuleId/${moduleId}?assigned=${assigned}`;
return this.http.get<ApiResult<User[]>>(url, { withCredentials: true });
return this.http.get<User[]>(url, { withCredentials: true });
}
getByGroupId(groupId: number, assigned: boolean = true): Observable<ApiResult<User[]>> {
getByGroupId(groupId: number, assigned: boolean = true): Observable<User[]> {
const url = `${this.baseUrl}/ByGroupId/${groupId}?assigned=${assigned}`;
return this.http.get<ApiResult<User[]>>(url, { withCredentials: true });
return this.http.get<User[]>(url, { withCredentials: true });
}
createByDir(createModel: DirUser): Observable<DirUser> {
console.log(createModel)
return this.http.post<DirUser>(`${this.baseUrl}/byDir`, createModel, { withCredentials: true });
}
}

View File

@@ -184,4 +184,4 @@ if (environment.production) {
}
platformBrowserDynamic(providers).bootstrapModule(AppModule)
.catch(err => console.log(err));
.catch(err => {});