1
0
mirror of https://github.com/bitwarden/server synced 2025-12-06 00:03:34 +00:00

[PM-26636] Set Key when Confirming (#6550)

* When confirming a uesr, we need to set the key. :face_palm:

* Adding default value.
This commit is contained in:
Jared McCannon
2025-11-10 14:46:52 -06:00
committed by GitHub
parent 4fac635272
commit 4de10c830d
5 changed files with 42 additions and 5 deletions

View File

@@ -681,7 +681,8 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
{ {
organizationUser.Id, organizationUser.Id,
organizationUser.UserId, organizationUser.UserId,
RevisionDate = DateTime.UtcNow.Date RevisionDate = DateTime.UtcNow.Date,
Key = organizationUser.Key
}); });
return rowCount > 0; return rowCount > 0;

View File

@@ -950,8 +950,9 @@ public class OrganizationUserRepository : Repository<Core.Entities.OrganizationU
var result = await dbContext.OrganizationUsers var result = await dbContext.OrganizationUsers
.Where(ou => ou.Id == organizationUser.Id && ou.Status == OrganizationUserStatusType.Accepted) .Where(ou => ou.Id == organizationUser.Id && ou.Status == OrganizationUserStatusType.Accepted)
.ExecuteUpdateAsync(x => .ExecuteUpdateAsync(x => x
x.SetProperty(y => y.Status, OrganizationUserStatusType.Confirmed)); .SetProperty(y => y.Status, OrganizationUserStatusType.Confirmed)
.SetProperty(y => y.Key, organizationUser.Key));
if (result <= 0) if (result <= 0)
{ {

View File

@@ -1,7 +1,8 @@
CREATE PROCEDURE [dbo].[OrganizationUser_ConfirmById] CREATE PROCEDURE [dbo].[OrganizationUser_ConfirmById]
@Id UNIQUEIDENTIFIER, @Id UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER, @UserId UNIQUEIDENTIFIER,
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7),
@Key NVARCHAR(MAX) = NULL
AS AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
@@ -12,7 +13,8 @@ BEGIN
[dbo].[OrganizationUser] [dbo].[OrganizationUser]
SET SET
[Status] = 2, -- Set to Confirmed [Status] = 2, -- Set to Confirmed
[RevisionDate] = @RevisionDate [RevisionDate] = @RevisionDate,
[Key] = @Key
WHERE WHERE
[Id] = @Id [Id] = @Id
AND [Status] = 1 -- Only update if status is Accepted AND [Status] = 1 -- Only update if status is Accepted

View File

@@ -1484,6 +1484,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository.CreateTestOrganizationAsync(); var organization = await organizationRepository.CreateTestOrganizationAsync();
var user = await userRepository.CreateTestUserAsync(); var user = await userRepository.CreateTestUserAsync();
var orgUser = await organizationUserRepository.CreateAcceptedTestOrganizationUserAsync(organization, user); var orgUser = await organizationUserRepository.CreateAcceptedTestOrganizationUserAsync(organization, user);
const string key = "test-key";
orgUser.Key = key;
// Act // Act
var result = await organizationUserRepository.ConfirmOrganizationUserAsync(orgUser); var result = await organizationUserRepository.ConfirmOrganizationUserAsync(orgUser);
@@ -1493,6 +1495,7 @@ public class OrganizationUserRepositoryTests
var updatedUser = await organizationUserRepository.GetByIdAsync(orgUser.Id); var updatedUser = await organizationUserRepository.GetByIdAsync(orgUser.Id);
Assert.NotNull(updatedUser); Assert.NotNull(updatedUser);
Assert.Equal(OrganizationUserStatusType.Confirmed, updatedUser.Status); Assert.Equal(OrganizationUserStatusType.Confirmed, updatedUser.Status);
Assert.Equal(key, updatedUser.Key);
// Annul // Annul
await organizationRepository.DeleteAsync(organization); await organizationRepository.DeleteAsync(organization);

View File

@@ -0,0 +1,30 @@
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_ConfirmById]
@Id UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@RevisionDate DATETIME2(7),
@Key NVARCHAR(MAX) = NULL
AS
BEGIN
SET NOCOUNT ON
DECLARE @RowCount INT;
UPDATE
[dbo].[OrganizationUser]
SET
[Status] = 2, -- Set to Confirmed
[RevisionDate] = @RevisionDate,
[Key] = @Key
WHERE
[Id] = @Id
AND [Status] = 1 -- Only update if status is Accepted
SET @RowCount = @@ROWCOUNT;
IF @RowCount > 0
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
END
SELECT @RowCount;
END