-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor report function, improve auth handling in UI #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
MWG-Logan
commented
Dec 24, 2025
- Renamed and relocated Azure Function for project completion reports (ProjectCompletionReportFunction → ReportFunction) for better organization.
- Broadened "active" project filter to include "In Progress" status in ProjectReportingService.
- Enhanced Blazor UI to detect 401 Unauthorized responses and show a login prompt with sign-in button.
- Updated staticwebapp.config.json to require authentication for all routes (/) instead of just /api/.
- Minor UI formatting improvements to data grids.
- Renamed and relocated Azure Function for project completion reports (ProjectCompletionReportFunction → ReportFunction) for better organization. - Broadened "active" project filter to include "In Progress" status in ProjectReportingService. - Enhanced Blazor UI to detect 401 Unauthorized responses and show a login prompt with sign-in button. - Updated staticwebapp.config.json to require authentication for all routes (/*) instead of just /api/*. - Minor UI formatting improvements to data grids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the Azure Function for project reporting, improves authentication handling, and updates the project filtering logic. The changes enhance security by requiring authentication for all routes and adding user-friendly 401 error handling in the UI.
- Renamed
ProjectCompletionReportFunctiontoReportFunctionfor better organization - Updated project filter from "Active" to "In Progress" status in ConnectWise queries
- Added 401 Unauthorized detection with login prompt UI and automatic redirect functionality
- Extended authentication requirements from
/api/*to all routes (/*)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| Bezalu.ProjectReporting.API/Functions/ReportFunction.cs | Renamed class from ProjectCompletionReportFunction to ReportFunction for better naming consistency |
| Bezalu.ProjectReporting.API/Services/ProjectReportingService.cs | Updated ConnectWise query filter to search for projects with "In Progress" status instead of "Active" |
| Bezalu.ProjectReporting.Web/staticwebapp.config.json | Extended authentication requirement to all routes (/*) instead of just API routes |
| Bezalu.ProjectReporting.Web/Pages/Home.razor | Added 401 Unauthorized detection and login prompt UI with redirect functionality, plus minor formatting improvements to data grid columns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| logger.LogInformation("Retrieving active projects"); | ||
|
|
||
| // Query ConnectWise for projects with "Active" status |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 24 states "Query ConnectWise for projects with 'Active' status" but the code now queries for 'In Progress' status. The comment should be updated to reflect the actual query being performed.
| // Query ConnectWise for projects with "Active" status | |
| // Query ConnectWise for projects with status name containing "In Progress" |
|
|
||
| void TriggerLogin() | ||
| { | ||
| Nav.NavigateTo("/login?post_login_redirect_uri=.referrer", forceLoad: true); |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query parameter 'post_login_redirect_uri=.referrer' appears to use '.referrer' as a literal value, but this may not be recognized by Azure Static Web Apps authentication. Typically, you would use '.referrer' as a special placeholder that Azure Static Web Apps replaces with the referring URL, but this should be verified. If '.referrer' is not a recognized placeholder, consider using the actual current page URL or removing the query parameter to rely on the default redirect behavior defined in staticwebapp.config.json.
| Nav.NavigateTo("/login?post_login_redirect_uri=.referrer", forceLoad: true); | |
| var currentUri = new Uri(Nav.Uri); | |
| var redirectPath = currentUri.PathAndQuery + currentUri.Fragment; | |
| var encodedRedirect = Uri.EscapeDataString(redirectPath); | |
| Nav.NavigateTo($"/login?post_login_redirect_uri={encodedRedirect}", forceLoad: true); |
| if (response.StatusCode == HttpStatusCode.Unauthorized) | ||
| { | ||
| HandleUnauthorized("Please sign in to load projects."); | ||
| return; | ||
| } |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When handling unauthorized responses in LoadProjects, the loading state 'IsLoadingProjects' is not reset before returning. This will leave the UI in a loading state indefinitely. The 'finally' block won't execute because of the early return. Consider setting 'IsLoadingProjects = false' before the return statement, or restructure the code to ensure the finally block always executes.
| if (httpResp.StatusCode == HttpStatusCode.Unauthorized) | ||
| { | ||
| HandleUnauthorized("Please sign in to generate a report."); | ||
| return; | ||
| } |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When handling unauthorized responses in GenerateReport, the loading state 'IsGeneratingReport' is not reset before returning. This will leave the UI in a loading state indefinitely. The 'finally' block won't execute because of the early return. Consider setting 'IsGeneratingReport = false' before the return statement, or restructure the code to ensure the finally block always executes.
| if (httpResp.StatusCode == HttpStatusCode.Unauthorized) | ||
| { | ||
| HandleUnauthorized("Please sign in to download the PDF."); | ||
| return; | ||
| } |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When handling unauthorized responses in DownloadPdf, the loading state 'IsPdfLoading' is not reset before returning. This will leave the UI in a loading state indefinitely. The 'finally' block won't execute because of the early return. Consider setting 'IsPdfLoading = false' before the return statement, or restructure the code to ensure the finally block always executes.
| // Query ConnectWise for projects with "Active" status | ||
| var projects = await connectWiseClient.GetListAsync<CWProject>( | ||
| "project/projects?conditions=status/name='Active'&orderBy=name", | ||
| "project/projects?conditions=status/name contains 'In Progress'&orderBy=name", |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query filter syntax may be incorrect. In ConnectWise API conditions, the 'contains' operator is typically used with the 'like' keyword or as 'status/name like "%In Progress%"'. The current syntax 'status/name contains 'In Progress'' might not work as intended. Please verify this syntax against the ConnectWise API documentation, or consider using the equality operator with the exact status name instead.
| "project/projects?conditions=status/name contains 'In Progress'&orderBy=name", | |
| "project/projects?conditions=status/name=\"In Progress\"&orderBy=name", |