Skip to content

Conversation

@ucswift
Copy link
Member

@ucswift ucswift commented Aug 28, 2025

Summary by CodeRabbit

  • New Features
    • Device registration now supports an optional custom Push Location prefix; if not provided, it defaults to the department code.
  • Bug Fixes
    • Strengthened device registration validation to prevent empty Push Location values, improving reliability of push routing.

@request-info
Copy link

request-info bot commented Aug 28, 2025

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

This change simplifies PushUri.PushLocation to an auto-property, adds a non-empty PushLocation requirement during registration, and updates device registration to set PushLocation from an optional Prefix or fallback to the department code.

Changes

Cohort / File(s) Summary
Model: PushUri property simplification
Core/Resgrid.Model/PushUri.cs
Replaced custom PushLocation with [ProtoMember(9)] public string PushLocation { get; set; }; removed backing field and [Required]; eliminated setter side effects.
Service: Registration validation
Core/Resgrid.Services/PushService.cs
In PushService.Register, added string.IsNullOrWhiteSpace(pushUri.PushLocation) to the guard; registration now requires non-empty PushLocation.
API: Device registration logic
Web/Resgrid.Web.Services/Controllers/v4/DevicesController.cs
In RegisterDevice, PushLocation now set to registrationInput.Prefix if provided; otherwise fetched via department and set to department.Code (previously always used department code).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant DevicesController
  participant DeptRepo as Department Repository
  participant PushService

  Client->>DevicesController: POST /v4/devices/register (registrationInput)
  alt Prefix provided
    DevicesController->>DevicesController: PushLocation = Prefix
  else No Prefix
    DevicesController->>DeptRepo: GetById(DepartmentId)
    DeptRepo-->>DevicesController: Department(code)
    DevicesController->>DevicesController: PushLocation = department.code
  end
  DevicesController->>PushService: Register(pushUri)
  PushService->>PushService: Validate DeviceId && PushLocation not empty
  alt Validation fails
    PushService-->>DevicesController: false
    DevicesController-->>Client: 400/Failure
  else Validation passes
    PushService-->>DevicesController: true
    DevicesController-->>Client: 200/Success
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump and hop through fields of code,
Set PushLocation on the road—
Prefix first, or dept we choose,
With tidy props that never bruise.
Guards in place, no sneaky flight,
Devices register just right. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 2

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.Services/Controllers/v4/DevicesController.cs (1)

63-67: Unit registration will fail validation (empty PushLocation); use the same fallback as RegisterDevice.

PushService.RegisterUnit requires PushLocation to be non-empty. Setting it to "" will cause the registration to be dropped.

-					if (!string.IsNullOrWhiteSpace(registrationInput.Prefix))
-						pushRegisterionEvent.PushLocation = registrationInput.Prefix;
-					else
-						pushRegisterionEvent.PushLocation = "";
+					if (!string.IsNullOrWhiteSpace(registrationInput.Prefix?.Trim()))
+					{
+						pushRegisterionEvent.PushLocation = registrationInput.Prefix.Trim();
+					}
+					else
+					{
+						var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
+						if (department == null || string.IsNullOrWhiteSpace(department.Code))
+							return BadRequest();
+						pushRegisterionEvent.PushLocation = department.Code;
+					}
🧹 Nitpick comments (1)
Core/Resgrid.Model/PushUri.cs (1)

37-38: Constrain PushLocation length and ensure non-empty semantics are consistent.

Service-level checks now require a non-empty PushLocation. Persisted data should reflect that and be bounded. Add a MaxLength constraint (pick a safe upper bound for Novu/topic identifiers) and keep [Required] if nulls must be disallowed at the DB layer.

-		[ProtoMember(9)]
+		[MaxLength(64)]
+		[ProtoMember(9)]
 		public string PushLocation { get; set; }

Please confirm the correct maximum length (e.g., 32/64) based on provider constraints.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0ea711e and 5312ac7.

📒 Files selected for processing (3)
  • Core/Resgrid.Model/PushUri.cs (1 hunks)
  • Core/Resgrid.Services/PushService.cs (1 hunks)
  • Web/Resgrid.Web.Services/Controllers/v4/DevicesController.cs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.cs: Prefer functional patterns and immutable data where appropriate in C#
