mirror of
https://github.com/bitwarden/server
synced 2025-12-10 13:23:27 +00:00
[PM-20452] - Offloading Stripe Update (#6034)
* Adding job to update stripe subscriptions and increment seat count when inviting a user. * Updating name * Added ef migrations * Fixing script * Fixing procedures. Added repo tests. * Fixed set stored procedure. Fixed parameter name. * Added tests for database calls and updated stored procedures * Fixed build for sql file. * fixing sproc * File is nullsafe * Adding view to select from instead of table. * Updating UpdateSubscriptionStatus to use a CTE and do all the updates in 1 statement. * Setting revision date when incrementing seat count * Added feature flag check for the background job. * Fixing nullable property. * Removing new table and just adding the column to org. Updating to query and command. Updated tests. * Adding migration script rename * Add SyncSeats to Org.sql def * Adding contraint name * Removing old table files. * Added tests * Upped the frequency to be at the top of every 3rd hour. * Updating error message. * Removing extension method * Changed to GuidIdArray * Added xml doc and switched class to record
This commit is contained in:
@@ -220,4 +220,35 @@ public class OrganizationRepository : Repository<Organization, Guid>, IOrganizat
|
||||
return result.SingleOrDefault() ?? new OrganizationSeatCounts();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Organization>> GetOrganizationsForSubscriptionSyncAsync()
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
return await connection.QueryAsync<Organization>(
|
||||
"[dbo].[Organization_GetOrganizationsForSubscriptionSync]",
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task UpdateSuccessfulOrganizationSyncStatusAsync(IEnumerable<Guid> successfulOrganizations, DateTime syncDate)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
await connection.ExecuteAsync("[dbo].[Organization_UpdateSubscriptionStatus]",
|
||||
new
|
||||
{
|
||||
SuccessfulOrganizations = successfulOrganizations.ToGuidIdArrayTVP(),
|
||||
SyncDate = syncDate
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task IncrementSeatCountAsync(Guid organizationId, int increaseAmount, DateTime requestDate)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
await connection.ExecuteAsync("[dbo].[Organization_IncrementSeatCount]",
|
||||
new { OrganizationId = organizationId, SeatsToAdd = increaseAmount, RequestDate = requestDate },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,12 +660,14 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
|
||||
{
|
||||
await using var connection = new SqlConnection(_marsConnectionString);
|
||||
|
||||
var organizationUsersList = organizationUserCollection.ToList();
|
||||
|
||||
await connection.ExecuteAsync(
|
||||
$"[{Schema}].[OrganizationUser_CreateManyWithCollectionsAndGroups]",
|
||||
new
|
||||
{
|
||||
OrganizationUserData = JsonSerializer.Serialize(organizationUserCollection.Select(x => x.OrganizationUser)),
|
||||
CollectionData = JsonSerializer.Serialize(organizationUserCollection
|
||||
OrganizationUserData = JsonSerializer.Serialize(organizationUsersList.Select(x => x.OrganizationUser)),
|
||||
CollectionData = JsonSerializer.Serialize(organizationUsersList
|
||||
.SelectMany(x => x.Collections, (user, collection) => new CollectionUser
|
||||
{
|
||||
CollectionId = collection.Id,
|
||||
@@ -674,7 +676,7 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
|
||||
HidePasswords = collection.HidePasswords,
|
||||
Manage = collection.Manage
|
||||
})),
|
||||
GroupData = JsonSerializer.Serialize(organizationUserCollection
|
||||
GroupData = JsonSerializer.Serialize(organizationUsersList
|
||||
.SelectMany(x => x.Groups, (user, group) => new GroupUser
|
||||
{
|
||||
GroupId = group,
|
||||
|
||||
Reference in New Issue
Block a user