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-13298] Modify members access logic #18

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

Conversation

lizard-boy
Copy link

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

🎟️ Tracking

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

📔 Objective

An association of organization members to the ciphers they are assigned is needed. The members access report has been refactored to abstract the logic into a reusable query. The models will contain the cipher ids associated with each member. The existing members access report will continue using the same MembersAccessReportResponseModel while the new endpoint for associating members to ciphers will use a new `MemberCipherDetailsResponseModel' that contains the member info along with a distinct list of assigned cipher ids.

⏰ 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 changes to enhance member access logic and reporting capabilities in the Bitwarden server application. The modifications focus on associating organization members with their assigned ciphers and refactoring existing report generation.

  • Added new MemberCipherDetailsResponseModel in /src/Api/Tools/Models/Response/MemberCipherDetailsResponseModel.cs for associating members with ciphers
  • Introduced MemberAccessCipherDetailsQuery in /src/Core/Tools/ReportFeatures/MemberAccessCipherDetailsQuery.cs to generate detailed access reports
  • Modified ReportsController in /src/Api/Tools/Controllers/ReportsController.cs to include a new endpoint for retrieving member cipher details
  • Refactored MemberAccessReportResponseModel in /src/Api/Tools/Models/Response/MemberAccessReportModel.cs to use MemberAccessCipherDetails
  • Added IMemberAccessCipherDetailsQuery interface in /src/Core/Tools/ReportFeatures/OrganizationReportMembers/Interfaces/IMemberAccessCipherDetailsQuery.cs for querying member access details

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.

9 file(s) reviewed, 22 comment(s)
Edit PR Review Bot Settings | Greptile

/// Organization member information containing a list of cipher ids
/// assigned
/// </summary>
/// <param name="orgId">Organzation Id</param>
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in 'Organzation', should be 'Organization'

Comment on lines +40 to +43
if (!await _currentContext.AccessReports(orgId))
{
throw new NotFoundException();
}
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 a more specific exception like UnauthorizedException instead of NotFoundException for permission issues

throw new NotFoundException();
}

var memberCipherDetails = await GetMemberCipherDetails(new MemberAccessCipherDetailsRequest { OrganizationId = orgId });
Copy link

Choose a reason for hiding this comment

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

logic: Method name clash with the public method. Rename private method to avoid confusion

Comment on lines +80 to 85
private async Task<IEnumerable<MemberAccessCipherDetails>> GetMemberCipherDetails(MemberAccessCipherDetailsRequest request)
{
var memberCipherDetails =
await _memberAccessCipherDetailsQuery.GetMemberAccessCipherDetails(request);
return memberCipherDetails;
}
Copy link

Choose a reason for hiding this comment

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

style: This private method could be inlined as it's only called once and doesn't add much abstraction

Comment on lines 18 to 19
public Guid? UserGuid { get; set; }
public bool UsesKeyConnector { get; set; }
Copy link

Choose a reason for hiding this comment

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

logic: UserGuid is not being set in the constructor

Comment on lines +192 to +197
var userCiphers =
report.AccessDetails
.Where(x => x.ItemCount > 0)
.SelectMany(y => y.CollectionCipherIds)
.Distinct();
report.CipherIds = userCiphers;
Copy link

Choose a reason for hiding this comment

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

style: This LINQ query could be optimized by combining Where and SelectMany: var userCiphers = report.AccessDetails.Where(x => x.ItemCount > 0).SelectMany(y => y.CollectionCipherIds ?? Enumerable.Empty()).Distinct();

Comment on lines +201 to +203
var distinctItems = report.AccessDetails.Where(x => x.CollectionId.HasValue).Select(x => x.CollectionId).Distinct();
report.CollectionsCount = distinctItems.Count();
report.GroupsCount = report.AccessDetails.Select(x => x.GroupId).Where(y => y.HasValue).Distinct().Count();
Copy link

Choose a reason for hiding this comment

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

style: These counts could be calculated more efficiently using a single LINQ query with grouping

Comment on lines +6 to +9
public interface IMemberAccessCipherDetailsQuery
{
Task<IEnumerable<MemberAccessCipherDetails>> GetMemberAccessCipherDetails(MemberAccessCipherDetailsRequest request);
}
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 comments to describe the purpose of the interface and method


public static class ReportingServiceCollectionExtensions
{
public static void AddReportingServices(this IServiceCollection services)
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 method

Comment on lines +3 to +6
public class MemberAccessCipherDetailsRequest
{
public Guid OrganizationId { get; set; }
}
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 comments to describe the purpose of this class and its property

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