Browse Source
* [Reset Password] Organization Key Pair * Fixed type in Organization_ReadAbilites sproc * Fixed broken unit test by making sure premium addon was false * Updated PublicKey decorator and removed unecessary validationpull/1312/head
26 changed files with 535 additions and 12 deletions
@ -0,0 +1,59 @@ |
|||||||
|
using Bit.Core.Models.Table; |
||||||
|
using System.ComponentModel.DataAnnotations; |
||||||
|
using Bit.Core.Models.Business; |
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api |
||||||
|
{ |
||||||
|
public class OrganizationKeysRequestModel |
||||||
|
{ |
||||||
|
[Required] |
||||||
|
public string PublicKey { get; set; } |
||||||
|
[Required] |
||||||
|
public string EncryptedPrivateKey { get; set; } |
||||||
|
|
||||||
|
public OrganizationSignup ToOrganizationSignup(OrganizationSignup existingSignup) |
||||||
|
{ |
||||||
|
if (string.IsNullOrWhiteSpace(existingSignup.PublicKey)) |
||||||
|
{ |
||||||
|
existingSignup.PublicKey = PublicKey; |
||||||
|
} |
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(existingSignup.PrivateKey)) |
||||||
|
{ |
||||||
|
existingSignup.PrivateKey = EncryptedPrivateKey; |
||||||
|
} |
||||||
|
|
||||||
|
return existingSignup; |
||||||
|
} |
||||||
|
|
||||||
|
public OrganizationUpgrade ToOrganizationUpgrade(OrganizationUpgrade existingUpgrade) |
||||||
|
{ |
||||||
|
if (string.IsNullOrWhiteSpace(existingUpgrade.PublicKey)) |
||||||
|
{ |
||||||
|
existingUpgrade.PublicKey = PublicKey; |
||||||
|
} |
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(existingUpgrade.PrivateKey)) |
||||||
|
{ |
||||||
|
existingUpgrade.PrivateKey = EncryptedPrivateKey; |
||||||
|
} |
||||||
|
|
||||||
|
return existingUpgrade; |
||||||
|
} |
||||||
|
|
||||||
|
public Organization ToOrganization(Organization existingOrg) |
||||||
|
{ |
||||||
|
if (string.IsNullOrWhiteSpace(existingOrg.PublicKey)) |
||||||
|
{ |
||||||
|
existingOrg.PublicKey = PublicKey; |
||||||
|
} |
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(existingOrg.PrivateKey)) |
||||||
|
{ |
||||||
|
existingOrg.PrivateKey = EncryptedPrivateKey; |
||||||
|
} |
||||||
|
|
||||||
|
return existingOrg; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,372 @@ |
|||||||
|
-- Table: Organization (UseResetPassword) |
||||||
|
IF COL_LENGTH('[dbo].[Organization]', 'UseResetPassword') IS NULL |
||||||
|
BEGIN |
||||||
|
ALTER TABLE |
||||||
|
[dbo].[Organization] |
||||||
|
ADD |
||||||
|
[UseResetPassword] BIT NULL |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
UPDATE |
||||||
|
[dbo].[Organization] |
||||||
|
SET |
||||||
|
[UseResetPassword] = (CASE WHEN [PlanType] = 10 OR [PlanType] = 11 THEN 1 ELSE 0 END) |
||||||
|
GO |
||||||
|
|
||||||
|
ALTER TABLE |
||||||
|
[dbo].[Organization] |
||||||
|
ALTER COLUMN |
||||||
|
[UseResetPassword] BIT NOT NULL |
||||||
|
GO |
||||||
|
|
||||||
|
-- Table: Organization (PublicKey) |
||||||
|
IF COL_LENGTH('[dbo].[Organization]', 'PublicKey') IS NULL |
||||||
|
BEGIN |
||||||
|
ALTER TABLE |
||||||
|
[dbo].[Organization] |
||||||
|
ADD |
||||||
|
[PublicKey] VARCHAR (MAX) NULL |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
-- Table: Organization (PrivateKey) |
||||||
|
IF COL_LENGTH('[dbo].[Organization]', 'PrivateKey') IS NULL |
||||||
|
BEGIN |
||||||
|
ALTER TABLE |
||||||
|
[dbo].[Organization] |
||||||
|
ADD |
||||||
|
[PrivateKey] VARCHAR (MAX) NULL |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
-- View: Organization |
||||||
|
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'OrganizationView') |
||||||
|
BEGIN |
||||||
|
DROP VIEW [dbo].[OrganizationView] |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
CREATE VIEW [dbo].[OrganizationView] |
||||||
|
AS |
||||||
|
SELECT |
||||||
|
* |
||||||
|
FROM |
||||||
|
[dbo].[Organization] |
||||||
|
GO |
||||||
|
|
||||||
|
-- View: OrganizationUserOrganizationDetails |
||||||
|
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'OrganizationUserOrganizationDetailsView') |
||||||
|
BEGIN |
||||||
|
DROP VIEW [dbo].[OrganizationUserOrganizationDetailsView] |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
CREATE VIEW [dbo].[OrganizationUserOrganizationDetailsView] |
||||||
|
AS |
||||||
|
SELECT |
||||||
|
OU.[UserId], |
||||||
|
OU.[OrganizationId], |
||||||
|
O.[Name], |
||||||
|
O.[Enabled], |
||||||
|
O.[UsePolicies], |
||||||
|
O.[UseSso], |
||||||
|
O.[UseGroups], |
||||||
|
O.[UseDirectory], |
||||||
|
O.[UseEvents], |
||||||
|
O.[UseTotp], |
||||||
|
O.[Use2fa], |
||||||
|
O.[UseApi], |
||||||
|
O.[UseResetPassword], |
||||||
|
O.[SelfHost], |
||||||
|
O.[UsersGetPremium], |
||||||
|
O.[Seats], |
||||||
|
O.[MaxCollections], |
||||||
|
O.[MaxStorageGb], |
||||||
|
O.[Identifier], |
||||||
|
OU.[Key], |
||||||
|
OU.[ResetPasswordKey], |
||||||
|
O.[PublicKey], |
||||||
|
O.[PrivateKey], |
||||||
|
OU.[Status], |
||||||
|
OU.[Type], |
||||||
|
SU.[ExternalId] SsoExternalId, |
||||||
|
OU.[Permissions] |
||||||
|
FROM |
||||||
|
[dbo].[OrganizationUser] OU |
||||||
|
INNER JOIN |
||||||
|
[dbo].[Organization] O ON O.[Id] = OU.[OrganizationId] |
||||||
|
LEFT JOIN |
||||||
|
[dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId] |
||||||
|
GO |
||||||
|
|
||||||
|
-- Stored Procedure: Organization_Create |
||||||
|
IF OBJECT_ID('[dbo].[Organization_Create]') IS NOT NULL |
||||||
|
BEGIN |
||||||
|
DROP PROCEDURE [dbo].[Organization_Create] |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Organization_Create] |
||||||
|
@Id UNIQUEIDENTIFIER, |
||||||
|
@Identifier NVARCHAR(50), |
||||||
|
@Name NVARCHAR(50), |
||||||
|
@BusinessName NVARCHAR(50), |
||||||
|
@BusinessAddress1 NVARCHAR(50), |
||||||
|
@BusinessAddress2 NVARCHAR(50), |
||||||
|
@BusinessAddress3 NVARCHAR(50), |
||||||
|
@BusinessCountry VARCHAR(2), |
||||||
|
@BusinessTaxNumber NVARCHAR(30), |
||||||
|
@BillingEmail NVARCHAR(256), |
||||||
|
@Plan NVARCHAR(50), |
||||||
|
@PlanType TINYINT, |
||||||
|
@Seats SMALLINT, |
||||||
|
@MaxCollections SMALLINT, |
||||||
|
@UsePolicies BIT, |
||||||
|
@UseSso BIT, |
||||||
|
@UseGroups BIT, |
||||||
|
@UseDirectory BIT, |
||||||
|
@UseEvents BIT, |
||||||
|
@UseTotp BIT, |
||||||
|
@Use2fa BIT, |
||||||
|
@UseApi BIT, |
||||||
|
@UseResetPassword BIT, |
||||||
|
@SelfHost BIT, |
||||||
|
@UsersGetPremium BIT, |
||||||
|
@Storage BIGINT, |
||||||
|
@MaxStorageGb SMALLINT, |
||||||
|
@Gateway TINYINT, |
||||||
|
@GatewayCustomerId VARCHAR(50), |
||||||
|
@GatewaySubscriptionId VARCHAR(50), |
||||||
|
@ReferenceData VARCHAR(MAX), |
||||||
|
@Enabled BIT, |
||||||
|
@LicenseKey VARCHAR(100), |
||||||
|
@ApiKey VARCHAR(30), |
||||||
|
@PublicKey VARCHAR(MAX), |
||||||
|
@PrivateKey VARCHAR(MAX), |
||||||
|
@TwoFactorProviders NVARCHAR(MAX), |
||||||
|
@ExpirationDate DATETIME2(7), |
||||||
|
@CreationDate DATETIME2(7), |
||||||
|
@RevisionDate DATETIME2(7) |
||||||
|
AS |
||||||
|
BEGIN |
||||||
|
SET NOCOUNT ON |
||||||
|
|
||||||
|
INSERT INTO [dbo].[Organization] |
||||||
|
( |
||||||
|
[Id], |
||||||
|
[Identifier], |
||||||
|
[Name], |
||||||
|
[BusinessName], |
||||||
|
[BusinessAddress1], |
||||||
|
[BusinessAddress2], |
||||||
|
[BusinessAddress3], |
||||||
|
[BusinessCountry], |
||||||
|
[BusinessTaxNumber], |
||||||
|
[BillingEmail], |
||||||
|
[Plan], |
||||||
|
[PlanType], |
||||||
|
[Seats], |
||||||
|
[MaxCollections], |
||||||
|
[UsePolicies], |
||||||
|
[UseSso], |
||||||
|
[UseGroups], |
||||||
|
[UseDirectory], |
||||||
|
[UseEvents], |
||||||
|
[UseTotp], |
||||||
|
[Use2fa], |
||||||
|
[UseApi], |
||||||
|
[UseResetPassword], |
||||||
|
[SelfHost], |
||||||
|
[UsersGetPremium], |
||||||
|
[Storage], |
||||||
|
[MaxStorageGb], |
||||||
|
[Gateway], |
||||||
|
[GatewayCustomerId], |
||||||
|
[GatewaySubscriptionId], |
||||||
|
[ReferenceData], |
||||||
|
[Enabled], |
||||||
|
[LicenseKey], |
||||||
|
[ApiKey], |
||||||
|
[PublicKey], |
||||||
|
[PrivateKey], |
||||||
|
[TwoFactorProviders], |
||||||
|
[ExpirationDate], |
||||||
|
[CreationDate], |
||||||
|
[RevisionDate] |
||||||
|
) |
||||||
|
VALUES |
||||||
|
( |
||||||
|
@Id, |
||||||
|
@Identifier, |
||||||
|
@Name, |
||||||
|
@BusinessName, |
||||||
|
@BusinessAddress1, |
||||||
|
@BusinessAddress2, |
||||||
|
@BusinessAddress3, |
||||||
|
@BusinessCountry, |
||||||
|
@BusinessTaxNumber, |
||||||
|
@BillingEmail, |
||||||
|
@Plan, |
||||||
|
@PlanType, |
||||||
|
@Seats, |
||||||
|
@MaxCollections, |
||||||
|
@UsePolicies, |
||||||
|
@UseSso, |
||||||
|
@UseGroups, |
||||||
|
@UseDirectory, |
||||||
|
@UseEvents, |
||||||
|
@UseTotp, |
||||||
|
@Use2fa, |
||||||
|
@UseApi, |
||||||
|
@UseResetPassword, |
||||||
|
@SelfHost, |
||||||
|
@UsersGetPremium, |
||||||
|
@Storage, |
||||||
|
@MaxStorageGb, |
||||||
|
@Gateway, |
||||||
|
@GatewayCustomerId, |
||||||
|
@GatewaySubscriptionId, |
||||||
|
@ReferenceData, |
||||||
|
@Enabled, |
||||||
|
@LicenseKey, |
||||||
|
@ApiKey, |
||||||
|
@PublicKey, |
||||||
|
@PrivateKey, |
||||||
|
@TwoFactorProviders, |
||||||
|
@ExpirationDate, |
||||||
|
@CreationDate, |
||||||
|
@RevisionDate |
||||||
|
) |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
-- Stored Procedure: Organization_Update |
||||||
|
IF OBJECT_ID('[dbo].[Organization_Update]') IS NOT NULL |
||||||
|
BEGIN |
||||||
|
DROP PROCEDURE [dbo].[Organization_Update] |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Organization_Update] |
||||||
|
@Id UNIQUEIDENTIFIER, |
||||||
|
@Identifier NVARCHAR(50), |
||||||
|
@Name NVARCHAR(50), |
||||||
|
@BusinessName NVARCHAR(50), |
||||||
|
@BusinessAddress1 NVARCHAR(50), |
||||||
|
@BusinessAddress2 NVARCHAR(50), |
||||||
|
@BusinessAddress3 NVARCHAR(50), |
||||||
|
@BusinessCountry VARCHAR(2), |
||||||
|
@BusinessTaxNumber NVARCHAR(30), |
||||||
|
@BillingEmail NVARCHAR(256), |
||||||
|
@Plan NVARCHAR(50), |
||||||
|
@PlanType TINYINT, |
||||||
|
@Seats SMALLINT, |
||||||
|
@MaxCollections SMALLINT, |
||||||
|
@UsePolicies BIT, |
||||||
|
@UseSso BIT, |
||||||
|
@UseGroups BIT, |
||||||
|
@UseDirectory BIT, |
||||||
|
@UseEvents BIT, |
||||||
|
@UseTotp BIT, |
||||||
|
@Use2fa BIT, |
||||||
|
@UseApi BIT, |
||||||
|
@UseResetPassword BIT, |
||||||
|
@SelfHost BIT, |
||||||
|
@UsersGetPremium BIT, |
||||||
|
@Storage BIGINT, |
||||||
|
@MaxStorageGb SMALLINT, |
||||||
|
@Gateway TINYINT, |
||||||
|
@GatewayCustomerId VARCHAR(50), |
||||||
|
@GatewaySubscriptionId VARCHAR(50), |
||||||
|
@ReferenceData VARCHAR(MAX), |
||||||
|
@Enabled BIT, |
||||||
|
@LicenseKey VARCHAR(100), |
||||||
|
@ApiKey VARCHAR(30), |
||||||
|
@PublicKey VARCHAR(MAX), |
||||||
|
@PrivateKey VARCHAR(MAX), |
||||||
|
@TwoFactorProviders NVARCHAR(MAX), |
||||||
|
@ExpirationDate DATETIME2(7), |
||||||
|
@CreationDate DATETIME2(7), |
||||||
|
@RevisionDate DATETIME2(7) |
||||||
|
AS |
||||||
|
BEGIN |
||||||
|
SET NOCOUNT ON |
||||||
|
|
||||||
|
UPDATE |
||||||
|
[dbo].[Organization] |
||||||
|
SET |
||||||
|
[Identifier] = @Identifier, |
||||||
|
[Name] = @Name, |
||||||
|
[BusinessName] = @BusinessName, |
||||||
|
[BusinessAddress1] = @BusinessAddress1, |
||||||
|
[BusinessAddress2] = @BusinessAddress2, |
||||||
|
[BusinessAddress3] = @BusinessAddress3, |
||||||
|
[BusinessCountry] = @BusinessCountry, |
||||||
|
[BusinessTaxNumber] = @BusinessTaxNumber, |
||||||
|
[BillingEmail] = @BillingEmail, |
||||||
|
[Plan] = @Plan, |
||||||
|
[PlanType] = @PlanType, |
||||||
|
[Seats] = @Seats, |
||||||
|
[MaxCollections] = @MaxCollections, |
||||||
|
[UsePolicies] = @UsePolicies, |
||||||
|
[UseSso] = @UseSso, |
||||||
|
[UseGroups] = @UseGroups, |
||||||
|
[UseDirectory] = @UseDirectory, |
||||||
|
[UseEvents] = @UseEvents, |
||||||
|
[UseTotp] = @UseTotp, |
||||||
|
[Use2fa] = @Use2fa, |
||||||
|
[UseApi] = @UseApi, |
||||||
|
[UseResetPassword] = @UseResetPassword, |
||||||
|
[SelfHost] = @SelfHost, |
||||||
|
[UsersGetPremium] = @UsersGetPremium, |
||||||
|
[Storage] = @Storage, |
||||||
|
[MaxStorageGb] = @MaxStorageGb, |
||||||
|
[Gateway] = @Gateway, |
||||||
|
[GatewayCustomerId] = @GatewayCustomerId, |
||||||
|
[GatewaySubscriptionId] = @GatewaySubscriptionId, |
||||||
|
[ReferenceData] = @ReferenceData, |
||||||
|
[Enabled] = @Enabled, |
||||||
|
[LicenseKey] = @LicenseKey, |
||||||
|
[ApiKey] = @ApiKey, |
||||||
|
[PublicKey] = @PublicKey, |
||||||
|
[PrivateKey] = @PrivateKey, |
||||||
|
[TwoFactorProviders] = @TwoFactorProviders, |
||||||
|
[ExpirationDate] = @ExpirationDate, |
||||||
|
[CreationDate] = @CreationDate, |
||||||
|
[RevisionDate] = @RevisionDate |
||||||
|
WHERE |
||||||
|
[Id] = @Id |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
-- Stored Procedure: Organization_ReadAbilities |
||||||
|
IF OBJECT_ID('[dbo].[Organization_ReadAbilities]') IS NOT NULL |
||||||
|
BEGIN |
||||||
|
DROP PROCEDURE [dbo].[Organization_ReadAbilities] |
||||||
|
END |
||||||
|
GO |
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Organization_ReadAbilities] |
||||||
|
AS |
||||||
|
BEGIN |
||||||
|
SET NOCOUNT ON |
||||||
|
|
||||||
|
SELECT |
||||||
|
[Id], |
||||||
|
[UseEvents], |
||||||
|
[Use2fa], |
||||||
|
CASE |
||||||
|
WHEN [Use2fa] = 1 AND [TwoFactorProviders] IS NOT NULL AND [TwoFactorProviders] != '{}' THEN |
||||||
|
1 |
||||||
|
ELSE |
||||||
|
0 |
||||||
|
END AS [Using2fa], |
||||||
|
[UsersGetPremium], |
||||||
|
[UseSso], |
||||||
|
[UseResetPassword], |
||||||
|
[Enabled] |
||||||
|
FROM |
||||||
|
[dbo].[Organization] |
||||||
|
END |
||||||
|
GO |
||||||
Loading…
Reference in new issue