Skip to content
Closed
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
remove validation-token
  • Loading branch information
Nicole Garcia committed Nov 10, 2022
commit a0523363332eb58baa5bcda9a0eff155e1dedcf2
13 changes: 5 additions & 8 deletions src/app/guards/admin-guard/admin.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ export class AdminGuard implements CanActivate {
private userInfoService: UserInfoService,
) { }

canActivate(): Observable<boolean> {
return this.isAdminBasedInGroup().pipe(
map((isAdmin: boolean) => {
if (!isAdmin) { this.router.navigate(['login']); }
return isAdmin;
})
);
canActivate(){
const isAdmin = this.isAdminBasedInGroup();
if (!isAdmin) { this.router.navigate(['login']); }
return isAdmin;
}

isAdminBasedInGroup(): Observable<boolean> {
isAdminBasedInGroup() {
return this.userInfoService.isAdmin();
}
}
3 changes: 2 additions & 1 deletion src/app/modules/login/services/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class LoginService {
const user = JSON.parse(token);
return user && this.cookieService.check('idtoken') ? of(true) : of(false);
} else {
return this.isValidToken(token);
return of(true);
//return this.isValidToken(token);
}
}

Expand Down
35 changes: 17 additions & 18 deletions src/app/modules/shared/components/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EnvironmentType } from 'src/environments/enum';
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
})
export class SidebarComponent implements OnInit, OnDestroy {
export class SidebarComponent implements OnInit {
itemsSidebar: ItemSidebar[] = [];
navStart;
sidebarItems$: Subscription;
Expand All @@ -34,42 +34,41 @@ export class SidebarComponent implements OnInit, OnDestroy {

ngOnInit(): void {
const currentRouting = this.router.routerState.snapshot.url;
this.sidebarItems$ = this.getSidebarItems().subscribe(() => this.highlightMenuOption(currentRouting));
this.getSidebarItems();
this.highlightMenuOption(currentRouting);
this.navStart.subscribe((evt) => {
this.highlightMenuOption(evt.url);
});
}

ngOnDestroy(): void {
this.sidebarItems$.unsubscribe();
}

toggleSideBar() {
$('#wrapper').toggleClass('toggled');
$('#show-sidebar').toggle();
$('#hide-sidebar').toggle();
}

getSidebarItems(): Observable<void> {
return this.userInfoService.isAdmin().pipe(
map((isAdmin) => {
if (isAdmin) {
this.itemsSidebar = [
getSidebarItems(){
if (this.userInfoService.isAdmin()){
this.itemsSidebar = [
{ route: '/time-clock', icon: 'far fa-clock', text: 'Time Clock', active: false },
{ route: '/time-entries', icon: 'far fa-file-alt', text: 'Time Entries', active: false },
{ route: '/reports', icon: 'fas fa-chart-bar', text: 'Reports', active: false },
{ route: '/activities-management', icon: 'fas fa-list-ol', text: 'Activities', active: false },
{ route: '/customers-management', icon: 'fas fa-users', text: 'Customers', active: false },
{ route: '/users', icon: 'fas fa-user-friends', text: 'Users', active: false },
];
} else {
this.itemsSidebar = [
{ route: '/time-clock', icon: 'far fa-clock', text: 'Time Clock', active: false },
{ route: '/time-entries', icon: 'far fa-file-alt', text: 'Time Entries', active: false },
];
}
})
);
}else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else {
} else {

this.itemsSidebar = [
{ route: '/time-clock', icon: 'far fa-clock', text: 'Time Clock', active: false },
{ route: '/time-entries', icon: 'far fa-file-alt', text: 'Time Entries', active: false },
{ route: '/reports', icon: 'fas fa-chart-bar', text: 'Reports', active: false },
{ route: '/activities-management', icon: 'fas fa-list-ol', text: 'Activities', active: false },
{ route: '/customers-management', icon: 'fas fa-users', text: 'Customers', active: false },
{ route: '/users', icon: 'fas fa-user-friends', text: 'Users', active: false },
];
}

}

highlightMenuOption(route) {
Expand Down
4 changes: 1 addition & 3 deletions src/app/modules/shared/components/user/user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ export class UserComponent implements OnInit {
this.azureAdB2CService.setTenantId();
}
} else {
this.loginService.isLogin().subscribe(isLogin => {
if (isLogin) {
if (this.loginService.isLogin()) {
this.userName = this.loginService.getName();
this.userEmail = this.loginService.getUserEmail();
this.azureAdB2CService.setTenantId();
}
});
}
}
}
5 changes: 1 addition & 4 deletions src/app/modules/user/services/user-info.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ export class UserInfoService {
} else {
const user = this.helper.decodeToken(token);
const {groups = []} = user;
if (groups.includes(groupName)) {
return this.loginService.isValidToken(token);
}
return groups.includes(groupName);
}
return of(false);
}

isAdmin(): Observable<boolean> {
Expand Down