Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
feat: TT-155 create a service to verifyGroup in user
  • Loading branch information
thegreatyamori authored and Angeluz-07 committed Mar 19, 2021
commit f4359a730f0e695be9efe14db43364c6c1cbab57
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {NavigationStart, Router} from '@angular/router';
import {Observable} from 'rxjs';
import {filter} from 'rxjs/operators';
import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service';
import { Store } from '@ngrx/store';

@Component({
selector: 'app-sidebar',
Expand All @@ -20,6 +21,8 @@ export class SidebarComponent implements OnInit {
private azureAdB2CService: AzureAdB2CService,
private router: Router,
private featureManagerService: FeatureManagerService,
private store: Store,
private bc2azure: AzureAdB2CService,
) {
this.navStart = this.router.events.pipe(
filter(evt => evt instanceof NavigationStart)
Expand All @@ -34,6 +37,9 @@ export class SidebarComponent implements OnInit {
this.navStart.subscribe(evt => {
this.highlightMenuOption(evt.url);
});

console.log(this.bc2azure.getUserId());

}

toggleSideBar() {
Expand Down
22 changes: 22 additions & 0 deletions src/app/modules/user/services/user-info.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TestBed } from '@angular/core/testing';

import { UserInfoService } from './user-info.service';

describe('UserInfoService', () => {
let service: UserInfoService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UserInfoService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should verify if an user belongs to a certain group in the UI', () => {
const input = 'time-tracker-admin';

expect(service.verifyGroup(input)).toBeTruthy();
});
});
21 changes: 21 additions & 0 deletions src/app/modules/user/services/user-info.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { getUserGroupsInfo } from '../store/user.selectors';

@Injectable({
providedIn: 'root'
})
export class UserInfoService {

constructor(private store: Store) { }

verifyGroup(groupName: string): boolean {
let isGroupBelongsToUser: boolean;

const groupsStored = this.store.pipe(select(getUserGroupsInfo)).subscribe((groups) => {
isGroupBelongsToUser = groups.includes(groupName);
});

return isGroupBelongsToUser;
}
}
21 changes: 21 additions & 0 deletions src/app/modules/user/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';

@Injectable({
providedIn: 'root',
})
export class UserService {

constructor(private http: HttpClient) {
}

baseUrl = `${environment.timeTrackerApiUrl}/users`;

loadUser(userId): Observable<any> {
return this.http.get(`${this.baseUrl}/${userId}`);
}

}