Skip to content

Commit

Permalink
sonar comments resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaIn2 committed Feb 24, 2025
1 parent 1ab10df commit 5265db3
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/app/core/services/credential-procedure.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { CredentialProcedureService } from './credential-procedure.service';
import { environment } from 'src/environments/environment';
import { HttpErrorResponse, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { HttpErrorResponse, provideHttpClient } from '@angular/common/http';
import { ProcedureRequest } from '../models/dto/procedure-request.dto';
import { ProcedureResponse } from "../models/dto/procedure-response.dto";
import { LearCredentialEmployeeDataDetail } from "../models/dto/lear-credential-employee-data-detail.dto";
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('CredentialProcedureService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: [CredentialProcedureService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
providers: [CredentialProcedureService, provideHttpClient(), provideHttpClientTesting()]
});

service = TestBed.inject(CredentialProcedureService);
Expand Down
18 changes: 8 additions & 10 deletions src/app/core/services/policies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { TranslateService } from '@ngx-translate/core';
import { DialogWrapperService } from 'src/app/shared/components/dialog/dialog-wrapper/dialog-wrapper.service';
import { Observable, of, switchMap, take } from 'rxjs';
import { Observable, of, switchMap, take, map } from 'rxjs';

@Injectable({
providedIn: 'root'
Expand All @@ -14,22 +14,20 @@ export class PoliciesService {
private readonly dialog = inject(DialogWrapperService);
private readonly translate = inject(TranslateService);


private executePolicy(tmfFunction: string, action: string, redirectUrl: string, authFlag: boolean = false): Observable<boolean> {
if (this.authService.hasPower(tmfFunction, action)) {
return of(true);
return of(true);
} else {
const errorTitle = this.translate.instant(`error.policy.title`);
const errorMessage = this.translate.instant(`error.policy.message`);

const dialogRef = this.dialog.openErrorInfoDialog(errorMessage, errorTitle);
dialogRef.afterClosed().pipe(
return dialogRef.afterClosed().pipe(
take(1),
switchMap(() => authFlag ? this.authService.logout() : of(null))
).subscribe(() => {
this.router.navigate([redirectUrl]).then(() => false);
});
return of(false);
switchMap(() => authFlag ? this.authService.logout() : of(null)),
switchMap(() => this.router.navigate([redirectUrl])),
map(() => false)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient } from '@angular/common/http';
import { of, throwError } from 'rxjs';
import { CredentialDetailComponent } from './credential-detail.component';
import { ActivatedRoute, provideRouter, Router, RouterLink, RouterModule } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { CredentialProcedureService } from 'src/app/core/services/credential-procedure.service';
import { LEARCredentialEmployeeJwtPayload } from "../../core/models/entity/lear-credential-employee.entity";
import { LearCredentialEmployeeDataDetail } from "../../core/models/dto/lear-credential-employee-data-detail.dto";
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('CredentialDetailComponent', () => {
}),
},
},
provideHttpClient(withInterceptorsFromDi()),
provideHttpClient(),
]
})
.overrideComponent(CredentialDetailComponent, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient } from '@angular/common/http';
import { of } from 'rxjs';
import { CredentialIssuanceComponent } from './credential-issuance.component';
import { RouterModule, ActivatedRoute } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { RouterModule, ActivatedRoute, convertToParamMap } from '@angular/router';
import { TranslateModule, TranslateService} from '@ngx-translate/core';
import { OidcSecurityService, StsConfigLoader } from "angular-auth-oidc-client";
import { AuthService } from "../../core/services/auth.service";
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { convertToParamMap } from '@angular/router';

(globalThis as any).structuredClone = (obj: any) => JSON.parse(JSON.stringify(obj));

