1
0
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:
Kyle Spearrin 2017-02-21 21:31:52 -05:00
parent 9ca2baba74
commit f101541ff8
11 changed files with 174 additions and 0 deletions

22
src/Core/Domains/Share.cs Normal file
View 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();
}
}
}

View File

@ -0,0 +1,9 @@
namespace Bit.Core.Enums
{
public enum ShareStatusType : byte
{
Pending = 0,
Accepted = 1,
Rejected = 2
}
}

View File

@ -0,0 +1,9 @@
using System;
using Bit.Core.Domains;
namespace Bit.Core.Repositories
{
public interface IShareRepository : IRepository<Share, Guid>
{
}
}

View 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)
{ }
}
}

View File

@ -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>

View 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

View 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

View 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

View 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

View 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);

View File

@ -0,0 +1,6 @@
CREATE VIEW [dbo].[ShareView]
AS
SELECT
*
FROM
[dbo].[Share]