Skip to content
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

[PM-10563] Notification Center API #26

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

[PM-10563] Notification Center API #26

wants to merge 19 commits into from

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-10563

📔 Objective

Notification API:

  • List notifications for user.
    • Optional pagination by continuation token and page size, including validation.
    • Updated Dapper, EF and Sql migrations.
  • Mark notification as read and deleted
    • fixed bug, where incorrect date time was populated in MarkNotificationDeletedCommand and MarkNotificationReadCommand during create operation - now UTC format

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Greptile Summary

This pull request introduces a Notification Center API with pagination and status management features for the Bitwarden server. Key changes include:

  • Added NotificationsController with endpoints for listing, marking as read, and marking as deleted notifications
  • Implemented pagination support in GetNotificationStatusDetailsForUserQuery and repository interfaces
  • Updated MarkNotificationDeletedCommand and MarkNotificationReadCommand to use UTC time consistently
  • Created new models for notification filtering and response handling
  • Modified stored procedure Notification_ReadByUserIdAndStatus to support pagination
  • Added comprehensive unit and integration tests for new functionality
  • Registered Notification Center services in the dependency injection container

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

21 file(s) reviewed, 31 comment(s)
Edit PR Review Bot Settings | Greptile

notificationStatusDetailsPagedResult.ContinuationToken);
}

[HttpPatch("{id}/delete")]
Copy link

Choose a reason for hiding this comment

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

style: Consider using HttpPut instead of HttpPatch for idempotent operations

await _markNotificationDeletedCommand.MarkDeletedAsync(id);
}

[HttpPatch("{id}/read")]
Copy link

Choose a reason for hiding this comment

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

style: Consider using HttpPut instead of HttpPatch for idempotent operations

/// <summary>
/// A cursor for use in pagination.
/// </summary>
[StringLength(9)]
Copy link

Choose a reason for hiding this comment

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

style: Consider increasing the maximum length to accommodate larger page numbers

Comment on lines +28 to +29
[Range(10, 1000)]
public int PageSize { get; set; } = 10;
Copy link

Choose a reason for hiding this comment

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

style: Consider allowing a smaller minimum page size, such as 1, for more flexibility

Comment on lines +33 to +34
if (!string.IsNullOrWhiteSpace(ContinuationToken) &&
(!int.TryParse(ContinuationToken, out var pageNumber) || pageNumber <= 0))
Copy link

Choose a reason for hiding this comment

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

style: Use long.TryParse instead of int.TryParse to handle larger page numbers

Comment on lines +29 to +31
RevisionDate = DateTime.UtcNow - TimeSpan.FromMinutes(3),
ReadDate = DateTime.UtcNow - TimeSpan.FromMinutes(1),
DeletedDate = DateTime.UtcNow,
Copy link

Choose a reason for hiding this comment

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

style: Use fixed dates instead of DateTime.UtcNow for more predictable tests

}
}

public class NotificationStatusDetailsListCustomization(int count) : ICustomization
Copy link

Choose a reason for hiding this comment

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

style: Consider adding XML documentation for this new class to improve code clarity

Comment on lines +46 to +49
public class NotificationStatusDetailsListCustomizeAttribute(int count) : BitCustomizeAttribute
{
public override ICustomization GetCustomization() => new NotificationStatusDetailsListCustomization(count);
}
Copy link

Choose a reason for hiding this comment

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

style: Add XML documentation for this new attribute class

LEFT JOIN [dbo].[OrganizationUserView] ou ON n.[OrganizationId] = ou.[OrganizationId]
AND ou.[UserId] = @UserId
WHERE (n.[NotificationStatusUserId] IS NULL OR n.[NotificationStatusUserId] = @UserId)
AND [ClientType] IN (0, CASE WHEN @ClientType != 0 THEN @ClientType END)
Copy link

Choose a reason for hiding this comment

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

logic: this logic might allow unintended client types if @ClientType is 0

Comment on lines +26 to +35
AND ((@Read IS NULL AND @Deleted IS NULL)
OR (n.[NotificationStatusUserId] IS NOT NULL
AND (@Read IS NULL
OR IIF((@Read = 1 AND n.[ReadDate] IS NOT NULL) OR
(@Read = 0 AND n.[ReadDate] IS NULL),
1, 0) = 1)
AND (@Deleted IS NULL
OR IIF((@Deleted = 1 AND n.[DeletedDate] IS NOT NULL) OR
(@Deleted = 0 AND n.[DeletedDate] IS NULL),
1, 0) = 1)))
Copy link

Choose a reason for hiding this comment

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

style: complex nested logic for @READ and @deleted filters may be hard to maintain

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