Skip to content

[PM-22097] Add Columns to Collections for Org User Default Collection #5908

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Core/Entities/Collection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
๏ปฟusing System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Utilities;

#nullable enable
Expand All @@ -14,6 +15,8 @@ public class Collection : ITableObject<Guid>
public string? ExternalId { get; set; }
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
public CollectionType Type { get; set; } = CollectionType.SharedCollection;
public string? DefaultUserCollectionEmail { get; set; }

public void SetNewId()
{
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Enums/CollectionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
๏ปฟnamespace Bit.Core.Enums;

public enum CollectionType
{
SharedCollection = 0,
DefaultUserCollection = 1,
}
12 changes: 9 additions & 3 deletions src/Sql/dbo/Stored Procedures/Collection_Create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
@Name VARCHAR(MAX),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
@RevisionDate DATETIME2(7),
@DefaultUserCollectionEmail NVARCHAR(256) = NULL,
@Type TINYINT = 0
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -16,7 +18,9 @@ BEGIN
[Name],
[ExternalId],
[CreationDate],
[RevisionDate]
[RevisionDate],
[DefaultUserCollectionEmail],
[Type]
)
VALUES
(
Expand All @@ -25,7 +29,9 @@ BEGIN
@Name,
@ExternalId,
@CreationDate,
@RevisionDate
@RevisionDate,
@DefaultUserCollectionEmail,
@Type
)

EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ CREATE PROCEDURE [dbo].[Collection_CreateWithGroupsAndUsers]
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Groups AS [dbo].[CollectionAccessSelectionType] READONLY,
@Users AS [dbo].[CollectionAccessSelectionType] READONLY
@Users AS [dbo].[CollectionAccessSelectionType] READONLY,
@DefaultUserCollectionEmail NVARCHAR(256) = NULL,
@Type TINYINT = 0
AS
BEGIN
SET NOCOUNT ON

EXEC [dbo].[Collection_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
EXEC [dbo].[Collection_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate, @DefaultUserCollectionEmail, @Type

-- Groups
;WITH [AvailableGroupsCTE] AS(
Expand Down
8 changes: 6 additions & 2 deletions src/Sql/dbo/Stored Procedures/Collection_ReadByUserId.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ BEGIN
ExternalId,
MIN([ReadOnly]) AS [ReadOnly],
MIN([HidePasswords]) AS [HidePasswords],
MAX([Manage]) AS [Manage]
MAX([Manage]) AS [Manage],
[DefaultUserCollectionEmail],
[Type]
FROM
[dbo].[UserCollectionDetails](@UserId)
GROUP BY
Expand All @@ -22,5 +24,7 @@ BEGIN
[Name],
CreationDate,
RevisionDate,
ExternalId
ExternalId,
[DefaultUserCollectionEmail],
[Type]
END
10 changes: 7 additions & 3 deletions src/Sql/dbo/Stored Procedures/Collection_Update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
@Name VARCHAR(MAX),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
@RevisionDate DATETIME2(7),
@DefaultUserCollectionEmail NVARCHAR(256) = NULL,
@Type TINYINT = 0
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -16,9 +18,11 @@ BEGIN
[Name] = @Name,
[ExternalId] = @ExternalId,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
[RevisionDate] = @RevisionDate,
[DefaultUserCollectionEmail] = @DefaultUserCollectionEmail,
[Type] = @Type
WHERE
[Id] = @Id

EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
END
END
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Groups AS [dbo].[CollectionAccessSelectionType] READONLY,
@Users AS [dbo].[CollectionAccessSelectionType] READONLY
@Users AS [dbo].[CollectionAccessSelectionType] READONLY,
@DefaultUserCollectionEmail NVARCHAR(256) = NULL,
@Type TINYINT = 0
AS
BEGIN
SET NOCOUNT ON

EXEC [dbo].[Collection_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
EXEC [dbo].[Collection_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate, @DefaultUserCollectionEmail, @Type

-- Groups
-- Delete groups that are no longer in source
Expand Down
14 changes: 8 additions & 6 deletions src/Sql/dbo/Tables/Collection.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
๏ปฟCREATE TABLE [dbo].[Collection] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Name] VARCHAR (MAX) NOT NULL,
[ExternalId] NVARCHAR (300) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
[Id] UNIQUEIDENTIFIER NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Name] VARCHAR (MAX) NOT NULL,
[ExternalId] NVARCHAR (300) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
[DefaultUserCollectionEmail] NVARCHAR(256) NULL,
[Type] TINYINT NOT NULL DEFAULT(0),
CONSTRAINT [PK_Collection] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Collection_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) ON DELETE CASCADE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ BEGIN
C.[Name],
C.[CreationDate],
C.[RevisionDate],
C.[ExternalId]
C.[ExternalId],
C.[DefaultUserCollectionEmail],
C.[Type]

IF (@IncludeAccessRelationships = 1)
BEGIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ BEGIN
C.[Name],
C.[CreationDate],
C.[RevisionDate],
C.[ExternalId]
C.[ExternalId],
C.[DefaultUserCollectionEmail],
C.[Type]

IF (@IncludeAccessRelationships = 1)
BEGIN
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
IF NOT EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'Collection'
AND COLUMN_NAME = 'DefaultUserCollectionEmail'
)
BEGIN
ALTER TABLE [dbo].[Collection]
ADD [DefaultUserCollectionEmail] NVARCHAR(256) NULL
END
GO

IF NOT EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'Collection'
AND COLUMN_NAME = 'Type'
)
BEGIN
ALTER TABLE [dbo].[Collection]
ADD [Type] TINYINT NOT NULL DEFAULT (0)
END
GO

IF OBJECT_ID('[dbo].[CollectionView]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[CollectionView]';
END
GO

IF OBJECT_ID('[dbo].[Collection_ReadById]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Collection_ReadById]';
END
GO

IF OBJECT_ID('[dbo].[Collection_ReadByIds]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Collection_ReadByIds]';
END
GO

IF OBJECT_ID('[dbo].[Collection_ReadByOrganizationId]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Collection_ReadByOrganizationId]';
END
GO

IF OBJECT_ID('[dbo].[UserCollectionDetails]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[UserCollectionDetails]';
END
GO
Loading
Loading