mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
Fix password re-prompt not working in org view (#1296)
* Fix password reprompt not working in org view * Also fix Cipher_UpdateWithCollections and CipherDetails_CreateWithCollections. Rename migration script
This commit is contained in:
parent
179e6aa76b
commit
6ada46f906
@ -60,7 +60,6 @@ namespace Bit.Core.Models.Api
|
|||||||
{
|
{
|
||||||
existingCipher.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
existingCipher.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
||||||
existingCipher.Favorite = Favorite;
|
existingCipher.Favorite = Favorite;
|
||||||
existingCipher.Reprompt = Reprompt;
|
|
||||||
ToCipher(existingCipher);
|
ToCipher(existingCipher);
|
||||||
return existingCipher;
|
return existingCipher;
|
||||||
}
|
}
|
||||||
@ -91,6 +90,8 @@ namespace Bit.Core.Models.Api
|
|||||||
throw new ArgumentException("Unsupported type: " + nameof(Type) + ".");
|
throw new ArgumentException("Unsupported type: " + nameof(Type) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingCipher.Reprompt = Reprompt;
|
||||||
|
|
||||||
var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
|
var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
|
||||||
var hasAttachments = (Attachments?.Count ?? 0) > 0;
|
var hasAttachments = (Attachments?.Count ?? 0) > 0;
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ namespace Bit.Core.Models.Api
|
|||||||
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
|
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
|
||||||
OrganizationUseTotp = orgUseTotp;
|
OrganizationUseTotp = orgUseTotp;
|
||||||
DeletedDate = cipher.DeletedDate;
|
DeletedDate = cipher.DeletedDate;
|
||||||
|
Reprompt = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
@ -81,6 +82,7 @@ namespace Bit.Core.Models.Api
|
|||||||
public bool OrganizationUseTotp { get; set; }
|
public bool OrganizationUseTotp { get; set; }
|
||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
public DateTime? DeletedDate { get; set; }
|
public DateTime? DeletedDate { get; set; }
|
||||||
|
public CipherRepromptType Reprompt { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CipherResponseModel : CipherMiniResponseModel
|
public class CipherResponseModel : CipherMiniResponseModel
|
||||||
@ -92,14 +94,12 @@ namespace Bit.Core.Models.Api
|
|||||||
Favorite = cipher.Favorite;
|
Favorite = cipher.Favorite;
|
||||||
Edit = cipher.Edit;
|
Edit = cipher.Edit;
|
||||||
ViewPassword = cipher.ViewPassword;
|
ViewPassword = cipher.ViewPassword;
|
||||||
Reprompt = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
public bool Favorite { get; set; }
|
public bool Favorite { get; set; }
|
||||||
public bool Edit { get; set; }
|
public bool Edit { get; set; }
|
||||||
public bool ViewPassword { get; set; }
|
public bool ViewPassword { get; set; }
|
||||||
public CipherRepromptType Reprompt { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CipherDetailsResponseModel : CipherResponseModel
|
public class CipherDetailsResponseModel : CipherResponseModel
|
||||||
|
@ -668,6 +668,8 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
ciphersTable.Columns.Add(revisionDateColumn);
|
ciphersTable.Columns.Add(revisionDateColumn);
|
||||||
var deletedDateColumn = new DataColumn(nameof(c.DeletedDate), typeof(DateTime));
|
var deletedDateColumn = new DataColumn(nameof(c.DeletedDate), typeof(DateTime));
|
||||||
ciphersTable.Columns.Add(deletedDateColumn);
|
ciphersTable.Columns.Add(deletedDateColumn);
|
||||||
|
var repromptColumn = new DataColumn(nameof(c.Reprompt), typeof(short));
|
||||||
|
ciphersTable.Columns.Add(repromptColumn);
|
||||||
|
|
||||||
foreach (DataColumn col in ciphersTable.Columns)
|
foreach (DataColumn col in ciphersTable.Columns)
|
||||||
{
|
{
|
||||||
@ -693,6 +695,7 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
row[creationDateColumn] = cipher.CreationDate;
|
row[creationDateColumn] = cipher.CreationDate;
|
||||||
row[revisionDateColumn] = cipher.RevisionDate;
|
row[revisionDateColumn] = cipher.RevisionDate;
|
||||||
row[deletedDateColumn] = cipher.DeletedDate.HasValue ? (object)cipher.DeletedDate : DBNull.Value;
|
row[deletedDateColumn] = cipher.DeletedDate.HasValue ? (object)cipher.DeletedDate : DBNull.Value;
|
||||||
|
row[repromptColumn] = cipher.Reprompt;
|
||||||
|
|
||||||
ciphersTable.Rows.Add(row);
|
ciphersTable.Rows.Add(row);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
@ViewPassword BIT, -- not used
|
@ViewPassword BIT, -- not used
|
||||||
@OrganizationUseTotp BIT, -- not used
|
@OrganizationUseTotp BIT, -- not used
|
||||||
@DeletedDate DATETIME2(7),
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -22,7 +23,7 @@ BEGIN
|
|||||||
|
|
||||||
EXEC [dbo].[CipherDetails_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
EXEC [dbo].[CipherDetails_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||||
@Attachments, @CreationDate, @RevisionDate, @FolderId, @Favorite, @Edit, @ViewPassword,
|
@Attachments, @CreationDate, @RevisionDate, @FolderId, @Favorite, @Edit, @ViewPassword,
|
||||||
@OrganizationUseTotp, @DeletedDate
|
@OrganizationUseTotp, @DeletedDate, @Reprompt
|
||||||
|
|
||||||
DECLARE @UpdateCollectionsSuccess INT
|
DECLARE @UpdateCollectionsSuccess INT
|
||||||
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
@Attachments NVARCHAR(MAX),
|
@Attachments NVARCHAR(MAX),
|
||||||
@CreationDate DATETIME2(7),
|
@CreationDate DATETIME2(7),
|
||||||
@RevisionDate DATETIME2(7),
|
@RevisionDate DATETIME2(7),
|
||||||
@DeletedDate DATETIME2(7)
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -26,7 +27,8 @@ BEGIN
|
|||||||
[Attachments],
|
[Attachments],
|
||||||
[CreationDate],
|
[CreationDate],
|
||||||
[RevisionDate],
|
[RevisionDate],
|
||||||
[DeletedDate]
|
[DeletedDate],
|
||||||
|
[Reprompt]
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
@ -40,7 +42,8 @@ BEGIN
|
|||||||
@Attachments,
|
@Attachments,
|
||||||
@CreationDate,
|
@CreationDate,
|
||||||
@RevisionDate,
|
@RevisionDate,
|
||||||
@DeletedDate
|
@DeletedDate,
|
||||||
|
@Reprompt
|
||||||
)
|
)
|
||||||
|
|
||||||
IF @OrganizationId IS NOT NULL
|
IF @OrganizationId IS NOT NULL
|
||||||
|
@ -10,13 +10,14 @@
|
|||||||
@CreationDate DATETIME2(7),
|
@CreationDate DATETIME2(7),
|
||||||
@RevisionDate DATETIME2(7),
|
@RevisionDate DATETIME2(7),
|
||||||
@DeletedDate DATETIME2(7),
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
|
|
||||||
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||||
@Attachments, @CreationDate, @RevisionDate, @DeletedDate
|
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt
|
||||||
|
|
||||||
DECLARE @UpdateCollectionsSuccess INT
|
DECLARE @UpdateCollectionsSuccess INT
|
||||||
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
@Attachments NVARCHAR(MAX),
|
@Attachments NVARCHAR(MAX),
|
||||||
@CreationDate DATETIME2(7),
|
@CreationDate DATETIME2(7),
|
||||||
@RevisionDate DATETIME2(7),
|
@RevisionDate DATETIME2(7),
|
||||||
@DeletedDate DATETIME2(7)
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -26,7 +27,8 @@ BEGIN
|
|||||||
[Attachments] = @Attachments,
|
[Attachments] = @Attachments,
|
||||||
[CreationDate] = @CreationDate,
|
[CreationDate] = @CreationDate,
|
||||||
[RevisionDate] = @RevisionDate,
|
[RevisionDate] = @RevisionDate,
|
||||||
[DeletedDate] = @DeletedDate
|
[DeletedDate] = @DeletedDate,
|
||||||
|
[Reprompt] = @Reprompt
|
||||||
WHERE
|
WHERE
|
||||||
[Id] = @Id
|
[Id] = @Id
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
@CreationDate DATETIME2(7),
|
@CreationDate DATETIME2(7),
|
||||||
@RevisionDate DATETIME2(7),
|
@RevisionDate DATETIME2(7),
|
||||||
@DeletedDate DATETIME2(7),
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
|
@ -1,196 +0,0 @@
|
|||||||
IF COL_LENGTH('[dbo].[Cipher]', 'Reprompt') IS NULL
|
|
||||||
BEGIN
|
|
||||||
ALTER TABLE [dbo].[Cipher]
|
|
||||||
ADD [Reprompt] TINYINT NULL;
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
IF OBJECT_ID('[dbo].[CipherDetails]') IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
DROP FUNCTION [dbo].[CipherDetails]
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
CREATE FUNCTION [dbo].[CipherDetails](@UserId UNIQUEIDENTIFIER)
|
|
||||||
RETURNS TABLE
|
|
||||||
AS RETURN
|
|
||||||
SELECT
|
|
||||||
C.[Id],
|
|
||||||
C.[UserId],
|
|
||||||
C.[OrganizationId],
|
|
||||||
C.[Type],
|
|
||||||
C.[Data],
|
|
||||||
C.[Attachments],
|
|
||||||
C.[CreationDate],
|
|
||||||
C.[RevisionDate],
|
|
||||||
CASE
|
|
||||||
WHEN
|
|
||||||
@UserId IS NULL
|
|
||||||
OR C.[Favorites] IS NULL
|
|
||||||
OR JSON_VALUE(C.[Favorites], CONCAT('$."', @UserId, '"')) IS NULL
|
|
||||||
THEN 0
|
|
||||||
ELSE 1
|
|
||||||
END [Favorite],
|
|
||||||
CASE
|
|
||||||
WHEN
|
|
||||||
@UserId IS NULL
|
|
||||||
OR C.[Folders] IS NULL
|
|
||||||
THEN NULL
|
|
||||||
ELSE TRY_CONVERT(UNIQUEIDENTIFIER, JSON_VALUE(C.[Folders], CONCAT('$."', @UserId, '"')))
|
|
||||||
END [FolderId],
|
|
||||||
C.[DeletedDate],
|
|
||||||
C.[Reprompt]
|
|
||||||
FROM
|
|
||||||
[dbo].[Cipher] C
|
|
||||||
GO
|
|
||||||
|
|
||||||
IF OBJECT_ID('[dbo].[UserCipherDetails]') IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
EXECUTE sp_refreshsqlmodule N'[dbo].[UserCipherDetails]';
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
IF OBJECT_ID('[dbo].[CipherDetails_Create]') IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
DROP PROCEDURE [dbo].[CipherDetails_Create]
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[CipherDetails_Create]
|
|
||||||
@Id UNIQUEIDENTIFIER,
|
|
||||||
@UserId UNIQUEIDENTIFIER,
|
|
||||||
@OrganizationId UNIQUEIDENTIFIER,
|
|
||||||
@Type TINYINT,
|
|
||||||
@Data NVARCHAR(MAX),
|
|
||||||
@Favorites NVARCHAR(MAX), -- not used
|
|
||||||
@Folders NVARCHAR(MAX), -- not used
|
|
||||||
@Attachments NVARCHAR(MAX), -- not used
|
|
||||||
@CreationDate DATETIME2(7),
|
|
||||||
@RevisionDate DATETIME2(7),
|
|
||||||
@FolderId UNIQUEIDENTIFIER,
|
|
||||||
@Favorite BIT,
|
|
||||||
@Edit BIT, -- not used
|
|
||||||
@ViewPassword BIT, -- not used
|
|
||||||
@OrganizationUseTotp BIT, -- not used
|
|
||||||
@DeletedDate DATETIME2(7),
|
|
||||||
@Reprompt TINYINT
|
|
||||||
AS
|
|
||||||
BEGIN
|
|
||||||
SET NOCOUNT ON
|
|
||||||
|
|
||||||
DECLARE @UserIdKey VARCHAR(50) = CONCAT('"', @UserId, '"')
|
|
||||||
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$.', @UserIdKey)
|
|
||||||
|
|
||||||
INSERT INTO [dbo].[Cipher]
|
|
||||||
(
|
|
||||||
[Id],
|
|
||||||
[UserId],
|
|
||||||
[OrganizationId],
|
|
||||||
[Type],
|
|
||||||
[Data],
|
|
||||||
[Favorites],
|
|
||||||
[Folders],
|
|
||||||
[CreationDate],
|
|
||||||
[RevisionDate],
|
|
||||||
[DeletedDate],
|
|
||||||
[Reprompt]
|
|
||||||
)
|
|
||||||
VALUES
|
|
||||||
(
|
|
||||||
@Id,
|
|
||||||
CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
|
||||||
@OrganizationId,
|
|
||||||
@Type,
|
|
||||||
@Data,
|
|
||||||
CASE WHEN @Favorite = 1 THEN CONCAT('{', @UserIdKey, ':true}') ELSE NULL END,
|
|
||||||
CASE WHEN @FolderId IS NOT NULL THEN CONCAT('{', @UserIdKey, ':"', @FolderId, '"', '}') ELSE NULL END,
|
|
||||||
@CreationDate,
|
|
||||||
@RevisionDate,
|
|
||||||
@DeletedDate,
|
|
||||||
@Reprompt
|
|
||||||
)
|
|
||||||
|
|
||||||
IF @OrganizationId IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
|
||||||
END
|
|
||||||
ELSE IF @UserId IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
|
||||||
END
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
IF OBJECT_ID('[dbo].[CipherDetails_Update]') IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
DROP PROCEDURE [dbo].[CipherDetails_Update]
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
|
|
||||||
CREATE PROCEDURE [dbo].[CipherDetails_Update]
|
|
||||||
@Id UNIQUEIDENTIFIER,
|
|
||||||
@UserId UNIQUEIDENTIFIER,
|
|
||||||
@OrganizationId UNIQUEIDENTIFIER,
|
|
||||||
@Type TINYINT,
|
|
||||||
@Data NVARCHAR(MAX),
|
|
||||||
@Favorites NVARCHAR(MAX), -- not used
|
|
||||||
@Folders NVARCHAR(MAX), -- not used
|
|
||||||
@Attachments NVARCHAR(MAX), -- not used
|
|
||||||
@CreationDate DATETIME2(7),
|
|
||||||
@RevisionDate DATETIME2(7),
|
|
||||||
@FolderId UNIQUEIDENTIFIER,
|
|
||||||
@Favorite BIT,
|
|
||||||
@Edit BIT, -- not used
|
|
||||||
@ViewPassword BIT, -- not used
|
|
||||||
@OrganizationUseTotp BIT, -- not used
|
|
||||||
@DeletedDate DATETIME2(2),
|
|
||||||
@Reprompt TINYINT
|
|
||||||
AS
|
|
||||||
BEGIN
|
|
||||||
SET NOCOUNT ON
|
|
||||||
|
|
||||||
DECLARE @UserIdKey VARCHAR(50) = CONCAT('"', @UserId, '"')
|
|
||||||
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$.', @UserIdKey)
|
|
||||||
|
|
||||||
UPDATE
|
|
||||||
[dbo].[Cipher]
|
|
||||||
SET
|
|
||||||
[UserId] = CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
|
||||||
[OrganizationId] = @OrganizationId,
|
|
||||||
[Type] = @Type,
|
|
||||||
[Data] = @Data,
|
|
||||||
[Folders] =
|
|
||||||
CASE
|
|
||||||
WHEN @FolderId IS NOT NULL AND [Folders] IS NULL THEN
|
|
||||||
CONCAT('{', @UserIdKey, ':"', @FolderId, '"', '}')
|
|
||||||
WHEN @FolderId IS NOT NULL THEN
|
|
||||||
JSON_MODIFY([Folders], @UserIdPath, CAST(@FolderId AS VARCHAR(50)))
|
|
||||||
ELSE
|
|
||||||
JSON_MODIFY([Folders], @UserIdPath, NULL)
|
|
||||||
END,
|
|
||||||
[Favorites] =
|
|
||||||
CASE
|
|
||||||
WHEN @Favorite = 1 AND [Favorites] IS NULL THEN
|
|
||||||
CONCAT('{', @UserIdKey, ':true}')
|
|
||||||
WHEN @Favorite = 1 THEN
|
|
||||||
JSON_MODIFY([Favorites], @UserIdPath, CAST(1 AS BIT))
|
|
||||||
ELSE
|
|
||||||
JSON_MODIFY([Favorites], @UserIdPath, NULL)
|
|
||||||
END,
|
|
||||||
[Reprompt] = @Reprompt,
|
|
||||||
[CreationDate] = @CreationDate,
|
|
||||||
[RevisionDate] = @RevisionDate,
|
|
||||||
[DeletedDate] = @DeletedDate
|
|
||||||
WHERE
|
|
||||||
[Id] = @Id
|
|
||||||
|
|
||||||
IF @OrganizationId IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
|
||||||
END
|
|
||||||
ELSE IF @UserId IS NOT NULL
|
|
||||||
BEGIN
|
|
||||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
|
||||||
END
|
|
||||||
END
|
|
||||||
GO
|
|
@ -0,0 +1,450 @@
|
|||||||
|
IF COL_LENGTH('[dbo].[Cipher]', 'Reprompt') IS NULL
|
||||||
|
BEGIN
|
||||||
|
ALTER TABLE [dbo].[Cipher]
|
||||||
|
ADD [Reprompt] TINYINT NULL;
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CipherDetails]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP FUNCTION [dbo].[CipherDetails]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE FUNCTION [dbo].[CipherDetails](@UserId UNIQUEIDENTIFIER)
|
||||||
|
RETURNS TABLE
|
||||||
|
AS RETURN
|
||||||
|
SELECT
|
||||||
|
C.[Id],
|
||||||
|
C.[UserId],
|
||||||
|
C.[OrganizationId],
|
||||||
|
C.[Type],
|
||||||
|
C.[Data],
|
||||||
|
C.[Attachments],
|
||||||
|
C.[CreationDate],
|
||||||
|
C.[RevisionDate],
|
||||||
|
CASE
|
||||||
|
WHEN
|
||||||
|
@UserId IS NULL
|
||||||
|
OR C.[Favorites] IS NULL
|
||||||
|
OR JSON_VALUE(C.[Favorites], CONCAT('$."', @UserId, '"')) IS NULL
|
||||||
|
THEN 0
|
||||||
|
ELSE 1
|
||||||
|
END [Favorite],
|
||||||
|
CASE
|
||||||
|
WHEN
|
||||||
|
@UserId IS NULL
|
||||||
|
OR C.[Folders] IS NULL
|
||||||
|
THEN NULL
|
||||||
|
ELSE TRY_CONVERT(UNIQUEIDENTIFIER, JSON_VALUE(C.[Folders], CONCAT('$."', @UserId, '"')))
|
||||||
|
END [FolderId],
|
||||||
|
C.[DeletedDate],
|
||||||
|
C.[Reprompt]
|
||||||
|
FROM
|
||||||
|
[dbo].[Cipher] C
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[UserCipherDetails]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXECUTE sp_refreshsqlmodule N'[dbo].[UserCipherDetails]';
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CipherView]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXECUTE sp_refreshsqlmodule N'[dbo].[CipherView]';
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CipherDetails_Create]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[CipherDetails_Create]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[CipherDetails_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX), -- not used
|
||||||
|
@Folders NVARCHAR(MAX), -- not used
|
||||||
|
@Attachments NVARCHAR(MAX), -- not used
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@FolderId UNIQUEIDENTIFIER,
|
||||||
|
@Favorite BIT,
|
||||||
|
@Edit BIT, -- not used
|
||||||
|
@ViewPassword BIT, -- not used
|
||||||
|
@OrganizationUseTotp BIT, -- not used
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DECLARE @UserIdKey VARCHAR(50) = CONCAT('"', @UserId, '"')
|
||||||
|
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$.', @UserIdKey)
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[Cipher]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[UserId],
|
||||||
|
[OrganizationId],
|
||||||
|
[Type],
|
||||||
|
[Data],
|
||||||
|
[Favorites],
|
||||||
|
[Folders],
|
||||||
|
[CreationDate],
|
||||||
|
[RevisionDate],
|
||||||
|
[DeletedDate],
|
||||||
|
[Reprompt]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
||||||
|
@OrganizationId,
|
||||||
|
@Type,
|
||||||
|
@Data,
|
||||||
|
CASE WHEN @Favorite = 1 THEN CONCAT('{', @UserIdKey, ':true}') ELSE NULL END,
|
||||||
|
CASE WHEN @FolderId IS NOT NULL THEN CONCAT('{', @UserIdKey, ':"', @FolderId, '"', '}') ELSE NULL END,
|
||||||
|
@CreationDate,
|
||||||
|
@RevisionDate,
|
||||||
|
@DeletedDate,
|
||||||
|
@Reprompt
|
||||||
|
)
|
||||||
|
|
||||||
|
IF @OrganizationId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
||||||
|
END
|
||||||
|
ELSE IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CipherDetails_Update]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[CipherDetails_Update]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[CipherDetails_Update]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX), -- not used
|
||||||
|
@Folders NVARCHAR(MAX), -- not used
|
||||||
|
@Attachments NVARCHAR(MAX), -- not used
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@FolderId UNIQUEIDENTIFIER,
|
||||||
|
@Favorite BIT,
|
||||||
|
@Edit BIT, -- not used
|
||||||
|
@ViewPassword BIT, -- not used
|
||||||
|
@OrganizationUseTotp BIT, -- not used
|
||||||
|
@DeletedDate DATETIME2(2),
|
||||||
|
@Reprompt TINYINT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DECLARE @UserIdKey VARCHAR(50) = CONCAT('"', @UserId, '"')
|
||||||
|
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$.', @UserIdKey)
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
[dbo].[Cipher]
|
||||||
|
SET
|
||||||
|
[UserId] = CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
||||||
|
[OrganizationId] = @OrganizationId,
|
||||||
|
[Type] = @Type,
|
||||||
|
[Data] = @Data,
|
||||||
|
[Folders] =
|
||||||
|
CASE
|
||||||
|
WHEN @FolderId IS NOT NULL AND [Folders] IS NULL THEN
|
||||||
|
CONCAT('{', @UserIdKey, ':"', @FolderId, '"', '}')
|
||||||
|
WHEN @FolderId IS NOT NULL THEN
|
||||||
|
JSON_MODIFY([Folders], @UserIdPath, CAST(@FolderId AS VARCHAR(50)))
|
||||||
|
ELSE
|
||||||
|
JSON_MODIFY([Folders], @UserIdPath, NULL)
|
||||||
|
END,
|
||||||
|
[Favorites] =
|
||||||
|
CASE
|
||||||
|
WHEN @Favorite = 1 AND [Favorites] IS NULL THEN
|
||||||
|
CONCAT('{', @UserIdKey, ':true}')
|
||||||
|
WHEN @Favorite = 1 THEN
|
||||||
|
JSON_MODIFY([Favorites], @UserIdPath, CAST(1 AS BIT))
|
||||||
|
ELSE
|
||||||
|
JSON_MODIFY([Favorites], @UserIdPath, NULL)
|
||||||
|
END,
|
||||||
|
[Reprompt] = @Reprompt,
|
||||||
|
[CreationDate] = @CreationDate,
|
||||||
|
[RevisionDate] = @RevisionDate,
|
||||||
|
[DeletedDate] = @DeletedDate
|
||||||
|
WHERE
|
||||||
|
[Id] = @Id
|
||||||
|
|
||||||
|
IF @OrganizationId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
||||||
|
END
|
||||||
|
ELSE IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[Cipher_Update]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Cipher_Update]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Cipher_Update]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX),
|
||||||
|
@Folders NVARCHAR(MAX),
|
||||||
|
@Attachments NVARCHAR(MAX),
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
[dbo].[Cipher]
|
||||||
|
SET
|
||||||
|
[UserId] = CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
||||||
|
[OrganizationId] = @OrganizationId,
|
||||||
|
[Type] = @Type,
|
||||||
|
[Data] = @Data,
|
||||||
|
[Favorites] = @Favorites,
|
||||||
|
[Folders] = @Folders,
|
||||||
|
[Attachments] = @Attachments,
|
||||||
|
[CreationDate] = @CreationDate,
|
||||||
|
[RevisionDate] = @RevisionDate,
|
||||||
|
[DeletedDate] = @DeletedDate,
|
||||||
|
[Reprompt] = @Reprompt
|
||||||
|
WHERE
|
||||||
|
[Id] = @Id
|
||||||
|
|
||||||
|
IF @OrganizationId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
||||||
|
END
|
||||||
|
ELSE IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[Cipher_Create]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Cipher_Create]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Cipher_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX),
|
||||||
|
@Folders NVARCHAR(MAX),
|
||||||
|
@Attachments NVARCHAR(MAX),
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[Cipher]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[UserId],
|
||||||
|
[OrganizationId],
|
||||||
|
[Type],
|
||||||
|
[Data],
|
||||||
|
[Favorites],
|
||||||
|
[Folders],
|
||||||
|
[Attachments],
|
||||||
|
[CreationDate],
|
||||||
|
[RevisionDate],
|
||||||
|
[DeletedDate],
|
||||||
|
[Reprompt]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
CASE WHEN @OrganizationId IS NULL THEN @UserId ELSE NULL END,
|
||||||
|
@OrganizationId,
|
||||||
|
@Type,
|
||||||
|
@Data,
|
||||||
|
@Favorites,
|
||||||
|
@Folders,
|
||||||
|
@Attachments,
|
||||||
|
@CreationDate,
|
||||||
|
@RevisionDate,
|
||||||
|
@DeletedDate,
|
||||||
|
@Reprompt
|
||||||
|
)
|
||||||
|
|
||||||
|
IF @OrganizationId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
||||||
|
END
|
||||||
|
ELSE IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[Cipher_CreateWithCollections]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Cipher_CreateWithCollections]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Cipher_CreateWithCollections]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX),
|
||||||
|
@Folders NVARCHAR(MAX),
|
||||||
|
@Attachments NVARCHAR(MAX),
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||||
|
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt
|
||||||
|
|
||||||
|
DECLARE @UpdateCollectionsSuccess INT
|
||||||
|
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[Cipher_UpdateWithCollections]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Cipher_UpdateWithCollections]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Cipher_UpdateWithCollections]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX),
|
||||||
|
@Folders NVARCHAR(MAX),
|
||||||
|
@Attachments NVARCHAR(MAX),
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
BEGIN TRANSACTION Cipher_UpdateWithCollections
|
||||||
|
|
||||||
|
DECLARE @UpdateCollectionsSuccess INT
|
||||||
|
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||||
|
|
||||||
|
IF @UpdateCollectionsSuccess < 0
|
||||||
|
BEGIN
|
||||||
|
COMMIT TRANSACTION Cipher_UpdateWithCollections
|
||||||
|
SELECT -1 -- -1 = Failure
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
[dbo].[Cipher]
|
||||||
|
SET
|
||||||
|
[UserId] = NULL,
|
||||||
|
[OrganizationId] = @OrganizationId,
|
||||||
|
[Data] = @Data,
|
||||||
|
[Attachments] = @Attachments,
|
||||||
|
[RevisionDate] = @RevisionDate,
|
||||||
|
[DeletedDate] = @DeletedDate
|
||||||
|
-- No need to update CreationDate, Favorites, Folders, or Type since that data will not change
|
||||||
|
WHERE
|
||||||
|
[Id] = @Id
|
||||||
|
|
||||||
|
COMMIT TRANSACTION Cipher_UpdateWithCollections
|
||||||
|
|
||||||
|
IF @Attachments IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
|
||||||
|
EXEC [dbo].[User_UpdateStorage] @UserId
|
||||||
|
END
|
||||||
|
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
|
||||||
|
|
||||||
|
SELECT 0 -- 0 = Success
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CipherDetails_CreateWithCollections]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[CipherDetails_CreateWithCollections]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[CipherDetails_CreateWithCollections]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data NVARCHAR(MAX),
|
||||||
|
@Favorites NVARCHAR(MAX), -- not used
|
||||||
|
@Folders NVARCHAR(MAX), -- not used
|
||||||
|
@Attachments NVARCHAR(MAX), -- not used
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@FolderId UNIQUEIDENTIFIER,
|
||||||
|
@Favorite BIT,
|
||||||
|
@Edit BIT, -- not used
|
||||||
|
@ViewPassword BIT, -- not used
|
||||||
|
@OrganizationUseTotp BIT, -- not used
|
||||||
|
@DeletedDate DATETIME2(7),
|
||||||
|
@Reprompt TINYINT,
|
||||||
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
EXEC [dbo].[CipherDetails_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||||
|
@Attachments, @CreationDate, @RevisionDate, @FolderId, @Favorite, @Edit, @ViewPassword,
|
||||||
|
@OrganizationUseTotp, @DeletedDate, @Reprompt
|
||||||
|
|
||||||
|
DECLARE @UpdateCollectionsSuccess INT
|
||||||
|
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||||
|
END
|
@ -9,10 +9,6 @@
|
|||||||
<EmbeddedResource Include="DbScripts\**\*.sql" />
|
<EmbeddedResource Include="DbScripts\**\*.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="DbScripts\2021-04-13_00_CipherPasswordPrompt.sql" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="dbup-sqlserver" Version="4.4.0" />
|
<PackageReference Include="dbup-sqlserver" Version="4.4.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
|
||||||
|
Loading…
Reference in New Issue
Block a user