mirror of
https://github.com/bitwarden/server
synced 2025-12-20 10:13:39 +00:00
Merge remote-tracking branch 'origin/main' into arch/seeder-api
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
CREATE OR ALTER VIEW [dbo].[UserProviderAccessView]
|
||||
AS
|
||||
SELECT DISTINCT
|
||||
PU.[UserId],
|
||||
PO.[OrganizationId]
|
||||
FROM
|
||||
[dbo].[ProviderUserView] PU
|
||||
INNER JOIN
|
||||
[dbo].[ProviderOrganizationView] PO ON PO.[ProviderId] = PU.[ProviderId]
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_ReadByUserIdWithPolicyDetails]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@PolicyType TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserEmail NVARCHAR(256)
|
||||
SELECT @UserEmail = Email
|
||||
FROM
|
||||
[dbo].[UserView]
|
||||
WHERE
|
||||
Id = @UserId
|
||||
|
||||
;WITH OrgUsers AS
|
||||
(
|
||||
-- All users except invited (Status <> 0): direct UserId match
|
||||
SELECT
|
||||
OU.[Id],
|
||||
OU.[OrganizationId],
|
||||
OU.[Type],
|
||||
OU.[Status],
|
||||
OU.[Permissions]
|
||||
FROM
|
||||
[dbo].[OrganizationUserView] OU
|
||||
WHERE
|
||||
OU.[Status] <> 0
|
||||
AND OU.[UserId] = @UserId
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Invited users: email match
|
||||
SELECT
|
||||
OU.[Id],
|
||||
OU.[OrganizationId],
|
||||
OU.[Type],
|
||||
OU.[Status],
|
||||
OU.[Permissions]
|
||||
FROM
|
||||
[dbo].[OrganizationUserView] OU
|
||||
WHERE
|
||||
OU.[Status] = 0
|
||||
AND OU.[Email] = @UserEmail
|
||||
AND @UserEmail IS NOT NULL
|
||||
),
|
||||
Providers AS
|
||||
(
|
||||
SELECT
|
||||
OrganizationId
|
||||
FROM
|
||||
[dbo].[UserProviderAccessView]
|
||||
WHERE
|
||||
UserId = @UserId
|
||||
)
|
||||
SELECT
|
||||
OU.[Id] AS [OrganizationUserId],
|
||||
P.[OrganizationId],
|
||||
P.[Type] AS [PolicyType],
|
||||
P.[Enabled] AS [PolicyEnabled],
|
||||
P.[Data] AS [PolicyData],
|
||||
OU.[Type] AS [OrganizationUserType],
|
||||
OU.[Status] AS [OrganizationUserStatus],
|
||||
OU.[Permissions] AS [OrganizationUserPermissionsData],
|
||||
CASE WHEN PR.[OrganizationId] IS NULL THEN 0 ELSE 1 END AS [IsProvider]
|
||||
FROM
|
||||
[dbo].[PolicyView] P
|
||||
INNER JOIN
|
||||
OrgUsers OU ON P.[OrganizationId] = OU.[OrganizationId]
|
||||
LEFT JOIN
|
||||
Providers PR ON PR.[OrganizationId] = OU.[OrganizationId]
|
||||
WHERE
|
||||
P.[Type] = @PolicyType
|
||||
END
|
||||
GO
|
||||
@@ -0,0 +1,64 @@
|
||||
CREATE OR ALTER VIEW [dbo].[ProviderUserProviderOrganizationDetailsView]
|
||||
AS
|
||||
SELECT
|
||||
PU.[UserId],
|
||||
PO.[OrganizationId],
|
||||
O.[Name],
|
||||
O.[Enabled],
|
||||
O.[UsePolicies],
|
||||
O.[UseSso],
|
||||
O.[UseKeyConnector],
|
||||
O.[UseScim],
|
||||
O.[UseGroups],
|
||||
O.[UseDirectory],
|
||||
O.[UseEvents],
|
||||
O.[UseTotp],
|
||||
O.[Use2fa],
|
||||
O.[UseApi],
|
||||
O.[UseResetPassword],
|
||||
O.[UseSecretsManager],
|
||||
O.[UsePasswordManager],
|
||||
O.[SelfHost],
|
||||
O.[UsersGetPremium],
|
||||
O.[UseCustomPermissions],
|
||||
O.[Seats],
|
||||
O.[MaxCollections],
|
||||
O.[MaxStorageGb],
|
||||
O.[Identifier],
|
||||
PO.[Key],
|
||||
O.[PublicKey],
|
||||
O.[PrivateKey],
|
||||
PU.[Status],
|
||||
PU.[Type],
|
||||
PO.[ProviderId],
|
||||
PU.[Id] ProviderUserId,
|
||||
P.[Name] ProviderName,
|
||||
O.[PlanType],
|
||||
O.[LimitCollectionCreation],
|
||||
O.[LimitCollectionDeletion],
|
||||
O.[AllowAdminAccessToAllCollectionItems],
|
||||
O.[UseRiskInsights],
|
||||
O.[UseAdminSponsoredFamilies],
|
||||
P.[Type] ProviderType,
|
||||
O.[LimitItemDeletion],
|
||||
O.[UseOrganizationDomains],
|
||||
O.[UseAutomaticUserConfirmation],
|
||||
SS.[Enabled] SsoEnabled,
|
||||
SS.[Data] SsoConfig
|
||||
FROM
|
||||
[dbo].[ProviderUser] PU
|
||||
INNER JOIN
|
||||
[dbo].[ProviderOrganization] PO ON PO.[ProviderId] = PU.[ProviderId]
|
||||
INNER JOIN
|
||||
[dbo].[Organization] O ON O.[Id] = PO.[OrganizationId]
|
||||
INNER JOIN
|
||||
[dbo].[Provider] P ON P.[Id] = PU.[ProviderId]
|
||||
LEFT JOIN
|
||||
[dbo].[SsoConfig] SS ON SS.[OrganizationId] = O.[Id]
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[ProviderUserProviderOrganizationDetails_ReadByUserIdStatus]') IS NOT NULL
|
||||
BEGIN
|
||||
EXECUTE sp_refreshsqlmodule N'[dbo].[ProviderUserProviderOrganizationDetails_ReadByUserIdStatus]';
|
||||
END
|
||||
GO
|
||||
@@ -0,0 +1,161 @@
|
||||
IF COL_LENGTH('dbo.OrganizationReport', 'ApplicationCount') IS NULL
|
||||
BEGIN
|
||||
ALTER TABLE [dbo].[OrganizationReport]
|
||||
ADD [ApplicationCount] INT NULL,
|
||||
[ApplicationAtRiskCount] INT NULL,
|
||||
[CriticalApplicationCount] INT NULL,
|
||||
[CriticalApplicationAtRiskCount] INT NULL,
|
||||
[MemberCount] INT NULL,
|
||||
[MemberAtRiskCount] INT NULL,
|
||||
[CriticalMemberCount] INT NULL,
|
||||
[CriticalMemberAtRiskCount] INT NULL,
|
||||
[PasswordCount] INT NULL,
|
||||
[PasswordAtRiskCount] INT NULL,
|
||||
[CriticalPasswordCount] INT NULL,
|
||||
[CriticalPasswordAtRiskCount] INT NULL
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ReportData NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@ContentEncryptionKey VARCHAR(MAX),
|
||||
@SummaryData NVARCHAR(MAX),
|
||||
@ApplicationData NVARCHAR(MAX),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@ApplicationCount INT = NULL,
|
||||
@ApplicationAtRiskCount INT = NULL,
|
||||
@CriticalApplicationCount INT = NULL,
|
||||
@CriticalApplicationAtRiskCount INT = NULL,
|
||||
@MemberCount INT = NULL,
|
||||
@MemberAtRiskCount INT = NULL,
|
||||
@CriticalMemberCount INT = NULL,
|
||||
@CriticalMemberAtRiskCount INT = NULL,
|
||||
@PasswordCount INT = NULL,
|
||||
@PasswordAtRiskCount INT = NULL,
|
||||
@CriticalPasswordCount INT = NULL,
|
||||
@CriticalPasswordAtRiskCount INT = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
INSERT INTO [dbo].[OrganizationReport](
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[ReportData],
|
||||
[CreationDate],
|
||||
[ContentEncryptionKey],
|
||||
[SummaryData],
|
||||
[ApplicationData],
|
||||
[RevisionDate],
|
||||
[ApplicationCount],
|
||||
[ApplicationAtRiskCount],
|
||||
[CriticalApplicationCount],
|
||||
[CriticalApplicationAtRiskCount],
|
||||
[MemberCount],
|
||||
[MemberAtRiskCount],
|
||||
[CriticalMemberCount],
|
||||
[CriticalMemberAtRiskCount],
|
||||
[PasswordCount],
|
||||
[PasswordAtRiskCount],
|
||||
[CriticalPasswordCount],
|
||||
[CriticalPasswordAtRiskCount]
|
||||
)
|
||||
VALUES (
|
||||
@Id,
|
||||
@OrganizationId,
|
||||
@ReportData,
|
||||
@CreationDate,
|
||||
@ContentEncryptionKey,
|
||||
@SummaryData,
|
||||
@ApplicationData,
|
||||
@RevisionDate,
|
||||
@ApplicationCount,
|
||||
@ApplicationAtRiskCount,
|
||||
@CriticalApplicationCount,
|
||||
@CriticalApplicationAtRiskCount,
|
||||
@MemberCount,
|
||||
@MemberAtRiskCount,
|
||||
@CriticalMemberCount,
|
||||
@CriticalMemberAtRiskCount,
|
||||
@PasswordCount,
|
||||
@PasswordAtRiskCount,
|
||||
@CriticalPasswordCount,
|
||||
@CriticalPasswordAtRiskCount
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ReportData NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@ContentEncryptionKey VARCHAR(MAX),
|
||||
@SummaryData NVARCHAR(MAX),
|
||||
@ApplicationData NVARCHAR(MAX),
|
||||
@RevisionDate DATETIME2(7),
|
||||
@ApplicationCount INT = NULL,
|
||||
@ApplicationAtRiskCount INT = NULL,
|
||||
@CriticalApplicationCount INT = NULL,
|
||||
@CriticalApplicationAtRiskCount INT = NULL,
|
||||
@MemberCount INT = NULL,
|
||||
@MemberAtRiskCount INT = NULL,
|
||||
@CriticalMemberCount INT = NULL,
|
||||
@CriticalMemberAtRiskCount INT = NULL,
|
||||
@PasswordCount INT = NULL,
|
||||
@PasswordAtRiskCount INT = NULL,
|
||||
@CriticalPasswordCount INT = NULL,
|
||||
@CriticalPasswordAtRiskCount INT = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
UPDATE [dbo].[OrganizationReport]
|
||||
SET
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[ReportData] = @ReportData,
|
||||
[CreationDate] = @CreationDate,
|
||||
[ContentEncryptionKey] = @ContentEncryptionKey,
|
||||
[SummaryData] = @SummaryData,
|
||||
[ApplicationData] = @ApplicationData,
|
||||
[RevisionDate] = @RevisionDate,
|
||||
[ApplicationCount] = @ApplicationCount,
|
||||
[ApplicationAtRiskCount] = @ApplicationAtRiskCount,
|
||||
[CriticalApplicationCount] = @CriticalApplicationCount,
|
||||
[CriticalApplicationAtRiskCount] = @CriticalApplicationAtRiskCount,
|
||||
[MemberCount] = @MemberCount,
|
||||
[MemberAtRiskCount] = @MemberAtRiskCount,
|
||||
[CriticalMemberCount] = @CriticalMemberCount,
|
||||
[CriticalMemberAtRiskCount] = @CriticalMemberAtRiskCount,
|
||||
[PasswordCount] = @PasswordCount,
|
||||
[PasswordAtRiskCount] = @PasswordAtRiskCount,
|
||||
[CriticalPasswordCount] = @CriticalPasswordCount,
|
||||
[CriticalPasswordAtRiskCount] = @CriticalPasswordAtRiskCount
|
||||
WHERE [Id] = @Id;
|
||||
END;
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW [dbo].[OrganizationReportView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationReport]
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_GetLatestByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT TOP 1
|
||||
*
|
||||
FROM [dbo].[OrganizationReportView]
|
||||
WHERE [OrganizationId] = @OrganizationId
|
||||
ORDER BY [RevisionDate] DESC
|
||||
END
|
||||
GO
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_UpdateMetrics]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@ApplicationCount INT,
|
||||
@ApplicationAtRiskCount INT,
|
||||
@CriticalApplicationCount INT,
|
||||
@CriticalApplicationAtRiskCount INT,
|
||||
@MemberCount INT,
|
||||
@MemberAtRiskCount INT,
|
||||
@CriticalMemberCount INT,
|
||||
@CriticalMemberAtRiskCount INT,
|
||||
@PasswordCount INT,
|
||||
@PasswordAtRiskCount INT,
|
||||
@CriticalPasswordCount INT,
|
||||
@CriticalPasswordAtRiskCount INT,
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
UPDATE
|
||||
[dbo].[OrganizationReport]
|
||||
SET
|
||||
[ApplicationCount] = @ApplicationCount,
|
||||
[ApplicationAtRiskCount] = @ApplicationAtRiskCount,
|
||||
[CriticalApplicationCount] = @CriticalApplicationCount,
|
||||
[CriticalApplicationAtRiskCount] = @CriticalApplicationAtRiskCount,
|
||||
[MemberCount] = @MemberCount,
|
||||
[MemberAtRiskCount] = @MemberAtRiskCount,
|
||||
[CriticalMemberCount] = @CriticalMemberCount,
|
||||
[CriticalMemberAtRiskCount] = @CriticalMemberAtRiskCount,
|
||||
[PasswordCount] = @PasswordCount,
|
||||
[PasswordAtRiskCount] = @PasswordAtRiskCount,
|
||||
[CriticalPasswordCount] = @CriticalPasswordCount,
|
||||
[CriticalPasswordAtRiskCount] = @CriticalPasswordAtRiskCount,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
END
|
||||
Reference in New Issue
Block a user