1
0
mirror of https://github.com/bitwarden/server synced 2025-12-16 16:23:31 +00:00

[AC-10362] Remove OrganizationUser.AccessAll from code (#4622)

* Remove OrganizationUser.AccessAll from code

* Add shadow property

* Remove remaining reference

* dotnet format

* Fix tests

* Bump migration dates
This commit is contained in:
Thomas Rittson
2024-08-26 21:03:44 +10:00
committed by GitHub
parent 78beac9f19
commit 22bd755b3c
21 changed files with 8249 additions and 159 deletions

View File

@@ -9,7 +9,6 @@ using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.AdminConsole.Helpers;
using Dapper;
using Microsoft.Data.SqlClient;
@@ -420,6 +419,7 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
public async Task<ICollection<Guid>?> CreateManyAsync(IEnumerable<OrganizationUser> organizationUsers)
{
organizationUsers = organizationUsers.ToList();
if (!organizationUsers.Any())
{
return default;
@@ -430,12 +430,11 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
organizationUser.SetNewId();
}
var orgUsersTVP = organizationUsers.ToTvp();
using (var connection = new SqlConnection(_marsConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[{Table}_CreateMany2]",
new { OrganizationUsersInput = orgUsersTVP },
$"[{Schema}].[{Table}_CreateMany]",
new { jsonData = JsonSerializer.Serialize(organizationUsers) },
commandType: CommandType.StoredProcedure);
}
@@ -444,17 +443,17 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
public async Task ReplaceManyAsync(IEnumerable<OrganizationUser> organizationUsers)
{
organizationUsers = organizationUsers.ToList();
if (!organizationUsers.Any())
{
return;
}
var orgUsersTVP = organizationUsers.ToTvp();
using (var connection = new SqlConnection(_marsConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[{Table}_UpdateMany2]",
new { OrganizationUsersInput = orgUsersTVP },
$"[{Schema}].[{Table}_UpdateMany]",
new { jsonData = JsonSerializer.Serialize(organizationUsers) },
commandType: CommandType.StoredProcedure);
}
}
@@ -539,27 +538,11 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
public UpdateEncryptedDataForKeyRotation UpdateForKeyRotation(
Guid userId, IEnumerable<OrganizationUser> resetPasswordKeys)
{
return async (SqlConnection connection, SqlTransaction transaction) =>
{
const string sql = @"
UPDATE
[dbo].[OrganizationUser]
SET
[ResetPasswordKey] = AR.[ResetPasswordKey]
FROM
[dbo].[OrganizationUser] OU
INNER JOIN
@ResetPasswordKeys AR ON OU.Id = AR.Id
WHERE
OU.[UserId] = @UserId";
var organizationUsersTVP = resetPasswordKeys.ToTvp();
return async (connection, transaction) =>
await connection.ExecuteAsync(
sql,
new { UserId = userId, resetPasswordKeys = organizationUsersTVP },
$"[{Schema}].[OrganizationUser_UpdateDataForKeyRotation]",
new { UserId = userId, OrganizationUserJson = JsonSerializer.Serialize(resetPasswordKeys) },
transaction: transaction,
commandType: CommandType.Text);
};
commandType: CommandType.StoredProcedure);
}
}