Skip to content

Commit

Permalink
refactor: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
llorentelemmc committed Nov 10, 2024
1 parent 0a44d26 commit 305be7d
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 75 deletions.
2 changes: 2 additions & 0 deletions AMW_angular/io/src/app/resource/resource-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface ResourceType {
id: number;
name: string;
hasChildren: boolean;
children: ResourceType[];
}
12 changes: 0 additions & 12 deletions AMW_angular/io/src/app/resource/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Resource } from './resource';
import { ResourceType } from './resource-type';
import { Release } from './release';
import { Relation } from './relation';
import { Property } from './property';
Expand Down Expand Up @@ -66,17 +65,6 @@ export class ResourceService extends BaseService {
);
}

getAllResourceTypes(): Observable<ResourceType[]> {
return this.http
.get<ResourceType[]>(`${this.getBaseUrl()}/resources/resourceTypes`, {
headers: this.getHeaders(),
})
.pipe(
map((resources) => resources.map(toResource)),
catchError(this.handleError),
);
}

getByType(type: string): Observable<Resource[]> {
return this.http
.get<Resource[]>(`${this.getBaseUrl()}/resources?type=${type}`, {
Expand Down
8 changes: 6 additions & 2 deletions AMW_angular/io/src/app/resources/resource-types.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, Signal } from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, startWith, Subject } from 'rxjs';
import { toSignal } from '@angular/core/rxjs-interop';
import { shareReplay, switchMap } from 'rxjs/operators';
import { ResourceType } from './resourceType';
import { BaseService } from '../base/base.service';
import { ResourceType } from '../resource/resource-type';

@Injectable({ providedIn: 'root' })
export class ResourceTypesService extends BaseService {
Expand All @@ -25,6 +25,10 @@ export class ResourceTypesService extends BaseService {
super();
}

getAllResourceTypes(): Observable<ResourceType[]> {
return this.http.get<ResourceType[]>(`${this.getBaseUrl()}/resources/resourceTypes`);
}

getPredefinedResourceTypes(): Observable<ResourceType[]> {
return this.http.get<ResourceType[]>(`${this.getBaseUrl()}/resources/predefinedResourceTypes`);
}
Expand Down
4 changes: 0 additions & 4 deletions AMW_angular/io/src/app/resources/resourceType.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
>}
</nav>
<nav class="nav flex-column">
@for (resourceType of rootResourceTypes(); track resourceType.name){<a href="#">{{ resourceType.name }}</a
>}
@for (resourceType of rootResourceTypes(); track resourceType.name){
<a href="#">
{{ resourceType.name }}
@if (resourceType.hasChildren) {<span class="plus-sign">+</span>}
</a>
}
</nav>
</div></app-page
>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component, computed, inject, Signal, signal }
import { AuthService } from '../auth/auth.service';
import { PageComponent } from '../layout/page/page.component';
import { LoadingIndicatorComponent } from '../shared/elements/loading-indicator.component';
import { ResourceType } from './resourceType';
import { ResourceTypesService } from './resource-types.service';
import { ResourceType } from '../resource/resource-type';

@Component({
selector: 'app-resources-page',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Restriction } from './restriction';
import { Tag } from './tag';
import { EnvironmentService } from '../../deployment/environment.service';
import { ResourceService } from '../../resource/resource.service';
import { ResourceTypesService } from '../../resources/resource-types.service';
import { Environment } from 'src/app/deployment/environment';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
Expand All @@ -27,6 +28,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
let permissionService: PermissionService;
let environmentService: EnvironmentService;
let resourceService: ResourceService;
let resourceTypesService: ResourceTypesService;

const mockRoute: any = { snapshot: {} };
mockRoute.params = new Subject<any>();
Expand All @@ -50,6 +52,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
EnvironmentService,
PermissionService,
ResourceService,
ResourceTypesService,
{ provide: ActivatedRoute, useValue: mockRoute },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
Expand All @@ -63,6 +66,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
permissionService = TestBed.inject(PermissionService);
environmentService = TestBed.inject(EnvironmentService);
resourceService = TestBed.inject(ResourceService);
resourceTypesService = TestBed.inject(ResourceTypesService);
});

