mirror of
https://github.com/bitwarden/server.git
synced 2025-05-28 06:44:50 -05:00
added share data model
This commit is contained in:
parent
9ca2baba74
commit
f101541ff8
22
src/Core/Domains/Share.cs
Normal file
22
src/Core/Domains/Share.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Domains
|
||||
{
|
||||
public class Share : IDataObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public Guid CipherId { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string Permissions { get; set; }
|
||||
public Enums.ShareStatusType Status { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
}
|
||||
}
|
9
src/Core/Enums/ShareStatusType.cs
Normal file
9
src/Core/Enums/ShareStatusType.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum ShareStatusType : byte
|
||||
{
|
||||
Pending = 0,
|
||||
Accepted = 1,
|
||||
Rejected = 2
|
||||
}
|
||||
}
|
9
src/Core/Repositories/IShareRepository.cs
Normal file
9
src/Core/Repositories/IShareRepository.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IShareRepository : IRepository<Share, Guid>
|
||||
{
|
||||
}
|
||||
}
|
16
src/Core/Repositories/SqlServer/ShareRepository.cs
Normal file
16
src/Core/Repositories/SqlServer/ShareRepository.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
public class ShareRepository : Repository<Share, Guid>, IShareRepository
|
||||
{
|
||||
public ShareRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString)
|
||||
{ }
|
||||
|
||||
public ShareRepository(string connectionString)
|
||||
: base(connectionString)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -103,5 +103,11 @@
|
||||
<Build Include="dbo\Stored Procedures\Grant_ReadBySubjectId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Grant_Save.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_ReadAccountRevisionDateById.sql" />
|
||||
<Build Include="dbo\Tables\Share.sql" />
|
||||
<Build Include="dbo\Views\ShareView.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Share_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Share_DeleteById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Share_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Share_Update.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
36
src/Sql/dbo/Stored Procedures/Share_Create.sql
Normal file
36
src/Sql/dbo/Stored Procedures/Share_Create.sql
Normal file
@ -0,0 +1,36 @@
|
||||
CREATE PROCEDURE [dbo].[Share_Create]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@CipherId UNIQUEIDENTIFIER,
|
||||
@Key NVARCHAR(MAX),
|
||||
@Permissions NVARCHAR(MAX),
|
||||
@Status TINYINT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[Share]
|
||||
(
|
||||
[Id],
|
||||
[UserId],
|
||||
[CipherId],
|
||||
[Key],
|
||||
[Permissions],
|
||||
[Status],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@UserId,
|
||||
@CipherId,
|
||||
@Key,
|
||||
@Permissions,
|
||||
@Status,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
END
|
12
src/Sql/dbo/Stored Procedures/Share_DeleteById.sql
Normal file
12
src/Sql/dbo/Stored Procedures/Share_DeleteById.sql
Normal file
@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[Share_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Share]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
13
src/Sql/dbo/Stored Procedures/Share_ReadById.sql
Normal file
13
src/Sql/dbo/Stored Procedures/Share_ReadById.sql
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[Share_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ShareView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
26
src/Sql/dbo/Stored Procedures/Share_Update.sql
Normal file
26
src/Sql/dbo/Stored Procedures/Share_Update.sql
Normal file
@ -0,0 +1,26 @@
|
||||
CREATE PROCEDURE [dbo].[Share_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@CipherId UNIQUEIDENTIFIER,
|
||||
@Key NVARCHAR(MAX),
|
||||
@Permissions NVARCHAR(MAX),
|
||||
@Status TINYINT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[Share]
|
||||
SET
|
||||
[UserId] = @UserId,
|
||||
[CipherId] = @CipherId,
|
||||
[Key] = @Key,
|
||||
[Permissions] = @Permissions,
|
||||
[Status] = @Status,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
19
src/Sql/dbo/Tables/Share.sql
Normal file
19
src/Sql/dbo/Tables/Share.sql
Normal file
@ -0,0 +1,19 @@
|
||||
CREATE TABLE [dbo].[Share] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Key] VARCHAR(MAX) NULL,
|
||||
[Permissions] VARCHAR(MAX) NULL,
|
||||
[Status] TINYINT NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_Share] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_Share_Cipher] FOREIGN KEY ([CipherId]) REFERENCES [dbo].[Cipher] ([Id]),
|
||||
CONSTRAINT [FK_Share_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
||||
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Share_CipherId_Status]
|
||||
ON [dbo].[Share]([CipherId] ASC, [Status] ASC);
|
||||
|
6
src/Sql/dbo/Views/ShareView.sql
Normal file
6
src/Sql/dbo/Views/ShareView.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[ShareView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[Share]
|
Loading…
x
Reference in New Issue
Block a user