-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use highest status instead of newest for legacy #509
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThis pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Warning Rate limit exceeded@Andreass2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 10 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
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: 4
🧹 Outside diff range and nitpick comments (4)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs (1)
27-33
: LGTM! Consider adding XML documentation.The implementation correctly combines the purge check with the status ordering logic.
Consider adding XML documentation to describe the method's behavior and return value:
+ /// <summary> + /// Gets the highest status that is not purged or fetched from the correspondence. + /// </summary> + /// <param name="correspondence">The correspondence entity.</param> + /// <returns>The highest status entity that is not purged or fetched, or null if no such status exists.</returns> public static CorrespondenceStatusEntity? GetHighestStatusWithoutPurged(this CorrespondenceEntity correspondence)src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs (2)
Line range hint
71-89
: Update comments to reflect the new status selection logicThe comments stating "Include correspondences with active status" are now misleading as the method uses highest status rather than most recent status.
Consider updating the comments to:
- if (includeActive) // Include correspondences with active status + if (includeActive) // Include correspondences where highest status is active - if (includeArchived) // Include correspondences with active status + if (includeArchived) // Include correspondences where highest status is archived - if (includePurged) // Include correspondences with active status + if (includePurged) // Include correspondences where highest status is purged
Line range hint
64-64
: Consider renaming method to reflect new behaviorThe method name
IncludeByStatuses
doesn't indicate whether it uses the newest or highest status for filtering.Consider renaming to be more explicit:
- public static IQueryable<CorrespondenceEntity> IncludeByStatuses + public static IQueryable<CorrespondenceEntity> IncludeByHighestStatusessrc/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs (1)
Line range hint
59-67
: Consider documenting status precedence rulesThe logic now depends on status hierarchy rather than timestamp. This change in behavior should be documented:
- For maintainers: Add code comments explaining the status precedence rules
- For users: Update API documentation to reflect this change in status determination
+ // Status precedence: The status hierarchy determines which status is returned, + // rather than using the most recent status. This ensures consistent status + // representation for legacy requests. var latestStatus = correspondence.GetHighestStatus();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs
(1 hunks)src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs
(1 hunks)src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
(1 hunks)src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs
(1 hunks)
🔇 Additional comments (4)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs (1)
20-26
: Verify enum ordering for status hierarchy.
The implementation assumes that higher enum values represent "higher" status levels. We should verify this assumption to ensure correct status ordering.
Consider documenting the status hierarchy in comments or creating a separate method that explicitly defines the status order, making it more maintainable and less dependent on enum values.
Example approach:
private static readonly Dictionary<CorrespondenceStatus, int> StatusHierarchy = new()
{
{ CorrespondenceStatus.Initialized, 1 },
{ CorrespondenceStatus.ReadyForPublish, 2 },
// ... other statuses
};
✅ Verification successful
The enum values show a clear progression from Initialized (0)
-> ReadyForPublish (1)
-> Published (2)
-> Fetched (3)
, where higher numeric values represent later stages in the correspondence lifecycle. Let me verify if there are any additional statuses by searching for potential derived or extended enums.
Enum ordering is correct for status hierarchy
The implementation in GetHighestStatus
correctly uses enum values to determine the highest status. The CorrespondenceStatus
enum shows a clear progression where higher numeric values represent more advanced states in the correspondence lifecycle:
- Initialized (0)
- ReadyForPublish (1)
- Published (2)
- Fetched (3)
The method correctly excludes Fetched
status and uses OrderByDescending
to get the highest remaining status, which aligns with the business logic of the correspondence workflow.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the CorrespondenceStatus enum values and their ordering
# Search for the enum definition
ast-grep --pattern 'enum CorrespondenceStatus {
$$$
}'
# Alternative: Search using ripgrep
rg -A 20 "enum CorrespondenceStatus"
Length of output: 4121
Script:
#!/bin/bash
# Search for any additional status enums or extensions
rg -g "*.cs" "enum.*Status|Status.*enum" -B 2 -A 20
Length of output: 11156
src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs (2)
59-59
: Verify status hierarchy implementation
The change from GetLatestStatus()
to GetHighestStatus()
represents a fundamental shift in how correspondence status is determined. While this aligns with the PR objectives, we should ensure the status hierarchy is correctly implemented.
✅ Verification successful
Change from GetLatestStatus to GetHighestStatus is correctly implemented
The implementation is verified to be correct based on the following evidence:
-
The
GetHighestStatus()
method in CorrespondenceExtensions.cs is properly implemented:- Uses
OrderByDescending(s => s.Status)
to sort by status enum value - Excludes
Fetched
status from consideration - Returns the highest status based on enum value ordering
- Uses
-
The status hierarchy is clearly defined in CorrespondenceStatus enum:
- Starts from
Initialized = 0
- Progresses through
ReadyForPublish = 1
- Higher values represent more advanced states
- Starts from
-
The change aligns with the PR objectives of using highest status instead of newest for legacy requests, and the implementation correctly switches from timestamp-based ordering (
StatusChanged
) to enum-value-based ordering (Status
).
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the implementation of GetHighestStatus and status hierarchy
# Check the implementation of GetHighestStatus
ast-grep --pattern 'GetHighestStatus() {
$$$
}'
# Check for any status enum or hierarchy definition
rg -A 10 'enum CorrespondenceStatus'
# Look for tests validating the status hierarchy
fd -e cs -e csproj --exec rg -l 'GetHighestStatus|CorrespondenceStatus.*Test'
Length of output: 2591
Script:
#!/bin/bash
# Let's check the implementation of GetHighestStatus in CorrespondenceExtensions
rg -A 20 "GetHighestStatus" ./src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
# Let's also check if there's any ordering or comparison logic for statuses
rg -A 10 "CorrespondenceStatus.*>|CompareTo|OrderBy.*Status" ./src/Altinn.Correspondence.Application/
# Check for any test files that might validate the status hierarchy
fd "test" -e cs --exec rg -l "CorrespondenceStatus|GetHighestStatus"
Length of output: 34270
Line range hint 59-146
: Verify impact on status-dependent logic
The change to GetHighestStatus()
affects downstream logic that depends on the status value. The code uses this status for:
- Availability check (
IsAvailableForRecipient()
) - Response construction
- Status-based field population (Archived, Confirmed dates)
We should ensure these dependencies work correctly with the new status determination method.
✅ Verification successful
Let me analyze the results from the shell script execution to verify the impact of GetHighestStatus()
on status-dependent logic.
The search results show several key findings:
- The
IsAvailableForRecipient()
method is well-defined inCorrespondenceExtensions.cs
and has a clear list of valid statuses:
[Published, Fetched, Read, Replied, Confirmed, Archived, Reserved]
- The status transitions and dependencies are consistently enforced across handlers:
Read
requires priorFetched
statusConfirmed
requires priorFetched
statusArchived
requires priorConfirmed
status if confirmation is needed
- The
GetHighestStatus()
implementation inCorrespondenceExtensions.cs
excludesFetched
status and orders by status value:
.Where(s => s.Status != CorrespondenceStatus.Fetched)
.OrderByDescending(s => s.Status)
- The status value is used consistently for:
- Availability checks via
IsAvailableForRecipient()
- Response construction with proper status text
- Status-based field population (Archived, Confirmed dates)
Let me generate the final response:
GetHighestStatus()
implementation maintains status-dependent logic integrity
The new status determination method correctly preserves the status transition rules and dependencies by:
- Excluding
Fetched
status which is transient and shouldn't affect the highest status - Using status value ordering that aligns with the valid status progression
- Maintaining compatibility with
IsAvailableForRecipient()
checks
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for status-dependent logic across the codebase
# Look for methods that depend on correspondence status
rg -A 5 'IsAvailableForRecipient|CorrespondenceStatus\.'
# Check for tests covering status-dependent scenarios
fd -e cs --exec rg -l 'IsAvailableForRecipient.*Test|CorrespondenceStatus.*Test'
Length of output: 54973
src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs (1)
135-135
: Verify business impact of switching from newest to highest status
The change from GetLatestStatusWithoutPurged()
to GetHighestStatusWithoutPurged()
could impact existing consumers expecting the newest status. Please ensure this aligns with business requirements.
✅ Verification successful
Let me analyze the findings from the shell script results:
-
The codebase shows a clear pattern of using two different status retrieval methods:
GetLatestStatus()
- Used in most handlers for regular operationsGetHighestStatus()
- Used specifically in legacy handlers
-
The change in
LegacyGetCorrespondencesHandler.cs
fromGetLatestStatusWithoutPurged()
toGetHighestStatusWithoutPurged()
is consistent with:LegacyGetCorrespondenceOverviewHandler.cs
which usesGetHighestStatus()
- Other legacy handlers that are designed to maintain backward compatibility
-
The implementation in
CorrespondenceExtensions.cs
shows:GetLatestStatus()
orders by timestamp (newest)GetHighestStatus()
orders by status value (highest)- Both methods exclude
Fetched
status - Both have variants that exclude purged status
-
This change appears to be part of a deliberate pattern to handle legacy requests differently from regular requests, maintaining consistency across legacy handlers.
Change is consistent with legacy handler pattern and safe to proceed
The switch from GetLatestStatusWithoutPurged()
to GetHighestStatusWithoutPurged()
in LegacyGetCorrespondencesHandler
aligns with the established pattern of using highest status for legacy handlers, as evidenced by similar implementation in LegacyGetCorrespondenceOverviewHandler
. Regular handlers continue to use latest status, maintaining the intended separation between legacy and current implementations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for other status-related implementations and tests
# to ensure consistency and identify potential impacts
# Check for other status-related methods
rg -A 3 "GetLatestStatus|GetHighestStatus" --type cs
# Look for related test cases
rg -A 5 "test.*Status" --type cs
Length of output: 44656
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
Show resolved
Hide resolved
src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs
Show resolved
Hide resolved
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.
Looks good.
But I think there should be added a warning or some type of documentation internally the status enum order having an impact on the logic in the 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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
(1 hunks)src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs
🔇 Additional comments (1)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs (1)
20-32
: Verify CorrespondenceStatus enum ordering
The implementation looks clean and consistent. However, since MaxBy(s => s.Status)
relies on the enum values' ordering, we should verify that the CorrespondenceStatus
enum values are ordered correctly to ensure the "highest" status is determined as intended.
✅ Verification successful
CorrespondenceStatus enum ordering is correct for MaxBy operation
The enum values are properly ordered with increasing severity/progression:
- Basic states: Initialized(0) → ReadyForPublish(1) → Published(2) → Fetched(3) → Read(4) → Replied(5) → Confirmed(6)
- Terminal states: PurgedByRecipient(7), PurgedByAltinn(8), Archived(9)
The MaxBy(s => s.Status)
operation will correctly identify the highest status since:
- The enum values follow a logical progression
- Terminal states (Purged/Archived) have the highest values
- The
IsPurged()
extension method correctly filters both purge states when needed
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the ordering of CorrespondenceStatus enum values
# Search for the CorrespondenceStatus enum definition
ast-grep --pattern 'enum CorrespondenceStatus {
$$$
}'
Length of output: 58
Script:
#!/bin/bash
# Let's try searching for enum definition using ripgrep instead
rg "enum CorrespondenceStatus" -A 15 --type cs
Length of output: 3164
Script:
#!/bin/bash
# Let's get the complete enum definition to see all status values
rg "enum CorrespondenceStatus" -A 30 --type cs src/Altinn.Correspondence.Core/Models/Enums/CorrespondenceStatus.cs
Length of output: 893
Script:
#!/bin/bash
# Let's check if there are any more status values and also look for IsPurged extension method
rg "enum CorrespondenceStatus" -A 40 --type cs src/Altinn.Correspondence.Core/Models/Enums/CorrespondenceStatus.cs
# Search for IsPurged extension method
rg "IsPurged" -A 5 --type cs
Length of output: 6038
Script:
#!/bin/bash
# Let's get the complete enum to see if there are any more status values after PurgedByRecipient
rg "PurgedByRecipient = 7" -A 10 --type cs src/Altinn.Correspondence.Core/Models/Enums/CorrespondenceStatus.cs
Length of output: 370
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
Outdated
Show resolved
Hide resolved
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
🧹 Outside diff range and nitpick comments (1)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs (1)
20-33
: Document the behavioral difference between Latest and Highest statusConsider adding XML documentation to explain the semantic difference between Latest (time-based) and Highest (enum value-based) status selection. This will help developers choose the appropriate method for their use case.
Example documentation:
/// <summary> /// Gets the status with the highest enum value, excluding Fetched status. /// Unlike GetLatestStatus which uses timestamp, this method prioritizes by status severity. /// </summary> public static CorrespondenceStatusEntity? GetHighestStatus(...)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/Altinn.Correspondence.Application/Helpers/CorrespondenceExtensions.cs
(1 hunks)src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Altinn.Correspondence.Persistence/Helpers/QueryableExtensions.cs
Description
Related Issue(s)
Verification
Documentation
Summary by CodeRabbit
New Features
Bug Fixes
Documentation