-
-
Notifications
You must be signed in to change notification settings - Fork 76
CU-8687aj3gt Trying to fix User Push reg issue. #241
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
|
Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details? |
WalkthroughThis 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
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.
📒 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.csCore/Resgrid.Services/PushService.csCore/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)
| if (pushUri == null || String.IsNullOrWhiteSpace(pushUri.DeviceId) || string.IsNullOrWhiteSpace(pushUri.PushLocation)) | ||
| return false; |
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.
🛠️ Refactor suggestion
Good guard; align style and mirror DeviceId check in RegisterUnit.
- Minor: use
string.IsNullOrWhiteSpaceconsistently. - Important:
RegisterUnitshould also validateDeviceId.
- 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.
| if (!string.IsNullOrWhiteSpace(registrationInput.Prefix)) | ||
| push.PushLocation = registrationInput.Prefix; | ||
| else | ||
| { | ||
| var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); | ||
| push.PushLocation = department.Code; | ||
| } |
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.
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.
| 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.
|
Approve |
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.
This PR is approved.
Summary by CodeRabbit