it('should have default data', () => {
Expand All @@ -80,7 +84,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
} as Environment,
]);
expect(component.resourceGroups).toEqual([]);
expect(component.resourceTypes).toEqual([{ id: null, name: null }]);
expect(component.resourceTypes).toEqual([{ id: null, name: null, hasChildren: false, children: [] }]);
expect(component.restrictionType).toEqual('role');
});

Expand All @@ -98,7 +102,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
spyOn(permissionService, 'getAllPermissionEnumValues').and.returnValue(of(permissions));
spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments));
spyOn(resourceService, 'getAllResourceGroups').and.callThrough();
spyOn(resourceService, 'getAllResourceTypes').and.callThrough();
spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough();
// when
component.ngOnInit();
mockRoute.params.next({ restrictionType: 'role' });
Expand All @@ -109,7 +113,7 @@ describe('PermissionComponent without any params (default: type Role)', () => {
expect(permissionService.getAllPermissionEnumValues).toHaveBeenCalled();
expect(environmentService.getAllIncludingGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceTypes).toHaveBeenCalled();
expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled();
expect(component.permissions).toEqual(permissions);
expect(component.restriction).toBeNull();
expect(component.groupedEnvironments['All']).toContain({
Expand Down Expand Up @@ -402,6 +406,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => {
let permissionService: PermissionService;
let environmentService: EnvironmentService;
let resourceService: ResourceService;
let resourceTypesService: ResourceTypesService;

const mockRoute: any = { snapshot: {} };
mockRoute.params = new Subject<any>();
Expand All @@ -424,6 +429,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => {
EnvironmentService,
PermissionService,
ResourceService,
ResourceTypesService,
{ provide: ActivatedRoute, useValue: mockRoute },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
Expand All @@ -436,6 +442,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => {
permissionService = TestBed.inject(PermissionService);
environmentService = TestBed.inject(EnvironmentService);
resourceService = TestBed.inject(ResourceService);
resourceTypesService = TestBed.inject(ResourceTypesService);
});

it('should invoke some services on ngOnInt', () => {
Expand All @@ -452,7 +459,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => {
spyOn(permissionService, 'getAllPermissionEnumValues').and.returnValue(of(permissions));
spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments));
spyOn(resourceService, 'getAllResourceGroups').and.callThrough();
spyOn(resourceService, 'getAllResourceTypes').and.callThrough();
spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough();
spyOn(permissionService, 'getAllUserRestrictionNames').and.callThrough();
// when
component.ngOnInit();
Expand All @@ -463,7 +470,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => {
expect(permissionService.getAllPermissionEnumValues).toHaveBeenCalled();
expect(environmentService.getAllIncludingGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceTypes).toHaveBeenCalled();
expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled();
expect(permissionService.getAllUserRestrictionNames).toHaveBeenCalled();
expect(component.permissions).toEqual(permissions);
expect(component.restriction).toBeNull();
Expand Down Expand Up @@ -502,6 +509,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => {
let permissionService: PermissionService;
let environmentService: EnvironmentService;
let resourceService: ResourceService;
let resourceTypesService: ResourceTypesService;

const mockRoute: any = { snapshot: {} };
mockRoute.params = new Subject<any>();
Expand All @@ -524,6 +532,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => {
EnvironmentService,
PermissionService,
ResourceService,
ResourceTypesService,
{ provide: ActivatedRoute, useValue: mockRoute },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
Expand All @@ -536,6 +545,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => {
permissionService = TestBed.inject(PermissionService);
environmentService = TestBed.inject(EnvironmentService);
resourceService = TestBed.inject(ResourceService);
resourceTypesService = TestBed.inject(ResourceTypesService);
});
it('should invoke some services on ngOnInt', () => {
// given
Expand Down Expand Up @@ -565,7 +575,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => {
spyOn(permissionService, 'getOwnUserAndRoleRestrictions').and.returnValue(of(restrictions));
spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments));
spyOn(resourceService, 'getAllResourceGroups').and.callThrough();
spyOn(resourceService, 'getAllResourceTypes').and.callThrough();
spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough();
// when
component.ngOnInit();
mockRoute.params.next({ actingUser: 'testUser' });
Expand All @@ -578,7 +588,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => {
expect(component.userNames).not.toContain('testUser');
expect(environmentService.getAllIncludingGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceGroups).toHaveBeenCalled();
expect(resourceService.getAllResourceTypes).toHaveBeenCalled();
expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled();
expect(permissionService.getOwnUserAndRoleRestrictions).toHaveBeenCalled();
expect(component.assignableRestrictions).toEqual(restrictions);
expect(component.assignablePermissions).toEqual(permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '@ng-bootstrap/ng-bootstrap';
import { LoadingIndicatorComponent } from '../../shared/elements/loading-indicator.component';
import { ButtonComponent } from '../../shared/button/button.component';
import { ResourceTypesService } from '../../resources/resource-types.service';

@Component({
selector: 'app-permission',
Expand Down Expand Up @@ -62,7 +63,7 @@ export class PermissionComponent implements OnInit {
Global: [],
};
resourceGroups: Resource[] = [];
resourceTypes: ResourceType[] = [{ id: null, name: null }];
resourceTypes: ResourceType[] = [{ id: null, name: null, hasChildren: false, children: [] }];

defaultNavItem: string = 'Roles';
// role | user
Expand Down Expand Up @@ -90,6 +91,7 @@ export class PermissionComponent implements OnInit {
private permissionService: PermissionService,
private environmentService: EnvironmentService,
private resourceService: ResourceService,
private resourceTypesService: ResourceTypesService,
private activatedRoute: ActivatedRoute,
private location: Location,
) {
Expand Down Expand Up @@ -392,7 +394,7 @@ export class PermissionComponent implements OnInit {

private getAllResourceTypes() {
this.isLoading = true;
this.resourceService.getAllResourceTypes().subscribe({
this.resourceTypesService.getAllResourceTypes().subscribe({
next: (r) => (this.resourceTypes = this.resourceTypes.concat(r)),
error: (e) => (this.errorMessage = e),
complete: () => (this.isLoading = false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,24 @@ describe('RestrictionAddComponent', () => {
// given
restrictionComponent.delegationMode = true;
restrictionComponent.resourceTypes = [
{ id: 1, name: 'APP' },
{ id: 2, name: 'AS' },
{ id: 3, name: 'FOO' },
{
id: 1,
name: 'APP',
hasChildren: false,
children: [],
},
{
id: 2,
name: 'AS',
hasChildren: false,
children: [],
},
{
id: 3,
name: 'FOO',
hasChildren: false,
children: [],
},
];
restrictionComponent.selectedPermissionNames = ['NEO'];
restrictionComponent.selectedContextNames = ['T', 'S'];
Expand Down Expand Up @@ -262,9 +277,24 @@ describe('RestrictionAddComponent', () => {
// given
restrictionComponent.delegationMode = true;
restrictionComponent.resourceTypes = [
{ id: 1, name: 'APP' },
{ id: 2, name: 'AS' },
{ id: 3, name: 'FOO' },
{
id: 1,
name: 'APP',
hasChildren: false,
children: [],
},
{
id: 2,
name: 'AS',
hasChildren: false,
children: [],
},
{
id: 3,
name: 'FOO',
hasChildren: false,
children: [],
},
];
restrictionComponent.selectedPermissionNames = ['NEO'];
restrictionComponent.selectedContextNames = ['T'];
Expand Down Expand Up @@ -306,9 +336,24 @@ describe('RestrictionAddComponent', () => {
// given
restrictionComponent.delegationMode = true;
restrictionComponent.resourceTypes = [
{ id: 1, name: 'APP' },
{ id: 2, name: 'AS' },
{ id: 3, name: 'FOO' },
{
id: 1,
name: 'APP',
hasChildren: false,
children: [],
},
{
id: 2,
name: 'AS',
hasChildren: false,
children: [],
},
{
id: 3,
name: 'FOO',
hasChildren: false,
children: [],
},
];
restrictionComponent.selectedPermissionNames = ['NEO'];
restrictionComponent.selectedContextNames = ['T'];
Expand Down
Loading

0 comments on commit 305be7d

Please sign in to comment.