Skip to content

Commit f4359a7

Browse files
thegreatyamoriAngeluz-07
authored andcommitted
feat: TT-155 create a service to verifyGroup in user
1 parent a970234 commit f4359a7

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

src/app/modules/shared/components/sidebar/sidebar.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {NavigationStart, Router} from '@angular/router';
55
import {Observable} from 'rxjs';
66
import {filter} from 'rxjs/operators';
77
import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service';
8+
import { Store } from '@ngrx/store';
89

910
@Component({
1011
selector: 'app-sidebar',
@@ -20,6 +21,8 @@ export class SidebarComponent implements OnInit {
2021
private azureAdB2CService: AzureAdB2CService,
2122
private router: Router,
2223
private featureManagerService: FeatureManagerService,
24+
private store: Store,
25+
private bc2azure: AzureAdB2CService,
2326
) {
2427
this.navStart = this.router.events.pipe(
2528
filter(evt => evt instanceof NavigationStart)
@@ -34,6 +37,9 @@ export class SidebarComponent implements OnInit {
3437
this.navStart.subscribe(evt => {
3538
this.highlightMenuOption(evt.url);
3639
});
40+
41+
console.log(this.bc2azure.getUserId());
42+
3743
}
3844

3945
toggleSideBar() {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { UserInfoService } from './user-info.service';
4+
5+
describe('UserInfoService', () => {
6+
let service: UserInfoService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(UserInfoService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
17+
it('should verify if an user belongs to a certain group in the UI', () => {
18+
const input = 'time-tracker-admin';
19+
20+
expect(service.verifyGroup(input)).toBeTruthy();
21+
});
22+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
import { select, Store } from '@ngrx/store';
3+
import { getUserGroupsInfo } from '../store/user.selectors';
4+
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
export class UserInfoService {
9+
10+
constructor(private store: Store) { }
11+
12+
verifyGroup(groupName: string): boolean {
13+
let isGroupBelongsToUser: boolean;
14+
15+
const groupsStored = this.store.pipe(select(getUserGroupsInfo)).subscribe((groups) => {
16+
isGroupBelongsToUser = groups.includes(groupName);
17+
});
18+
19+
return isGroupBelongsToUser;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
4+
import { Observable } from 'rxjs';
5+
import { environment } from 'src/environments/environment';
6+
7+
@Injectable({
8+
providedIn: 'root',
9+
})
10+
export class UserService {
11+
12+
constructor(private http: HttpClient) {
13+
}
14+
15+
baseUrl = `${environment.timeTrackerApiUrl}/users`;
16+
17+
loadUser(userId): Observable<any> {
18+
return this.http.get(`${this.baseUrl}/${userId}`);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)