mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[AC-1255] Search Existing Organizations by partial Email (#2830)
* [AC-1255] Added email search field input validation * [AC-1255] Reverted added email pattern * [AC-1255] Modified Organization search by Email to search using substring
This commit is contained in:
@ -104,13 +104,26 @@ public class OrganizationRepository : Repository<Core.Entities.Organization, Org
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(ownerEmail))
|
if (!string.IsNullOrWhiteSpace(ownerEmail))
|
||||||
{
|
{
|
||||||
query = from o in query
|
if (dbContext.Database.IsNpgsql())
|
||||||
join ou in dbContext.OrganizationUsers
|
{
|
||||||
on o.Id equals ou.OrganizationId
|
query = from o in query
|
||||||
join u in dbContext.Users
|
join ou in dbContext.OrganizationUsers
|
||||||
on ou.UserId equals u.Id
|
on o.Id equals ou.OrganizationId
|
||||||
where u.Email == ownerEmail && ou.Type == OrganizationUserType.Owner
|
join u in dbContext.Users
|
||||||
select o;
|
on ou.UserId equals u.Id
|
||||||
|
where ou.Type == OrganizationUserType.Owner && EF.Functions.ILike(EF.Functions.Collate(u.Email, "default"), $"{ownerEmail}%")
|
||||||
|
select o;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = from o in query
|
||||||
|
join ou in dbContext.OrganizationUsers
|
||||||
|
on o.Id equals ou.OrganizationId
|
||||||
|
join u in dbContext.Users
|
||||||
|
on ou.UserId equals u.Id
|
||||||
|
where ou.Type == OrganizationUserType.Owner && EF.Functions.Like(u.Email, $"{ownerEmail}%")
|
||||||
|
select o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await query.OrderByDescending(o => o.CreationDate).Skip(skip).Take(take).ToArrayAsync();
|
return await query.OrderByDescending(o => o.CreationDate).Skip(skip).Take(take).ToArrayAsync();
|
||||||
|
@ -8,7 +8,8 @@ AS
|
|||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
||||||
|
DECLARE @OwnerLikeSearch NVARCHAR(55) = @OwnerEmail + '%'
|
||||||
|
|
||||||
IF @OwnerEmail IS NOT NULL
|
IF @OwnerEmail IS NOT NULL
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
@ -23,7 +24,7 @@ BEGIN
|
|||||||
O.[PlanType] >= 8 AND O.[PlanType] <= 11 -- Get 'Team' and 'Enterprise' Organizations
|
O.[PlanType] >= 8 AND O.[PlanType] <= 11 -- Get 'Team' and 'Enterprise' Organizations
|
||||||
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] = @OwnerEmail)
|
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||||
ORDER BY O.[CreationDate] DESC
|
ORDER BY O.[CreationDate] DESC
|
||||||
OFFSET @Skip ROWS
|
OFFSET @Skip ROWS
|
||||||
FETCH NEXT @Take ROWS ONLY
|
FETCH NEXT @Take ROWS ONLY
|
||||||
|
@ -15,6 +15,7 @@ AS
|
|||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
||||||
|
DECLARE @OwnerLikeSearch NVARCHAR(55) = @OwnerEmail + '%'
|
||||||
|
|
||||||
IF @OwnerEmail IS NOT NULL
|
IF @OwnerEmail IS NOT NULL
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -30,7 +31,7 @@ BEGIN
|
|||||||
O.[PlanType] >= 8 AND O.[PlanType] <= 11 -- Get 'Team' and 'Enterprise' Organizations
|
O.[PlanType] >= 8 AND O.[PlanType] <= 11 -- Get 'Team' and 'Enterprise' Organizations
|
||||||
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] = @OwnerEmail)
|
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||||
ORDER BY O.[CreationDate] DESC
|
ORDER BY O.[CreationDate] DESC
|
||||||
OFFSET @Skip ROWS
|
OFFSET @Skip ROWS
|
||||||
FETCH NEXT @Take ROWS ONLY
|
FETCH NEXT @Take ROWS ONLY
|
||||||
|
Reference in New Issue
Block a user