Expand Down Expand Up @@ -58,7 +57,7 @@ describe('CredentialIssuanceComponent', () => {
{ provide: OidcSecurityService, useValue: oidcSecurityService },
{ provide: StsConfigLoader, useValue: configService },
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClient(),
]
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { provideHttpClientTesting } from '@angular/common/http/testing';
import { AuthService } from 'src/app/core/services/auth.service';
import { AuthModule } from 'angular-auth-oidc-client';
import { By } from '@angular/platform-browser';
import { CredentialProcedure, ProcedureResponse } from 'src/app/core/models/dto/procedure-response.dto';
import { CredentialProcedure} from 'src/app/core/models/dto/procedure-response.dto';
import { credentialProcedureListMock } from 'src/app/core/mocks/credential-procedure-list';
import { MatSort } from '@angular/material/sort';
import { ElementRef } from '@angular/core';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient } from '@angular/common/http';

describe('CredentialManagementComponent', () => {
let component: CredentialManagementComponent;
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('CredentialManagementComponent', () => {
},
},
},
provideHttpClient(withInterceptorsFromDi()),
provideHttpClient(),
provideHttpClientTesting(),
]
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpErrorResponse, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { HttpErrorResponse, provideHttpClient } from '@angular/common/http';
import { BehaviorSubject, of, throwError } from 'rxjs';
import { RouterModule } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Credential Offer Stepper', () => {
{ provide: OidcSecurityService, useValue: oidcSecurityService },
{ provide: StsConfigLoader, useValue: configService },
{ provide: CredentialProcedureService, useValue: procedureService },
provideHttpClient(withInterceptorsFromDi())
provideHttpClient()
]
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FormsModule, FormGroupDirective, FormGroup, FormControl } from '@angular/forms';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient } from '@angular/common/http';
import { FormCredentialComponent } from './form-credential.component';
import { CredentialProcedureService } from 'src/app/core/services/credential-procedure.service';
import { CountryService } from './services/country.service';
Expand All @@ -9,7 +9,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { AuthService } from 'src/app/core/services/auth.service';
import { Observer, of } from 'rxjs';
import { of } from 'rxjs';
import { MaxLengthDirective } from '../../directives/validators/max-length-directive.directive';
import { CustomEmailValidatorDirective } from '../../directives/validators/custom-email-validator.directive';
import { UnicodeValidatorDirective } from '../../directives/validators/unicode-validator.directive';
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('FormCredentialComponent', () => {
{ provide: AuthService, useValue: mockAuthService },
{ provide: Router, useValue: mockRouter },
{ provide: ActivatedRoute, useValue: { snapshot: { paramMap: {} } } },
provideHttpClient(withInterceptorsFromDi())
provideHttpClient()
]
}).compileComponents();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AuthModule } from 'angular-auth-oidc-client';
import { Mandatee, Mandator, Power, Signer } from "../../../../core/models/entity/lear-credential-employee.entity";
import { TempPower } from "../../../../core/models/temporal/temp-power.interface";
import { Country } from './country.service';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient } from '@angular/common/http';

(globalThis as any).structuredClone = (obj: any) => JSON.parse(JSON.stringify(obj));

Expand All @@ -36,7 +36,7 @@ describe('FormCredentialService', () => {
providers: [
FormCredentialService,
TranslateService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClient(),
provideHttpClientTesting(),
]
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<mat-icon>{{ isMenuOpen ? 'keyboard_arrow_up' : 'keyboard_arrow_down' }}</mat-icon>
</button>
<mat-menu #menu="matMenu">
@if(isCredentialIssuer()){
@if(isCredentialIssuerAndConfigure()){
<button mat-menu-item [routerLink]="'/settings'">
<mat-icon>settings</mat-icon>
<span>{{ "navbar.menu.settings" | translate }}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class NavbarComponent implements OnInit {
});
}

public isCredentialIssuer():boolean{
public isCredentialIssuerAndConfigure():boolean{
if(this.authService.hasPower('CredentialIssuer','Configure')) return true
return false;
}
Expand Down

0 comments on commit 5265db3

Please sign in to comment.