-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[PM-36965] feat: Add CSV export of cohort to cohort management table #7847
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
Draft
cyprain-okeke
wants to merge
5
commits into
main
Choose a base branch
from
billing/pm-36965/determining-eligibility-add.csv-export-of-cohort-to-cohort-management-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd8a0ee
[PM-36965] feat: Add CSV export of cohort to cohort management
cyprain-okeke c5af1ff
Merge branch 'main' into billing/pm-36965/determining-eligibility-addβ¦
cyprain-okeke eb9f5ad
Convert generated migrations to file-scoped namespace
cyprain-okeke 871ab8b
Log on post-abort disposal and document the broad export catch
cyprain-okeke fb61051
Merge branch 'main' into billing/pm-36965/determining-eligibility-addβ¦
cyprain-okeke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Core/Billing/Organizations/PlanMigration/Models/CohortAssignmentExportRow.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ο»Ώnamespace Bit.Core.Billing.Organizations.PlanMigration.Models; | ||
|
|
||
| /// <summary> | ||
| /// A single organization's row in a cohort CSV export. Pure data: the export query yields these, | ||
| /// and the Admin controller is responsible for CSV formatting and HTTP streaming. Contains no | ||
| /// Vault Data -- only org-level operational metadata. | ||
| /// </summary> | ||
| /// <param name="Id"> | ||
| /// The assignment <c>Id</c>. Used only as the keyset-paging tiebreaker; it is NOT written to the CSV. | ||
| /// </param> | ||
| /// <param name="OrganizationName">The organization's display name (joined from the Organization table).</param> | ||
| /// <param name="AssignedAt"> | ||
| /// The date the organization was assigned to the cohort (the assignment <c>CreationDate</c>). | ||
| /// </param> | ||
| public record CohortAssignmentExportRow( | ||
| Guid Id, | ||
| Guid OrganizationId, | ||
| string OrganizationName, | ||
| DateTime AssignedAt, | ||
| DateTime? ScheduledDate, | ||
| DateTime? MigratedDate); |
51 changes: 51 additions & 0 deletions
51
src/Core/Billing/Organizations/PlanMigration/Queries/IExportCohortAssignmentsQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| ο»Ώusing Bit.Core.Billing.Organizations.PlanMigration.Models; | ||
| using Bit.Core.Billing.Organizations.PlanMigration.Repositories; | ||
|
|
||
| namespace Bit.Core.Billing.Organizations.PlanMigration.Queries; | ||
|
|
||
| public interface IExportCohortAssignmentsQuery | ||
| { | ||
| /// <summary> | ||
| /// Streams every organization assigned to the cohort as <see cref="CohortAssignmentExportRow"/> | ||
| /// records, in a deterministic, cross-provider-stable order. Pure data: the caller is | ||
| /// responsible for any CSV formatting or HTTP streaming. The cohort's current state is read at | ||
| /// enumeration time (no caching). | ||
| /// </summary> | ||
| IAsyncEnumerable<CohortAssignmentExportRow> GetByCohortIdAsync(Guid cohortId); | ||
| } | ||
|
|
||
| public class ExportCohortAssignmentsQuery( | ||
| IOrganizationPlanMigrationCohortAssignmentRepository assignmentRepository) | ||
| : IExportCohortAssignmentsQuery | ||
| { | ||
| // Bounded page size keeps memory flat regardless of cohort size; each page is its own | ||
| // short-lived database read. | ||
| private const int _pageSize = 1000; | ||
|
|
||
| public async IAsyncEnumerable<CohortAssignmentExportRow> GetByCohortIdAsync(Guid cohortId) | ||
| { | ||
| DateTime? afterCreationDate = null; | ||
| Guid? afterId = null; | ||
|
|
||
| while (true) | ||
| { | ||
| var page = await assignmentRepository.GetExportRowsByCohortIdAsync( | ||
| cohortId, afterCreationDate, afterId, _pageSize); | ||
|
|
||
| foreach (var row in page) | ||
| { | ||
| yield return row; | ||
| } | ||
|
|
||
| // A page shorter than the requested size means there is nothing left to read. | ||
| if (page.Count < _pageSize) | ||
| { | ||
| yield break; | ||
| } | ||
|
|
||
| var last = page[^1]; | ||
| afterCreationDate = last.AssignedAt; | ||
| afterId = last.Id; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.