-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AC-1698] Check if a user has 2FA enabled more efficiently #4524
Conversation
… premium access by organization ID The code changes include: - Addition of a new stored procedure [dbo].[OrganizationUserUserDetailsWithPremiumAccess_ReadByOrganizationId] to read organization user details with premium access by organization ID - Modification of the IUserService interface to include an optional parameter for checking two-factor authentication with premium access - Modification of the UserService class to handle the new optional parameter in the TwoFactorIsEnabledAsync method - Addition of a new method GetManyDetailsWithPremiumAccessByOrganizationAsync in the IOrganizationUserRepository interface to retrieve organization user details with premium access by organization ID - Addition of a new view [dbo].[OrganizationUserUserDetailsWithPremiumAccessView] to retrieve organization user details with premium access
New Issues
Fixed Issues
|
…ync_vNext method to IOrganizationService
…od instead of changing the existing one
# Conflicts: # src/Admin/Controllers/UsersController.cs # src/Api/AdminConsole/Public/Controllers/MembersController.cs # src/Core/Constants.cs
src/Infrastructure.EntityFramework/Repositories/UserRepository.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/Core/Constants.cs
@@ -0,0 +1,31 @@ | |||
CREATE OR ALTER PROCEDURE [dbo].[User_ReadByIdsWithCalculatedPremium] | |||
@Ids AS [dbo].[GuidIdArray] READONLY | |||
AS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if in scope, but we have been moving away from using data types to pass in arrays, now we would pass in json :
CREATE OR ALTER PROCEDURE [dbo].[User_ReadByIdsWithCalculatedPremium]
@Ids NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
-- Declare a table variable to hold the parsed JSON data
DECLARE @ParsedIds TABLE (Id UNIQUEIDENTIFIER);
-- Parse the JSON input into the table variable
INSERT INTO @ParsedIds (Id)
SELECT value
FROM OPENJSON(@Ids);
-- Check if the input table is empty
IF (SELECT COUNT(1) FROM @ParsedIds) < 1
BEGIN
RETURN(-1);
END
-- Main query to fetch user details and calculate premium access
SELECT
U.*,
CASE
WHEN U.[Premium] = 1
OR EXISTS (
SELECT 1
FROM [dbo].[OrganizationUser] OU
JOIN [dbo].[Organization] O ON OU.[OrganizationId] = O.[Id]
WHERE OU.[UserId] = U.[Id]
AND O.[UsersGetPremium] = 1
AND O.[Enabled] = 1
)
THEN 1
ELSE 0
END AS HasPremiumAccess
FROM
[dbo].[UserView] U
WHERE
U.[Id] IN (SELECT [Id] FROM @ParsedIds);
END;`''''
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented that change. Thanks for providing the updated sproc!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
# Conflicts: # src/Core/Constants.cs
fa708e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving for AC after conflict resolution
🎟️ Tracking
https://bitwarden.atlassian.net/browse/AC-1698
📔 Objective
The members page loads slowly for large organizations because the database calls to check each user's 2FA status are not optimized.
This PR improves performance by making a single database call to check 2FA status for multiple users at once.
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes