Skip to content

RE1-T106 Notification page fix#300

Merged
ucswift merged 1 commit intomasterfrom
develop
Mar 15, 2026
Merged

RE1-T106 Notification page fix#300
ucswift merged 1 commit intomasterfrom
develop

Conversation

@ucswift
Copy link
Copy Markdown
Member

@ucswift ucswift commented Mar 15, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of notification data to gracefully manage edge cases.
  • Refactor

    • Enhanced asynchronous operations in notification processing for better performance.

@request-info
Copy link
Copy Markdown

request-info bot commented Mar 15, 2026

Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

Two files modified: DepartmentNotification.cs adds null or whitespace checks to translation methods with type-specific return values, while NotificationsController.cs converts synchronous method calls to asynchronous awaits in the user notification aggregation path.

Changes

Cohort / File(s) Summary
Null/Whitespace Handling
Core/Resgrid.Model/DepartmentNotification.cs
Early-return logic added to TranslateBefore and TranslateCurrent methods. Returns "Any" for UnitStatusChanged and PersonnelStaffingChanged when data is null/whitespace; returns "None" for PersonnelStatusChanged in the same scenario. Preserves existing parsing behavior for non-whitespace values.
Async/Await Conversion
Web/Resgrid.Web/Areas/User/Controllers/NotificationsController.cs
Replaces synchronous UserHelper.GetFullNameForUser(user.UserId) calls with async await calls in UsersToNotify aggregation, in both conditional branches of string content building.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'RE1-T106 Notification page fix' is vague and generic, using non-descriptive terms like 'fix' without conveying the specific changes made (null/whitespace handling in DepartmentNotification and async refactoring in NotificationsController). Consider using a more descriptive title such as 'Add null/whitespace checks to DepartmentNotification translation methods' to better reflect the primary changes in the changeset.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Web/Resgrid.Web/Areas/User/Controllers/NotificationsController.cs (1)

97-104: ⚠️ Potential issue | 🟠 Major

Handle stale user IDs before dereferencing user.UserId.

Line 99 can return null, and Line 102 / Line 104 dereference it immediately. That means older notifications with deleted or stale recipients can still break the page here. UserHelper.GetFullNameForUser already accepts the stored userId, so either pass that directly or skip missing users.

Suggested fix
 					if (!String.IsNullOrWhiteSpace(notification.UsersToNotify))
 					{
 						var users = notification.UsersToNotify.Split(char.Parse(","));
 						foreach (var userId in users)
 						{
-							var user = _usersService.GetUserById(userId);
-
-							if (sb.Length > 0)
-								sb.Append("," + await UserHelper.GetFullNameForUser(user.UserId));
-							else
-								sb.Append(await UserHelper.GetFullNameForUser(user.UserId));
+							var fullName = await UserHelper.GetFullNameForUser(userId);
+							if (string.IsNullOrWhiteSpace(fullName))
+								continue;
+
+							if (sb.Length > 0)
+								sb.Append(',');
+
+							sb.Append(fullName);
 						}
 					}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Web/Resgrid.Web/Areas/User/Controllers/NotificationsController.cs` around
lines 97 - 104, NotificationsController is dereferencing user.UserId after
calling _usersService.GetUserById(userId), which can return null for
stale/deleted users; update the loop over users to handle nulls by either
skipping when user == null or by calling UserHelper.GetFullNameForUser with the
original userId instead of user.UserId. Specifically, in the foreach over users,
check if _usersService.GetUserById(userId) returned null and continue (or call
UserHelper.GetFullNameForUser(userId) directly), and keep the existing
StringBuilder logic when appending names so null lookups no longer throw.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Core/Resgrid.Model/DepartmentNotification.cs`:
- Around line 91-92: The TranslateBefore and TranslateCurrent methods in
DepartmentNotification use int.Parse in multiple places (e.g., the branches
around the BeforeData/CurrentData checks and the parse calls referenced at lines
noted in your comment) which will throw on malformed data; replace every
int.Parse usage in these methods (including redundant double-parses) with
int.TryParse and fall back to the existing sentinel strings ("Any" for empty
BeforeData, "Unknown" where currently used) so invalid or legacy values do not
throw—specifically update all parse points in TranslateBefore and
TranslateCurrent to attempt TryParse into a local int and use the fallback when
TryParse fails, and remove duplicate parse calls by reusing the parsed result.

---

Outside diff comments:
In `@Web/Resgrid.Web/Areas/User/Controllers/NotificationsController.cs`:
- Around line 97-104: NotificationsController is dereferencing user.UserId after
calling _usersService.GetUserById(userId), which can return null for
stale/deleted users; update the loop over users to handle nulls by either
skipping when user == null or by calling UserHelper.GetFullNameForUser with the
original userId instead of user.UserId. Specifically, in the foreach over users,
check if _usersService.GetUserById(userId) returned null and continue (or call
UserHelper.GetFullNameForUser(userId) directly), and keep the existing
StringBuilder logic when appending names so null lookups no longer throw.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f17fc74f-2321-4a9d-9ead-7c017be08146

📥 Commits

Reviewing files that changed from the base of the PR and between f4ef7f2 and e9912b9.

📒 Files selected for processing (2)
  • Core/Resgrid.Model/DepartmentNotification.cs
  • Web/Resgrid.Web/Areas/User/Controllers/NotificationsController.cs

Comment on lines +91 to +92
if (string.IsNullOrWhiteSpace(BeforeData))
return "Any";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n Core/Resgrid.Model/DepartmentNotification.cs | head -300

Repository: Resgrid/Core

Length of output: 9712


Use non-throwing parsing in these translation branches.

These guards fix the blank-data case, but lines 97, 126, 155, 217, 246, and 275 still use int.Parse on any other non-empty value. A legacy or partially corrupted notification row will still throw while rendering the page. Additionally, lines 157, 248, and 277 contain redundant parse calls that should also be made non-throwing.

Switch all these branches to int.TryParse with the current "Unknown"/"Any" sentinel fallback.

Suggested pattern
-						int id = int.Parse(BeforeData);
+						if (!int.TryParse(BeforeData, out var id))
+							return "Unknown";

Apply the same pattern to all instances in both TranslateBefore and TranslateCurrent methods.

Also applies to: 120-121, 149-150, 157, 211-212, 240-241, 248, 269-270, 277

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Core/Resgrid.Model/DepartmentNotification.cs` around lines 91 - 92, The
TranslateBefore and TranslateCurrent methods in DepartmentNotification use
int.Parse in multiple places (e.g., the branches around the
BeforeData/CurrentData checks and the parse calls referenced at lines noted in
your comment) which will throw on malformed data; replace every int.Parse usage
in these methods (including redundant double-parses) with int.TryParse and fall
back to the existing sentinel strings ("Any" for empty BeforeData, "Unknown"
where currently used) so invalid or legacy values do not throw—specifically
update all parse points in TranslateBefore and TranslateCurrent to attempt
TryParse into a local int and use the fallback when TryParse fails, and remove
duplicate parse calls by reusing the parsed result.

@ucswift
Copy link
Copy Markdown
Member Author

ucswift commented Mar 15, 2026

Approve

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is approved.

@ucswift ucswift merged commit 9151444 into master Mar 15, 2026
18 of 19 checks passed
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.

1 participant