mirror of
https://github.com/bitwarden/server.git
synced 2024-12-24 17:17:40 +01:00
collection externalId
This commit is contained in:
parent
2684de0fff
commit
75f01a5774
14
src/Core/Models/Api/Public/CollectionBaseModel.cs
Normal file
14
src/Core/Models/Api/Public/CollectionBaseModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public abstract class CollectionBaseModel
|
||||
{
|
||||
/// <summary>
|
||||
/// External identifier for reference or linking this collection to another system.
|
||||
/// </summary>
|
||||
/// <example>external_id_123456</example>
|
||||
[StringLength(300)]
|
||||
public string ExternalId { get; set; }
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
[Required]
|
||||
public bool? AccessAll { get; set; }
|
||||
/// <summary>
|
||||
/// External identifier linking this group to another system, such as a user directory.
|
||||
/// External identifier for reference or linking this group to another system, such as a user directory.
|
||||
/// </summary>
|
||||
/// <example>external_id_123456</example>
|
||||
[StringLength(300)]
|
||||
|
@ -46,7 +46,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
[Required]
|
||||
public bool? AccessAll { get; set; }
|
||||
/// <summary>
|
||||
/// External identifier linking this member to another system, such as a user directory.
|
||||
/// External identifier for reference or linking this member to another system, such as a user directory.
|
||||
/// </summary>
|
||||
/// <example>external_id_123456</example>
|
||||
[StringLength(300)]
|
||||
|
@ -3,7 +3,7 @@ using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class CollectionUpdateRequestModel
|
||||
public class CollectionUpdateRequestModel : CollectionBaseModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The associated groups that this collection is assigned to.
|
||||
@ -12,8 +12,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
|
||||
public Collection ToCollection(Collection existingCollection)
|
||||
{
|
||||
// TODO
|
||||
// existingCollection.ExternalId = ExternalId;
|
||||
existingCollection.ExternalId = ExternalId;
|
||||
return existingCollection;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
/// <summary>
|
||||
/// A collection.
|
||||
/// </summary>
|
||||
public class CollectionResponseModel : IResponseModel
|
||||
public class CollectionResponseModel : CollectionBaseModel, IResponseModel
|
||||
{
|
||||
public CollectionResponseModel(Collection collection, IEnumerable<SelectionReadOnly> groups)
|
||||
{
|
||||
@ -20,7 +20,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
}
|
||||
|
||||
Id = collection.Id;
|
||||
// ExternalId = group.ExternalId; TODO: Add external is for referencing purposes
|
||||
ExternalId = collection.ExternalId;
|
||||
Groups = groups?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ namespace Bit.Core.Models.Api
|
||||
[EncryptedString]
|
||||
[EncryptedStringLength(1000)]
|
||||
public string Name { get; set; }
|
||||
[StringLength(300)]
|
||||
public string ExternalId { get; set; }
|
||||
public IEnumerable<SelectionReadOnlyRequestModel> Groups { get; set; }
|
||||
|
||||
public Collection ToCollection(Guid orgId)
|
||||
@ -26,6 +28,7 @@ namespace Bit.Core.Models.Api
|
||||
public Collection ToCollection(Collection existingCollection)
|
||||
{
|
||||
existingCollection.Name = Name;
|
||||
existingCollection.ExternalId = ExternalId;
|
||||
return existingCollection;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,13 @@ namespace Bit.Core.Models.Api
|
||||
Id = collection.Id.ToString();
|
||||
OrganizationId = collection.OrganizationId.ToString();
|
||||
Name = collection.Name;
|
||||
ExternalId = collection.ExternalId;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ExternalId { get; set; }
|
||||
}
|
||||
|
||||
public class CollectionDetailsResponseModel : CollectionResponseModel
|
||||
|
@ -8,6 +8,7 @@ namespace Bit.Core.Models.Table
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ExternalId { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
@ -13,6 +14,7 @@ BEGIN
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[Name],
|
||||
[ExternalId],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
@ -21,6 +23,7 @@ BEGIN
|
||||
@Id,
|
||||
@OrganizationId,
|
||||
@Name,
|
||||
@ExternalId,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
@ -2,6 +2,7 @@
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Groups AS [dbo].[SelectionReadOnlyArray] READONLY
|
||||
@ -9,7 +10,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Collection_Create] @Id, @OrganizationId, @Name, @CreationDate, @RevisionDate
|
||||
EXEC [dbo].[Collection_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
||||
|
||||
;WITH [AvailableGroupsCTE] AS(
|
||||
SELECT
|
||||
|
@ -2,6 +2,7 @@
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
@ -13,6 +14,7 @@ BEGIN
|
||||
SET
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Name] = @Name,
|
||||
[ExternalId] = @ExternalId,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
|
@ -2,6 +2,7 @@
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Groups AS [dbo].[SelectionReadOnlyArray] READONLY
|
||||
@ -9,7 +10,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Collection_Update] @Id, @OrganizationId, @Name, @CreationDate, @RevisionDate
|
||||
EXEC [dbo].[Collection_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
||||
|
||||
;WITH [AvailableGroupsCTE] AS(
|
||||
SELECT
|
||||
|
@ -2,6 +2,7 @@
|
||||
[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,
|
||||
CONSTRAINT [PK_Collection] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
|
@ -384,3 +384,199 @@ BEGIN
|
||||
[OrganizationUserId] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
IF COL_LENGTH('[dbo].[Collection]', 'ExternalId') IS NULL
|
||||
BEGIN
|
||||
ALTER TABLE
|
||||
[dbo].[Collection]
|
||||
ADD
|
||||
[ExternalId] NVARCHAR(300) NULL
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[Collection_Create]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Collection_Create]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_Create]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[Collection]
|
||||
(
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[Name],
|
||||
[ExternalId],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@OrganizationId,
|
||||
@Name,
|
||||
@ExternalId,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[Collection_Update]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Collection_Update]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[Collection]
|
||||
SET
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Name] = @Name,
|
||||
[ExternalId] = @ExternalId,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[Collection_CreateWithGroups]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Collection_CreateWithGroups]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_CreateWithGroups]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Groups AS [dbo].[SelectionReadOnlyArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Collection_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
||||
|
||||
;WITH [AvailableGroupsCTE] AS(
|
||||
SELECT
|
||||
[Id]
|
||||
FROM
|
||||
[dbo].[Group]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
)
|
||||
INSERT INTO [dbo].[CollectionGroup]
|
||||
(
|
||||
[CollectionId],
|
||||
[GroupId],
|
||||
[ReadOnly]
|
||||
)
|
||||
SELECT
|
||||
@Id,
|
||||
[Id],
|
||||
[ReadOnly]
|
||||
FROM
|
||||
@Groups
|
||||
WHERE
|
||||
[Id] IN (SELECT [Id] FROM [AvailableGroupsCTE])
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[Collection_UpdateWithGroups]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Collection_UpdateWithGroups]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_UpdateWithGroups]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Name VARCHAR(MAX),
|
||||
@ExternalId NVARCHAR(300),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Groups AS [dbo].[SelectionReadOnlyArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Collection_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
||||
|
||||
;WITH [AvailableGroupsCTE] AS(
|
||||
SELECT
|
||||
Id
|
||||
FROM
|
||||
[dbo].[Group]
|
||||
WHERE
|
||||
OrganizationId = @OrganizationId
|
||||
)
|
||||
MERGE
|
||||
[dbo].[CollectionGroup] AS [Target]
|
||||
USING
|
||||
@Groups AS [Source]
|
||||
ON
|
||||
[Target].[CollectionId] = @Id
|
||||
AND [Target].[GroupId] = [Source].[Id]
|
||||
WHEN NOT MATCHED BY TARGET
|
||||
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
|
||||
INSERT VALUES
|
||||
(
|
||||
@Id,
|
||||
[Source].[Id],
|
||||
[Source].[ReadOnly]
|
||||
)
|
||||
WHEN MATCHED AND [Target].[ReadOnly] != [Source].[ReadOnly] THEN
|
||||
UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly]
|
||||
WHEN NOT MATCHED BY SOURCE
|
||||
AND [Target].[CollectionId] = @Id THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'CollectionView')
|
||||
BEGIN
|
||||
DROP VIEW [dbo].[CollectionView]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE VIEW [dbo].[CollectionView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[Collection]
|
||||
GO
|
||||
|
Loading…
Reference in New Issue
Block a user