Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting and eslint pipeline #1044

Merged
merged 24 commits into from
Oct 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
wider print width
auumgn committed Oct 26, 2023

Verified

This commit was signed with the committer’s verified signature.
madonuko madomado
commit aefd8200fa13e834f78435c195e15617a9bcfece
2 changes: 1 addition & 1 deletion ui/src/.prettierrc
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80
"printWidth": 120
}
11 changes: 2 additions & 9 deletions ui/src/app/account/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { inject } from '@angular/core'
import {
ActivatedRouteSnapshot,
Router,
RouterStateSnapshot,
} from '@angular/router'
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'

import { StateStorageService } from './service/state-storage.service'
import { AccountService } from './service/account.service'
import { Observable, filter, map } from 'rxjs'

export const AuthGuard = (
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | boolean => {
export const AuthGuard = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean => {
const authorities = route.data['authorities']

const router = inject(Router)
54 changes: 9 additions & 45 deletions ui/src/app/account/login/login.component.html
Original file line number Diff line number Diff line change
@@ -7,23 +7,11 @@
*ngIf="authenticationError"
jhiTranslate="login.messages.error.authentication.string"
>
<strong>Failed to sign in!</strong> Please check your credentials and
try again.
<strong>Failed to sign in!</strong> Please check your credentials and try again.
</div>
<form
id="signin-form"
class="form"
role="form"
(ngSubmit)="login()"
[formGroup]="loginForm"
>
<form id="signin-form" class="form" role="form" (ngSubmit)="login()" [formGroup]="loginForm">
<div class="form-group">
<label
class="username-label"
for="username"
jhiTranslate="global.form.email.label.string"
>Email</label
>
<label class="username-label" for="username" jhiTranslate="global.form.email.label.string">Email</label>
<!-- TODO: add translation -->
<input
type="text"
@@ -35,11 +23,7 @@
/>
</div>
<div class="form-group">
<label
for="password"
jhiTranslate="login.form.password.label.string"
>Password</label
>
<label for="password" jhiTranslate="login.form.password.label.string">Password</label>
<!-- TODO: add translation -->
<input
type="password"
@@ -51,36 +35,16 @@
/>
</div>
<div *ngIf="showMfa" class="form-group">
<div
class="alert alert-danger"
jhiTranslate="login.form.mfaCode.prompt.string"
>
<div class="alert alert-danger" jhiTranslate="login.form.mfaCode.prompt.string">
Please enter the MFA code from your authenticator app
</div>
<div
*ngIf="mfaError"
class="alert alert-danger"
jhiTranslate="login.form.mfaCode.error.string"
>
<div *ngIf="mfaError" class="alert alert-danger" jhiTranslate="login.form.mfaCode.error.string">
Invalid MFA code
</div>
<label for="mfaCode" jhiTranslate="login.form.mfaCode.label.string"
>MFA code</label
>
<input
type="text"
class="form-control"
name="mfaCode"
id="mfaCode"
formControlName="mfaCode"
/>
<label for="mfaCode" jhiTranslate="login.form.mfaCode.label.string">MFA code</label>
<input type="text" class="form-control" name="mfaCode" id="mfaCode" formControlName="mfaCode" />
</div>
<button
id="signin-button"
type="submit"
class="btn btn-primary"
jhiTranslate="login.form.button.string"
>
<button id="signin-button" type="submit" class="btn btn-primary" jhiTranslate="login.form.button.string">
Sign in
</button>
</form>
29 changes: 6 additions & 23 deletions ui/src/app/account/login/login.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
ComponentFixture,
TestBed,
tick,
fakeAsync,
} from '@angular/core/testing'
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'
import { LoginComponent } from './login.component'
import { ReactiveFormsModule } from '@angular/forms'
import { RouterTestingModule } from '@angular/router/testing'
@@ -16,21 +11,13 @@
let component: LoginComponent
let fixture: ComponentFixture<LoginComponent>
let loginService: jasmine.SpyObj<LoginService>
let stateStorageService: jasmine.SpyObj<StateStorageService>

Check warning on line 14 in ui/src/app/account/login/login.component.spec.ts

GitHub Actions / format

'stateStorageService' is assigned a value but never used
let accountService: jasmine.SpyObj<AccountService>

beforeEach(() => {
const loginServiceSpy = jasmine.createSpyObj('LoginService', [
'login',
'logout',
])
const stateStorageServiceSpy = jasmine.createSpyObj('StateStorageService', [
'getUrl',
'storeUrl',
])
const accountServiceSpy = jasmine.createSpyObj('AccountService', [
'getAccountData',
])
const loginServiceSpy = jasmine.createSpyObj('LoginService', ['login', 'logout'])
const stateStorageServiceSpy = jasmine.createSpyObj('StateStorageService', ['getUrl', 'storeUrl'])
const accountServiceSpy = jasmine.createSpyObj('AccountService', ['getAccountData'])

TestBed.configureTestingModule({
declarations: [LoginComponent],
@@ -45,12 +32,8 @@
fixture = TestBed.createComponent(LoginComponent)
component = fixture.componentInstance
loginService = TestBed.inject(LoginService) as jasmine.SpyObj<LoginService>
stateStorageService = TestBed.inject(
StateStorageService
) as jasmine.SpyObj<StateStorageService>
accountService = TestBed.inject(
AccountService
) as jasmine.SpyObj<AccountService>
stateStorageService = TestBed.inject(StateStorageService) as jasmine.SpyObj<StateStorageService>
accountService = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService>
})

it('should create', () => {
8 changes: 2 additions & 6 deletions ui/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -47,9 +47,7 @@
}

ngAfterViewInit() {
setTimeout(() =>
this.renderer.selectRootElement('#username').scrollIntoView()
)
setTimeout(() => this.renderer.selectRootElement('#username').scrollIntoView())
}

cancel() {
@@ -74,8 +72,8 @@

this.loginService
.login({
username: this.loginForm.get('username')!.value!,

Check warning on line 75 in ui/src/app/account/login/login.component.ts

GitHub Actions / format

Forbidden non-null assertion

Check warning on line 75 in ui/src/app/account/login/login.component.ts

GitHub Actions / format

Forbidden non-null assertion
password: this.loginForm.get('password')!.value!,

Check warning on line 76 in ui/src/app/account/login/login.component.ts

GitHub Actions / format

Forbidden non-null assertion

Check warning on line 76 in ui/src/app/account/login/login.component.ts

GitHub Actions / format

Forbidden non-null assertion
mfaCode: this.loginForm.get('mfaCode')?.value,
})
.subscribe({
@@ -100,7 +98,7 @@
this.mfaSent = false
},
// TODO: review any type
error: (err) => {

Check warning on line 101 in ui/src/app/account/login/login.component.ts

GitHub Actions / format

'err' is defined but never used
this.loginService.logout()
this.authenticationError = true
},
@@ -111,9 +109,7 @@
loginSuccess(): void {
this.router.navigate([''])

this.eventService.broadcast(
new Event(EventType.LOG_IN_SUCCESS, 'logged in')
)
this.eventService.broadcast(new Event(EventType.LOG_IN_SUCCESS, 'logged in'))

// previousState was set in the authExpiredInterceptor before being redirected to login modal.
// since login is successful, go to stored previousState and clear previousState
62 changes: 11 additions & 51 deletions ui/src/app/account/service/account.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { Injectable } from '@angular/core'
import { SessionStorageService } from 'ngx-webstorage'
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'
import {
BehaviorSubject,
EMPTY,
Observable,
Subject,
catchError,
map,
of,
takeUntil,
tap,
} from 'rxjs'
import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeUntil, tap } from 'rxjs'

Check warning on line 4 in ui/src/app/account/service/account.service.ts

GitHub Actions / format

'of' is defined but never used

Check warning on line 4 in ui/src/app/account/service/account.service.ts

GitHub Actions / format

'tap' is defined but never used

import { SERVER_API_URL } from '../../../app/app.constants'
import { IAccount } from '../model/account.model'
@@ -20,13 +10,11 @@

@Injectable({ providedIn: 'root' })
export class AccountService {
private accountData = new BehaviorSubject<IAccount | null | undefined>(
undefined
)
private accountData = new BehaviorSubject<IAccount | null | undefined>(undefined)
private isFetchingAccountData = false
private stopFetchingAccountData = new Subject()
private authenticated = false
private authenticationState = new BehaviorSubject<any>(null)

Check warning on line 17 in ui/src/app/account/service/account.service.ts

GitHub Actions / format

Unexpected any. Specify a different type
private logoutAsResourceUrl = SERVER_API_URL + 'services/userservice/api'

constructor(
@@ -65,9 +53,7 @@
// After retrieve the account info, the language will be changed to
// the user's preferred language configured in the account setting
if (this.accountData.value?.langKey) {
const langKey =
this.sessionStorage.retrieve('locale') ||
this.accountData.value.langKey
const langKey = this.sessionStorage.retrieve('locale') || this.accountData.value.langKey
// TODO: uncomment when language service is implemented
//this.languageService.changeLanguage(langKey);
}
@@ -83,34 +69,19 @@
}

getMfaSetup(): Observable<HttpResponse<any>> {
return this.http.get<any>(
SERVER_API_URL + 'services/userservice/api/account/mfa',
{ observe: 'response' }
)
return this.http.get<any>(SERVER_API_URL + 'services/userservice/api/account/mfa', { observe: 'response' })
}

save(account: any): Observable<HttpResponse<any>> {
return this.http.post(
SERVER_API_URL + 'services/userservice/api/account',
account,
{ observe: 'response' }
)
return this.http.post(SERVER_API_URL + 'services/userservice/api/account', account, { observe: 'response' })
}

enableMfa(mfaSetup: any): Observable<HttpResponse<any>> {
return this.http.post(
SERVER_API_URL + 'services/userservice/api/account/mfa/on',
mfaSetup,
{ observe: 'response' }
)
return this.http.post(SERVER_API_URL + 'services/userservice/api/account/mfa/on', mfaSetup, { observe: 'response' })
}

disableMfa(): Observable<HttpResponse<any>> {
return this.http.post(
SERVER_API_URL + 'services/userservice/api/account/mfa/off',
null,
{ observe: 'response' }
)
return this.http.post(SERVER_API_URL + 'services/userservice/api/account/mfa/off', null, { observe: 'response' })
}
// TODO: any - this seems to only be used for logging out (only ever receives null as arg)
authenticate(identity: any) {
@@ -120,11 +91,7 @@
}

hasAnyAuthority(authorities: string[]): boolean {
if (
!this.authenticated ||
!this.accountData ||
!this.accountData.value?.authorities
) {
if (!this.authenticated || !this.accountData || !this.accountData.value?.authorities) {
return false
}

@@ -141,10 +108,7 @@
if (!this.authenticated) {
return false
} else {
return (
this.accountData.value!.authorities &&
this.accountData.value!.authorities.includes(authority)
)
return this.accountData.value!.authorities && this.accountData.value!.authorities.includes(authority)
}
}

@@ -201,15 +165,11 @@
}

getSalesforceId(): string | null {
return this.isAuthenticated() && this.accountData
? this.accountData.value!.salesforceId
: null
return this.isAuthenticated() && this.accountData ? this.accountData.value!.salesforceId : null
}

isOrganizationOwner(): boolean | null {
return this.isIdentityResolved() && this.accountData
? this.accountData.value!.mainContact
: false
return this.isIdentityResolved() && this.accountData ? this.accountData.value!.mainContact : false
}

isLoggedAs(): boolean {
4 changes: 1 addition & 3 deletions ui/src/app/account/service/login.service.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,7 @@ export class LoginService {

logout() {
if (this.accountService.isAuthenticated()) {
this.authServerProvider
.logout()
.subscribe(() => this.accountService.authenticate(null))
this.authServerProvider.logout().subscribe(() => this.accountService.authenticate(null))
} else {
this.accountService.authenticate(null)
}
3 changes: 1 addition & 2 deletions ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@ import { navbarRoute } from './layout/navbar/navbar.route'
const routes: Routes = [
{
path: '',
loadChildren: () =>
import('./account/account.module').then((m) => m.AccountModule),
loadChildren: () => import('./account/account.module').then((m) => m.AccountModule),
},
{
path: '',
Loading

Unchanged files with check annotations Beta

export interface ILoginResult {
mfaRequired: boolean
oauth2AccessToken?: any

Check warning on line 3 in ui/src/app/account/model/login.model.ts

GitHub Actions / format

Unexpected any. Specify a different type
}
export interface ILoginCredentials {