mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 13:08:17 -05:00
[PM-18076] - Fix compiler warnings (#5451)
* fixed warnings in UpdateOrganizationUserCommand.cs * Removed null dereference and multiple enumeration warning. * Removed unused param. Imported type for xml docs * imported missing type. * Added nullable block around method.
This commit is contained in:
parent
63f1c3cee3
commit
0d89409abd
@ -63,10 +63,10 @@ public class UpdateOrganizationUserCommand : IUpdateOrganizationUserCommand
|
||||
List<CollectionAccessSelection>? collectionAccess, IEnumerable<Guid>? groupAccess)
|
||||
{
|
||||
// Avoid multiple enumeration
|
||||
collectionAccess = collectionAccess?.ToList();
|
||||
var collectionAccessList = collectionAccess?.ToList() ?? [];
|
||||
groupAccess = groupAccess?.ToList();
|
||||
|
||||
if (organizationUser.Id.Equals(default(Guid)))
|
||||
if (organizationUser.Id.Equals(Guid.Empty))
|
||||
{
|
||||
throw new BadRequestException("Invite the user first.");
|
||||
}
|
||||
@ -93,9 +93,9 @@ public class UpdateOrganizationUserCommand : IUpdateOrganizationUserCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (collectionAccess?.Any() == true)
|
||||
if (collectionAccessList.Count != 0)
|
||||
{
|
||||
await ValidateCollectionAccessAsync(originalOrganizationUser, collectionAccess.ToList());
|
||||
await ValidateCollectionAccessAsync(originalOrganizationUser, collectionAccessList);
|
||||
}
|
||||
|
||||
if (groupAccess?.Any() == true)
|
||||
@ -111,14 +111,15 @@ public class UpdateOrganizationUserCommand : IUpdateOrganizationUserCommand
|
||||
await _organizationService.ValidateOrganizationCustomPermissionsEnabledAsync(organizationUser.OrganizationId, organizationUser.Type);
|
||||
|
||||
if (organizationUser.Type != OrganizationUserType.Owner &&
|
||||
!await _hasConfirmedOwnersExceptQuery.HasConfirmedOwnersExceptAsync(organizationUser.OrganizationId, new[] { organizationUser.Id }))
|
||||
!await _hasConfirmedOwnersExceptQuery.HasConfirmedOwnersExceptAsync(organizationUser.OrganizationId,
|
||||
[organizationUser.Id]))
|
||||
{
|
||||
throw new BadRequestException("Organization must have at least one confirmed owner.");
|
||||
}
|
||||
|
||||
if (collectionAccess?.Count > 0)
|
||||
if (collectionAccessList?.Count > 0)
|
||||
{
|
||||
var invalidAssociations = collectionAccess.Where(cas => cas.Manage && (cas.ReadOnly || cas.HidePasswords));
|
||||
var invalidAssociations = collectionAccessList.Where(cas => cas.Manage && (cas.ReadOnly || cas.HidePasswords));
|
||||
if (invalidAssociations.Any())
|
||||
{
|
||||
throw new BadRequestException("The Manage property is mutually exclusive and cannot be true while the ReadOnly or HidePasswords properties are also true.");
|
||||
@ -140,7 +141,7 @@ public class UpdateOrganizationUserCommand : IUpdateOrganizationUserCommand
|
||||
}
|
||||
}
|
||||
|
||||
await _organizationUserRepository.ReplaceAsync(organizationUser, collectionAccess);
|
||||
await _organizationUserRepository.ReplaceAsync(organizationUser, collectionAccessList);
|
||||
|
||||
if (groupAccess != null)
|
||||
{
|
||||
|
@ -24,8 +24,7 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
||||
|
||||
public record SignUpOrganizationResponse(
|
||||
Organization Organization,
|
||||
OrganizationUser OrganizationUser,
|
||||
Collection DefaultCollection);
|
||||
OrganizationUser OrganizationUser);
|
||||
|
||||
public interface ICloudOrganizationSignUpCommand
|
||||
{
|
||||
@ -34,7 +33,6 @@ public interface ICloudOrganizationSignUpCommand
|
||||
|
||||
public class CloudOrganizationSignUpCommand(
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IFeatureService featureService,
|
||||
IOrganizationBillingService organizationBillingService,
|
||||
IPaymentService paymentService,
|
||||
IPolicyService policyService,
|
||||
@ -144,7 +142,7 @@ public class CloudOrganizationSignUpCommand(
|
||||
// TODO: add reference events for SmSeats and Service Accounts - see AC-1481
|
||||
});
|
||||
|
||||
return new SignUpOrganizationResponse(returnValue.organization, returnValue.organizationUser, returnValue.defaultCollection);
|
||||
return new SignUpOrganizationResponse(returnValue.organization, returnValue.organizationUser);
|
||||
}
|
||||
|
||||
public void ValidatePasswordManagerPlan(Plan plan, OrganizationUpgrade upgrade)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
||||
|
||||
|
@ -73,6 +73,11 @@ public class TwoFactorAuthenticationPolicyValidator : IPolicyValidator
|
||||
{
|
||||
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||
|
||||
if (organization is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentActiveRevocableOrganizationUsers =
|
||||
(await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId))
|
||||
.Where(ou => ou.Status != OrganizationUserStatusType.Invited &&
|
||||
@ -90,9 +95,11 @@ public class TwoFactorAuthenticationPolicyValidator : IPolicyValidator
|
||||
var revocableUsersWithTwoFactorStatus =
|
||||
await _twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(currentActiveRevocableOrganizationUsers);
|
||||
|
||||
var nonCompliantUsers = revocableUsersWithTwoFactorStatus.Where(x => !x.twoFactorIsEnabled);
|
||||
var nonCompliantUsers = revocableUsersWithTwoFactorStatus
|
||||
.Where(x => !x.twoFactorIsEnabled)
|
||||
.ToArray();
|
||||
|
||||
if (!nonCompliantUsers.Any())
|
||||
if (nonCompliantUsers.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -249,6 +249,7 @@ public class OrganizationUserRepository : Repository<Core.Entities.OrganizationU
|
||||
}
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
public async Task<(OrganizationUserUserDetails? OrganizationUser, ICollection<CollectionAccessSelection> Collections)> GetDetailsByIdWithCollectionsAsync(Guid id)
|
||||
{
|
||||
var organizationUserUserDetails = await GetDetailsByIdAsync(id);
|
||||
@ -269,6 +270,7 @@ public class OrganizationUserRepository : Repository<Core.Entities.OrganizationU
|
||||
return (organizationUserUserDetails, collections);
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
public async Task<OrganizationUserOrganizationDetails> GetDetailsByUserAsync(Guid userId, Guid organizationId, OrganizationUserStatusType? status = null)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user