Use modern C# features appropriately
Use meaningful, descriptive names for types, methods, and parameters; avoid unclear abbreviations
Separate state from behavior (e.g., use records for state and place operations in separate static classes)
Prefer pure methods over methods with side effects
Use extension methods appropriately for domain-specific operations
Design for testability; avoid hidden dependencies inside methods and prefer explicit, pure functions
Minimize constructor injection; keep the number of injected dependencies small
Prefer composition with interfaces to extend behavior

Files:

  • Web/Resgrid.Web.Services/Controllers/v4/DevicesController.cs
  • Core/Resgrid.Services/PushService.cs
  • Core/Resgrid.Model/PushUri.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (csharp)

Comment on lines +38 to 39
if (pushUri == null || String.IsNullOrWhiteSpace(pushUri.DeviceId) || string.IsNullOrWhiteSpace(pushUri.PushLocation))
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Good guard; align style and mirror DeviceId check in RegisterUnit.

  • Minor: use string.IsNullOrWhiteSpace consistently.
  • Important: RegisterUnit should also validate DeviceId.
-			if (pushUri == null || String.IsNullOrWhiteSpace(pushUri.DeviceId) || string.IsNullOrWhiteSpace(pushUri.PushLocation))
+			if (pushUri == null || string.IsNullOrWhiteSpace(pushUri.DeviceId) || string.IsNullOrWhiteSpace(pushUri.PushLocation))
 				return false;

Also update RegisterUnit’s guard (outside this hunk) to include DeviceId:

if (pushUri == null || !pushUri.UnitId.HasValue || string.IsNullOrWhiteSpace(pushUri.DeviceId) || string.IsNullOrWhiteSpace(pushUri.PushLocation))
	return false;
🤖 Prompt for AI Agents
In Core/Resgrid.Services/PushService.cs around lines 38-39, change the guard to
use the lowercase string.IsNullOrWhiteSpace for consistency and ensure
RegisterUnit’s guard (elsewhere in the file) mirrors the same checks by adding a
DeviceId validation; update RegisterUnit’s null/unit check to also verify
DeviceId is not null/whitespace in addition to UnitId and PushLocation so both
entrypoints validate DeviceId consistently.

Comment on lines +157 to +163
if (!string.IsNullOrWhiteSpace(registrationInput.Prefix))
push.PushLocation = registrationInput.Prefix;
else
{
var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
push.PushLocation = department.Code;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid NRE and guarantee non-empty PushLocation; trim Prefix and validate department fallback.

If department is null (or Code empty) this throws, and PushService.Register rejects empty locations. Harden this block.

-					if (!string.IsNullOrWhiteSpace(registrationInput.Prefix))
-						push.PushLocation = registrationInput.Prefix;
-					else
-					{
-						var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
-						push.PushLocation = department.Code;
-					}
+					if (!string.IsNullOrWhiteSpace(registrationInput.Prefix?.Trim()))
+					{
+						push.PushLocation = registrationInput.Prefix.Trim();
+					}
+					else
+					{
+						var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
+						if (department == null || string.IsNullOrWhiteSpace(department.Code))
+							return BadRequest();
+						push.PushLocation = department.Code;
+					}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!string.IsNullOrWhiteSpace(registrationInput.Prefix))
push.PushLocation = registrationInput.Prefix;
else
{
var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
push.PushLocation = department.Code;
}
if (!string.IsNullOrWhiteSpace(registrationInput.Prefix?.Trim()))
{
push.PushLocation = registrationInput.Prefix.Trim();
}
else
{
var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);
if (department == null || string.IsNullOrWhiteSpace(department.Code))
return BadRequest();
push.PushLocation = department.Code;
}
🤖 Prompt for AI Agents
In Web/Resgrid.Web.Services/Controllers/v4/DevicesController.cs around lines 157
to 163, trim registrationInput.Prefix and only use it if not null/whitespace;
otherwise await _departmentsService.GetDepartmentByIdAsync and verify the
department is not null and department.Code is not null/whitespace (use trimmed
values). If neither provides a valid non-empty PushLocation, return a BadRequest
(or appropriate error) instead of assigning an empty value so
PushService.Register won’t be given an empty location.

@ucswift
Copy link
Member Author

ucswift commented Aug 28, 2025

Approve

Copy link

@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 8b3f079 into master Aug 28, 2025
16 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.

2 participants