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:
@ -103,15 +103,28 @@ public class OrganizationRepository : Repository<Core.Entities.Organization, Org
|
||||
select o;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(ownerEmail))
|
||||
{
|
||||
if (dbContext.Database.IsNpgsql())
|
||||
{
|
||||
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 u.Email == ownerEmail && ou.Type == OrganizationUserType.Owner
|
||||
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();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
||||
DECLARE @OwnerLikeSearch NVARCHAR(55) = @OwnerEmail + '%'
|
||||
|
||||
IF @OwnerEmail IS NOT NULL
|
||||
BEGIN
|
||||
@ -23,7 +24,7 @@ BEGIN
|
||||
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 (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||
AND (U.[Email] = @OwnerEmail)
|
||||
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||
ORDER BY O.[CreationDate] DESC
|
||||
OFFSET @Skip ROWS
|
||||
FETCH NEXT @Take ROWS ONLY
|
||||
|
@ -15,6 +15,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
|
||||
DECLARE @OwnerLikeSearch NVARCHAR(55) = @OwnerEmail + '%'
|
||||
|
||||
IF @OwnerEmail IS NOT NULL
|
||||
BEGIN
|
||||
@ -30,7 +31,7 @@ BEGIN
|
||||
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 (@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
|
||||
AND (U.[Email] = @OwnerEmail)
|
||||
AND (U.[Email] LIKE @OwnerLikeSearch)
|
||||
ORDER BY O.[CreationDate] DESC
|
||||
OFFSET @Skip ROWS
|
||||
FETCH NEXT @Take ROWS ONLY
|
||||
|
Reference in New Issue
Block a user