Skip to content

Conversation

@MWG-Logan
Copy link
Owner

  • 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.
Copilot AI review requested due to automatic review settings December 24, 2025 19:24
@MWG-Logan MWG-Logan merged commit 52dd1b0 into dev Dec 24, 2025
8 of 9 checks passed
Copy link
Contributor

Copilot AI left a 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 ProjectCompletionReportFunction to ReportFunction for 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
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
// Query ConnectWise for projects with "Active" status
// Query ConnectWise for projects with status name containing "In Progress"

Copilot uses AI. Check for mistakes.

void TriggerLogin()
{
Nav.NavigateTo("/login?post_login_redirect_uri=.referrer", forceLoad: true);
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment on lines +151 to +155
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
HandleUnauthorized("Please sign in to load projects.");
return;
}
Copy link

Copilot AI Dec 24, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +183 to +187
if (httpResp.StatusCode == HttpStatusCode.Unauthorized)
{
HandleUnauthorized("Please sign in to generate a report.");
return;
}
Copy link

Copilot AI Dec 24, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +221 to +225
if (httpResp.StatusCode == HttpStatusCode.Unauthorized)
{
HandleUnauthorized("Please sign in to download the PDF.");
return;
}
Copy link

Copilot AI Dec 24, 2025

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.

Copilot uses AI. Check for mistakes.
// 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",
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
"project/projects?conditions=status/name contains 'In Progress'&orderBy=name",
"project/projects?conditions=status/name=\"In Progress\"&orderBy=name",

Copilot uses AI. Check for mistakes.
@MWG-Logan MWG-Logan deleted the proj-status-fix branch December 26, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants