Skip to content

Commit 607fc91

Browse files
Reihtwjimmyjaramillowilc0519jisazacMarco Aguirre
authored
Tta 83 improve admins validation in frontend (#908)
* fix: TTA-83 improve admin validation * fix: TTA-83 improve admin validation * feat TTA-83: frontend admin validation * fix TTA-83: Returning to login functions to subscribe * fix TTA-83: Fixing login component tests * fix TTA-83: Sonarcloud fix * fix TTA-83: Adding legacy login * fix TTA-83: fixing tests * Tta 83 solving conflicts (#912) * Tta 50 error when editing an entry (#907) * fix: TTA-50 Error when editing an entry * fix: TTA-50 Error when editing an entry * Tta 94 refactor endpoints to make it work on tt stage and tt prod (#903) * Innecesary env files deleted * New changes to env files * Add 1 git-crypt collaborator New collaborators: F295BDD1 Marco Aguirre <[email protected]> * Add 1 git-crypt collaborator New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> * Add 2 git-crypt collaborators New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> F295BDD1 Marco Aguirre <[email protected]> * New keys and env variables added * env files added & modified * Make run now uses .dev.env * Pipeline modified * is the .env needed? * using encrypted .stage.env * load secrets * adding env variables * scopes cannot be empty * use env * using env var * using env file * adding mask * using docker buildkit * only on tags * using buildkit directly * using dash source * docker buildkit * missing folders added * nginx fix * fixing secrets * problem with double qoutes * fixing quotes in .stage.env * fixing secrets * loading to env * quotes fixed * replacing \r * fixing trailing \n * one line expose * fixing endpoint url * removing unnecessary jobs * update creds * adding with space at the end of the file * primer commit * cambios en users list components * Se ajusta la variable isDevelopmentOrProd * revision tests * reportsUrl como variable global Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> * Set copy of package.json and npm install before copying all other project files (#906) * Set copy of package.json and npm install before copying all other project files * Fix error on COPY on Dockerfiles Co-authored-by: Gustavo Lozada <[email protected]> * feat: TTA-113 Set a new logo for TT - version 2 (#909) Co-authored-by: Jimmy Jaramillo <[email protected]> * chore(release): 1.74.0 [skip ci]nn Co-authored-by: wilc0519 <[email protected]> Co-authored-by: Juan Esteban Isaza Cadavid <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> Co-authored-by: GuLozada99 <[email protected]> Co-authored-by: Gustavo Lozada <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> * Update TTA 83 Branch (#913) * Tta 50 error when editing an entry (#907) * fix: TTA-50 Error when editing an entry * fix: TTA-50 Error when editing an entry * Tta 94 refactor endpoints to make it work on tt stage and tt prod (#903) * Innecesary env files deleted * New changes to env files * Add 1 git-crypt collaborator New collaborators: F295BDD1 Marco Aguirre <[email protected]> * Add 1 git-crypt collaborator New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> * Add 2 git-crypt collaborators New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> F295BDD1 Marco Aguirre <[email protected]> * New keys and env variables added * env files added & modified * Make run now uses .dev.env * Pipeline modified * is the .env needed? * using encrypted .stage.env * load secrets * adding env variables * scopes cannot be empty * use env * using env var * using env file * adding mask * using docker buildkit * only on tags * using buildkit directly * using dash source * docker buildkit * missing folders added * nginx fix * fixing secrets * problem with double qoutes * fixing quotes in .stage.env * fixing secrets * loading to env * quotes fixed * replacing \r * fixing trailing \n * one line expose * fixing endpoint url * removing unnecessary jobs * update creds * adding with space at the end of the file * primer commit * cambios en users list components * Se ajusta la variable isDevelopmentOrProd * revision tests * reportsUrl como variable global Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> * Set copy of package.json and npm install before copying all other project files (#906) * Set copy of package.json and npm install before copying all other project files * Fix error on COPY on Dockerfiles Co-authored-by: Gustavo Lozada <[email protected]> * feat: TTA-113 Set a new logo for TT - version 2 (#909) Co-authored-by: Jimmy Jaramillo <[email protected]> * chore(release): 1.74.0 [skip ci]nn Co-authored-by: wilc0519 <[email protected]> Co-authored-by: Juan Esteban Isaza Cadavid <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> Co-authored-by: GuLozada99 <[email protected]> Co-authored-by: Gustavo Lozada <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> * second try of merge from master (#914) * Tta 50 error when editing an entry (#907) * fix: TTA-50 Error when editing an entry * fix: TTA-50 Error when editing an entry * Tta 94 refactor endpoints to make it work on tt stage and tt prod (#903) * Innecesary env files deleted * New changes to env files * Add 1 git-crypt collaborator New collaborators: F295BDD1 Marco Aguirre <[email protected]> * Add 1 git-crypt collaborator New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> * Add 2 git-crypt collaborators New collaborators: 1CC2872D Rodolfo Diaz <[email protected]> F295BDD1 Marco Aguirre <[email protected]> * New keys and env variables added * env files added & modified * Make run now uses .dev.env * Pipeline modified * is the .env needed? * using encrypted .stage.env * load secrets * adding env variables * scopes cannot be empty * use env * using env var * using env file * adding mask * using docker buildkit * only on tags * using buildkit directly * using dash source * docker buildkit * missing folders added * nginx fix * fixing secrets * problem with double qoutes * fixing quotes in .stage.env * fixing secrets * loading to env * quotes fixed * replacing \r * fixing trailing \n * one line expose * fixing endpoint url * removing unnecessary jobs * update creds * adding with space at the end of the file * primer commit * cambios en users list components * Se ajusta la variable isDevelopmentOrProd * revision tests * reportsUrl como variable global Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> * Set copy of package.json and npm install before copying all other project files (#906) * Set copy of package.json and npm install before copying all other project files * Fix error on COPY on Dockerfiles Co-authored-by: Gustavo Lozada <[email protected]> * feat: TTA-113 Set a new logo for TT - version 2 (#909) Co-authored-by: Jimmy Jaramillo <[email protected]> * chore(release): 1.74.0 [skip ci]nn Co-authored-by: wilc0519 <[email protected]> Co-authored-by: Juan Esteban Isaza Cadavid <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> Co-authored-by: GuLozada99 <[email protected]> Co-authored-by: Gustavo Lozada <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: wilc0519 <[email protected]> Co-authored-by: Juan Esteban Isaza Cadavid <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Marco Aguirre <[email protected]> Co-authored-by: Rodolfo IOET <[email protected]> Co-authored-by: jisazac <[email protected]> Co-authored-by: Juan Isaza <[email protected]> Co-authored-by: GuLozada99 <[email protected]> Co-authored-by: Gustavo Lozada <[email protected]> Co-authored-by: Jimmy Jaramillo <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> Co-authored-by: Rodolfo <[email protected]> Co-authored-by: = <=>
1 parent 0733f6e commit 607fc91

File tree

16 files changed

+33219
-324
lines changed

16 files changed

+33219
-324
lines changed

package-lock.json

Lines changed: 33008 additions & 206 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@angular/platform-browser": "10.2.2",
2727
"@angular/platform-browser-dynamic": "10.2.2",
2828
"@angular/router": "10.2.2",
29+
"@auth0/angular-jwt": "^5.0.2",
2930
"@azure/app-configuration": "1.1.0",
3031
"@azure/identity": "1.1.0",
3132
"@ng-select/ng-select": "7.2.0",

src/app/app.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { ActivityEffects } from './modules/activities-management/store/activity-
4848
import { ProjectEffects } from './modules/customer-management/components/projects/components/store/project.effects';
4949
import { TechnologyEffects } from './modules/shared/store/technology.effects';
5050
import { ProjectTypeEffects } from './modules/customer-management/components/projects-type/store/project-type.effects';
51-
import { reducers, metaReducers } from './reducers';
51+
import { reducers } from './reducers';
5252
import { CLIENT_URL, environment } from '../environments/environment';
5353
import { EnvironmentType } from '../environments/enum';
5454
import { CustomerComponent } from './modules/customer-management/pages/customer.component';
@@ -179,7 +179,6 @@ const maskConfig: Partial<IConfig> = {
179179
MatIconModule,
180180
MatListModule,
181181
StoreModule.forRoot(reducers, {
182-
metaReducers,
183182
}),
184183
environment.production === EnvironmentType.TT_DEV
185184
? StoreDevtoolsModule.instrument({

src/app/guards/login-guard/login.guard.spec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LoginGuard } from './login.guard';
77
import { LoginService } from '../../modules/login/services/login.service';
88
import { HttpClientTestingModule } from '@angular/common/http/testing';
99
import { SocialAuthService } from 'angularx-social-login';
10+
import { of } from 'rxjs';
1011

1112

1213
describe('LoginGuard', () => {
@@ -15,13 +16,13 @@ describe('LoginGuard', () => {
1516
let azureAdB2CService: AzureAdB2CService;
1617
const azureAdB2CServiceStub = {
1718
isLogin() {
18-
return true;
19+
return of(true);
1920
}
2021
};
2122
let loginService: LoginService;
2223
const loginServiceStub = {
2324
isLogin() {
24-
return true;
25+
return of(true);
2526
}
2627
};
2728
const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['']);
@@ -46,36 +47,41 @@ describe('LoginGuard', () => {
4647
it('can activate the route when user is logged-in on Production', () => {
4748
loginGuard.isProduction = true;
4849
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true);
49-
const canActivate = loginGuard.canActivate();
50+
loginGuard.canActivate().subscribe(canActivate => {
51+
expect(canActivate).toEqual(true);
52+
});
5053
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
51-
expect(canActivate).toEqual(true);
5254
});
5355

56+
5457
it('can activate the route when user is logged-in Locally', () => {
5558
loginGuard.isProduction = false;
56-
spyOn(loginService, 'isLogin').and.returnValue(true);
57-
const canActivate = loginGuard.canActivate();
59+
spyOn(loginService, 'isLogin').and.returnValue(of(true));
60+
loginGuard.canActivate().subscribe(isLogin => {
61+
expect(isLogin).toEqual(true);
62+
});
5863
expect(loginService.isLogin).toHaveBeenCalled();
59-
expect(canActivate).toEqual(true);
6064
});
6165

6266
it('can not active the route and is redirected to login if user is not logged-in on Production', inject([Router], (router: Router) => {
6367
loginGuard.isProduction = true;
6468
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false);
6569
spyOn(router, 'navigate').and.stub();
66-
const canActivate = loginGuard.canActivate();
70+
loginGuard.canActivate().subscribe(canActivate => {
71+
expect(canActivate).toEqual(false);
72+
});
6773
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
68-
expect(canActivate).toEqual(false);
6974
expect(router.navigate).toHaveBeenCalledWith(['login']);
7075
}));
7176

7277
it('can not active the route and is redirected to login if user is not logged-in Locally', inject([Router], (router: Router) => {
7378
loginGuard.isProduction = false;
74-
spyOn(loginService, 'isLogin').and.returnValue(false);
79+
spyOn(loginService, 'isLogin').and.returnValue(of(false));
7580
spyOn(router, 'navigate').and.stub();
76-
const canActivate = loginGuard.canActivate();
81+
loginGuard.canActivate().subscribe(isLogin => {
82+
expect(isLogin).toEqual(false);
83+
});
7784
expect(loginService.isLogin).toHaveBeenCalled();
78-
expect(canActivate).toEqual(false);
7985
expect(router.navigate).toHaveBeenCalledWith(['login']);
8086
}));
8187

src/app/guards/login-guard/login.guard.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Router, CanActivate } from '@angular/router';
33
import { AzureAdB2CService } from '../../modules/login/services/azure.ad.b2c.service';
44
import { LoginService } from '../../modules/login/services/login.service';
55
import { environment } from 'src/environments/environment';
6+
import { map } from 'rxjs/operators';
67
import { EnvironmentType } from 'src/environments/enum';
8+
import { of } from 'rxjs';
79

810

911
@Injectable({
@@ -21,19 +23,22 @@ export class LoginGuard implements CanActivate {
2123
if (this.isProduction) {
2224
if (this.azureAdB2CService.isLogin()) {
2325
this.azureAdB2CService.setCookies();
24-
return true;
26+
return of(true);
2527
} else {
2628
this.router.navigate(['login']);
27-
return false;
29+
return of(false);
2830
}
2931
} else {
30-
if (this.loginService.isLogin()) {
31-
this.loginService.setCookies();
32-
return true;
33-
} else {
34-
this.router.navigate(['login']);
35-
return false;
36-
}
32+
return this.loginService.isLogin().pipe(
33+
map(isLogin => {
34+
if (!isLogin) {
35+
this.router.navigate(['login']);
36+
return false;
37+
}
38+
this.loginService.setCookies();
39+
return true;
40+
})
41+
);
3742
}
3843
}
3944
}

src/app/modules/login/login.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('LoginComponent', () => {
1818

1919
const azureAdB2CServiceStub = {
2020
isLogin() {
21-
return true;
21+
return of(true);
2222
},
2323
signIn() {
2424
return of();
@@ -29,7 +29,7 @@ describe('LoginComponent', () => {
2929

3030
const loginServiceStub = {
3131
isLogin() {
32-
return true;
32+
return of(true);
3333
},
3434
signIn() {
3535
return of();
@@ -99,7 +99,7 @@ describe('LoginComponent', () => {
9999
}));
100100

101101
it('should sign up or login with google if is not logged-in into the app Locally', inject([Router], (router: Router) => {
102-
spyOn(loginService, 'isLogin').and.returnValue(false);
102+
spyOn(loginService, 'isLogin').and.returnValue(of(false));
103103
spyOn(loginService, 'setLocalStorage').and.returnValue();
104104
spyOn(loginService, 'getUser').and.returnValue(of(() => {}));
105105
spyOn(loginService, 'setCookies').and.returnValue();
@@ -123,7 +123,7 @@ describe('LoginComponent', () => {
123123
}));
124124

125125
it('should not sign-up or login with google if is already logged-in into the app Locally', inject([Router], (router: Router) => {
126-
spyOn(loginService, 'isLogin').and.returnValue(true);
126+
spyOn(loginService, 'isLogin').and.returnValue(of(true));
127127
spyOn(router, 'navigate').and.stub();
128128
component.loginWithGoogle();
129129
expect(loginService.isLogin).toHaveBeenCalled();

src/app/modules/login/login.component.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SocialAuthService, SocialUser } from 'angularx-social-login';
77
import { environment } from 'src/environments/environment';
88
import { EnvironmentType } from 'src/environments/enum';
99
import { LoginService } from './services/login.service';
10+
1011
@Component({
1112
selector: 'app-login',
1213
templateUrl: './login.component.html',
@@ -31,7 +32,9 @@ export class LoginComponent implements OnInit {
3132
this.loginService.setLocalStorage('idToken', user.idToken);
3233
this.loginService.getUser(user.idToken).subscribe((response) => {
3334
this.loginService.setCookies();
34-
this.loginService.setLocalStorage('user2', JSON.stringify(response));
35+
const tokenObject = JSON.stringify(response);
36+
const tokenJson = JSON.parse(tokenObject);
37+
this.loginService.setLocalStorage('user', tokenJson.token);
3538
this.router.navigate(['']);
3639
});
3740
}
@@ -49,11 +52,14 @@ export class LoginComponent implements OnInit {
4952
});
5053
}
5154
}
55+
5256
loginWithGoogle() {
53-
if (this.loginService.isLogin()) {
54-
this.router.navigate(['']);
55-
} else {
56-
this.loginService.signIn();
57-
}
57+
this.loginService.isLogin().subscribe(isLogin => {
58+
if (isLogin) {
59+
this.router.navigate(['']);
60+
} else {
61+
this.loginService.signIn();
62+
}
63+
});
5864
}
5965
}

src/app/modules/login/services/login.service.spec.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
22
import { TestBed } from '@angular/core/testing';
3+
import { JwtHelperService } from '@auth0/angular-jwt';
34
import { SocialAuthService } from 'angularx-social-login';
45
import { CookieService } from 'ngx-cookie-service';
56
import { of } from 'rxjs';
@@ -14,6 +15,10 @@ describe('LoginService', () => {
1415
let account;
1516
const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['signOut', 'signIn']);
1617
const cookieStoreStub = {};
18+
const helper = new JwtHelperService();
19+
const getAccountInfo = () => {
20+
return helper.decodeToken(account);
21+
};
1722

1823
beforeEach(() => {
1924
TestBed.configureTestingModule({
@@ -27,12 +32,7 @@ describe('LoginService', () => {
2732
cookieService = TestBed.inject(CookieService);
2833
httpMock = TestBed.inject(HttpTestingController);
2934
socialAuthService = TestBed.inject(SocialAuthService);
30-
account = {
31-
id: 'abc',
32-
name: 'abc',
33-
email: 'abc',
34-
groups: ['abc'],
35-
};
35+
account = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImFiYyIsIm5hbWUiOiJhYmMiLCJlbWFpbCI6ImFiYyIsImdyb3VwcyI6WyJhYmMiXX0.UNxyDT8XzXJhI1F3LySBU7TJlpENPUPHj8my7Obw2ZM';
3636
let store = {};
3737
const mockLocalStorage = {
3838
getItem: (key: string): string => {
@@ -48,7 +48,7 @@ describe('LoginService', () => {
4848
spyOn(localStorage, 'getItem').and.callFake(mockLocalStorage.getItem);
4949
spyOn(localStorage, 'setItem').and.callFake(mockLocalStorage.setItem);
5050
spyOn(localStorage, 'clear').and.callFake(mockLocalStorage.clear);
51-
localStorage.setItem('user2', JSON.stringify(account));
51+
localStorage.setItem('user', account);
5252
});
5353

5454
it('should be created', () => {
@@ -58,19 +58,19 @@ describe('LoginService', () => {
5858
it('should get name from localStorage', () => {
5959
const name = service.getName();
6060

61-
expect(name).toEqual(account.name);
61+
expect(name).toEqual(getAccountInfo().name);
6262
});
6363

6464
it('should get userId from localStorage', () => {
6565
const userId = service.getUserId();
6666

67-
expect(userId).toEqual(account.id);
67+
expect(userId).toEqual(getAccountInfo().id);
6868
});
6969

7070
it('should get UserGroup from localStorage', () => {
7171
const userGroup = service.getUserGroup();
7272

73-
expect(userGroup).toEqual(account.groups);
73+
expect(userGroup).toEqual(getAccountInfo().groups);
7474
});
7575

7676
it('should get BearerToken from localStorage', () => {
@@ -99,18 +99,19 @@ describe('LoginService', () => {
9999

100100
it('should return true when user is Login', () => {
101101
spyOn(cookieService, 'check').and.returnValue(true);
102+
spyOn(service, 'isValidToken').and.returnValue(of(true));
102103

103-
const isLogin = service.isLogin();
104-
105-
expect(isLogin).toBeTruthy();
104+
service.isLogin().subscribe(isLogin => {
105+
expect(isLogin).toEqual(true);
106+
});
106107
});
107108

108109
it('should return false when user is not Login', () => {
109-
spyOn(cookieService, 'check').and.returnValue(false);
110+
spyOn(service, 'isValidToken').and.returnValue(of(false));
110111

111-
const isLogin = service.isLogin();
112-
113-
expect(isLogin).toBeFalsy();
112+
service.isLogin().subscribe(isLogin => {
113+
expect(isLogin).toEqual(false);
114+
});
114115
});
115116

116117
it('should login with social angularx-social-login', () => {

0 commit comments

Comments
 (0)