-
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
[PM-13693] Fixed null warnings #4896
base: main
Are you sure you want to change the base?
Conversation
…le fixed\n\nCo-authored-by: Luris Solis <[email protected]>\nCo-authored-by: Benson Bird <[email protected]>
…D parameter and rename methods\n\nCo-authored-by: Luris Solis <[email protected]>\nCo-authored-by: Benson Bird <[email protected]>
…d of the null checks because it already assumes that x.u is not null\n\nCo-authored-by: Luris Solis <[email protected]>\nCo-authored-by: Benson Bird <[email protected]>
Thank you for your contribution! We've added this to our internal Community PR board for review. |
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.
Just one note, thanks for the contribution!
@@ -166,7 +166,7 @@ private async Task<HttpResponseMessage> CallFreshdeskApiAsync(HttpRequestMessage | |||
} | |||
} | |||
await Task.Delay(30000 * (retriedCount + 1)); | |||
return await CallFreshdeskApiAsync(request, retriedCount++); | |||
return await CallFreshdeskApiAsync(request, retriedCount + 1); |
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.
We should probably update this to just increment retriedCount a single time. GitHub isn't letting me to an actual suggestion but it would look like this:
retriedCount++;
await Task.Delay(30000 * retriedCount);
return await CallFreshdeskApiAsync(request, retriedCount);
IEnumerable<KeyValuePair<int, int>> folderRelationships, | ||
Guid importingUserId) |
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.
Love this change, I really dislike trying to grab info from the first item in a list. Much nicer this way.
UsesKeyConnector = x.u.UsesKeyConnector, | ||
AccessSecretsManager = x.ou.AccessSecretsManager, | ||
HasMasterPassword = x.u != null && !string.IsNullOrWhiteSpace(x.u.MasterPassword) | ||
HasMasterPassword = !string.IsNullOrWhiteSpace(x.u.MasterPassword) |
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.
Generated SQLite from before change
SELECT "o"."Id",
"o"."UserId",
"o"."OrganizationId",
"u"."Name",
COALESCE("u"."Email", "o"."Email") AS "Email",
"u"."AvatarColor",
"u"."TwoFactorProviders",
"u"."Premium",
"o"."Status",
"o"."Type",
"o"."ExternalId",
"s"."ExternalId" AS "SsoExternalId",
"o"."Permissions",
"o"."ResetPasswordKey",
"u"."Id" IS NOT NULL AND "u"."UsesKeyConnector" AS "UsesKeyConnector",
"o"."AccessSecretsManager",
"u"."Id" IS NOT NULL AND "u"."MasterPassword" IS NOT NULL AND trim("u"."MasterPassword") <> 'P|CfDJ8KUSA3v4Y1dFg8Rnf6FjA5fdvqaglKtClSQ1I3diP2vxzTdwq2_dCgDHF-chiyxdEEkJZ_XZnvZFhIpQGoqQL4f35sOzasRWeL8HXy0O59nSBVpX2WOp565OeY4fYRwuNg' AS "HasMasterPassword"
FROM "OrganizationUser" AS "o"
LEFT JOIN "User" AS "u" ON "o"."UserId" = "u"."Id"
LEFT JOIN "SsoUser" AS "s" ON "o"."UserId" = "s"."UserId" AND "o"."OrganizationId" = "s"."OrganizationId"
After change:
SELECT "o"."Id",
"o"."UserId",
"o"."OrganizationId",
"u"."Name",
COALESCE("u"."Email",
"o"."Email") AS "Email",
"u"."AvatarColor",
"u"."TwoFactorProviders",
"u"."Premium",
"o"."Status",
"o"."Type",
"o"."ExternalId",
"s"."ExternalId" AS "SsoExternalId",
"o"."Permissions",
"o"."ResetPasswordKey",
"u"."UsesKeyConnector",
"o"."AccessSecretsManager",
"u"."MasterPassword" IS NOT NULL AND trim("u"."MasterPassword") <> 'P|CfDJ8KUSA3v4Y1dFg8Rnf6FjA5dJYW3Rjd8aosV-K01yVWmZVkVbItCW4oOuqXMvKO2PD9DIw0XKjy8sqgWtIKF1q7cT1JKgc3F2mwImAtRqP5WfrlURovVo9WdKmv2sI9lHUg' AS "HasMasterPassword"
FROM "OrganizationUser" AS "o"
LEFT JOIN "User" AS "u" ON "o"."UserId" = "u"."Id"
LEFT JOIN "SsoUser" AS "s" ON "o"."UserId" = "s"."UserId" AND "o"."OrganizationId" = "s"."OrganizationId"
And the equivalent hand wrote SQL:
SELECT
OU.[Id],
OU.[UserId],
OU.[OrganizationId],
U.[Name],
ISNULL(U.[Email], OU.[Email]) Email,
U.[AvatarColor],
U.[TwoFactorProviders],
U.[Premium],
OU.[Status],
OU.[Type],
OU.[AccessSecretsManager],
OU.[ExternalId],
SU.[ExternalId] SsoExternalId,
OU.[Permissions],
OU.[ResetPasswordKey],
U.[UsesKeyConnector],
CASE WHEN U.[MasterPassword] IS NOT NULL THEN 1 ELSE 0 END AS HasMasterPassword
FROM
[dbo].[OrganizationUser] OU
LEFT JOIN
[dbo].[User] U ON U.[Id] = OU.[UserId]
LEFT JOIN
[dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId]
So this seems like a good change to me.
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 also double checked this because I was concerned about orgUsers in the invited state that are not linked to a user, but they're excluded by the inner join on User.Id
. So we should always have a User available. And as has been pointed out, we access x.u
before this anyway, so clearly we do.
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.
Thanks for your contribution @MJebran ! The code owned by team-admin-console-dev
looks good to me.
UsesKeyConnector = x.u.UsesKeyConnector, | ||
AccessSecretsManager = x.ou.AccessSecretsManager, | ||
HasMasterPassword = x.u != null && !string.IsNullOrWhiteSpace(x.u.MasterPassword) | ||
HasMasterPassword = !string.IsNullOrWhiteSpace(x.u.MasterPassword) |
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 also double checked this because I was concerned about orgUsers in the invited state that are not linked to a user, but they're excluded by the inner join on User.Id
. So we should always have a User available. And as has been pointed out, we access x.u
before this anyway, so clearly we do.
@@ -57,7 +57,7 @@ public async Task PostImport([FromBody] ImportCiphersRequestModel model) | |||
var userId = _userService.GetProperUserId(User).Value; | |||
var folders = model.Folders.Select(f => f.ToFolder(userId)).ToList(); | |||
var ciphers = model.Ciphers.Select(c => c.ToCipherDetails(userId, false)).ToList(); | |||
await _cipherService.ImportCiphersAsync(folders, ciphers, model.FolderRelationships); | |||
await _cipherService.ImportFolderCiphersAsync(folders, ciphers, model.FolderRelationships, userId); |
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.
Initially these were likely meant to be method overloads. If we are changing the name I'd prefer:
await _cipherService.ImportFolderCiphersAsync(folders, ciphers, model.FolderRelationships, userId); | |
await _cipherService.ImportIntoIndividualVaultAsync(folders, ciphers, model.FolderRelationships, userId); |
@@ -85,7 +85,7 @@ public async Task PostImport([FromQuery] string organizationId, | |||
|
|||
var userId = _userService.GetProperUserId(User).Value; | |||
var ciphers = model.Ciphers.Select(l => l.ToOrganizationCipherDetails(orgId)).ToList(); | |||
await _cipherService.ImportCiphersAsync(collections, ciphers, model.CollectionRelationships, userId); | |||
await _cipherService.ImportCollectionCiphersAsync(collections, ciphers, model.CollectionRelationships, userId); |
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.
Initially these were likely meant to be method overloads. If we are changing the name I'd prefer:
await _cipherService.ImportCollectionCiphersAsync(collections, ciphers, model.CollectionRelationships, userId); | |
await _cipherService.ImportIntoOrganizationalVaultAsync(collections, ciphers, model.CollectionRelationships, userId); |
@@ -678,15 +678,14 @@ await _collectionCipherRepository.UpdateCollectionsForAdminAsync(cipher.Id, | |||
await _pushService.PushSyncCipherUpdateAsync(cipher, collectionIds); | |||
} | |||
|
|||
public async Task ImportCiphersAsync( | |||
public async Task ImportFolderCiphersAsync( |
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.
Note to self: These should likely be moved into a tools-owned import service leveraging methods from the CipherService/Repository
Co-authored-by: Benson Bird <[email protected]> Co-authored-by: Luris Solis <[email protected]>
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 Tools
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.
Billing changes look good. Thank you for your contribution!
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.
There are some CI failures that are blocking merge.
- formatting - please run
dotnet format
from the root of the repository and then commit the result. - tests failures - for some reason, removing the null check on
UsesKeyConnector
inOrganizationUserUserViewQuery
has broken the SCIM integration tests. It throws a null reference exception even though when I debug everything seems to have a value. However, this also made me notice that we're using it in the SCIMPostUserCommand
to return an invited user's details, however I think the inner join in this query would exclude invited users. I will find some time to look into this further.
Co-authored-by: Luris Solis <[email protected]>\Co-authored-by: Benson Bird <[email protected]>
218e417
No New Or Fixed Issues Found |
🎟️ Tracking
github issue link:
#2013
link to 14 specified issues mentioned in the above link:
https://pvs-studio.com/en/blog/posts/csharp/0947/
📔 Objective
We fixed 4 issues that could have cased null error, issues were warnings themselves
Changed a method that was not Undernet test, looking for conformation to add tests.
Collaborators (mob programmed)
https://github.com/luris26
https://github.com/BensonB12
🦮 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