Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public interface IOrganizationUserRepository : IRepository<OrganizationUser, Gui
Task<ICollection<OrganizationUserUserDetails>> GetManyDetailsByOrganizationAsync_vNext(Guid organizationId, bool includeGroups = false, bool includeSharedCollections = false);
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetailsByUserAsync(Guid userId,
OrganizationUserStatusType? status = null);
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyConfirmedAndAcceptedDetailsByUserAsync(Guid userId);
Task<OrganizationUserOrganizationDetails?> GetDetailsByUserAsync(Guid userId, Guid organizationId,
OrganizationUserStatusType? status = null);
Task UpdateGroupsAsync(Guid orgUserId, IEnumerable<Guid> groupIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ public async Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetai
}
}

public async Task<ICollection<OrganizationUserOrganizationDetails>> GetManyConfirmedAndAcceptedDetailsByUserAsync(Guid userId)
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<OrganizationUserOrganizationDetails>(
"[dbo].[OrganizationUserOrganizationDetails_ReadConfirmedAndAcceptedByUserId]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);

return results.ToList();
}
}

public async Task<OrganizationUserOrganizationDetails?> GetDetailsByUserAsync(Guid userId,
Guid organizationId, OrganizationUserStatusType? status = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ public async Task<OrganizationUserOrganizationDetails> GetDetailsByUserAsync(Gui
{
var dbContext = GetDatabaseContext(scope);
var view = new OrganizationUserOrganizationDetailsViewQuery();
var t = await (view.Run(dbContext)).ToArrayAsync();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t related to my PR, but it’s dead code and not being used. It was introduced about five years ago. Since AC owns this code now, I think we should remove it.

var entity = await view.Run(dbContext)
.FirstOrDefaultAsync(o => o.UserId == userId &&
o.OrganizationId == organizationId &&
Expand Down Expand Up @@ -574,6 +573,22 @@ public async Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetai
}
}

public async Task<ICollection<OrganizationUserOrganizationDetails>> GetManyConfirmedAndAcceptedDetailsByUserAsync(Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var view = new OrganizationUserOrganizationDetailsViewQuery();
var query = from organizationUserDetails in view.Run(dbContext)
where organizationUserDetails.UserId == userId &&
(organizationUserDetails.Status == OrganizationUserStatusType.Confirmed ||
organizationUserDetails.Status == OrganizationUserStatusType.Accepted)
select organizationUserDetails;
var organizationUsers = await query.ToListAsync();
return organizationUsers;
}
}

public async Task<IEnumerable<OrganizationUserPublicKey>> GetManyPublicKeysByOrganizationUserAsync(Guid organizationId, IEnumerable<Guid> Ids)
{
using (var scope = ServiceScopeFactory.CreateScope())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE PROCEDURE [dbo].[OrganizationUserOrganizationDetails_ReadConfirmedAndAcceptedByUserId]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid using And in proc names (see note: "Do not use And between parameter names in procedure names"):
https://contributing.bitwarden.com/contributing/code-style/sql/#common-examples

@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON

SELECT
*
FROM
[dbo].[OrganizationUserOrganizationDetailsView]
WHERE
[UserId] = @UserId
AND [Status] IN (1, 2) -- Accepted = 1, Confirmed = 2
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
IF OBJECT_ID('[dbo].[OrganizationUserOrganizationDetails_ReadConfirmedAndAcceptedByUserId]') IS NOT NULL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEGIN
DROP PROCEDURE [dbo].[OrganizationUserOrganizationDetails_ReadConfirmedAndAcceptedByUserId]
END
GO

CREATE PROCEDURE [dbo].[OrganizationUserOrganizationDetails_ReadConfirmedAndAcceptedByUserId]
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON

SELECT
*
FROM
[dbo].[OrganizationUserOrganizationDetailsView]
WHERE
[UserId] = @UserId
AND [Status] IN (1, 2) -- Accepted = 1, Confirmed = 2
END
Loading