Skip to content

Commit 0735d19

Browse files
helen229Copilot
andauthored
Update Requested Review link (#12684)
* temp test * test preferredApprovers * add withCredentials * test allowed approvers with credentials * add login check * Update src/dotnet/APIView/ClientSPA/src/app/_components/shared/nav-bar/nav-bar.component.ts Co-authored-by: Copilot <[email protected]> * fix comment via combineLatest * fix comments --------- Co-authored-by: Copilot <[email protected]>
1 parent eb2c44c commit 0735d19

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/dotnet/APIView/ClientSPA/src/app/_components/shared/nav-bar/nav-bar.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
</button>
88
<div class="navbar-collapse collapse">
99
<ul class="navbar-nav ms-auto">
10+
<li *ngIf="isLoggedIn && isApprover" class="nav-item">
11+
<a href="{{RequestReviewPageUrl}}" class="nav-link">Requested Reviews</a>
12+
</li>
1013
<li *ngIf="isLoggedIn" class="nav-item">
1114
<a class="nav-link position-relative" (click)="notificationsSidePanel = !notificationsSidePanel">
1215
<i class="bi bi-bell"></i>
@@ -24,9 +27,6 @@
2427
<li><a class="dropdown-item" href="{{logoutPageWebAppUrl}}">Log Out</a></li>
2528
</ul>
2629
</li>
27-
<li *ngIf="isLoggedIn && isApprover" class="nav-item">
28-
<a href="{{RequestReviewPageUrl}}" class="nav-link">Requested Reviews</a>
29-
</li>
3030
<li class="nav-item">
3131
<a href="https://github.com/Azure/azure-sdk-tools/blob/main/src/dotnet/APIView/APIViewWeb/README.md" class="nav-link">Help</a>
3232
</li>

src/dotnet/APIView/ClientSPA/src/app/_components/shared/nav-bar/nav-bar.component.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { HttpClient } from '@angular/common/http';
4+
import { combineLatest } from 'rxjs';
45
import { REVIEW_ID_ROUTE_PARAM } from 'src/app/_helpers/router-helpers';
56
import { NotificationsFilter, SiteNotification } from 'src/app/_models/notificationsModel';
67
import { UserProfile } from 'src/app/_models/userProfile';
@@ -38,17 +39,18 @@ export class NavBarComponent implements OnInit {
3839

3940
ngOnInit(): void {
4041
this.reviewId = this.route.snapshot.paramMap.get(REVIEW_ID_ROUTE_PARAM);
41-
this.authService.isLoggedIn().subscribe(isLoggedIn => {
42-
this.isLoggedIn = isLoggedIn;
43-
});
4442

45-
this.userProfileService.getUserProfile().subscribe(
46-
(userProfile : any) => {
47-
this.userProfile = userProfile;
48-
// Check if user is an approver
43+
// Use combineLatest to wait for both isLoggedIn and userProfile before checking approver status
44+
combineLatest([
45+
this.authService.isLoggedIn(),
46+
this.userProfileService.getUserProfile()
47+
]).subscribe(([isLoggedIn, userProfile]) => {
48+
this.isLoggedIn = isLoggedIn;
49+
this.userProfile = userProfile;
50+
if (isLoggedIn && userProfile) {
4951
this.checkApproverStatus();
5052
}
51-
);
53+
});
5254

5355
this.notificationsService.notifications$.subscribe(notifications => {
5456
this.notifications = notifications;
@@ -78,22 +80,24 @@ export class NavBarComponent implements OnInit {
7880
}
7981

8082
private checkApproverStatus() {
81-
if (this.userProfile?.userName) {
82-
// Call the API to get allowed approvers
83-
this.http.get<string>(`${this.configService.apiUrl}/Reviews/allowedApprovers`).subscribe({
84-
next: (allowedApprovers) => {
85-
if (allowedApprovers) {
86-
// Split comma-separated string and check if current user is in the list
87-
const approversList = allowedApprovers.split(',').map(username => username.trim());
88-
this.isApprover = approversList.includes(this.userProfile?.userName || '');
89-
}
90-
},
91-
error: (error) => {
92-
console.error('Failed to fetch allowed approvers:', error);
83+
if (!this.userProfile?.userName || !this.isLoggedIn) {
84+
this.isApprover = false;
85+
return;
86+
}
87+
88+
this.http.get<string>(`${this.configService.apiUrl}/Reviews/allowedApprovers`, { withCredentials: true }).subscribe({
89+
next: (allowedApprovers) => {
90+
if (allowedApprovers) {
91+
const approversList = allowedApprovers.split(',').map(username => username.trim());
92+
this.isApprover = approversList.includes(this.userProfile?.userName || '');
93+
} else {
9394
this.isApprover = false;
94-
// Optionally, notify the user here if desired
9595
}
96-
});
97-
}
96+
},
97+
error: (error) => {
98+
console.error('Failed to fetch allowed approvers:', error);
99+
this.isApprover = false;
100+
}
101+
});
98102
}
99103
}

0 commit comments

Comments
 (0)