mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 21:18:13 -05:00
[PM-16040] Update Organization_UnassignedToProviderSearch.sql SPROC to allow Reseller plan types (#5332)
* Update Organization_UnassignedToProviderSearch.sql SPROC * Robert's feedback
This commit is contained in:
parent
3f3da558b6
commit
37b5cef085
@ -117,11 +117,17 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
|
|||||||
|
|
||||||
var dbContext = GetDatabaseContext(scope);
|
var dbContext = GetDatabaseContext(scope);
|
||||||
|
|
||||||
|
var disallowedPlanTypes = new List<PlanType>
|
||||||
|
{
|
||||||
|
PlanType.Free,
|
||||||
|
PlanType.Custom,
|
||||||
|
PlanType.FamiliesAnnually2019,
|
||||||
|
PlanType.FamiliesAnnually
|
||||||
|
};
|
||||||
|
|
||||||
var query =
|
var query =
|
||||||
from o in dbContext.Organizations
|
from o in dbContext.Organizations
|
||||||
where
|
where o.PlanType.NotIn(disallowedPlanTypes) &&
|
||||||
((o.PlanType >= PlanType.TeamsMonthly2019 && o.PlanType <= PlanType.EnterpriseAnnually2019) ||
|
|
||||||
(o.PlanType >= PlanType.TeamsMonthly2020 && o.PlanType <= PlanType.EnterpriseAnnually)) &&
|
|
||||||
!dbContext.ProviderOrganizations.Any(po => po.OrganizationId == o.Id) &&
|
!dbContext.ProviderOrganizations.Any(po => po.OrganizationId == o.Id) &&
|
||||||
(string.IsNullOrWhiteSpace(name) || EF.Functions.Like(o.Name, $"%{name}%"))
|
(string.IsNullOrWhiteSpace(name) || EF.Functions.Like(o.Name, $"%{name}%"))
|
||||||
select o;
|
select o;
|
||||||
@ -155,7 +161,7 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
|
|||||||
select o;
|
select o;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await query.OrderByDescending(o => o.CreationDate).Skip(skip).Take(take).ToArrayAsync();
|
return await query.OrderByDescending(o => o.CreationDate).ThenByDescending(o => o.Id).Skip(skip).Take(take).ToArrayAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateStorageAsync(Guid id)
|
public async Task UpdateStorageAsync(Guid id)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
CREATE PROCEDURE [dbo].[Organization_UnassignedToProviderSearch]
|
CREATE PROCEDURE [dbo].[Organization_UnassignedToProviderSearch]
|
||||||
@Name NVARCHAR(50),
|
@Name NVARCHAR(55),
|
||||||
@OwnerEmail NVARCHAR(256),
|
@OwnerEmail NVARCHAR(256),
|
||||||
@Skip INT = 0,
|
@Skip INT = 0,
|
||||||
@Take INT = 25
|
@Take INT = 25
|
||||||
@ -21,11 +21,11 @@ BEGIN
|
|||||||
INNER JOIN
|
INNER JOIN
|
||||||
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
||||||
WHERE
|
WHERE
|
||||||
((O.[PlanType] >= 2 AND O.[PlanType] <= 5) OR (O.[PlanType] >= 8 AND O.[PlanType] <= 20) AND (O.PlanType <> 16)) -- All 'Teams' and 'Enterprise' organizations
|
O.[PlanType] NOT IN (0, 1, 6, 7) -- Not 'Free', 'Custom' or 'Families'
|
||||||
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
||||||
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||||
AND (U.[Email] LIKE @OwnerLikeSearch)
|
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||||
ORDER BY O.[CreationDate] DESC
|
ORDER BY O.[CreationDate] DESC, O.[Id]
|
||||||
OFFSET @Skip ROWS
|
OFFSET @Skip ROWS
|
||||||
FETCH NEXT @Take ROWS ONLY
|
FETCH NEXT @Take ROWS ONLY
|
||||||
END
|
END
|
||||||
@ -36,10 +36,10 @@ BEGIN
|
|||||||
FROM
|
FROM
|
||||||
[dbo].[OrganizationView] O
|
[dbo].[OrganizationView] O
|
||||||
WHERE
|
WHERE
|
||||||
((O.[PlanType] >= 2 AND O.[PlanType] <= 5) OR (O.[PlanType] >= 8 AND O.[PlanType] <= 20) AND (O.PlanType <> 16)) -- All 'Teams' and 'Enterprise' organizations
|
O.[PlanType] NOT IN (0, 1, 6, 7) -- Not 'Free', 'Custom' or 'Families'
|
||||||
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
||||||
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||||
ORDER BY O.[CreationDate] DESC
|
ORDER BY O.[CreationDate] DESC, O.[Id]
|
||||||
OFFSET @Skip ROWS
|
OFFSET @Skip ROWS
|
||||||
FETCH NEXT @Take ROWS ONLY
|
FETCH NEXT @Take ROWS ONLY
|
||||||
END
|
END
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
-- Drop existing SPROC
|
||||||
|
IF OBJECT_ID('[dbo].[Organization_UnassignedToProviderSearch]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Organization_UnassignedToProviderSearch]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Organization_UnassignedToProviderSearch]
|
||||||
|
@Name NVARCHAR(55),
|
||||||
|
@OwnerEmail NVARCHAR(256),
|
||||||
|
@Skip INT = 0,
|
||||||
|
@Take INT = 25
|
||||||
|
WITH RECOMPILE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
||||||
|
DECLARE @OwnerLikeSearch NVARCHAR(55) = @OwnerEmail + '%'
|
||||||
|
|
||||||
|
IF @OwnerEmail IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
SELECT
|
||||||
|
O.*
|
||||||
|
FROM
|
||||||
|
[dbo].[OrganizationView] O
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[OrganizationUser] OU ON O.[Id] = OU.[OrganizationId]
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
||||||
|
WHERE
|
||||||
|
O.[PlanType] NOT IN (0, 1, 6, 7) -- Not 'Free', 'Custom' or 'Families'
|
||||||
|
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
||||||
|
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||||
|
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||||
|
ORDER BY O.[CreationDate] DESC, O.[Id]
|
||||||
|
OFFSET @Skip ROWS
|
||||||
|
FETCH NEXT @Take ROWS ONLY
|
||||||
|
END
|
||||||
|
ELSE
|
||||||
|
BEGIN
|
||||||
|
SELECT
|
||||||
|
O.*
|
||||||
|
FROM
|
||||||
|
[dbo].[OrganizationView] O
|
||||||
|
WHERE
|
||||||
|
O.[PlanType] NOT IN (0, 1, 6, 7) -- Not 'Free', 'Custom' or 'Families'
|
||||||
|
AND NOT EXISTS (SELECT * FROM [dbo].[ProviderOrganizationView] PO WHERE PO.[OrganizationId] = O.[Id])
|
||||||
|
AND (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||||
|
ORDER BY O.[CreationDate] DESC, O.[Id]
|
||||||
|
OFFSET @Skip ROWS
|
||||||
|
FETCH NEXT @Take ROWS ONLY
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
Loading…
x
Reference in New Issue
Block a user