diff --git a/.gitattributes b/.gitattributes index 1d012697d..ecb84500f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.sh eol=lf +*.cs eol=lf .dockerignore eol=lf dockerfile eol=lf \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 299489da4..0f3051b6e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,9 +72,9 @@ jobs: run: dotnet tool restore shell: pwsh - # - name: Verify Format - # run: dotnet tool run dotnet-format --check - # shell: pwsh + - name: Verify Format + run: dotnet tool run dotnet-format --check + shell: pwsh - name: Test OSS solution run: dotnet test ./test --configuration Debug --no-build diff --git a/bitwarden_license/src/Sso/Controllers/AccountController.cs b/bitwarden_license/src/Sso/Controllers/AccountController.cs index eaa12e6f3..03c3f8a9b 100644 --- a/bitwarden_license/src/Sso/Controllers/AccountController.cs +++ b/bitwarden_license/src/Sso/Controllers/AccountController.cs @@ -1,8 +1,18 @@ -using Bit.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Bit.Core; using Bit.Core.Enums; +using Bit.Core.Models; +using Bit.Core.Models.Api; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; +using Bit.Core.Settings; +using Bit.Core.Utilities; using Bit.Sso.Models; using Bit.Sso.Utilities; using IdentityModel; @@ -11,20 +21,10 @@ using IdentityServer4.Extensions; using IdentityServer4.Services; using IdentityServer4.Stores; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Bit.Core.Models; -using Bit.Core.Models.Api; -using Bit.Core.Utilities; -using Bit.Core.Models.Data; -using Bit.Core.Settings; +using Microsoft.Extensions.Logging; namespace Bit.Sso.Controllers { @@ -83,7 +83,7 @@ namespace Bit.Sso.Controllers _eventService = eventService; _globalSettings = globalSettings; } - + [HttpGet] public async Task PreValidate(string domainHint) { @@ -382,7 +382,7 @@ namespace Bit.Sso.Controllers { email = providerUserId; } - + if (!Guid.TryParse(provider, out var orgId)) { // TODO: support non-org (server-wide) SSO in the future? @@ -432,7 +432,7 @@ namespace Bit.Sso.Controllers { throw new Exception(_i18nService.T("CouldNotFindOrganization", orgId)); } - + // Try to find OrgUser via existing User Id (accepted/confirmed user) if (existingUser != null) { @@ -442,7 +442,7 @@ namespace Bit.Sso.Controllers // If no Org User found by Existing User Id - search all organization users via email orgUser ??= await _organizationUserRepository.GetByOrganizationEmailAsync(orgId, email); - + // All Existing User flows handled below if (existingUser != null) { @@ -457,11 +457,11 @@ namespace Bit.Sso.Controllers // Org User is not created - no invite has been sent throw new Exception(_i18nService.T("UserAlreadyExistsInviteProcess")); } - + if (orgUser.Status == OrganizationUserStatusType.Invited) { // Org User is invited - they must manually accept the invite via email and authenticate with MP - throw new Exception(_i18nService.T("UserAlreadyInvited", email, organization.Name)); + throw new Exception(_i18nService.T("UserAlreadyInvited", email, organization.Name)); } // Accepted or Confirmed - create SSO link and return; @@ -507,7 +507,7 @@ namespace Bit.Sso.Controllers ApiKey = CoreHelpers.SecureRandomString(30) }; await _userService.RegisterUserAsync(user); - + // If the organization has 2fa policy enabled, make sure to default jit user 2fa to email var twoFactorPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.TwoFactorAuthentication); @@ -516,14 +516,14 @@ namespace Bit.Sso.Controllers user.SetTwoFactorProviders(new Dictionary { [TwoFactorProviderType.Email] = new TwoFactorProvider - { - MetaData = new Dictionary { ["Email"] = user.Email.ToLowerInvariant() }, - Enabled = true - } + { + MetaData = new Dictionary { ["Email"] = user.Email.ToLowerInvariant() }, + Enabled = true + } }); await _userService.UpdateTwoFactorProviderAsync(user, TwoFactorProviderType.Email); } - + // Create Org User if null or else update existing Org User if (orgUser == null) { @@ -541,10 +541,10 @@ namespace Bit.Sso.Controllers orgUser.UserId = user.Id; await _organizationUserRepository.ReplaceAsync(orgUser); } - + // Create sso user record await CreateSsoUserRecord(providerUserId, user.Id, orgId, orgUser); - + return user; } diff --git a/bitwarden_license/src/Sso/Controllers/HomeController.cs b/bitwarden_license/src/Sso/Controllers/HomeController.cs index 1a5d31e00..771d93a00 100644 --- a/bitwarden_license/src/Sso/Controllers/HomeController.cs +++ b/bitwarden_license/src/Sso/Controllers/HomeController.cs @@ -1,11 +1,11 @@ using System; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using IdentityServer4.Services; +using System.Diagnostics; using System.Threading.Tasks; using Bit.Sso.Models; -using System.Diagnostics; +using IdentityServer4.Services; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Mvc; namespace Bit.Sso.Controllers { diff --git a/bitwarden_license/src/Sso/Controllers/InfoController.cs b/bitwarden_license/src/Sso/Controllers/InfoController.cs index 4d949bf9c..7f3058ae9 100644 --- a/bitwarden_license/src/Sso/Controllers/InfoController.cs +++ b/bitwarden_license/src/Sso/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Sso.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Sso.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/bitwarden_license/src/Sso/Utilities/DynamicAuthenticationSchemeProvider.cs b/bitwarden_license/src/Sso/Utilities/DynamicAuthenticationSchemeProvider.cs index 7220e12a9..c774ba555 100644 --- a/bitwarden_license/src/Sso/Utilities/DynamicAuthenticationSchemeProvider.cs +++ b/bitwarden_license/src/Sso/Utilities/DynamicAuthenticationSchemeProvider.cs @@ -9,8 +9,8 @@ using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; using Bit.Sso.Models; using Bit.Sso.Utilities; using IdentityModel; @@ -136,7 +136,7 @@ namespace Bit.Core.Business.Sso await LoadAllDynamicSchemesIntoCacheAsync(); schemes.AddRange(_handlerSchemesCopy); - + return schemes.ToArray(); } diff --git a/bitwarden_license/src/Sso/Utilities/ExtendedOptionsMonitorCache.cs b/bitwarden_license/src/Sso/Utilities/ExtendedOptionsMonitorCache.cs index 6d657625d..951be7378 100644 --- a/bitwarden_license/src/Sso/Utilities/ExtendedOptionsMonitorCache.cs +++ b/bitwarden_license/src/Sso/Utilities/ExtendedOptionsMonitorCache.cs @@ -1,6 +1,6 @@ -using Microsoft.Extensions.Options; -using System; +using System; using System.Collections.Concurrent; +using Microsoft.Extensions.Options; namespace Bit.Sso.Utilities { @@ -35,4 +35,4 @@ namespace Bit.Sso.Utilities return _cache.TryRemove(name ?? Options.DefaultName, out _); } } -} \ No newline at end of file +} diff --git a/bitwarden_license/src/Sso/Utilities/IExtendedOptionsMonitorCache.cs b/bitwarden_license/src/Sso/Utilities/IExtendedOptionsMonitorCache.cs index 6b039f559..73a5352a8 100644 --- a/bitwarden_license/src/Sso/Utilities/IExtendedOptionsMonitorCache.cs +++ b/bitwarden_license/src/Sso/Utilities/IExtendedOptionsMonitorCache.cs @@ -6,4 +6,4 @@ namespace Bit.Sso.Utilities { void AddOrUpdate(string name, TOptions options); } -} \ No newline at end of file +} diff --git a/bitwarden_license/src/Sso/Utilities/ServiceCollectionExtensions.cs b/bitwarden_license/src/Sso/Utilities/ServiceCollectionExtensions.cs index 89a545c53..38d9f38b5 100644 --- a/bitwarden_license/src/Sso/Utilities/ServiceCollectionExtensions.cs +++ b/bitwarden_license/src/Sso/Utilities/ServiceCollectionExtensions.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using Bit.Core.Business.Sso; using Bit.Core.IdentityServer; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; using Bit.Sso.Models; using IdentityServer4.Models; using IdentityServer4.ResponseHandling; diff --git a/bitwarden_license/src/Sso/Utilities/SsoAuthenticationMiddleware.cs b/bitwarden_license/src/Sso/Utilities/SsoAuthenticationMiddleware.cs index 04b636cb6..68c81a138 100644 --- a/bitwarden_license/src/Sso/Utilities/SsoAuthenticationMiddleware.cs +++ b/bitwarden_license/src/Sso/Utilities/SsoAuthenticationMiddleware.cs @@ -12,7 +12,7 @@ namespace Bit.Sso.Utilities public class SsoAuthenticationMiddleware { private readonly RequestDelegate _next; - + public SsoAuthenticationMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes) { _next = next ?? throw new ArgumentNullException(nameof(next)); diff --git a/bitwarden_license/test/CmmCore.Test/AutoFixture/ProviderUserFixtures.cs b/bitwarden_license/test/CmmCore.Test/AutoFixture/ProviderUserFixtures.cs index 8dd7a94c6..c732fc3ba 100644 --- a/bitwarden_license/test/CmmCore.Test/AutoFixture/ProviderUserFixtures.cs +++ b/bitwarden_license/test/CmmCore.Test/AutoFixture/ProviderUserFixtures.cs @@ -15,7 +15,7 @@ namespace Bit.CommCore.Test.AutoFixture.ProviderUserFixtures Status = status; Type = type; } - + public void Customize(IFixture fixture) { fixture.Customize(composer => composer diff --git a/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs b/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs index b10c24926..09bf1c2da 100644 --- a/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs +++ b/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Bit.CommCore.Test.AutoFixture.ProviderUserFixtures; using Bit.CommCore.Services; +using Bit.CommCore.Test.AutoFixture.ProviderUserFixtures; +using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Enums.Provider; using Bit.Core.Exceptions; @@ -14,14 +15,13 @@ using Bit.Core.Models.Table.Provider; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Utilities; +using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; using Microsoft.AspNetCore.DataProtection; using NSubstitute; using NSubstitute.ReturnsExtensions; using Xunit; using ProviderUser = Bit.Core.Models.Table.Provider.ProviderUser; -using Bit.Core.Context; -using Bit.Test.Common.AutoFixture; -using Bit.Test.Common.AutoFixture.Attributes; namespace Bit.CommCore.Test.Services { @@ -34,19 +34,19 @@ namespace Bit.CommCore.Test.Services () => sutProvider.Sut.CreateAsync(default)); Assert.Contains("Invalid owner.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task CreateAsync_Success(User user, SutProvider sutProvider) { var userRepository = sutProvider.GetDependency(); - userRepository.GetByEmailAsync(user.Email).Returns(user); - + userRepository.GetByEmailAsync(user.Email).Returns(user); + await sutProvider.Sut.CreateAsync(user.Email); - + await sutProvider.GetDependency().ReceivedWithAnyArgs().CreateAsync(default); await sutProvider.GetDependency().ReceivedWithAnyArgs().SendProviderSetupInviteEmailAsync(default, default, default); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task CompleteSetupAsync_UserIdIsInvalid_Throws(SutProvider sutProvider) { @@ -54,13 +54,13 @@ namespace Bit.CommCore.Test.Services () => sutProvider.Sut.CompleteSetupAsync(default, default, default, default)); Assert.Contains("Invalid owner.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task CompleteSetupAsync_TokenIsInvalid_Throws(User user, Provider provider, SutProvider sutProvider) { var userService = sutProvider.GetDependency(); - userService.GetUserByIdAsync(user.Id).Returns(user); + userService.GetUserByIdAsync(user.Id).Returns(user); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.CompleteSetupAsync(provider, user.Id, default, default)); @@ -69,7 +69,7 @@ namespace Bit.CommCore.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task CompleteSetupAsync_Success(User user, Provider provider, string key, - [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)]ProviderUser providerUser, + [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser providerUser, SutProvider sutProvider) { providerUser.ProviderId = provider.Id; @@ -85,7 +85,7 @@ namespace Bit.CommCore.Test.Services sutProvider.GetDependency().CreateProtector("ProviderServiceDataProtector") .Returns(protector); sutProvider.Create(); - + var token = protector.Protect($"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}"); await sutProvider.Sut.CompleteSetupAsync(provider, user.Id, token, key); @@ -94,23 +94,23 @@ namespace Bit.CommCore.Test.Services await sutProvider.GetDependency().Received() .ReplaceAsync(Arg.Is(pu => pu.UserId == user.Id && pu.ProviderId == provider.Id && pu.Key == key)); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task UpdateAsync_ProviderIdIsInvalid_Throws(Provider provider, SutProvider sutProvider) { provider.Id = default; - + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.UpdateAsync(provider)); Assert.Contains("Cannot create provider this way.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task UpdateAsync_Success(Provider provider, SutProvider sutProvider) { await sutProvider.Sut.UpdateAsync(provider); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_ProviderIdIsInvalid_Throws(ProviderUserInvite invite, SutProvider sutProvider) { @@ -125,7 +125,7 @@ namespace Bit.CommCore.Test.Services sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_EmailsInvalid_Throws(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) @@ -135,10 +135,10 @@ namespace Bit.CommCore.Test.Services sutProvider.GetDependency().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true); providerUserInvite.UserIdentifiers = null; - + await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(providerUserInvite)); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_AlreadyInvited(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) @@ -152,7 +152,7 @@ namespace Bit.CommCore.Test.Services var result = await sutProvider.Sut.InviteUserAsync(providerUserInvite); Assert.Empty(result); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_Success(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) @@ -168,23 +168,23 @@ namespace Bit.CommCore.Test.Services Assert.True(result.TrueForAll(pu => pu.Status == ProviderUserStatusType.Invited), "Status must be invited"); Assert.True(result.TrueForAll(pu => pu.ProviderId == providerUserInvite.ProviderId), "Provider Id must be correct"); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ResendInviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite invite, SutProvider sutProvider) - { + { sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.ResendInvitesAsync(invite)); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ResendInvitesAsync_Errors(Provider provider, - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, - [ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, - [ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu4, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, + [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, + [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu4, SutProvider sutProvider) { - var providerUsers = new[] {pu1, pu2, pu3, pu4}; + var providerUsers = new[] { pu1, pu2, pu3, pu4 }; pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id; var invite = new ProviderUserInvite @@ -205,7 +205,7 @@ namespace Bit.CommCore.Test.Services Assert.Equal("User invalid.", result[2].Item2); Assert.Equal("User invalid.", result[3].Item2); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ResendInvitesAsync_Success(Provider provider, IEnumerable providerUsers, SutProvider sutProvider) @@ -240,62 +240,62 @@ namespace Bit.CommCore.Test.Services () => sutProvider.Sut.AcceptUserAsync(default, default, default)); Assert.Equal("User invalid.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task AcceptUserAsync_AlreadyAccepted_Throws( - [ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser providerUser, User user, + [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser providerUser, User user, SutProvider sutProvider) { var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); - + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default)); Assert.Equal("Already accepted.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task AcceptUserAsync_TokenIsInvalid_Throws( - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) { var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); - + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default)); Assert.Equal("Invalid token.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task AcceptUserAsync_WrongEmail_Throws( - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) { var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); - + var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName"); var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector"); sutProvider.GetDependency().CreateProtector("ProviderServiceDataProtector") .Returns(protector); sutProvider.Create(); - + var token = protector.Protect($"ProviderUserInvite {providerUser.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}"); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, token)); Assert.Equal("User email does not match invite.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task AcceptUserAsync_Success( - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) { var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); - + var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName"); var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector"); sutProvider.GetDependency().CreateProtector("ProviderServiceDataProtector") @@ -310,53 +310,53 @@ namespace Bit.CommCore.Test.Services Assert.Equal(ProviderUserStatusType.Accepted, pu.Status); Assert.Equal(user.Id, pu.UserId); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUsersAsync_NoValid( - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, - [ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, - [ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, + [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, + [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3, SutProvider sutProvider) { pu1.ProviderId = pu3.ProviderId; - var providerUsers = new[] {pu1, pu2, pu3}; + var providerUsers = new[] { pu1, pu2, pu3 }; var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); var dict = providerUsers.ToDictionary(pu => pu.Id, _ => "key"); var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, default); - + Assert.Empty(result); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUsersAsync_Success( - [ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, User u1, - [ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, User u2, - [ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, User u3, + [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, User u1, + [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, User u2, + [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3, User u3, Provider provider, User user, SutProvider sutProvider) { pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id; pu1.UserId = u1.Id; pu2.UserId = u2.Id; pu3.UserId = u3.Id; - var providerUsers = new[] {pu1, pu2, pu3}; + var providerUsers = new[] { pu1, pu2, pu3 }; var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); var providerRepository = sutProvider.GetDependency(); providerRepository.GetByIdAsync(provider.Id).Returns(provider); var userRepository = sutProvider.GetDependency(); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {u1, u2, u3}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { u1, u2, u3 }); var dict = providerUsers.ToDictionary(pu => pu.Id, _ => "key"); var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, user.Id); - + Assert.Equal("Invalid user.", result[0].Item2); Assert.Equal("", result[1].Item2); Assert.Equal("Invalid user.", result[2].Item2); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task SaveUserAsync_UserIdIsInvalid_Throws(ProviderUser providerUser, SutProvider sutProvider) @@ -369,7 +369,7 @@ namespace Bit.CommCore.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task SaveUserAsync_Success( - [ProviderUser(type: ProviderUserType.ProviderAdmin)]ProviderUser providerUser, User savingUser, + [ProviderUser(type: ProviderUserType.ProviderAdmin)] ProviderUser providerUser, User savingUser, SutProvider sutProvider) { var providerUserRepository = sutProvider.GetDependency(); @@ -380,7 +380,7 @@ namespace Bit.CommCore.Test.Services await sutProvider.GetDependency().Received() .LogProviderUserEventAsync(providerUser, EventType.ProviderUser_Updated, null); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsersAsync_NoRemainingOwner_Throws(Provider provider, User deletingUser, ICollection providerUsers, SutProvider sutProvider) @@ -397,16 +397,16 @@ namespace Bit.CommCore.Test.Services sutProvider.GetDependency().GetByIdAsync(provider.Id).Returns(provider); var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); - providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new ProviderUser[] {}); - + providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new ProviderUser[] { }); + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.DeleteUsersAsync(provider.Id, userIds, deletingUser.Id)); Assert.Equal("Provider must have at least one confirmed ProviderAdmin.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] - public async Task DeleteUsersAsync_Success(Provider provider, User deletingUser, ICollection providerUsers, - [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)]ProviderUser remainingOwner, + public async Task DeleteUsersAsync_Success(Provider provider, User deletingUser, ICollection providerUsers, + [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser remainingOwner, SutProvider sutProvider) { var userIds = providerUsers.Select(pu => pu.Id); @@ -421,10 +421,10 @@ namespace Bit.CommCore.Test.Services sutProvider.GetDependency().GetByIdAsync(provider.Id).Returns(provider); var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); - providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new[] {remainingOwner}); - + providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new[] { remainingOwner }); + var result = await sutProvider.Sut.DeleteUsersAsync(provider.Id, userIds, deletingUser.Id); - + Assert.NotEmpty(result); Assert.Equal("You cannot remove yourself.", result[0].Item2); Assert.Equal("", result[1].Item2); diff --git a/src/Admin/Controllers/ErrorController.cs b/src/Admin/Controllers/ErrorController.cs index bef21cd12..af6091204 100644 --- a/src/Admin/Controllers/ErrorController.cs +++ b/src/Admin/Controllers/ErrorController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc; namespace Bit.Admin.Controllers diff --git a/src/Admin/Controllers/HomeController.cs b/src/Admin/Controllers/HomeController.cs index c8aa35c04..f2c899064 100644 --- a/src/Admin/Controllers/HomeController.cs +++ b/src/Admin/Controllers/HomeController.cs @@ -1,10 +1,10 @@ using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using Bit.Admin.Models; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Settings; using System.Net.Http; using System.Threading.Tasks; +using Bit.Admin.Models; +using Bit.Core.Settings; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; namespace Bit.Admin.Controllers diff --git a/src/Admin/Controllers/InfoController.cs b/src/Admin/Controllers/InfoController.cs index b49a9a29d..e09f0a9f3 100644 --- a/src/Admin/Controllers/InfoController.cs +++ b/src/Admin/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Admin.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Admin.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Admin/Controllers/LogsController.cs b/src/Admin/Controllers/LogsController.cs index 716c5631c..21f1fca81 100644 --- a/src/Admin/Controllers/LogsController.cs +++ b/src/Admin/Controllers/LogsController.cs @@ -41,7 +41,7 @@ namespace Bit.Admin.Controllers }, continuationToken: cursor ).AsQueryable(); - + if (level.HasValue) { query = query.Where(l => l.Level == level.Value.ToString()); @@ -84,7 +84,7 @@ namespace Bit.Admin.Controllers var query = cosmosContainer.GetItemLinqQueryable() .AsQueryable() .Where(l => l.Id == id.ToString()); - + var response = await query.ToFeedIterator().ReadNextAsync(); if (response == null || response.Count == 0) { diff --git a/src/Admin/Controllers/OrganizationsController.cs b/src/Admin/Controllers/OrganizationsController.cs index b7054c28e..613807b7d 100644 --- a/src/Admin/Controllers/OrganizationsController.cs +++ b/src/Admin/Controllers/OrganizationsController.cs @@ -1,16 +1,16 @@ using System; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Repositories; +using System.Collections.Generic; using System.Threading.Tasks; using Bit.Admin.Models; -using System.Collections.Generic; +using Bit.Core.Enums; +using Bit.Core.Models.Business; using Bit.Core.Models.Table; -using Bit.Core.Utilities; +using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; -using Bit.Core.Models.Business; -using Bit.Core.Enums; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Admin.Controllers { @@ -143,7 +143,8 @@ namespace Bit.Admin.Controllers model.ToOrganization(organization); await _organizationRepository.ReplaceAsync(organization); await _applicationCacheService.UpsertOrganizationAbilityAsync(organization); - await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.OrganizationEditedByAdmin, organization) { + await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.OrganizationEditedByAdmin, organization) + { EventRaisedByUser = _userService.GetUserName(User), SalesAssistedTrialStarted = model.SalesAssistedTrialStarted, }); diff --git a/src/Admin/Controllers/ToolsController.cs b/src/Admin/Controllers/ToolsController.cs index 28dff84af..600755011 100644 --- a/src/Admin/Controllers/ToolsController.cs +++ b/src/Admin/Controllers/ToolsController.cs @@ -319,8 +319,8 @@ namespace Bit.Admin.Controllers }; return View(model); - } - + } + [ValidateAntiForgeryToken] public async Task TaxRateUpload(IFormFile file) { @@ -332,7 +332,7 @@ namespace Bit.Admin.Controllers // Build rates and validate them first before updating DB & Stripe var taxRateUpdates = new List(); var currentTaxRates = await _taxRateRepository.GetAllActiveAsync(); - using var reader = new StreamReader(file.OpenReadStream()); + using var reader = new StreamReader(file.OpenReadStream()); while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); @@ -370,8 +370,8 @@ namespace Bit.Admin.Controllers taxRate.Rate = rate; taxRate.State = state ?? taxRate.State; taxRateUpdates.Add(taxRate); - } - + } + foreach (var taxRate in taxRateUpdates) { if (!string.IsNullOrWhiteSpace(taxRate.Id)) @@ -384,17 +384,17 @@ namespace Bit.Admin.Controllers } } - return RedirectToAction("TaxRate"); + return RedirectToAction("TaxRate"); } [HttpPost] [ValidateAntiForgeryToken] - public async Task TaxRateAddEdit(TaxRateAddEditModel model) + public async Task TaxRateAddEdit(TaxRateAddEditModel model) { var existingRateCheck = await _taxRateRepository.GetByLocationAsync(new TaxRate() { Country = model.Country, PostalCode = model.PostalCode }); - if (existingRateCheck.Any()) + if (existingRateCheck.Any()) { - ModelState.AddModelError(nameof(model.PostalCode), "A tax rate already exists for this Country/Postal Code combination."); + ModelState.AddModelError(nameof(model.PostalCode), "A tax rate already exists for this Country/Postal Code combination."); } if (!ModelState.IsValid) @@ -423,7 +423,7 @@ namespace Bit.Admin.Controllers return RedirectToAction("TaxRate"); } - public async Task TaxRateArchive(string stripeTaxRateId) + public async Task TaxRateArchive(string stripeTaxRateId) { if (!string.IsNullOrWhiteSpace(stripeTaxRateId)) { diff --git a/src/Admin/Controllers/UsersController.cs b/src/Admin/Controllers/UsersController.cs index 08f2ae765..f65b1f97e 100644 --- a/src/Admin/Controllers/UsersController.cs +++ b/src/Admin/Controllers/UsersController.cs @@ -1,14 +1,14 @@ using System; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Repositories; +using System.Collections.Generic; using System.Threading.Tasks; using Bit.Admin.Models; -using System.Collections.Generic; using Bit.Core.Models.Table; -using Bit.Core.Utilities; +using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Admin.Controllers { diff --git a/src/Admin/HostedServices/AzureQueueBlockIpHostedService.cs b/src/Admin/HostedServices/AzureQueueBlockIpHostedService.cs index f7e11ba4a..ba958136a 100644 --- a/src/Admin/HostedServices/AzureQueueBlockIpHostedService.cs +++ b/src/Admin/HostedServices/AzureQueueBlockIpHostedService.cs @@ -2,10 +2,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure.Storage.Queues; using Bit.Core.Settings; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Azure.Storage.Queues; namespace Bit.Admin.HostedServices { diff --git a/src/Admin/HostedServices/AzureQueueMailHostedService.cs b/src/Admin/HostedServices/AzureQueueMailHostedService.cs index 17d4b2fc5..fbf3c4641 100644 --- a/src/Admin/HostedServices/AzureQueueMailHostedService.cs +++ b/src/Admin/HostedServices/AzureQueueMailHostedService.cs @@ -1,18 +1,18 @@ -using System; -using Microsoft.Extensions.Hosting; -using Azure.Storage.Queues; -using Microsoft.Extensions.Logging; -using Bit.Core.Settings; -using System.Threading.Tasks; -using System.Threading; -using Bit.Core.Services; -using Newtonsoft.Json; -using Bit.Core.Models.Mail; -using Azure.Storage.Queues.Models; -using System.Linq; +using System; using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Storage.Queues; +using Azure.Storage.Queues.Models; +using Bit.Core.Models.Mail; +using Bit.Core.Services; +using Bit.Core.Settings; using Bit.Core.Utilities; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Bit.Admin.HostedServices { @@ -30,7 +30,7 @@ namespace Bit.Admin.HostedServices ILogger logger, IMailService mailService, GlobalSettings globalSettings) - { + { _logger = logger; _mailService = mailService; _globalSettings = globalSettings; @@ -89,7 +89,7 @@ namespace Bit.Admin.HostedServices _logger.LogError(e, "Failed to send email"); // TODO: retries? } - + await _mailQueueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt); if (cancellationToken.IsCancellationRequested) diff --git a/src/Admin/Jobs/DeleteSendsJob.cs b/src/Admin/Jobs/DeleteSendsJob.cs index 6f45abb51..2aa0b2119 100644 --- a/src/Admin/Jobs/DeleteSendsJob.cs +++ b/src/Admin/Jobs/DeleteSendsJob.cs @@ -1,6 +1,6 @@ using System; -using System.Threading.Tasks; using System.Linq; +using System.Threading.Tasks; using Bit.Core; using Bit.Core.Context; using Bit.Core.Jobs; diff --git a/src/Admin/Models/CreateProviderModel.cs b/src/Admin/Models/CreateProviderModel.cs index ad4c547f4..582c388af 100644 --- a/src/Admin/Models/CreateProviderModel.cs +++ b/src/Admin/Models/CreateProviderModel.cs @@ -5,7 +5,7 @@ namespace Bit.Admin.Models public class CreateProviderModel { public CreateProviderModel() { } - + [Display(Name = "Owner Email")] [Required] public string OwnerEmail { get; set; } diff --git a/src/Admin/Models/OrganizationEditModel.cs b/src/Admin/Models/OrganizationEditModel.cs index fe9c445cb..9be51460a 100644 --- a/src/Admin/Models/OrganizationEditModel.cs +++ b/src/Admin/Models/OrganizationEditModel.cs @@ -5,8 +5,8 @@ using Bit.Core.Enums; using Bit.Core.Models.Business; using Bit.Core.Models.Data; using Bit.Core.Models.Table; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; namespace Bit.Admin.Models { @@ -92,7 +92,7 @@ namespace Bit.Admin.Models [Display(Name = "2FA")] public bool Use2fa { get; set; } [Display(Name = "API")] - public bool UseApi{ get; set; } + public bool UseApi { get; set; } [Display(Name = "Reset Password")] public bool UseResetPassword { get; set; } [Display(Name = "Self Host")] diff --git a/src/Admin/Models/OrganizationViewModel.cs b/src/Admin/Models/OrganizationViewModel.cs index 5a9bc4452..096acb5bf 100644 --- a/src/Admin/Models/OrganizationViewModel.cs +++ b/src/Admin/Models/OrganizationViewModel.cs @@ -25,11 +25,11 @@ namespace Bit.Admin.Models CollectionCount = collections.Count(); GroupCount = groups?.Count() ?? 0; PolicyCount = policies?.Count() ?? 0; - Owners = string.Join(", ", + Owners = string.Join(", ", orgUsers .Where(u => u.Type == OrganizationUserType.Owner && u.Status == OrganizationUserStatusType.Confirmed) .Select(u => u.Email)); - Admins = string.Join(", ", + Admins = string.Join(", ", orgUsers .Where(u => u.Type == OrganizationUserType.Admin && u.Status == OrganizationUserStatusType.Confirmed) .Select(u => u.Email)); diff --git a/src/Admin/Models/TaxRateAddEditModel.cs b/src/Admin/Models/TaxRateAddEditModel.cs index 7d098cd86..e55ec87c6 100644 --- a/src/Admin/Models/TaxRateAddEditModel.cs +++ b/src/Admin/Models/TaxRateAddEditModel.cs @@ -1,6 +1,6 @@ -namespace Bit.Admin.Models +namespace Bit.Admin.Models { - public class TaxRateAddEditModel + public class TaxRateAddEditModel { public string StripeTaxRateId { get; set; } public string Country { get; set; } diff --git a/src/Admin/Models/TaxRatesModel.cs b/src/Admin/Models/TaxRatesModel.cs index 4af8540fa..54a823a03 100644 --- a/src/Admin/Models/TaxRatesModel.cs +++ b/src/Admin/Models/TaxRatesModel.cs @@ -1,8 +1,8 @@ -using Bit.Core.Models.Table; +using Bit.Core.Models.Table; namespace Bit.Admin.Models { - public class TaxRatesModel: PagedModel + public class TaxRatesModel : PagedModel { public string Message { get; set; } } diff --git a/src/Admin/Models/UserEditModel.cs b/src/Admin/Models/UserEditModel.cs index 624e0cb8c..8e3d07073 100644 --- a/src/Admin/Models/UserEditModel.cs +++ b/src/Admin/Models/UserEditModel.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Bit.Core.Models.Business; using Bit.Core.Models.Table; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; namespace Bit.Admin.Models { @@ -30,7 +30,7 @@ namespace Bit.Admin.Models LicenseKey = user.LicenseKey; PremiumExpirationDate = user.PremiumExpirationDate; } - + public BillingInfo BillingInfo { get; set; } public string RandomLicenseKey => CoreHelpers.SecureRandomString(20); public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm"); diff --git a/src/Admin/Startup.cs b/src/Admin/Startup.cs index 90837b913..a2127675a 100644 --- a/src/Admin/Startup.cs +++ b/src/Admin/Startup.cs @@ -70,12 +70,12 @@ namespace Bit.Admin // Services services.AddBaseServices(); services.AddDefaultServices(globalSettings); - - #if OSS + +#if OSS services.AddOosServices(); - #else - services.AddCommCoreServices(); - #endif +#else + services.AddCommCoreServices(); +#endif // Mvc services.AddMvc(config => diff --git a/src/Api/Controllers/AccountsController.cs b/src/Api/Controllers/AccountsController.cs index 727df23be..21cc26f1a 100644 --- a/src/Api/Controllers/AccountsController.cs +++ b/src/Api/Controllers/AccountsController.cs @@ -1,6 +1,14 @@ -using Bit.Api.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Bit.Api.Models.Request; +using Bit.Api.Models.Request.Accounts; +using Bit.Api.Models.Response; +using Bit.Api.Utilities; using Bit.Core; using Bit.Core.Enums; +using Bit.Core.Enums.Provider; using Bit.Core.Exceptions; using Bit.Core.Models.Business; using Bit.Core.Models.Data; @@ -11,14 +19,6 @@ using Bit.Core.Settings; using Bit.Core.Utilities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Bit.Api.Models.Request; -using Bit.Api.Models.Request.Accounts; -using Bit.Api.Models.Response; -using Bit.Core.Enums.Provider; namespace Bit.Api.Controllers { @@ -66,7 +66,7 @@ namespace Bit.Api.Controllers [HttpPost("prelogin")] [AllowAnonymous] - public async Task PostPrelogin([FromBody]PreloginRequestModel model) + public async Task PostPrelogin([FromBody] PreloginRequestModel model) { var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email); if (kdfInformation == null) @@ -83,7 +83,7 @@ namespace Bit.Api.Controllers [HttpPost("register")] [AllowAnonymous] [CaptchaProtected] - public async Task PostRegister([FromBody]RegisterRequestModel model) + public async Task PostRegister([FromBody] RegisterRequestModel model) { var result = await _userService.RegisterUserAsync(model.ToUser(), model.MasterPasswordHash, model.Token, model.OrganizationUserId); @@ -103,13 +103,13 @@ namespace Bit.Api.Controllers [HttpPost("password-hint")] [AllowAnonymous] - public async Task PostPasswordHint([FromBody]PasswordHintRequestModel model) + public async Task PostPasswordHint([FromBody] PasswordHintRequestModel model) { await _userService.SendMasterPasswordHintAsync(model.Email); } [HttpPost("email-token")] - public async Task PostEmailToken([FromBody]EmailTokenRequestModel model) + public async Task PostEmailToken([FromBody] EmailTokenRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -132,7 +132,7 @@ namespace Bit.Api.Controllers } [HttpPost("email")] - public async Task PostEmail([FromBody]EmailRequestModel model) + public async Task PostEmail([FromBody] EmailRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -175,7 +175,7 @@ namespace Bit.Api.Controllers [HttpPost("verify-email-token")] [AllowAnonymous] - public async Task PostVerifyEmailToken([FromBody]VerifyEmailRequestModel model) + public async Task PostVerifyEmailToken([FromBody] VerifyEmailRequestModel model) { var user = await _userService.GetUserByIdAsync(new Guid(model.UserId)); if (user == null) @@ -198,7 +198,7 @@ namespace Bit.Api.Controllers } [HttpPost("password")] - public async Task PostPassword([FromBody]PasswordRequestModel model) + public async Task PostPassword([FromBody] PasswordRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -223,7 +223,7 @@ namespace Bit.Api.Controllers } [HttpPost("set-password")] - public async Task PostSetPasswordAsync([FromBody]SetPasswordRequestModel model) + public async Task PostSetPasswordAsync([FromBody] SetPasswordRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -231,7 +231,7 @@ namespace Bit.Api.Controllers throw new UnauthorizedAccessException(); } - var result = await _userService.SetPasswordAsync(model.ToUser(user), model.MasterPasswordHash, model.Key, + var result = await _userService.SetPasswordAsync(model.ToUser(user), model.MasterPasswordHash, model.Key, model.OrgIdentifier); if (result.Succeeded) { @@ -247,7 +247,7 @@ namespace Bit.Api.Controllers } [HttpPost("verify-password")] - public async Task PostVerifyPassword([FromBody]SecretVerificationRequestModel model) + public async Task PostVerifyPassword([FromBody] SecretVerificationRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -266,7 +266,7 @@ namespace Bit.Api.Controllers } [HttpPost("set-key-connector-key")] - public async Task PostSetKeyConnectorKeyAsync([FromBody]SetKeyConnectorKeyRequestModel model) + public async Task PostSetKeyConnectorKeyAsync([FromBody] SetKeyConnectorKeyRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -312,7 +312,7 @@ namespace Bit.Api.Controllers } [HttpPost("kdf")] - public async Task PostKdf([FromBody]KdfRequestModel model) + public async Task PostKdf([FromBody] KdfRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -337,7 +337,7 @@ namespace Bit.Api.Controllers } [HttpPost("key")] - public async Task PostKey([FromBody]UpdateKeyRequestModel model) + public async Task PostKey([FromBody] UpdateKeyRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -393,7 +393,7 @@ namespace Bit.Api.Controllers } [HttpPost("security-stamp")] - public async Task PostSecurityStamp([FromBody]SecretVerificationRequestModel model) + public async Task PostSecurityStamp([FromBody] SecretVerificationRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -449,7 +449,7 @@ namespace Bit.Api.Controllers [HttpPut("profile")] [HttpPost("profile")] - public async Task PutProfile([FromBody]UpdateProfileRequestModel model) + public async Task PutProfile([FromBody] UpdateProfileRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -477,7 +477,7 @@ namespace Bit.Api.Controllers } [HttpPost("keys")] - public async Task PostKeys([FromBody]KeysRequestModel model) + public async Task PostKeys([FromBody] KeysRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -503,7 +503,7 @@ namespace Bit.Api.Controllers [HttpDelete] [HttpPost("delete")] - public async Task Delete([FromBody]SecretVerificationRequestModel model) + public async Task Delete([FromBody] SecretVerificationRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -535,14 +535,14 @@ namespace Bit.Api.Controllers [AllowAnonymous] [HttpPost("delete-recover")] - public async Task PostDeleteRecover([FromBody]DeleteRecoverRequestModel model) + public async Task PostDeleteRecover([FromBody] DeleteRecoverRequestModel model) { await _userService.SendDeleteConfirmationAsync(model.Email); } [HttpPost("delete-recover-token")] [AllowAnonymous] - public async Task PostDeleteRecoverToken([FromBody]VerifyDeleteRecoverRequestModel model) + public async Task PostDeleteRecoverToken([FromBody] VerifyDeleteRecoverRequestModel model) { var user = await _userService.GetUserByIdAsync(new Guid(model.UserId)); if (user == null) @@ -566,7 +566,7 @@ namespace Bit.Api.Controllers } [HttpPost("iap-check")] - public async Task PostIapCheck([FromBody]IapCheckRequestModel model) + public async Task PostIapCheck([FromBody] IapCheckRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -660,7 +660,7 @@ namespace Bit.Api.Controllers [HttpPost("payment")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostPayment([FromBody]PaymentRequestModel model) + public async Task PostPayment([FromBody] PaymentRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -678,7 +678,7 @@ namespace Bit.Api.Controllers [HttpPost("storage")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostStorage([FromBody]StorageRequestModel model) + public async Task PostStorage([FromBody] StorageRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -755,7 +755,7 @@ namespace Bit.Api.Controllers [HttpPut("tax")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PutTaxInfo([FromBody]TaxInfoUpdateRequestModel model) + public async Task PutTaxInfo([FromBody] TaxInfoUpdateRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -793,7 +793,7 @@ namespace Bit.Api.Controllers } [HttpPost("api-key")] - public async Task ApiKey([FromBody]SecretVerificationRequestModel model) + public async Task ApiKey([FromBody] SecretVerificationRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -811,7 +811,7 @@ namespace Bit.Api.Controllers } [HttpPost("rotate-api-key")] - public async Task RotateApiKey([FromBody]SecretVerificationRequestModel model) + public async Task RotateApiKey([FromBody] SecretVerificationRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -829,9 +829,9 @@ namespace Bit.Api.Controllers var response = new ApiKeyResponseModel(user); return response; } - + [HttpPut("update-temp-password")] - public async Task PutUpdateTempPasswordAsync([FromBody]UpdateTempPasswordRequestModel model) + public async Task PutUpdateTempPasswordAsync([FromBody] UpdateTempPasswordRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -866,7 +866,7 @@ namespace Bit.Api.Controllers } [HttpPost("verify-otp")] - public async Task VerifyOTP([FromBody]VerifyOTPRequestModel model) + public async Task VerifyOTP([FromBody] VerifyOTPRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user is not { UsesKeyConnector: true }) diff --git a/src/Api/Controllers/CiphersController.cs b/src/Api/Controllers/CiphersController.cs index 568c9c36f..04045d673 100644 --- a/src/Api/Controllers/CiphersController.cs +++ b/src/Api/Controllers/CiphersController.cs @@ -1,27 +1,27 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Context; -using Bit.Core.Utilities; -using Bit.Api.Utilities; -using System.Collections.Generic; -using Bit.Core.Models.Table; -using Bit.Core.Settings; -using Core.Models.Data; using Azure.Messaging.EventGrid; using Bit.Api.Models.Request; using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Response; +using Bit.Api.Utilities; +using Bit.Core; +using Bit.Core.Context; +using Bit.Core.Exceptions; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; +using Bit.Core.Utilities; +using Core.Models.Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -using Bit.Core; namespace Bit.Api.Controllers { @@ -123,7 +123,7 @@ namespace Bit.Api.Controllers } [HttpPost("")] - public async Task Post([FromBody]CipherRequestModel model) + public async Task Post([FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = model.ToCipherDetails(userId); @@ -138,7 +138,7 @@ namespace Bit.Api.Controllers } [HttpPost("create")] - public async Task PostCreate([FromBody]CipherCreateRequestModel model) + public async Task PostCreate([FromBody] CipherCreateRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = model.Cipher.ToCipherDetails(userId); @@ -153,7 +153,7 @@ namespace Bit.Api.Controllers } [HttpPost("admin")] - public async Task PostAdmin([FromBody]CipherCreateRequestModel model) + public async Task PostAdmin([FromBody] CipherCreateRequestModel model) { var cipher = model.Cipher.ToOrganizationCipher(); if (!await _currentContext.EditAnyCollection(cipher.OrganizationId.Value)) @@ -170,7 +170,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string id, [FromBody]CipherRequestModel model) + public async Task Put(string id, [FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); @@ -179,7 +179,7 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? + var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? (Guid?)null : new Guid(model.OrganizationId); if (cipher.OrganizationId != modelOrgId) { @@ -195,7 +195,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/admin")] [HttpPost("{id}/admin")] - public async Task PutAdmin(string id, [FromBody]CipherRequestModel model) + public async Task PutAdmin(string id, [FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id)); @@ -241,7 +241,7 @@ namespace Bit.Api.Controllers } [HttpPost("import")] - public async Task PostImport([FromBody]ImportCiphersRequestModel model) + public async Task PostImport([FromBody] ImportCiphersRequestModel model) { if (!_globalSettings.SelfHosted && (model.Ciphers.Count() > 6000 || model.FolderRelationships.Count() > 6000 || @@ -257,8 +257,8 @@ namespace Bit.Api.Controllers } [HttpPost("import-organization")] - public async Task PostImport([FromQuery]string organizationId, - [FromBody]ImportOrganizationCiphersRequestModel model) + public async Task PostImport([FromQuery] string organizationId, + [FromBody] ImportOrganizationCiphersRequestModel model) { if (!_globalSettings.SelfHosted && (model.Ciphers.Count() > 6000 || model.CollectionRelationships.Count() > 12000 || @@ -281,7 +281,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/partial")] [HttpPost("{id}/partial")] - public async Task PutPartial(string id, [FromBody]CipherPartialRequestModel model) + public async Task PutPartial(string id, [FromBody] CipherPartialRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var folderId = string.IsNullOrWhiteSpace(model.FolderId) ? null : (Guid?)new Guid(model.FolderId); @@ -290,7 +290,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/share")] [HttpPost("{id}/share")] - public async Task PutShare(string id, [FromBody]CipherShareRequestModel model) + public async Task PutShare(string id, [FromBody] CipherShareRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipherId = new Guid(id); @@ -312,7 +312,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/collections")] [HttpPost("{id}/collections")] - public async Task PutCollections(string id, [FromBody]CipherCollectionsRequestModel model) + public async Task PutCollections(string id, [FromBody] CipherCollectionsRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); @@ -322,13 +322,13 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - await _cipherService.SaveCollectionsAsync(cipher, + await _cipherService.SaveCollectionsAsync(cipher, model.CollectionIds.Select(c => new Guid(c)), userId, false); } [HttpPut("{id}/collections-admin")] [HttpPost("{id}/collections-admin")] - public async Task PutCollectionsAdmin(string id, [FromBody]CipherCollectionsRequestModel model) + public async Task PutCollectionsAdmin(string id, [FromBody] CipherCollectionsRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(new Guid(id)); @@ -338,7 +338,7 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - await _cipherService.SaveCollectionsAsync(cipher, + await _cipherService.SaveCollectionsAsync(cipher, model.CollectionIds.Select(c => new Guid(c)), userId, true); } @@ -373,7 +373,7 @@ namespace Bit.Api.Controllers [HttpDelete("")] [HttpPost("delete")] - public async Task DeleteMany([FromBody]CipherBulkDeleteRequestModel model) + public async Task DeleteMany([FromBody] CipherBulkDeleteRequestModel model) { if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) { @@ -387,7 +387,7 @@ namespace Bit.Api.Controllers [HttpDelete("admin")] [HttpPost("delete-admin")] - public async Task DeleteManyAdmin([FromBody]CipherBulkDeleteRequestModel model) + public async Task DeleteManyAdmin([FromBody] CipherBulkDeleteRequestModel model) { if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) { @@ -432,7 +432,7 @@ namespace Bit.Api.Controllers } [HttpPut("delete")] - public async Task PutDeleteMany([FromBody]CipherBulkDeleteRequestModel model) + public async Task PutDeleteMany([FromBody] CipherBulkDeleteRequestModel model) { if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) { @@ -444,7 +444,7 @@ namespace Bit.Api.Controllers } [HttpPut("delete-admin")] - public async Task PutDeleteManyAdmin([FromBody]CipherBulkDeleteRequestModel model) + public async Task PutDeleteManyAdmin([FromBody] CipherBulkDeleteRequestModel model) { if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) { @@ -511,7 +511,7 @@ namespace Bit.Api.Controllers [HttpPut("move")] [HttpPost("move")] - public async Task MoveMany([FromBody]CipherBulkMoveRequestModel model) + public async Task MoveMany([FromBody] CipherBulkMoveRequestModel model) { if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) { @@ -525,7 +525,7 @@ namespace Bit.Api.Controllers [HttpPut("share")] [HttpPost("share")] - public async Task PutShareMany([FromBody]CipherBulkShareRequestModel model) + public async Task PutShareMany([FromBody] CipherBulkShareRequestModel model) { var organizationId = new Guid(model.Ciphers.First().OrganizationId); if (!await _currentContext.OrganizationUser(organizationId)) @@ -553,7 +553,7 @@ namespace Bit.Api.Controllers } [HttpPost("purge")] - public async Task PostPurge([FromBody]SecretVerificationRequestModel model, string organizationId = null) + public async Task PostPurge([FromBody] SecretVerificationRequestModel model, string organizationId = null) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) diff --git a/src/Api/Controllers/CollectionsController.cs b/src/Api/Controllers/CollectionsController.cs index 34f0f745d..56baacbc2 100644 --- a/src/Api/Controllers/CollectionsController.cs +++ b/src/Api/Controllers/CollectionsController.cs @@ -1,16 +1,16 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Context; -using Bit.Core.Models.Table; -using System.Collections.Generic; using Bit.Api.Models.Request; using Bit.Api.Models.Response; +using Bit.Core.Context; +using Bit.Core.Exceptions; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -111,7 +111,7 @@ namespace Bit.Api.Controllers } [HttpPost("")] - public async Task Post(string orgId, [FromBody]CollectionRequestModel model) + public async Task Post(string orgId, [FromBody] CollectionRequestModel model) { var orgIdGuid = new Guid(orgId); var collection = model.ToCollection(orgIdGuid); @@ -132,7 +132,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string orgId, string id, [FromBody]CollectionRequestModel model) + public async Task Put(string orgId, string id, [FromBody] CollectionRequestModel model) { if (!await CanEditCollectionAsync(orgId, id)) { @@ -146,7 +146,7 @@ namespace Bit.Api.Controllers } [HttpPut("{id}/users")] - public async Task PutUsers(string orgId, string id, [FromBody]IEnumerable model) + public async Task PutUsers(string orgId, string id, [FromBody] IEnumerable model) { var collection = await GetCollectionAsync(new Guid(id), new Guid(orgId)); await _collectionRepository.UpdateUsersAsync(collection.Id, model?.Select(g => g.ToSelectionReadOnly())); diff --git a/src/Api/Controllers/DevicesController.cs b/src/Api/Controllers/DevicesController.cs index 5a4b8c57e..013cecc75 100644 --- a/src/Api/Controllers/DevicesController.cs +++ b/src/Api/Controllers/DevicesController.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; using Bit.Core.Exceptions; using Bit.Core.Models.Table; +using Bit.Core.Repositories; using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -66,7 +66,7 @@ namespace Bit.Api.Controllers } [HttpPost("")] - public async Task Post([FromBody]DeviceRequestModel model) + public async Task Post([FromBody] DeviceRequestModel model) { var device = model.ToDevice(_userService.GetProperUserId(User)); await _deviceService.SaveAsync(device); @@ -77,7 +77,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string id, [FromBody]DeviceRequestModel model) + public async Task Put(string id, [FromBody] DeviceRequestModel model) { var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); if (device == null) @@ -93,7 +93,7 @@ namespace Bit.Api.Controllers [HttpPut("identifier/{identifier}/token")] [HttpPost("identifier/{identifier}/token")] - public async Task PutToken(string identifier, [FromBody]DeviceTokenRequestModel model) + public async Task PutToken(string identifier, [FromBody] DeviceTokenRequestModel model) { var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value); if (device == null) diff --git a/src/Api/Controllers/EmergencyAccessController.cs b/src/Api/Controllers/EmergencyAccessController.cs index 3a77791ab..b88f1131e 100644 --- a/src/Api/Controllers/EmergencyAccessController.cs +++ b/src/Api/Controllers/EmergencyAccessController.cs @@ -77,7 +77,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string id, [FromBody]EmergencyAccessUpdateRequestModel model) + public async Task Put(string id, [FromBody] EmergencyAccessUpdateRequestModel model) { var emergencyAccess = await _emergencyAccessRepository.GetByIdAsync(new Guid(id)); if (emergencyAccess == null) @@ -88,7 +88,7 @@ namespace Bit.Api.Controllers var userId = _userService.GetProperUserId(User); await _emergencyAccessService.SaveAsync(model.ToEmergencyAccess(emergencyAccess), userId.Value); } - + [HttpDelete("{id}")] [HttpPost("{id}/delete")] public async Task Delete(string id) @@ -96,7 +96,7 @@ namespace Bit.Api.Controllers var userId = _userService.GetProperUserId(User); await _emergencyAccessService.DeleteAsync(new Guid(id), userId.Value); } - + [HttpPost("invite")] public async Task Invite([FromBody] EmergencyAccessInviteRequestModel model) { @@ -138,7 +138,7 @@ namespace Bit.Api.Controllers var user = await _userService.GetUserByPrincipalAsync(User); await _emergencyAccessService.ApproveAsync(new Guid(id), user); } - + [HttpPost("{id}/reject")] public async Task Reject(string id) { @@ -153,14 +153,14 @@ namespace Bit.Api.Controllers var (result, grantor) = await _emergencyAccessService.TakeoverAsync(new Guid(id), user); return new EmergencyAccessTakeoverResponseModel(result, grantor); } - + [HttpPost("{id}/password")] public async Task Password(string id, [FromBody] EmergencyAccessPasswordRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); await _emergencyAccessService.PasswordAsync(new Guid(id), user, model.NewMasterPasswordHash, model.Key); } - + [HttpPost("{id}/view")] public async Task ViewCiphers(string id) { diff --git a/src/Api/Controllers/EventsController.cs b/src/Api/Controllers/EventsController.cs index ac3f38423..b1bc93a0a 100644 --- a/src/Api/Controllers/EventsController.cs +++ b/src/Api/Controllers/EventsController.cs @@ -2,13 +2,13 @@ using System.Linq; using System.Threading.Tasks; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; using Bit.Core.Context; +using Bit.Core.Exceptions; using Bit.Core.Models.Data; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -41,7 +41,7 @@ namespace Bit.Api.Controllers [HttpGet("")] public async Task> GetUser( - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { var dateRange = GetDateRange(start, end); var userId = _userService.GetProperUserId(User).Value; @@ -53,7 +53,7 @@ namespace Bit.Api.Controllers [HttpGet("~/ciphers/{id}/events")] public async Task> GetCipher(string id, - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id)); if (cipher == null) @@ -86,7 +86,7 @@ namespace Bit.Api.Controllers [HttpGet("~/organizations/{id}/events")] public async Task> GetOrganization(string id, - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { var orgId = new Guid(id); if (!await _currentContext.AccessEventLogs(orgId)) @@ -103,7 +103,7 @@ namespace Bit.Api.Controllers [HttpGet("~/organizations/{orgId}/users/{id}/events")] public async Task> GetOrganizationUser(string orgId, string id, - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id)); if (organizationUser == null || !organizationUser.UserId.HasValue || @@ -122,7 +122,7 @@ namespace Bit.Api.Controllers [HttpGet("~/providers/{providerId:guid}/events")] public async Task> GetProvider(Guid providerId, - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { if (!_currentContext.ProviderAccessEventLogs(providerId)) { @@ -138,7 +138,7 @@ namespace Bit.Api.Controllers [HttpGet("~/providers/{providerId:guid}/users/{id:guid}/events")] public async Task> GetProviderUser(Guid providerId, Guid id, - [FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null) + [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string continuationToken = null) { var providerUser = await _providerUserRepository.GetByIdAsync(id); if (providerUser == null || !providerUser.UserId.HasValue || diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index 4cd621a21..ddd401ec9 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -3,11 +3,11 @@ using System.Linq; using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; using Bit.Core.Exceptions; +using Bit.Core.Repositories; using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -52,7 +52,7 @@ namespace Bit.Api.Controllers } [HttpPost("")] - public async Task Post([FromBody]FolderRequestModel model) + public async Task Post([FromBody] FolderRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var folder = model.ToFolder(_userService.GetProperUserId(User).Value); @@ -62,7 +62,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string id, [FromBody]FolderRequestModel model) + public async Task Put(string id, [FromBody] FolderRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId); diff --git a/src/Api/Controllers/GroupsController.cs b/src/Api/Controllers/GroupsController.cs index 27217ad55..9febe3300 100644 --- a/src/Api/Controllers/GroupsController.cs +++ b/src/Api/Controllers/GroupsController.cs @@ -1,15 +1,15 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Context; -using System.Collections.Generic; using Bit.Api.Models.Request; using Bit.Api.Models.Response; +using Bit.Core.Context; +using Bit.Core.Exceptions; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -89,7 +89,7 @@ namespace Bit.Api.Controllers } [HttpPost("")] - public async Task Post(string orgId, [FromBody]GroupRequestModel model) + public async Task Post(string orgId, [FromBody] GroupRequestModel model) { var orgIdGuid = new Guid(orgId); if (!await _currentContext.ManageGroups(orgIdGuid)) @@ -104,7 +104,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string orgId, string id, [FromBody]GroupRequestModel model) + public async Task Put(string orgId, string id, [FromBody] GroupRequestModel model) { var group = await _groupRepository.GetByIdAsync(new Guid(id)); if (group == null || !await _currentContext.ManageGroups(group.OrganizationId)) @@ -117,7 +117,7 @@ namespace Bit.Api.Controllers } [HttpPut("{id}/users")] - public async Task PutUsers(string orgId, string id, [FromBody]IEnumerable model) + public async Task PutUsers(string orgId, string id, [FromBody] IEnumerable model) { var group = await _groupRepository.GetByIdAsync(new Guid(id)); if (group == null || !await _currentContext.ManageGroups(group.OrganizationId)) diff --git a/src/Api/Controllers/HibpController.cs b/src/Api/Controllers/HibpController.cs index 5616c0ac3..a11d92d8c 100644 --- a/src/Api/Controllers/HibpController.cs +++ b/src/Api/Controllers/HibpController.cs @@ -1,16 +1,16 @@ using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; +using System.Linq; +using System.Net; using System.Net.Http; using System.Security.Cryptography; -using Bit.Core.Services; +using System.Threading.Tasks; using Bit.Core.Context; -using System.Net; using Bit.Core.Exceptions; -using System.Linq; -using Bit.Core.Utilities; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { diff --git a/src/Api/Controllers/InfoController.cs b/src/Api/Controllers/InfoController.cs index 25c9e0423..82aa7b938 100644 --- a/src/Api/Controllers/InfoController.cs +++ b/src/Api/Controllers/InfoController.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -20,7 +20,7 @@ namespace Bit.Api.Controllers { return Json(CoreHelpers.GetVersion()); } - + [HttpGet("~/ip")] public JsonResult Ip() { diff --git a/src/Api/Controllers/InstallationsController.cs b/src/Api/Controllers/InstallationsController.cs index ec68bbdd7..3e28f325f 100644 --- a/src/Api/Controllers/InstallationsController.cs +++ b/src/Api/Controllers/InstallationsController.cs @@ -2,11 +2,11 @@ using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; using Bit.Core.Exceptions; +using Bit.Core.Repositories; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { diff --git a/src/Api/Controllers/LicensesController.cs b/src/Api/Controllers/LicensesController.cs index bd90d3b38..dc4baa140 100644 --- a/src/Api/Controllers/LicensesController.cs +++ b/src/Api/Controllers/LicensesController.cs @@ -1,13 +1,13 @@ -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Services; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Context; +using System; using System.Threading.Tasks; -using Bit.Core.Models.Business; +using Bit.Core.Context; using Bit.Core.Exceptions; +using Bit.Core.Models.Business; using Bit.Core.Repositories; -using System; +using Bit.Core.Services; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -40,7 +40,7 @@ namespace Bit.Api.Controllers } [HttpGet("user/{id}")] - public async Task GetUser(string id, [FromQuery]string key) + public async Task GetUser(string id, [FromQuery] string key) { var user = await _userRepository.GetByIdAsync(new Guid(id)); if (user == null) @@ -58,7 +58,7 @@ namespace Bit.Api.Controllers } [HttpGet("organization/{id}")] - public async Task GetOrganization(string id, [FromQuery]string key) + public async Task GetOrganization(string id, [FromQuery] string key) { var org = await _organizationRepository.GetByIdAsync(new Guid(id)); if (org == null) diff --git a/src/Api/Controllers/MiscController.cs b/src/Api/Controllers/MiscController.cs index abc4630c9..1cc760b95 100644 --- a/src/Api/Controllers/MiscController.cs +++ b/src/Api/Controllers/MiscController.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; +using System.Threading.Tasks; using Bit.Api.Models.Request; +using Bit.Core.Settings; using Bit.Core.Utilities; using Microsoft.AspNetCore.Authorization; -using Bit.Core.Settings; +using Microsoft.AspNetCore.Mvc; using Stripe; namespace Bit.Api.Controllers @@ -24,7 +24,7 @@ namespace Bit.Api.Controllers [Authorize("Application")] [HttpPost("~/bitpay-invoice")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostBitPayInvoice([FromBody]BitPayInvoiceRequestModel model) + public async Task PostBitPayInvoice([FromBody] BitPayInvoiceRequestModel model) { var invoice = await _bitPayClient.CreateInvoiceAsync(model.ToBitpayInvoice(_globalSettings)); return invoice.Url; diff --git a/src/Api/Controllers/OrganizationSponsorshipsController.cs b/src/Api/Controllers/OrganizationSponsorshipsController.cs index e9806d200..a9d59adf9 100644 --- a/src/Api/Controllers/OrganizationSponsorshipsController.cs +++ b/src/Api/Controllers/OrganizationSponsorshipsController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Bit.Api.Models.Request.Organizations; using Bit.Core.Context; @@ -43,7 +43,7 @@ namespace Bit.Api.Controllers public async Task CreateSponsorship(Guid sponsoringOrgId, [FromBody] OrganizationSponsorshipRequestModel model) { await _organizationsSponsorshipService.OfferSponsorshipAsync( - await _organizationRepository.GetByIdAsync(sponsoringOrgId), + await _organizationRepository.GetByIdAsync(sponsoringOrgId), await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default), model.PlanSponsorshipType, model.SponsoredEmail, model.FriendlyName, (await CurrentUser).Email); @@ -57,7 +57,7 @@ namespace Bit.Api.Controllers .GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default); await _organizationsSponsorshipService.ResendSponsorshipOfferAsync( - await _organizationRepository.GetByIdAsync(sponsoringOrgId), + await _organizationRepository.GetByIdAsync(sponsoringOrgId), sponsoringOrgUser, await _organizationSponsorshipRepository .GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUser.Id), diff --git a/src/Api/Controllers/OrganizationUsersController.cs b/src/Api/Controllers/OrganizationUsersController.cs index 779aa6678..3fc985dc2 100644 --- a/src/Api/Controllers/OrganizationUsersController.cs +++ b/src/Api/Controllers/OrganizationUsersController.cs @@ -1,18 +1,18 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Context; -using System.Collections.Generic; using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Response; +using Bit.Core.Context; using Bit.Core.Enums; +using Bit.Core.Exceptions; using Bit.Core.Models.Business; using Bit.Core.Models.Data; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -91,7 +91,7 @@ namespace Bit.Api.Controllers var responses = groupIds.Select(g => g.ToString()); return responses; } - + [HttpGet("{id}/reset-password-details")] public async Task GetResetPasswordDetails(string orgId, string id) { @@ -115,7 +115,7 @@ namespace Bit.Api.Controllers { throw new NotFoundException(); } - + // Retrieve Encrypted Private Key from organization var org = await _organizationRepository.GetByIdAsync(orgGuidId); if (org == null) @@ -127,7 +127,7 @@ namespace Bit.Api.Controllers } [HttpPost("invite")] - public async Task Invite(string orgId, [FromBody]OrganizationUserInviteRequestModel model) + public async Task Invite(string orgId, [FromBody] OrganizationUserInviteRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -139,9 +139,9 @@ namespace Bit.Api.Controllers var result = await _organizationService.InviteUsersAsync(orgGuidId, userId.Value, new (OrganizationUserInvite, string)[] { (new OrganizationUserInvite(model.ToData()), null) }); } - + [HttpPost("reinvite")] - public async Task> BulkReinvite(string orgId, [FromBody]OrganizationUserBulkRequestModel model) + public async Task> BulkReinvite(string orgId, [FromBody] OrganizationUserBulkRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -169,7 +169,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id}/accept")] - public async Task Accept(string orgId, string id, [FromBody]OrganizationUserAcceptRequestModel model) + public async Task Accept(string orgId, string id, [FromBody] OrganizationUserAcceptRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -181,7 +181,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id}/confirm")] - public async Task Confirm(string orgId, string id, [FromBody]OrganizationUserConfirmRequestModel model) + public async Task Confirm(string orgId, string id, [FromBody] OrganizationUserConfirmRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -196,7 +196,7 @@ namespace Bit.Api.Controllers [HttpPost("confirm")] public async Task> BulkConfirm(string orgId, - [FromBody]OrganizationUserBulkConfirmRequestModel model) + [FromBody] OrganizationUserBulkConfirmRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -213,7 +213,7 @@ namespace Bit.Api.Controllers } [HttpPost("public-keys")] - public async Task> UserPublicKeys(string orgId, [FromBody]OrganizationUserBulkRequestModel model) + public async Task> UserPublicKeys(string orgId, [FromBody] OrganizationUserBulkRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -228,7 +228,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string orgId, string id, [FromBody]OrganizationUserUpdateRequestModel model) + public async Task Put(string orgId, string id, [FromBody] OrganizationUserUpdateRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -249,7 +249,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/groups")] [HttpPost("{id}/groups")] - public async Task PutGroups(string orgId, string id, [FromBody]OrganizationUserUpdateGroupsRequestModel model) + public async Task PutGroups(string orgId, string id, [FromBody] OrganizationUserUpdateGroupsRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -266,26 +266,26 @@ namespace Bit.Api.Controllers var loggedInUserId = _userService.GetProperUserId(User); await _organizationService.UpdateUserGroupsAsync(organizationUser, model.GroupIds.Select(g => new Guid(g)), loggedInUserId); } - + [HttpPut("{userId}/reset-password-enrollment")] - public async Task PutResetPasswordEnrollment(string orgId, string userId, [FromBody]OrganizationUserResetPasswordEnrollmentRequestModel model) + public async Task PutResetPasswordEnrollment(string orgId, string userId, [FromBody] OrganizationUserResetPasswordEnrollmentRequestModel model) { var callingUserId = _userService.GetProperUserId(User); await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId), new Guid(userId), model.ResetPasswordKey, callingUserId); } - + [HttpPut("{id}/reset-password")] - public async Task PutResetPassword(string orgId, string id, [FromBody]OrganizationUserResetPasswordRequestModel model) + public async Task PutResetPassword(string orgId, string id, [FromBody] OrganizationUserResetPasswordRequestModel model) { - + var orgGuidId = new Guid(orgId); - + // Calling user must have Manage Reset Password permission if (!await _currentContext.ManageResetPassword(orgGuidId)) { throw new NotFoundException(); } - + // Get the users role, since provider users aren't a member of the organization we use the owner check var orgUserType = await _currentContext.OrganizationOwner(orgGuidId) ? OrganizationUserType.Owner @@ -326,7 +326,7 @@ namespace Bit.Api.Controllers [HttpDelete("")] [HttpPost("delete")] - public async Task> BulkDelete(string orgId, [FromBody]OrganizationUserBulkRequestModel model) + public async Task> BulkDelete(string orgId, [FromBody] OrganizationUserBulkRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index eac93529c..7d28946ad 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -5,18 +5,18 @@ using Bit.Api.Models.Request; using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; +using Bit.Api.Utilities; +using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Context; -using Bit.Api.Utilities; using Bit.Core.Models.Business; using Bit.Core.Models.Data; -using Bit.Core.Utilities; +using Bit.Core.Repositories; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; namespace Bit.Api.Controllers @@ -130,7 +130,7 @@ namespace Bit.Api.Controllers [HttpGet("{id}/license")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task GetLicense(string id, [FromQuery]Guid installationId) + public async Task GetLicense(string id, [FromQuery] Guid installationId) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -156,7 +156,7 @@ namespace Bit.Api.Controllers var responses = organizations.Select(o => new ProfileOrganizationResponseModel(o)); return new ListResponseModel(responses); } - + [HttpGet("{identifier}/auto-enroll-status")] public async Task GetAutoEnrollStatus(string identifier) { @@ -165,7 +165,7 @@ namespace Bit.Api.Controllers { throw new UnauthorizedAccessException(); } - + var organization = await _organizationRepository.GetByIdentifierAsync(identifier); if (organization == null) { @@ -184,14 +184,14 @@ namespace Bit.Api.Controllers { return new OrganizationAutoEnrollStatusResponseModel(organization.Id, false); } - + var data = JsonConvert.DeserializeObject(resetPasswordPolicy.Data); return new OrganizationAutoEnrollStatusResponseModel(organization.Id, data?.AutoEnrollEnabled ?? false); } [HttpPost("")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task Post([FromBody]OrganizationCreateRequestModel model) + public async Task Post([FromBody] OrganizationCreateRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -227,7 +227,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}")] [HttpPost("{id}")] - public async Task Put(string id, [FromBody]OrganizationUpdateRequestModel model) + public async Task Put(string id, [FromBody] OrganizationUpdateRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -250,7 +250,7 @@ namespace Bit.Api.Controllers [HttpPost("{id}/payment")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostPayment(string id, [FromBody]PaymentRequestModel model) + public async Task PostPayment(string id, [FromBody] PaymentRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -273,7 +273,7 @@ namespace Bit.Api.Controllers [HttpPost("{id}/upgrade")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostUpgrade(string id, [FromBody]OrganizationUpgradeRequestModel model) + public async Task PostUpgrade(string id, [FromBody] OrganizationUpgradeRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -304,7 +304,7 @@ namespace Bit.Api.Controllers [HttpPost("{id}/seat")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostSeat(string id, [FromBody]OrganizationSeatRequestModel model) + public async Task PostSeat(string id, [FromBody] OrganizationSeatRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -322,7 +322,7 @@ namespace Bit.Api.Controllers [HttpPost("{id}/storage")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostStorage(string id, [FromBody]StorageRequestModel model) + public async Task PostStorage(string id, [FromBody] StorageRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -340,7 +340,7 @@ namespace Bit.Api.Controllers [HttpPost("{id}/verify-bank")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PostVerifyBank(string id, [FromBody]OrganizationVerifyBankRequestModel model) + public async Task PostVerifyBank(string id, [FromBody] OrganizationVerifyBankRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -395,13 +395,13 @@ namespace Bit.Api.Controllers throw new BadRequestException("Your organization's Single Sign-On settings prevent you from leaving."); } - + await _organizationService.DeleteUserAsync(orgGuidId, user.Id); } [HttpDelete("{id}")] [HttpPost("{id}/delete")] - public async Task Delete(string id, [FromBody]SecretVerificationRequestModel model) + public async Task Delete(string id, [FromBody] SecretVerificationRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -452,7 +452,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id}/import")] - public async Task Import(string id, [FromBody]ImportOrganizationUsersRequestModel model) + public async Task Import(string id, [FromBody] ImportOrganizationUsersRequestModel model) { if (!_globalSettings.SelfHosted && !model.LargeImport && (model.Groups.Count() > 2000 || model.Users.Count(u => !u.Deleted) > 2000)) @@ -477,7 +477,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id}/api-key")] - public async Task ApiKey(string id, [FromBody]SecretVerificationRequestModel model) + public async Task ApiKey(string id, [FromBody] SecretVerificationRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -510,7 +510,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id}/rotate-api-key")] - public async Task RotateApiKey(string id, [FromBody]SecretVerificationRequestModel model) + public async Task RotateApiKey(string id, [FromBody] SecretVerificationRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -565,7 +565,7 @@ namespace Bit.Api.Controllers [HttpPut("{id}/tax")] [SelfHosted(NotSelfHostedOnly = true)] - public async Task PutTaxInfo(string id, [FromBody]OrganizationTaxInfoUpdateRequestModel model) + public async Task PutTaxInfo(string id, [FromBody] OrganizationTaxInfoUpdateRequestModel model) { var orgIdGuid = new Guid(id); if (!await _currentContext.OrganizationOwner(orgIdGuid)) @@ -591,7 +591,7 @@ namespace Bit.Api.Controllers }; await _paymentService.SaveTaxInfoAsync(organization, taxInfo); } - + [HttpGet("{id}/keys")] public async Task GetKeys(string id) { @@ -603,9 +603,9 @@ namespace Bit.Api.Controllers return new OrganizationKeysResponseModel(org); } - + [HttpPost("{id}/keys")] - public async Task PostKeys(string id, [FromBody]OrganizationKeysRequestModel model) + public async Task PostKeys(string id, [FromBody] OrganizationKeysRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -637,7 +637,7 @@ namespace Bit.Api.Controllers } [HttpPost("{id:guid}/sso")] - public async Task PostSso(Guid id, [FromBody]OrganizationSsoRequestModel model) + public async Task PostSso(Guid id, [FromBody] OrganizationSsoRequestModel model) { if (!await _currentContext.ManageSso(id)) { diff --git a/src/Api/Controllers/PlansController.cs b/src/Api/Controllers/PlansController.cs index 1d599e34f..b19eadc0c 100644 --- a/src/Api/Controllers/PlansController.cs +++ b/src/Api/Controllers/PlansController.cs @@ -1,10 +1,10 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Utilities; -using System.Linq; -using Bit.Core.Repositories; +using System.Linq; using System.Threading.Tasks; using Bit.Api.Models.Response; +using Bit.Core.Repositories; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { diff --git a/src/Api/Controllers/PoliciesController.cs b/src/Api/Controllers/PoliciesController.cs index 376e33ba7..c5f083de6 100644 --- a/src/Api/Controllers/PoliciesController.cs +++ b/src/Api/Controllers/PoliciesController.cs @@ -3,16 +3,16 @@ using System.Linq; using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; using Bit.Core.Context; using Bit.Core.Enums; -using Bit.Core.Utilities; +using Bit.Core.Exceptions; +using Bit.Core.Repositories; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -83,8 +83,8 @@ namespace Bit.Api.Controllers [AllowAnonymous] [HttpGet("token")] - public async Task> GetByToken(string orgId, [FromQuery]string email, - [FromQuery]string token, [FromQuery]string organizationUserId) + public async Task> GetByToken(string orgId, [FromQuery] string email, + [FromQuery] string token, [FromQuery] string organizationUserId) { var orgUserId = new Guid(organizationUserId); var tokenValid = CoreHelpers.UserInviteTokenIsValid(_organizationServiceDataProtector, token, @@ -107,7 +107,7 @@ namespace Bit.Api.Controllers } [HttpPut("{type}")] - public async Task Put(string orgId, int type, [FromBody]PolicyRequestModel model) + public async Task Put(string orgId, int type, [FromBody] PolicyRequestModel model) { var orgIdGuid = new Guid(orgId); if (!await _currentContext.ManagePolicies(orgIdGuid)) diff --git a/src/Api/Controllers/ProviderOrganizationsController.cs b/src/Api/Controllers/ProviderOrganizationsController.cs index e953bcb22..ae5182651 100644 --- a/src/Api/Controllers/ProviderOrganizationsController.cs +++ b/src/Api/Controllers/ProviderOrganizationsController.cs @@ -18,7 +18,7 @@ namespace Bit.Api.Controllers [Authorize("Application")] public class ProviderOrganizationsController : Controller { - + private readonly IProviderOrganizationRepository _providerOrganizationRepository; private readonly IProviderService _providerService; private readonly IUserService _userService; @@ -35,7 +35,7 @@ namespace Bit.Api.Controllers _userService = userService; _currentContext = currentContext; } - + [HttpGet("")] public async Task> Get(Guid providerId) { @@ -50,13 +50,13 @@ namespace Bit.Api.Controllers } [HttpPost("add")] - public async Task Add(Guid providerId, [FromBody]ProviderOrganizationAddRequestModel model) + public async Task Add(Guid providerId, [FromBody] ProviderOrganizationAddRequestModel model) { if (!_currentContext.ManageProviderOrganizations(providerId)) { throw new NotFoundException(); } - + var userId = _userService.GetProperUserId(User).Value; await _providerService.AddOrganization(providerId, model.OrganizationId, userId, model.Key); diff --git a/src/Api/Controllers/ProviderUsersController.cs b/src/Api/Controllers/ProviderUsersController.cs index 9ae3e9d32..f5752151a 100644 --- a/src/Api/Controllers/ProviderUsersController.cs +++ b/src/Api/Controllers/ProviderUsersController.cs @@ -5,13 +5,13 @@ using System.Threading.Tasks; using Bit.Api.Models.Request.Providers; using Bit.Api.Models.Response; using Bit.Api.Models.Response.Providers; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; using Bit.Core.Context; +using Bit.Core.Exceptions; using Bit.Core.Models.Business.Provider; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -62,7 +62,7 @@ namespace Bit.Api.Controllers } [HttpPost("invite")] - public async Task Invite(Guid providerId, [FromBody]ProviderUserInviteRequestModel model) + public async Task Invite(Guid providerId, [FromBody] ProviderUserInviteRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -73,9 +73,9 @@ namespace Bit.Api.Controllers _userService.GetProperUserId(User).Value, providerId); await _providerService.InviteUserAsync(invite); } - + [HttpPost("reinvite")] - public async Task> BulkReinvite(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) + public async Task> BulkReinvite(Guid providerId, [FromBody] ProviderUserBulkRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -87,7 +87,7 @@ namespace Bit.Api.Controllers return new ListResponseModel( result.Select(t => new ProviderUserBulkResponseModel(t.Item1.Id, t.Item2))); } - + [HttpPost("{id:guid}/reinvite")] public async Task Reinvite(Guid providerId, Guid id) { @@ -96,13 +96,13 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - var invite = ProviderUserInviteFactory.CreateReinvite(new [] { id }, + var invite = ProviderUserInviteFactory.CreateReinvite(new[] { id }, _userService.GetProperUserId(User).Value, providerId); await _providerService.ResendInvitesAsync(invite); } [HttpPost("{id:guid}/accept")] - public async Task Accept(Guid providerId, Guid id, [FromBody]ProviderUserAcceptRequestModel model) + public async Task Accept(Guid providerId, Guid id, [FromBody] ProviderUserAcceptRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) @@ -112,9 +112,9 @@ namespace Bit.Api.Controllers await _providerService.AcceptUserAsync(id, user, model.Token); } - + [HttpPost("{id:guid}/confirm")] - public async Task Confirm(Guid providerId, Guid id, [FromBody]ProviderUserConfirmRequestModel model) + public async Task Confirm(Guid providerId, Guid id, [FromBody] ProviderUserConfirmRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -127,7 +127,7 @@ namespace Bit.Api.Controllers [HttpPost("confirm")] public async Task> BulkConfirm(Guid providerId, - [FromBody]ProviderUserBulkConfirmRequestModel model) + [FromBody] ProviderUserBulkConfirmRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -142,7 +142,7 @@ namespace Bit.Api.Controllers } [HttpPost("public-keys")] - public async Task> UserPublicKeys(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) + public async Task> UserPublicKeys(Guid providerId, [FromBody] ProviderUserBulkRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -156,7 +156,7 @@ namespace Bit.Api.Controllers [HttpPut("{id:guid}")] [HttpPost("{id:guid}")] - public async Task Put(Guid providerId, Guid id, [FromBody]ProviderUserUpdateRequestModel model) + public async Task Put(Guid providerId, Guid id, [FromBody] ProviderUserUpdateRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { @@ -183,12 +183,12 @@ namespace Bit.Api.Controllers } var userId = _userService.GetProperUserId(User); - await _providerService.DeleteUsersAsync(providerId, new [] { id }, userId.Value); + await _providerService.DeleteUsersAsync(providerId, new[] { id }, userId.Value); } [HttpDelete("")] [HttpPost("delete")] - public async Task> BulkDelete(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) + public async Task> BulkDelete(Guid providerId, [FromBody] ProviderUserBulkRequestModel model) { if (!_currentContext.ProviderManageUsers(providerId)) { diff --git a/src/Api/Controllers/ProvidersController.cs b/src/Api/Controllers/ProvidersController.cs index 7488d2006..1b586a1c3 100644 --- a/src/Api/Controllers/ProvidersController.cs +++ b/src/Api/Controllers/ProvidersController.cs @@ -31,7 +31,7 @@ namespace Bit.Api.Controllers _currentContext = currentContext; _globalSettings = globalSettings; } - + [HttpGet("{id:guid}")] public async Task Get(Guid id) { @@ -48,10 +48,10 @@ namespace Bit.Api.Controllers return new ProviderResponseModel(provider); } - + [HttpPut("{id:guid}")] [HttpPost("{id:guid}")] - public async Task Put(Guid id, [FromBody]ProviderUpdateRequestModel model) + public async Task Put(Guid id, [FromBody] ProviderUpdateRequestModel model) { if (!_currentContext.ProviderProviderAdmin(id)) { @@ -67,9 +67,9 @@ namespace Bit.Api.Controllers await _providerService.UpdateAsync(model.ToProvider(provider, _globalSettings)); return new ProviderResponseModel(provider); } - + [HttpPost("{id:guid}/setup")] - public async Task Setup(Guid id, [FromBody]ProviderSetupRequestModel model) + public async Task Setup(Guid id, [FromBody] ProviderSetupRequestModel model) { if (!_currentContext.ProviderProviderAdmin(id)) { @@ -81,9 +81,9 @@ namespace Bit.Api.Controllers { throw new NotFoundException(); } - + var userId = _userService.GetProperUserId(User).Value; - + var response = await _providerService.CompleteSetupAsync(model.ToProvider(provider), userId, model.Token, model.Key); diff --git a/src/Api/Controllers/PushController.cs b/src/Api/Controllers/PushController.cs index 291723ca5..ba85e54db 100644 --- a/src/Api/Controllers/PushController.cs +++ b/src/Api/Controllers/PushController.cs @@ -1,14 +1,14 @@ -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Services; -using Microsoft.AspNetCore.Authorization; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Context; using Bit.Core.Exceptions; -using System.Threading.Tasks; -using System.Linq; -using Microsoft.AspNetCore.Hosting; using Bit.Core.Models.Api; -using Bit.Core.Utilities; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; namespace Bit.Api.Controllers @@ -39,7 +39,7 @@ namespace Bit.Api.Controllers } [HttpPost("register")] - public async Task PostRegister([FromBody]PushRegistrationRequestModel model) + public async Task PostRegister([FromBody] PushRegistrationRequestModel model) { CheckUsage(); await _pushRegistrationService.CreateOrUpdateRegistrationAsync(model.PushToken, Prefix(model.DeviceId), @@ -54,7 +54,7 @@ namespace Bit.Api.Controllers } [HttpPut("add-organization")] - public async Task PutAddOrganization([FromBody]PushUpdateRequestModel model) + public async Task PutAddOrganization([FromBody] PushUpdateRequestModel model) { CheckUsage(); await _pushRegistrationService.AddUserRegistrationOrganizationAsync( @@ -62,7 +62,7 @@ namespace Bit.Api.Controllers } [HttpPut("delete-organization")] - public async Task PutDeleteOrganization([FromBody]PushUpdateRequestModel model) + public async Task PutDeleteOrganization([FromBody] PushUpdateRequestModel model) { CheckUsage(); await _pushRegistrationService.DeleteUserRegistrationOrganizationAsync( @@ -70,7 +70,7 @@ namespace Bit.Api.Controllers } [HttpPost("send")] - public async Task PostSend([FromBody]PushSendRequestModel model) + public async Task PostSend([FromBody] PushSendRequestModel model) { CheckUsage(); diff --git a/src/Api/Controllers/SendsController.cs b/src/Api/Controllers/SendsController.cs index fc3034597..3d042f288 100644 --- a/src/Api/Controllers/SendsController.cs +++ b/src/Api/Controllers/SendsController.cs @@ -1,25 +1,25 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Bit.Core.Utilities; -using Bit.Core.Settings; -using Bit.Core.Enums; -using Bit.Core.Context; using Azure.Messaging.EventGrid; -using Bit.Api.Utilities; -using System.Collections.Generic; using Bit.Api.Models.Request; using Bit.Api.Models.Response; -using Bit.Core.Models.Table; -using Newtonsoft.Json; -using Bit.Core.Models.Data; -using Microsoft.Extensions.Logging; +using Bit.Api.Utilities; using Bit.Core; +using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace Bit.Api.Controllers { diff --git a/src/Api/Controllers/SettingsController.cs b/src/Api/Controllers/SettingsController.cs index d67e7ddff..05d8757fe 100644 --- a/src/Api/Controllers/SettingsController.cs +++ b/src/Api/Controllers/SettingsController.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Response; +using Bit.Core.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Bit.Core.Services; namespace Bit.Api.Controllers { @@ -35,7 +35,7 @@ namespace Bit.Api.Controllers [HttpPut("domains")] [HttpPost("domains")] - public async Task PutDomains([FromBody]UpdateDomainsRequestModel model) + public async Task PutDomains([FromBody] UpdateDomainsRequestModel model) { var user = await _userService.GetUserByPrincipalAsync(User); if (user == null) diff --git a/src/Api/Controllers/SyncController.cs b/src/Api/Controllers/SyncController.cs index 313db075e..cd3cd27c0 100644 --- a/src/Api/Controllers/SyncController.cs +++ b/src/Api/Controllers/SyncController.cs @@ -1,18 +1,18 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Bit.Api.Models.Response; +using Bit.Core.Enums; +using Bit.Core.Enums.Provider; +using Bit.Core.Exceptions; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Bit.Core.Services; -using Bit.Core.Repositories; -using Bit.Core.Enums; -using Bit.Core.Exceptions; -using System.Linq; -using Bit.Core.Models.Table; -using System.Collections.Generic; -using Bit.Api.Models.Response; -using Bit.Core.Enums.Provider; -using Bit.Core.Models.Data; -using Bit.Core.Settings; namespace Bit.Api.Controllers { diff --git a/src/Api/Controllers/TwoFactorController.cs b/src/Api/Controllers/TwoFactorController.cs index 9e8395fca..c10527e8a 100644 --- a/src/Api/Controllers/TwoFactorController.cs +++ b/src/Api/Controllers/TwoFactorController.cs @@ -1,23 +1,23 @@ using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Bit.Core.Exceptions; -using Bit.Core.Services; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; -using Bit.Core.Enums; using System.Linq; +using System.Threading.Tasks; using Bit.Api.Models.Request; using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Response; using Bit.Api.Models.Response.TwoFactor; using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Table; using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; using Bit.Core.Utilities; using Bit.Core.Utilities.Duo; -using Bit.Core.Settings; using Fido2NetLib; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { @@ -83,7 +83,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-authenticator")] - public async Task GetAuthenticator([FromBody]SecretVerificationRequestModel model) + public async Task GetAuthenticator([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, false); var response = new TwoFactorAuthenticatorResponseModel(user); @@ -93,7 +93,7 @@ namespace Bit.Api.Controllers [HttpPut("authenticator")] [HttpPost("authenticator")] public async Task PutAuthenticator( - [FromBody]UpdateTwoFactorAuthenticatorRequestModel model) + [FromBody] UpdateTwoFactorAuthenticatorRequestModel model) { var user = await CheckAsync(model, false); model.ToUser(user); @@ -111,7 +111,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-yubikey")] - public async Task GetYubiKey([FromBody]SecretVerificationRequestModel model) + public async Task GetYubiKey([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, true); var response = new TwoFactorYubiKeyResponseModel(user); @@ -120,7 +120,7 @@ namespace Bit.Api.Controllers [HttpPut("yubikey")] [HttpPost("yubikey")] - public async Task PutYubiKey([FromBody]UpdateTwoFactorYubicoOtpRequestModel model) + public async Task PutYubiKey([FromBody] UpdateTwoFactorYubicoOtpRequestModel model) { var user = await CheckAsync(model, true); model.ToUser(user); @@ -137,7 +137,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-duo")] - public async Task GetDuo([FromBody]SecretVerificationRequestModel model) + public async Task GetDuo([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, true); var response = new TwoFactorDuoResponseModel(user); @@ -146,7 +146,7 @@ namespace Bit.Api.Controllers [HttpPut("duo")] [HttpPost("duo")] - public async Task PutDuo([FromBody]UpdateTwoFactorDuoRequestModel model) + public async Task PutDuo([FromBody] UpdateTwoFactorDuoRequestModel model) { var user = await CheckAsync(model, true); try @@ -167,7 +167,7 @@ namespace Bit.Api.Controllers [HttpPost("~/organizations/{id}/two-factor/get-duo")] public async Task GetOrganizationDuo(string id, - [FromBody]SecretVerificationRequestModel model) + [FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, false); @@ -190,7 +190,7 @@ namespace Bit.Api.Controllers [HttpPut("~/organizations/{id}/two-factor/duo")] [HttpPost("~/organizations/{id}/two-factor/duo")] public async Task PutOrganizationDuo(string id, - [FromBody]UpdateTwoFactorDuoRequestModel model) + [FromBody] UpdateTwoFactorDuoRequestModel model) { var user = await CheckAsync(model, false); @@ -224,7 +224,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-webauthn")] - public async Task GetWebAuthn([FromBody]SecretVerificationRequestModel model) + public async Task GetWebAuthn([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, true); var response = new TwoFactorWebAuthnResponseModel(user); @@ -232,7 +232,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-webauthn-challenge")] - public async Task GetWebAuthnChallenge([FromBody]SecretVerificationRequestModel model) + public async Task GetWebAuthnChallenge([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, true); var reg = await _userService.StartWebAuthnRegistrationAsync(user); @@ -241,7 +241,7 @@ namespace Bit.Api.Controllers [HttpPut("webauthn")] [HttpPost("webauthn")] - public async Task PutWebAuthn([FromBody]TwoFactorWebAuthnRequestModel model) + public async Task PutWebAuthn([FromBody] TwoFactorWebAuthnRequestModel model) { var user = await CheckAsync(model, true); @@ -256,7 +256,7 @@ namespace Bit.Api.Controllers } [HttpDelete("webauthn")] - public async Task DeleteWebAuthn([FromBody]TwoFactorWebAuthnDeleteRequestModel model) + public async Task DeleteWebAuthn([FromBody] TwoFactorWebAuthnDeleteRequestModel model) { var user = await CheckAsync(model, true); await _userService.DeleteWebAuthnKeyAsync(user, model.Id.Value); @@ -265,7 +265,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-email")] - public async Task GetEmail([FromBody]SecretVerificationRequestModel model) + public async Task GetEmail([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, false); var response = new TwoFactorEmailResponseModel(user); @@ -273,7 +273,7 @@ namespace Bit.Api.Controllers } [HttpPost("send-email")] - public async Task SendEmail([FromBody]TwoFactorEmailRequestModel model) + public async Task SendEmail([FromBody] TwoFactorEmailRequestModel model) { var user = await CheckAsync(model, false); model.ToUser(user); @@ -282,7 +282,7 @@ namespace Bit.Api.Controllers [AllowAnonymous] [HttpPost("send-email-login")] - public async Task SendEmailLogin([FromBody]TwoFactorEmailRequestModel model) + public async Task SendEmailLogin([FromBody] TwoFactorEmailRequestModel model) { var user = await _userManager.FindByEmailAsync(model.Email.ToLowerInvariant()); if (user != null) @@ -300,7 +300,7 @@ namespace Bit.Api.Controllers [HttpPut("email")] [HttpPost("email")] - public async Task PutEmail([FromBody]UpdateTwoFactorEmailRequestModel model) + public async Task PutEmail([FromBody] UpdateTwoFactorEmailRequestModel model) { var user = await CheckAsync(model, false); model.ToUser(user); @@ -319,7 +319,7 @@ namespace Bit.Api.Controllers [HttpPut("disable")] [HttpPost("disable")] - public async Task PutDisable([FromBody]TwoFactorProviderRequestModel model) + public async Task PutDisable([FromBody] TwoFactorProviderRequestModel model) { var user = await CheckAsync(model, false); await _userService.DisableTwoFactorProviderAsync(user, model.Type.Value, _organizationService); @@ -330,7 +330,7 @@ namespace Bit.Api.Controllers [HttpPut("~/organizations/{id}/two-factor/disable")] [HttpPost("~/organizations/{id}/two-factor/disable")] public async Task PutOrganizationDisable(string id, - [FromBody]TwoFactorProviderRequestModel model) + [FromBody] TwoFactorProviderRequestModel model) { var user = await CheckAsync(model, false); @@ -352,7 +352,7 @@ namespace Bit.Api.Controllers } [HttpPost("get-recover")] - public async Task GetRecover([FromBody]SecretVerificationRequestModel model) + public async Task GetRecover([FromBody] SecretVerificationRequestModel model) { var user = await CheckAsync(model, false); var response = new TwoFactorRecoverResponseModel(user); @@ -361,7 +361,7 @@ namespace Bit.Api.Controllers [HttpPost("recover")] [AllowAnonymous] - public async Task PostRecover([FromBody]TwoFactorRecoveryRequestModel model) + public async Task PostRecover([FromBody] TwoFactorRecoveryRequestModel model) { if (!await _userService.RecoverTwoFactorAsync(model.Email, model.MasterPasswordHash, model.RecoveryCode, _organizationService)) diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index a7d9336b2..259ff19f6 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -1,10 +1,10 @@ using System; using System.Threading.Tasks; using Bit.Api.Models.Response; -using Microsoft.AspNetCore.Mvc; +using Bit.Core.Exceptions; using Bit.Core.Repositories; using Microsoft.AspNetCore.Authorization; -using Bit.Core.Exceptions; +using Microsoft.AspNetCore.Mvc; namespace Bit.Api.Controllers { diff --git a/src/Api/Jobs/JobsHostedService.cs b/src/Api/Jobs/JobsHostedService.cs index 2b71f6c0a..f2fa924ee 100644 --- a/src/Api/Jobs/JobsHostedService.cs +++ b/src/Api/Jobs/JobsHostedService.cs @@ -31,7 +31,7 @@ namespace Bit.Api.Jobs .StartNow() .WithCronSchedule("0 0 * * * ?") .Build(); - var emergencyAccessTimeoutTrigger = TriggerBuilder.Create() + var emergencyAccessTimeoutTrigger = TriggerBuilder.Create() .WithIdentity("EmergencyAccessTimeoutTrigger") .StartNow() .WithCronSchedule("0 0 * * * ?") diff --git a/src/Api/Models/CipherAttachmentModel.cs b/src/Api/Models/CipherAttachmentModel.cs index b7a7fa351..a51080658 100644 --- a/src/Api/Models/CipherAttachmentModel.cs +++ b/src/Api/Models/CipherAttachmentModel.cs @@ -12,7 +12,7 @@ namespace Bit.Api.Models FileName = data.FileName; Key = data.Key; } - + [EncryptedStringLength(1000)] public string FileName { get; set; } [EncryptedStringLength(1000)] diff --git a/src/Api/Models/Public/MemberBaseModel.cs b/src/Api/Models/Public/MemberBaseModel.cs index 326a4c561..916121139 100644 --- a/src/Api/Models/Public/MemberBaseModel.cs +++ b/src/Api/Models/Public/MemberBaseModel.cs @@ -16,7 +16,7 @@ namespace Bit.Api.Models.Public { throw new ArgumentNullException(nameof(user)); } - + Type = user.Type; AccessAll = user.AccessAll; ExternalId = user.ExternalId; @@ -29,7 +29,7 @@ namespace Bit.Api.Models.Public { throw new ArgumentNullException(nameof(user)); } - + Type = user.Type; AccessAll = user.AccessAll; ExternalId = user.ExternalId; diff --git a/src/Api/Models/Request/Accounts/TaxInfoUpdateRequestModel.cs b/src/Api/Models/Request/Accounts/TaxInfoUpdateRequestModel.cs index 6a332efda..a769ed30f 100644 --- a/src/Api/Models/Request/Accounts/TaxInfoUpdateRequestModel.cs +++ b/src/Api/Models/Request/Accounts/TaxInfoUpdateRequestModel.cs @@ -9,7 +9,7 @@ namespace Bit.Api.Models.Request.Accounts public string Country { get; set; } public string PostalCode { get; set; } - public virtual IEnumerable Validate (ValidationContext validationContext) + public virtual IEnumerable Validate(ValidationContext validationContext) { if (Country == "US" && string.IsNullOrWhiteSpace(PostalCode)) { diff --git a/src/Api/Models/Request/AttachmentRequestModel.cs b/src/Api/Models/Request/AttachmentRequestModel.cs index 864510d03..b5ca4fb61 100644 --- a/src/Api/Models/Request/AttachmentRequestModel.cs +++ b/src/Api/Models/Request/AttachmentRequestModel.cs @@ -1,4 +1,4 @@ -namespace Bit.Api.Models.Request +namespace Bit.Api.Models.Request { public class AttachmentRequestModel { diff --git a/src/Api/Models/Request/Organizations/OrganizationKeysRequestModel.cs b/src/Api/Models/Request/Organizations/OrganizationKeysRequestModel.cs index cdb7ba905..4c4f712be 100644 --- a/src/Api/Models/Request/Organizations/OrganizationKeysRequestModel.cs +++ b/src/Api/Models/Request/Organizations/OrganizationKeysRequestModel.cs @@ -10,7 +10,7 @@ namespace Bit.Api.Models.Request.Organizations public string PublicKey { get; set; } [Required] public string EncryptedPrivateKey { get; set; } - + public OrganizationSignup ToOrganizationSignup(OrganizationSignup existingSignup) { if (string.IsNullOrWhiteSpace(existingSignup.PublicKey)) @@ -25,7 +25,7 @@ namespace Bit.Api.Models.Request.Organizations return existingSignup; } - + public OrganizationUpgrade ToOrganizationUpgrade(OrganizationUpgrade existingUpgrade) { if (string.IsNullOrWhiteSpace(existingUpgrade.PublicKey)) diff --git a/src/Api/Models/Request/Organizations/OrganizationSponsorshipRedeemRequestModel.cs b/src/Api/Models/Request/Organizations/OrganizationSponsorshipRedeemRequestModel.cs index df5d990c3..dc857e8e6 100644 --- a/src/Api/Models/Request/Organizations/OrganizationSponsorshipRedeemRequestModel.cs +++ b/src/Api/Models/Request/Organizations/OrganizationSponsorshipRedeemRequestModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; diff --git a/src/Api/Models/Request/Organizations/OrganizationSponsorshipRequestModel.cs b/src/Api/Models/Request/Organizations/OrganizationSponsorshipRequestModel.cs index e310eb506..2fe13151b 100644 --- a/src/Api/Models/Request/Organizations/OrganizationSponsorshipRequestModel.cs +++ b/src/Api/Models/Request/Organizations/OrganizationSponsorshipRequestModel.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; using Bit.Core.Utilities; diff --git a/src/Api/Models/Request/Organizations/OrganizationSsoRequestModel.cs b/src/Api/Models/Request/Organizations/OrganizationSsoRequestModel.cs index 2d765a78c..d63c1d8d7 100644 --- a/src/Api/Models/Request/Organizations/OrganizationSsoRequestModel.cs +++ b/src/Api/Models/Request/Organizations/OrganizationSsoRequestModel.cs @@ -37,7 +37,7 @@ namespace Bit.Api.Models.Request.Organizations public class SsoConfigurationDataRequest : IValidatableObject { - public SsoConfigurationDataRequest() {} + public SsoConfigurationDataRequest() { } [Required] public SsoType ConfigType { get; set; } diff --git a/src/Api/Models/Request/Organizations/OrganizationSubscriptionUpdateRequestModel.cs b/src/Api/Models/Request/Organizations/OrganizationSubscriptionUpdateRequestModel.cs index 4b3d0c515..9adb0b7ec 100644 --- a/src/Api/Models/Request/Organizations/OrganizationSubscriptionUpdateRequestModel.cs +++ b/src/Api/Models/Request/Organizations/OrganizationSubscriptionUpdateRequestModel.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Bit.Api.Models.Request.Organizations { diff --git a/src/Api/Models/Request/Organizations/OrganizationUserRequestModels.cs b/src/Api/Models/Request/Organizations/OrganizationUserRequestModels.cs index 9e7c9d9af..d68660734 100644 --- a/src/Api/Models/Request/Organizations/OrganizationUserRequestModels.cs +++ b/src/Api/Models/Request/Organizations/OrganizationUserRequestModels.cs @@ -90,7 +90,7 @@ namespace Bit.Api.Models.Request.Organizations [Required] public IEnumerable GroupIds { get; set; } } - + public class OrganizationUserResetPasswordEnrollmentRequestModel { public string ResetPasswordKey { get; set; } diff --git a/src/Api/Models/Request/Providers/ProviderOrganizationCreateRequestModel.cs b/src/Api/Models/Request/Providers/ProviderOrganizationCreateRequestModel.cs index 26b187080..cd796c11f 100644 --- a/src/Api/Models/Request/Providers/ProviderOrganizationCreateRequestModel.cs +++ b/src/Api/Models/Request/Providers/ProviderOrganizationCreateRequestModel.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Bit.Api.Models.Request.Organizations; using Bit.Core.Utilities; diff --git a/src/Api/Models/Response/AttachmentUploadDataResponseModel.cs b/src/Api/Models/Response/AttachmentUploadDataResponseModel.cs index 804fb2c34..7acc5715c 100644 --- a/src/Api/Models/Response/AttachmentUploadDataResponseModel.cs +++ b/src/Api/Models/Response/AttachmentUploadDataResponseModel.cs @@ -1,4 +1,4 @@ -using Bit.Core.Enums; +using Bit.Core.Enums; using Bit.Core.Models.Api; namespace Bit.Api.Models.Response diff --git a/src/Api/Models/Response/EmergencyAccessResponseModel.cs b/src/Api/Models/Response/EmergencyAccessResponseModel.cs index 2d882fadc..d20ed2382 100644 --- a/src/Api/Models/Response/EmergencyAccessResponseModel.cs +++ b/src/Api/Models/Response/EmergencyAccessResponseModel.cs @@ -114,7 +114,7 @@ namespace Bit.Api.Models.Response KeyEncrypted = emergencyAccess.KeyEncrypted; Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings)); } - + public string KeyEncrypted { get; set; } public IEnumerable Ciphers { get; set; } } diff --git a/src/Api/Models/Response/OrganizationAutoEnrollStatusResponseModel.cs b/src/Api/Models/Response/OrganizationAutoEnrollStatusResponseModel.cs index 8eb9866ff..6ba4308d9 100644 --- a/src/Api/Models/Response/OrganizationAutoEnrollStatusResponseModel.cs +++ b/src/Api/Models/Response/OrganizationAutoEnrollStatusResponseModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Models.Api; namespace Bit.Api.Models.Response @@ -10,7 +10,7 @@ namespace Bit.Api.Models.Response Id = orgId.ToString(); ResetPasswordEnabled = resetPasswordEnabled; } - + public string Id { get; set; } public bool ResetPasswordEnabled { get; set; } } diff --git a/src/Api/Models/Response/OrganizationKeysResponseModel.cs b/src/Api/Models/Response/OrganizationKeysResponseModel.cs index 3d381643d..c8c1529e1 100644 --- a/src/Api/Models/Response/OrganizationKeysResponseModel.cs +++ b/src/Api/Models/Response/OrganizationKeysResponseModel.cs @@ -12,11 +12,11 @@ namespace Bit.Api.Models.Response { throw new ArgumentNullException(nameof(org)); } - + PublicKey = org.PublicKey; PrivateKey = org.PrivateKey; } - + public string PublicKey { get; set; } public string PrivateKey { get; set; } } diff --git a/src/Api/Models/Response/OrganizationUserResponseModel.cs b/src/Api/Models/Response/OrganizationUserResponseModel.cs index a461c8a5f..a46acc85a 100644 --- a/src/Api/Models/Response/OrganizationUserResponseModel.cs +++ b/src/Api/Models/Response/OrganizationUserResponseModel.cs @@ -108,7 +108,7 @@ namespace Bit.Api.Models.Response ResetPasswordKey = orgUser.ResetPasswordKey; EncryptedPrivateKey = orgUser.EncryptedPrivateKey; } - + public KdfType Kdf { get; set; } public int KdfIterations { get; set; } public string ResetPasswordKey { get; set; } diff --git a/src/Api/Models/Response/PlanResponseModel.cs b/src/Api/Models/Response/PlanResponseModel.cs index d00f1700f..539b6adab 100644 --- a/src/Api/Models/Response/PlanResponseModel.cs +++ b/src/Api/Models/Response/PlanResponseModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Enums; using Bit.Core.Models.Api; using Bit.Core.Models.StaticStore; diff --git a/src/Api/Models/Response/ProfileOrganizationResponseModel.cs b/src/Api/Models/Response/ProfileOrganizationResponseModel.cs index 60d654a16..a66198685 100644 --- a/src/Api/Models/Response/ProfileOrganizationResponseModel.cs +++ b/src/Api/Models/Response/ProfileOrganizationResponseModel.cs @@ -7,7 +7,7 @@ namespace Bit.Api.Models.Response { public class ProfileOrganizationResponseModel : ResponseModel { - public ProfileOrganizationResponseModel(string str) : base(str) {} + public ProfileOrganizationResponseModel(string str) : base(str) { } public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization") { @@ -45,7 +45,7 @@ namespace Bit.Api.Models.Response StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise) .UsersCanSponsor(organization); PlanProductType = StaticStore.GetPlan(organization.PlanType).Product; - + if (organization.SsoConfig != null) { var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig); diff --git a/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs b/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs index c3596ea0e..acfd7a3a0 100644 --- a/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs +++ b/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs @@ -14,7 +14,7 @@ namespace Bit.Api.Models.Response.Providers { throw new ArgumentNullException(nameof(providerOrganization)); } - + Id = providerOrganization.Id; ProviderId = providerOrganization.ProviderId; OrganizationId = providerOrganization.OrganizationId; @@ -31,7 +31,7 @@ namespace Bit.Api.Models.Response.Providers { throw new ArgumentNullException(nameof(providerOrganization)); } - + Id = providerOrganization.Id; ProviderId = providerOrganization.ProviderId; OrganizationId = providerOrganization.OrganizationId; @@ -40,7 +40,7 @@ namespace Bit.Api.Models.Response.Providers CreationDate = providerOrganization.CreationDate; RevisionDate = providerOrganization.RevisionDate; } - + public Guid Id { get; set; } public Guid ProviderId { get; set; } public Guid OrganizationId { get; set; } @@ -49,7 +49,7 @@ namespace Bit.Api.Models.Response.Providers public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } } - + public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel { public ProviderOrganizationOrganizationDetailsResponseModel(ProviderOrganizationOrganizationDetails providerOrganization, @@ -62,7 +62,7 @@ namespace Bit.Api.Models.Response.Providers OrganizationName = providerOrganization.OrganizationName; } - + public string OrganizationName { get; set; } } } diff --git a/src/Api/Models/Response/Providers/ProviderResponseModel.cs b/src/Api/Models/Response/Providers/ProviderResponseModel.cs index db7138cb8..73ebafc5a 100644 --- a/src/Api/Models/Response/Providers/ProviderResponseModel.cs +++ b/src/Api/Models/Response/Providers/ProviderResponseModel.cs @@ -23,7 +23,7 @@ namespace Bit.Api.Models.Response.Providers BusinessTaxNumber = provider.BusinessTaxNumber; BillingEmail = provider.BillingEmail; } - + public Guid Id { get; set; } public string Name { get; set; } public string BusinessName { get; set; } diff --git a/src/Api/Models/Response/Providers/ProviderUserResponseModel.cs b/src/Api/Models/Response/Providers/ProviderUserResponseModel.cs index e835393cd..775f1587b 100644 --- a/src/Api/Models/Response/Providers/ProviderUserResponseModel.cs +++ b/src/Api/Models/Response/Providers/ProviderUserResponseModel.cs @@ -23,7 +23,7 @@ namespace Bit.Api.Models.Response.Providers Status = providerUser.Status; Permissions = CoreHelpers.LoadClassFromJsonData(providerUser.Permissions); } - + public ProviderUserResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUser") : base(obj) { @@ -48,7 +48,7 @@ namespace Bit.Api.Models.Response.Providers public class ProviderUserUserDetailsResponseModel : ProviderUserResponseModel { - public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser, + public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUserUserDetails") : base(providerUser, obj) { if (providerUser == null) diff --git a/src/Api/Models/Response/SendFileDownloadDataResponseModel.cs b/src/Api/Models/Response/SendFileDownloadDataResponseModel.cs index 6659904b4..e8efed8a4 100644 --- a/src/Api/Models/Response/SendFileDownloadDataResponseModel.cs +++ b/src/Api/Models/Response/SendFileDownloadDataResponseModel.cs @@ -1,4 +1,4 @@ -using Bit.Core.Models.Api; +using Bit.Core.Models.Api; namespace Bit.Api.Models.Response { diff --git a/src/Api/Models/Response/SendFileUploadDataResponseModel.cs b/src/Api/Models/Response/SendFileUploadDataResponseModel.cs index 49eb95d72..20e3694fe 100644 --- a/src/Api/Models/Response/SendFileUploadDataResponseModel.cs +++ b/src/Api/Models/Response/SendFileUploadDataResponseModel.cs @@ -1,4 +1,4 @@ -using Bit.Core.Enums; +using Bit.Core.Enums; using Bit.Core.Models.Api; namespace Bit.Api.Models.Response @@ -6,7 +6,7 @@ namespace Bit.Api.Models.Response public class SendFileUploadDataResponseModel : ResponseModel { public SendFileUploadDataResponseModel() : base("send-fileUpload") { } - + public string Url { get; set; } public FileUploadType FileUploadType { get; set; } public SendResponseModel SendResponse { get; set; } diff --git a/src/Api/Models/Response/TaxRateResponseModel.cs b/src/Api/Models/Response/TaxRateResponseModel.cs index f845bf681..9270b66b8 100644 --- a/src/Api/Models/Response/TaxRateResponseModel.cs +++ b/src/Api/Models/Response/TaxRateResponseModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Models.Api; using Bit.Core.Models.Table; diff --git a/src/Api/Program.cs b/src/Api/Program.cs index 839013a5c..134b476a4 100644 --- a/src/Api/Program.cs +++ b/src/Api/Program.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; +using AspNetCoreRateLimit; using Bit.Core.Utilities; -using Serilog.Events; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; -using AspNetCoreRateLimit; +using Serilog.Events; namespace Bit.Api { diff --git a/src/Api/Public/Controllers/CollectionsController.cs b/src/Api/Public/Controllers/CollectionsController.cs index 1e3b02f40..350936349 100644 --- a/src/Api/Public/Controllers/CollectionsController.cs +++ b/src/Api/Public/Controllers/CollectionsController.cs @@ -85,7 +85,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType(typeof(CollectionResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put(Guid id, [FromBody]CollectionUpdateRequestModel model) + public async Task Put(Guid id, [FromBody] CollectionUpdateRequestModel model) { var existingCollection = await _collectionRepository.GetByIdAsync(id); if (existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId) diff --git a/src/Api/Public/Controllers/EventsController.cs b/src/Api/Public/Controllers/EventsController.cs index 34642bdc6..724799365 100644 --- a/src/Api/Public/Controllers/EventsController.cs +++ b/src/Api/Public/Controllers/EventsController.cs @@ -39,7 +39,7 @@ namespace Bit.Api.Public.Controllers /// [HttpGet] [ProducesResponseType(typeof(ListResponseModel), (int)HttpStatusCode.OK)] - public async Task List([FromQuery]EventFilterRequestModel request) + public async Task List([FromQuery] EventFilterRequestModel request) { var dateRange = request.ToDateRange(); var result = new PagedResult(); diff --git a/src/Api/Public/Controllers/GroupsController.cs b/src/Api/Public/Controllers/GroupsController.cs index e8de51caa..a761f3b33 100644 --- a/src/Api/Public/Controllers/GroupsController.cs +++ b/src/Api/Public/Controllers/GroupsController.cs @@ -104,7 +104,7 @@ namespace Bit.Api.Public.Controllers [HttpPost] [ProducesResponseType(typeof(GroupResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - public async Task Post([FromBody]GroupCreateUpdateRequestModel model) + public async Task Post([FromBody] GroupCreateUpdateRequestModel model) { var group = model.ToGroup(_currentContext.OrganizationId.Value); var associations = model.Collections?.Select(c => c.ToSelectionReadOnly()); @@ -126,7 +126,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType(typeof(GroupResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put(Guid id, [FromBody]GroupCreateUpdateRequestModel model) + public async Task Put(Guid id, [FromBody] GroupCreateUpdateRequestModel model) { var existingGroup = await _groupRepository.GetByIdAsync(id); if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId) @@ -152,7 +152,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task PutMemberIds(Guid id, [FromBody]UpdateMemberIdsRequestModel model) + public async Task PutMemberIds(Guid id, [FromBody] UpdateMemberIdsRequestModel model) { var existingGroup = await _groupRepository.GetByIdAsync(id); if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId) diff --git a/src/Api/Public/Controllers/MembersController.cs b/src/Api/Public/Controllers/MembersController.cs index 5b1ef5365..d9fb9a479 100644 --- a/src/Api/Public/Controllers/MembersController.cs +++ b/src/Api/Public/Controllers/MembersController.cs @@ -115,7 +115,7 @@ namespace Bit.Api.Public.Controllers [HttpPost] [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - public async Task Post([FromBody]MemberCreateRequestModel model) + public async Task Post([FromBody] MemberCreateRequestModel model) { var associations = model.Collections?.Select(c => c.ToSelectionReadOnly()); var invite = new OrganizationUserInvite @@ -144,7 +144,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put(Guid id, [FromBody]MemberUpdateRequestModel model) + public async Task Put(Guid id, [FromBody] MemberUpdateRequestModel model) { var existingUser = await _organizationUserRepository.GetByIdAsync(id); if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId) @@ -180,7 +180,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task PutGroupIds(Guid id, [FromBody]UpdateGroupIdsRequestModel model) + public async Task PutGroupIds(Guid id, [FromBody] UpdateGroupIdsRequestModel model) { var existingUser = await _organizationUserRepository.GetByIdAsync(id); if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId) diff --git a/src/Api/Public/Controllers/OrganizationController.cs b/src/Api/Public/Controllers/OrganizationController.cs index f804f0839..21456789b 100644 --- a/src/Api/Public/Controllers/OrganizationController.cs +++ b/src/Api/Public/Controllers/OrganizationController.cs @@ -40,7 +40,7 @@ namespace Bit.Api.Public.Controllers [HttpPost("import")] [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - public async Task Import([FromBody]OrganizationImportRequestModel model) + public async Task Import([FromBody] OrganizationImportRequestModel model) { if (!_globalSettings.SelfHosted && !model.LargeImport && (model.Groups.Count() > 2000 || model.Members.Count(u => !u.Deleted) > 2000)) diff --git a/src/Api/Public/Controllers/PoliciesController.cs b/src/Api/Public/Controllers/PoliciesController.cs index 6a5ac8525..4c9eb31bd 100644 --- a/src/Api/Public/Controllers/PoliciesController.cs +++ b/src/Api/Public/Controllers/PoliciesController.cs @@ -88,7 +88,7 @@ namespace Bit.Api.Public.Controllers [ProducesResponseType(typeof(PolicyResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put(PolicyType type, [FromBody]PolicyUpdateRequestModel model) + public async Task Put(PolicyType type, [FromBody] PolicyUpdateRequestModel model) { var policy = await _policyRepository.GetByOrganizationIdTypeAsync( _currentContext.OrganizationId.Value, type); diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index 494b6194e..a050b76e6 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -122,11 +122,11 @@ namespace Bit.Api services.AddDefaultServices(globalSettings); services.AddCoreLocalizationServices(); - #if OSS +#if OSS services.AddOosServices(); - #else - services.AddCommCoreServices(); - #endif +#else + services.AddCommCoreServices(); +#endif // MVC services.AddMvc(config => diff --git a/src/Api/Utilities/ApiHelpers.cs b/src/Api/Utilities/ApiHelpers.cs index 4076b8e78..5b86ef33e 100644 --- a/src/Api/Utilities/ApiHelpers.cs +++ b/src/Api/Utilities/ApiHelpers.cs @@ -1,13 +1,13 @@ -using Bit.Core.Utilities; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Azure.Messaging.EventGrid; -using Azure.Messaging.EventGrid.SystemEvents; -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Azure.Messaging.EventGrid; +using Azure.Messaging.EventGrid.SystemEvents; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; namespace Bit.Api.Utilities { diff --git a/src/Api/Utilities/DisableFormValueModelBindingAttribute.cs b/src/Api/Utilities/DisableFormValueModelBindingAttribute.cs index fee967c91..d7ad9b78c 100644 --- a/src/Api/Utilities/DisableFormValueModelBindingAttribute.cs +++ b/src/Api/Utilities/DisableFormValueModelBindingAttribute.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Mvc.Filters; +using System; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; -using System; namespace Bit.Api.Utilities { diff --git a/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs b/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs index 219c9f6a8..4083531fc 100644 --- a/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs +++ b/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs @@ -1,15 +1,15 @@ using System; using Bit.Api.Models.Public.Response; -using InternalApi = Bit.Core.Models.Api; using Bit.Core.Exceptions; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; using Stripe; -using Microsoft.Extensions.Hosting; +using InternalApi = Bit.Core.Models.Api; namespace Bit.Api.Utilities { diff --git a/src/Api/Utilities/ModelStateValidationFilterAttribute.cs b/src/Api/Utilities/ModelStateValidationFilterAttribute.cs index 99c1725f8..8cda1e542 100644 --- a/src/Api/Utilities/ModelStateValidationFilterAttribute.cs +++ b/src/Api/Utilities/ModelStateValidationFilterAttribute.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Mvc; +using System.Linq; +using Bit.Api.Models.Public.Response; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using InternalApi = Bit.Core.Models.Api; -using System.Linq; -using Bit.Api.Models.Public.Response; namespace Bit.Api.Utilities { diff --git a/src/Api/Utilities/MultipartFormDataHelper.cs b/src/Api/Utilities/MultipartFormDataHelper.cs index 4f685b4c2..20f875ba2 100644 --- a/src/Api/Utilities/MultipartFormDataHelper.cs +++ b/src/Api/Utilities/MultipartFormDataHelper.cs @@ -1,12 +1,12 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.Net.Http.Headers; -using System; +using System; using System.IO; using System.Threading.Tasks; using Bit.Api.Models.Request; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; using Newtonsoft.Json; namespace Bit.Api.Utilities diff --git a/src/Api/Utilities/ServiceCollectionExtensions.cs b/src/Api/Utilities/ServiceCollectionExtensions.cs index 6ca0cf066..74a3ec208 100644 --- a/src/Api/Utilities/ServiceCollectionExtensions.cs +++ b/src/Api/Utilities/ServiceCollectionExtensions.cs @@ -53,7 +53,7 @@ namespace Bit.Api.Utilities { new OpenApiSecurityScheme { - Reference = new OpenApiReference + Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "OAuth2 Client Credentials" diff --git a/src/Billing/Controllers/AppleController.cs b/src/Billing/Controllers/AppleController.cs index d10a0810d..944a2db49 100644 --- a/src/Billing/Controllers/AppleController.cs +++ b/src/Billing/Controllers/AppleController.cs @@ -1,13 +1,13 @@ -using Bit.Core; +using System; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using Bit.Core; using Bit.Core.Utilities; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using System; -using System.IO; -using System.Text; -using System.Threading.Tasks; namespace Bit.Billing.Controllers { diff --git a/src/Billing/Controllers/BitPayController.cs b/src/Billing/Controllers/BitPayController.cs index f0481e814..7bf56d019 100644 --- a/src/Billing/Controllers/BitPayController.cs +++ b/src/Billing/Controllers/BitPayController.cs @@ -1,4 +1,9 @@ -using Bit.Billing.Models; +using System; +using System.Data.SqlClient; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using Bit.Billing.Models; using Bit.Core.Enums; using Bit.Core.Repositories; using Bit.Core.Services; @@ -6,11 +11,6 @@ using Bit.Core.Utilities; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using System; -using System.Data.SqlClient; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; namespace Bit.Billing.Controllers { diff --git a/src/Billing/Controllers/FreshdeskController.cs b/src/Billing/Controllers/FreshdeskController.cs index c8a1d8378..6012733ef 100644 --- a/src/Billing/Controllers/FreshdeskController.cs +++ b/src/Billing/Controllers/FreshdeskController.cs @@ -1,20 +1,19 @@ -using Bit.Core.Repositories; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; using System.Text; using System.Threading.Tasks; -using System.ComponentModel.DataAnnotations; - +using Bit.Core.Repositories; using Bit.Core.Settings; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; namespace Bit.Billing.Controllers { diff --git a/src/Billing/Controllers/InfoController.cs b/src/Billing/Controllers/InfoController.cs index fb3a85914..016bee2c4 100644 --- a/src/Billing/Controllers/InfoController.cs +++ b/src/Billing/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Billing.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Billing.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Billing/Controllers/PayPalController.cs b/src/Billing/Controllers/PayPalController.cs index b519cce09..861e4db99 100644 --- a/src/Billing/Controllers/PayPalController.cs +++ b/src/Billing/Controllers/PayPalController.cs @@ -1,4 +1,8 @@ -using Bit.Billing.Utilities; +using System.Data.SqlClient; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using Bit.Billing.Utilities; using Bit.Core.Enums; using Bit.Core.Models.Table; using Bit.Core.Repositories; @@ -7,10 +11,6 @@ using Bit.Core.Utilities; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using System.Data.SqlClient; -using System.IO; -using System.Text; -using System.Threading.Tasks; namespace Bit.Billing.Controllers { @@ -183,7 +183,7 @@ namespace Bit.Billing.Controllers } } // Catch foreign key violations because user/org could have been deleted. - catch (SqlException e) when(e.Number == 547) { } + catch (SqlException e) when (e.Number == 547) { } } else if (ipnTransaction.PaymentStatus == "Refunded" || ipnTransaction.PaymentStatus == "Reversed") { diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index f6035e6d5..fb8b9dead 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -1,4 +1,10 @@ -using Bit.Core.Enums; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Business; using Bit.Core.Models.Table; using Bit.Core.Repositories; @@ -11,12 +17,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Stripe; -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.IO; -using System.Linq; -using System.Threading.Tasks; namespace Bit.Billing.Controllers { @@ -322,7 +322,7 @@ namespace Bit.Billing.Controllers await _transactionRepository.CreateAsync(tx); } // Catch foreign key violations because user/org could have been deleted. - catch (SqlException e) when(e.Number == 547) { } + catch (SqlException e) when (e.Number == 547) { } } else if (parsedEvent.Type.Equals("charge.refunded")) { @@ -773,10 +773,10 @@ namespace Bit.Billing.Controllers if (!string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.Country) && !string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.PostalCode)) { var localBitwardenTaxRates = await _taxRateRepository.GetByLocationAsync( - new Bit.Core.Models.Table.TaxRate() - { + new Bit.Core.Models.Table.TaxRate() + { Country = invoice.CustomerAddress.Country, - PostalCode = invoice.CustomerAddress.PostalCode + PostalCode = invoice.CustomerAddress.PostalCode } ); diff --git a/src/Billing/Jobs/JobsHostedService.cs b/src/Billing/Jobs/JobsHostedService.cs index 01cbadac7..8b2606e51 100644 --- a/src/Billing/Jobs/JobsHostedService.cs +++ b/src/Billing/Jobs/JobsHostedService.cs @@ -18,7 +18,7 @@ namespace Bit.Billing.Jobs IServiceProvider serviceProvider, ILogger logger, ILogger listenerLogger) - : base(globalSettings, serviceProvider, logger, listenerLogger) {} + : base(globalSettings, serviceProvider, logger, listenerLogger) { } public override async Task StartAsync(CancellationToken cancellationToken) { diff --git a/src/Billing/Program.cs b/src/Billing/Program.cs index 1b2e0875a..3407bf707 100644 --- a/src/Billing/Program.cs +++ b/src/Billing/Program.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Hosting; -using Bit.Core.Utilities; -using Serilog.Events; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.Billing { diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index ec520f062..87c54e52d 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -1,17 +1,17 @@ using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using System.Globalization; using Bit.Core.Context; using Bit.Core.Settings; -using Stripe; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.AspNetCore.Routing; -using System.Globalization; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; +using Stripe; namespace Bit.Billing { diff --git a/src/Core/AssemblyInfo.cs b/src/Core/AssemblyInfo.cs index f1b57904e..a5edd1a27 100644 --- a/src/Core/AssemblyInfo.cs +++ b/src/Core/AssemblyInfo.cs @@ -1,3 +1,3 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Core.Test")] diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 5c52e1422..68fd94295 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -11,7 +11,7 @@ public const long FileSize501mb = 501L * 1024L * 1024L; } - public static class TokenPurposes + public static class TokenPurposes { public const string LinkSso = "LinkSso"; } diff --git a/src/Core/Context/CurrentContentOrganization.cs b/src/Core/Context/CurrentContentOrganization.cs index 845609115..425a0a524 100644 --- a/src/Core/Context/CurrentContentOrganization.cs +++ b/src/Core/Context/CurrentContentOrganization.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.Table; diff --git a/src/Core/Context/CurrentContentProvider.cs b/src/Core/Context/CurrentContentProvider.cs index a0cb235a3..20f9bb898 100644 --- a/src/Core/Context/CurrentContentProvider.cs +++ b/src/Core/Context/CurrentContentProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Enums; using Bit.Core.Enums.Provider; using Bit.Core.Models.Data; diff --git a/src/Core/Context/CurrentContext.cs b/src/Core/Context/CurrentContext.cs index b426de113..4aa75a4f3 100644 --- a/src/Core/Context/CurrentContext.cs +++ b/src/Core/Context/CurrentContext.cs @@ -1,16 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using Microsoft.AspNetCore.Http; -using Bit.Core.Repositories; -using System.Threading.Tasks; using System.Security.Claims; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Enums.Provider; -using Bit.Core.Utilities; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Http; namespace Bit.Core.Context { @@ -414,7 +414,7 @@ namespace Bit.Core.Context } return Organizations; } - + public async Task> ProviderMembershipAsync( IProviderUserRepository providerUserRepository, Guid userId) { diff --git a/src/Core/Enums/BitwardenClient.cs b/src/Core/Enums/BitwardenClient.cs index f4031cb01..067eef92b 100644 --- a/src/Core/Enums/BitwardenClient.cs +++ b/src/Core/Enums/BitwardenClient.cs @@ -1,6 +1,6 @@ -namespace Bit.Core.Enums +namespace Bit.Core.Enums { - public static class BitwardenClient + public static class BitwardenClient { public const string Web = "web", diff --git a/src/Core/Enums/CipherStateAction.cs b/src/Core/Enums/CipherStateAction.cs index 1d2c1dcf6..87b73a41c 100644 --- a/src/Core/Enums/CipherStateAction.cs +++ b/src/Core/Enums/CipherStateAction.cs @@ -1,9 +1,9 @@ -namespace Bit.Core.Enums +namespace Bit.Core.Enums { - public enum CipherStateAction - { - Restore, - SoftDelete, - HardDelete, - } + public enum CipherStateAction + { + Restore, + SoftDelete, + HardDelete, + } } diff --git a/src/Core/Enums/EventType.cs b/src/Core/Enums/EventType.cs index 3df151730..840229038 100644 --- a/src/Core/Enums/EventType.cs +++ b/src/Core/Enums/EventType.cs @@ -62,7 +62,7 @@ Organization_DisabledKeyConnector = 1607, Policy_Updated = 1700, - + ProviderUser_Invited = 1800, ProviderUser_Confirmed = 1801, ProviderUser_Updated = 1802, diff --git a/src/Core/Enums/FileUploadType.cs b/src/Core/Enums/FileUploadType.cs index dc50eb669..4bdefd4dd 100644 --- a/src/Core/Enums/FileUploadType.cs +++ b/src/Core/Enums/FileUploadType.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Enums +namespace Bit.Core.Enums { public enum FileUploadType { diff --git a/src/Core/Enums/PlanSponsorshipType.cs b/src/Core/Enums/PlanSponsorshipType.cs index 79145bf1e..59f778e10 100644 --- a/src/Core/Enums/PlanSponsorshipType.cs +++ b/src/Core/Enums/PlanSponsorshipType.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Bit.Core.Enums { diff --git a/src/Core/Enums/ProductType.cs b/src/Core/Enums/ProductType.cs index 572a4f850..2f9b1d478 100644 --- a/src/Core/Enums/ProductType.cs +++ b/src/Core/Enums/ProductType.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Bit.Core.Enums { diff --git a/src/Core/Enums/SupportedDatabaseProviders.cs b/src/Core/Enums/SupportedDatabaseProviders.cs index 301297d4b..c38a023c4 100644 --- a/src/Core/Enums/SupportedDatabaseProviders.cs +++ b/src/Core/Enums/SupportedDatabaseProviders.cs @@ -1,6 +1,6 @@ -namespace Bit.Core.Enums +namespace Bit.Core.Enums { - public enum SupportedDatabaseProviders + public enum SupportedDatabaseProviders { SqlServer, MySql, diff --git a/src/Core/Identity/AuthenticatorTokenProvider.cs b/src/Core/Identity/AuthenticatorTokenProvider.cs index d511e8ec6..bfb6e117b 100644 --- a/src/Core/Identity/AuthenticatorTokenProvider.cs +++ b/src/Core/Identity/AuthenticatorTokenProvider.cs @@ -1,11 +1,11 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; using Bit.Core.Enums; -using OtpNet; +using Bit.Core.Models.Table; using Bit.Core.Services; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; +using OtpNet; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/DuoWebTokenProvider.cs b/src/Core/Identity/DuoWebTokenProvider.cs index 3dc1a37a2..2ff6cfe1c 100644 --- a/src/Core/Identity/DuoWebTokenProvider.cs +++ b/src/Core/Identity/DuoWebTokenProvider.cs @@ -1,13 +1,13 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; +using System; +using System.Threading.Tasks; using Bit.Core.Enums; -using Bit.Core.Utilities.Duo; using Bit.Core.Models; -using System; -using Microsoft.Extensions.DependencyInjection; +using Bit.Core.Models.Table; using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities.Duo; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/EmailTokenProvider.cs b/src/Core/Identity/EmailTokenProvider.cs index fb874cf76..47d19e36f 100644 --- a/src/Core/Identity/EmailTokenProvider.cs +++ b/src/Core/Identity/EmailTokenProvider.cs @@ -1,11 +1,11 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; using Bit.Core.Enums; -using Bit.Core.Services; -using Microsoft.Extensions.DependencyInjection; using Bit.Core.Models; +using Bit.Core.Models.Table; +using Bit.Core.Services; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/OrganizationDuoWebTokenProvider.cs b/src/Core/Identity/OrganizationDuoWebTokenProvider.cs index 2153c0023..537fd62a5 100644 --- a/src/Core/Identity/OrganizationDuoWebTokenProvider.cs +++ b/src/Core/Identity/OrganizationDuoWebTokenProvider.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -using Bit.Core.Models.Table; using Bit.Core.Enums; -using Bit.Core.Utilities.Duo; using Bit.Core.Models; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities.Duo; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/ReadOnlyDatabaseIdentityUserStore.cs b/src/Core/Identity/ReadOnlyDatabaseIdentityUserStore.cs index a4413af76..82fcc5b50 100644 --- a/src/Core/Identity/ReadOnlyDatabaseIdentityUserStore.cs +++ b/src/Core/Identity/ReadOnlyDatabaseIdentityUserStore.cs @@ -1,9 +1,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Bit.Core.Repositories; using Bit.Core.Services; +using Microsoft.AspNetCore.Identity; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/ReadOnlyEnvIdentityUserStore.cs b/src/Core/Identity/ReadOnlyEnvIdentityUserStore.cs index baa7e5c14..8897a5bb9 100644 --- a/src/Core/Identity/ReadOnlyEnvIdentityUserStore.cs +++ b/src/Core/Identity/ReadOnlyEnvIdentityUserStore.cs @@ -48,7 +48,7 @@ namespace Bit.Core.Identity { return Task.FromResult(null); } - + return Task.FromResult(new IdentityUser { Id = normalizedEmail, diff --git a/src/Core/Identity/RoleStore.cs b/src/Core/Identity/RoleStore.cs index 33fb27b43..28b0b5825 100644 --- a/src/Core/Identity/RoleStore.cs +++ b/src/Core/Identity/RoleStore.cs @@ -1,8 +1,8 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Bit.Core.Models.Table; +using Microsoft.AspNetCore.Identity; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/TwoFactorRememberTokenProvider.cs b/src/Core/Identity/TwoFactorRememberTokenProvider.cs index 2a7a1c23a..4be07ab92 100644 --- a/src/Core/Identity/TwoFactorRememberTokenProvider.cs +++ b/src/Core/Identity/TwoFactorRememberTokenProvider.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; -using Microsoft.Extensions.Options; +using Bit.Core.Models.Table; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/U2fTokenProvider.cs b/src/Core/Identity/U2fTokenProvider.cs index b289c8be0..7fc97455e 100644 --- a/src/Core/Identity/U2fTokenProvider.cs +++ b/src/Core/Identity/U2fTokenProvider.cs @@ -1,20 +1,20 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using Bit.Core.Models; -using Bit.Core.Repositories; -using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; -using U2fLib = U2F.Core.Crypto.U2F; -using U2F.Core.Models; -using U2F.Core.Exceptions; -using U2F.Core.Utils; -using System; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; +using U2F.Core.Exceptions; +using U2F.Core.Models; +using U2F.Core.Utils; +using U2fLib = U2F.Core.Crypto.U2F; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/UserStore.cs b/src/Core/Identity/UserStore.cs index 0aa7ffcc2..45ddeec45 100644 --- a/src/Core/Identity/UserStore.cs +++ b/src/Core/Identity/UserStore.cs @@ -1,12 +1,12 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; +using Bit.Core.Context; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; -using Bit.Core.Context; using Bit.Core.Settings; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.Identity diff --git a/src/Core/Identity/WebAuthnTokenProvider.cs b/src/Core/Identity/WebAuthnTokenProvider.cs index 7f2e5e415..18e44a0f7 100644 --- a/src/Core/Identity/WebAuthnTokenProvider.cs +++ b/src/Core/Identity/WebAuthnTokenProvider.cs @@ -1,18 +1,18 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using Bit.Core.Models; -using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; -using System; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models; +using Bit.Core.Models.Table; using Bit.Core.Services; -using Microsoft.Extensions.DependencyInjection; -using Fido2NetLib.Objects; -using Fido2NetLib; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Fido2NetLib; +using Fido2NetLib.Objects; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; namespace Bit.Core.Identity { diff --git a/src/Core/Identity/YubicoOtpTokenProvider.cs b/src/Core/Identity/YubicoOtpTokenProvider.cs index 249db4872..009f9f942 100644 --- a/src/Core/Identity/YubicoOtpTokenProvider.cs +++ b/src/Core/Identity/YubicoOtpTokenProvider.cs @@ -1,13 +1,13 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using YubicoDotNetClient; +using System; using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Table; using Bit.Core.Services; using Bit.Core.Settings; -using System; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; +using YubicoDotNetClient; namespace Bit.Core.Identity { diff --git a/src/Core/IdentityServer/ApiClient.cs b/src/Core/IdentityServer/ApiClient.cs index c950d3e50..56c2e2037 100644 --- a/src/Core/IdentityServer/ApiClient.cs +++ b/src/Core/IdentityServer/ApiClient.cs @@ -1,7 +1,7 @@ -using IdentityServer4.Models; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Settings; +using IdentityServer4.Models; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/ApiResources.cs b/src/Core/IdentityServer/ApiResources.cs index d0898b430..8c38104d0 100644 --- a/src/Core/IdentityServer/ApiResources.cs +++ b/src/Core/IdentityServer/ApiResources.cs @@ -1,6 +1,6 @@ -using IdentityModel; +using System.Collections.Generic; +using IdentityModel; using IdentityServer4.Models; -using System.Collections.Generic; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/ApiScopes.cs b/src/Core/IdentityServer/ApiScopes.cs index 76a362027..cea3023ca 100644 --- a/src/Core/IdentityServer/ApiScopes.cs +++ b/src/Core/IdentityServer/ApiScopes.cs @@ -1,5 +1,5 @@ -using IdentityServer4.Models; -using System.Collections.Generic; +using System.Collections.Generic; +using IdentityServer4.Models; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/BaseRequestValidator.cs b/src/Core/IdentityServer/BaseRequestValidator.cs index 972df3603..a48301958 100644 --- a/src/Core/IdentityServer/BaseRequestValidator.cs +++ b/src/Core/IdentityServer/BaseRequestValidator.cs @@ -1,25 +1,25 @@ -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using Bit.Core.Repositories; -using IdentityServer4.Validation; -using Microsoft.AspNetCore.Identity; -using System; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Reflection; using System.Security.Claims; using System.Text.Json; using System.Threading.Tasks; -using Bit.Core.Services; -using System.Linq; -using Bit.Core.Models; -using Bit.Core.Identity; -using Bit.Core.Models.Data; -using Bit.Core.Utilities; -using System.ComponentModel.DataAnnotations; -using System.Reflection; -using Microsoft.Extensions.Logging; -using Bit.Core.Models.Api; using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Identity; +using Bit.Core.Models; +using Bit.Core.Models.Api; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using IdentityServer4.Validation; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Logging; namespace Bit.Core.IdentityServer { @@ -319,7 +319,7 @@ namespace Bit.Core.IdentityServer var orgPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(userOrg.OrganizationId, PolicyType.RequireSso); // Owners and Admins are exempt from this policy - if (orgPolicy != null && orgPolicy.Enabled && + if (orgPolicy != null && orgPolicy.Enabled && userOrg.Type != OrganizationUserType.Owner && userOrg.Type != OrganizationUserType.Admin) { return false; diff --git a/src/Core/IdentityServer/ClientStore.cs b/src/Core/IdentityServer/ClientStore.cs index 8958820f7..5b3ae8c40 100644 --- a/src/Core/IdentityServer/ClientStore.cs +++ b/src/Core/IdentityServer/ClientStore.cs @@ -1,17 +1,17 @@ -using System.Linq; -using IdentityServer4.Stores; -using System.Threading.Tasks; -using IdentityServer4.Models; +using System; using System.Collections.Generic; -using Bit.Core.Repositories; -using System; -using IdentityModel; -using Bit.Core.Utilities; +using System.Collections.ObjectModel; +using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; +using Bit.Core.Context; +using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; -using Bit.Core.Context; -using System.Collections.ObjectModel; +using Bit.Core.Utilities; +using IdentityModel; +using IdentityServer4.Models; +using IdentityServer4.Stores; namespace Bit.Core.IdentityServer { @@ -45,7 +45,7 @@ namespace Bit.Core.IdentityServer _userRepository = userRepository; _globalSettings = globalSettings; _staticClientStore = staticClientStore; - _licensingService = licensingService; + _licensingService = licensingService; _currentContext = currentContext; _organizationUserRepository = organizationUserRepository; _providerUserRepository = providerUserRepository; @@ -138,11 +138,11 @@ namespace Bit.Core.IdentityServer var user = await _userRepository.GetByIdAsync(id); if (user != null) { - var claims = new Collection() + var claims = new Collection() { new ClientClaim(JwtClaimTypes.Subject, user.Id.ToString()), new ClientClaim(JwtClaimTypes.AuthenticationMethod, "Application", "external") - }; + }; var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, user.Id); var providers = await _currentContext.ProviderMembershipAsync(_providerUserRepository, user.Id); var isPremium = await _licensingService.ValidateUserPremiumAsync(user); diff --git a/src/Core/IdentityServer/ConfigureOpenIdConnectDistributedOptions.cs b/src/Core/IdentityServer/ConfigureOpenIdConnectDistributedOptions.cs index 50fa1dcfb..2e5826f6f 100644 --- a/src/Core/IdentityServer/ConfigureOpenIdConnectDistributedOptions.cs +++ b/src/Core/IdentityServer/ConfigureOpenIdConnectDistributedOptions.cs @@ -1,10 +1,10 @@ using System; +using Bit.Core.Settings; using IdentityServer4.Configuration; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Options; -using Bit.Core.Settings; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/CustomTokenRequestValidator.cs b/src/Core/IdentityServer/CustomTokenRequestValidator.cs index 876706ce9..ae7a74ff3 100644 --- a/src/Core/IdentityServer/CustomTokenRequestValidator.cs +++ b/src/Core/IdentityServer/CustomTokenRequestValidator.cs @@ -1,21 +1,21 @@ using System; -using Bit.Core.Models.Table; -using Bit.Core.Repositories; -using IdentityServer4.Validation; -using Microsoft.AspNetCore.Identity; using System.Collections.Generic; -using System.Security.Claims; -using System.Threading.Tasks; -using Bit.Core.Services; -using Bit.Core.Settings; -using Bit.Core.Context; using System.Linq; +using System.Security.Claims; using System.Text.Json; +using System.Threading.Tasks; +using Bit.Core.Context; using Bit.Core.Identity; using Bit.Core.Models.Data; -using Microsoft.Extensions.Logging; -using IdentityServer4.Extensions; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; using IdentityModel; +using IdentityServer4.Extensions; +using IdentityServer4.Validation; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Logging; namespace Bit.Core.IdentityServer { @@ -64,7 +64,7 @@ namespace Bit.Core.IdentityServer protected async override Task<(User, bool)> ValidateContextAsync(CustomTokenRequestValidationContext context) { - var email = context.Result.ValidatedRequest.Subject?.GetDisplayName() + var email = context.Result.ValidatedRequest.Subject?.GetDisplayName() ?? context.Result.ValidatedRequest.ClientClaims?.FirstOrDefault(claim => claim.Type == JwtClaimTypes.Email)?.Value; var user = string.IsNullOrWhiteSpace(email) ? null : await _userManager.FindByEmailAsync(email); return (user, user != null); @@ -94,7 +94,8 @@ namespace Bit.Core.IdentityServer // Apikey login if (context.Result.ValidatedRequest.GrantType == "client_credentials") { - if (user.UsesKeyConnector) { + if (user.UsesKeyConnector) + { // KeyConnectorUrl is configured in the CLI client, we just need to tell the client to use it context.Result.CustomResponse["ApiUseKeyConnector"] = true; context.Result.CustomResponse["ResetMasterPassword"] = false; @@ -129,8 +130,8 @@ namespace Bit.Core.IdentityServer context.Result.CustomResponse = customResponse; } - protected override void SetSsoResult(CustomTokenRequestValidationContext context, - Dictionary customResponse) + protected override void SetSsoResult(CustomTokenRequestValidationContext context, + Dictionary customResponse) { context.Result.Error = "invalid_grant"; context.Result.ErrorDescription = "Single Sign on required."; diff --git a/src/Core/IdentityServer/DistributedCacheCookieManager.cs b/src/Core/IdentityServer/DistributedCacheCookieManager.cs index 19b41cb8c..e18f5742a 100644 --- a/src/Core/IdentityServer/DistributedCacheCookieManager.cs +++ b/src/Core/IdentityServer/DistributedCacheCookieManager.cs @@ -22,7 +22,7 @@ namespace Bit.Core.IdentityServer { var id = Guid.NewGuid().ToString(); var cacheKey = GetKey(key, id); - + var expiresUtc = options.Expires ?? DateTimeOffset.UtcNow.AddMinutes(15); var cacheOptions = new DistributedCacheEntryOptions() .SetAbsoluteExpiration(expiresUtc); diff --git a/src/Core/IdentityServer/DistributedCacheTicketDataFormatter.cs b/src/Core/IdentityServer/DistributedCacheTicketDataFormatter.cs index e25aaf092..c1f6570b2 100644 --- a/src/Core/IdentityServer/DistributedCacheTicketDataFormatter.cs +++ b/src/Core/IdentityServer/DistributedCacheTicketDataFormatter.cs @@ -34,7 +34,7 @@ namespace Bit.Core.IdentityServer var options = new DistributedCacheEntryOptions(); options.SetAbsoluteExpiration(expiresUtc); - + var ticket = TicketSerializer.Default.Serialize(data); Cache.Set(cacheKey, ticket, options); diff --git a/src/Core/IdentityServer/OidcIdentityClient.cs b/src/Core/IdentityServer/OidcIdentityClient.cs index fafe46ae8..6bc7c5d46 100644 --- a/src/Core/IdentityServer/OidcIdentityClient.cs +++ b/src/Core/IdentityServer/OidcIdentityClient.cs @@ -1,7 +1,7 @@ -using IdentityServer4; -using IdentityServer4.Models; -using System.Collections.Generic; +using System.Collections.Generic; using Bit.Core.Settings; +using IdentityServer4; +using IdentityServer4.Models; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/ProfileService.cs b/src/Core/IdentityServer/ProfileService.cs index 2b29b11d2..353fa8778 100644 --- a/src/Core/IdentityServer/ProfileService.cs +++ b/src/Core/IdentityServer/ProfileService.cs @@ -1,16 +1,16 @@ -using IdentityServer4.Services; -using System.Threading.Tasks; -using IdentityServer4.Models; -using Bit.Core.Repositories; -using Bit.Core.Services; -using System.Security.Claims; +using System; using System.Collections.Generic; using System.Linq; -using System; -using IdentityModel; -using Bit.Core.Utilities; +using System.Security.Claims; +using System.Threading.Tasks; using Bit.Core.Context; +using Bit.Core.Repositories; +using Bit.Core.Services; using Bit.Core.Settings; +using Bit.Core.Utilities; +using IdentityModel; +using IdentityServer4.Models; +using IdentityServer4.Services; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/ResourceOwnerPasswordValidator.cs b/src/Core/IdentityServer/ResourceOwnerPasswordValidator.cs index 2f9387a75..c28d353e1 100644 --- a/src/Core/IdentityServer/ResourceOwnerPasswordValidator.cs +++ b/src/Core/IdentityServer/ResourceOwnerPasswordValidator.cs @@ -1,16 +1,16 @@ -using Bit.Core.Models.Table; +using System.Collections.Generic; +using System.Security.Claims; +using System.Threading.Tasks; +using Bit.Core.Context; +using Bit.Core.Identity; +using Bit.Core.Models.Table; using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Settings; +using Bit.Core.Utilities; using IdentityServer4.Models; using IdentityServer4.Validation; using Microsoft.AspNetCore.Identity; -using System.Collections.Generic; -using System.Security.Claims; -using System.Threading.Tasks; -using Bit.Core.Services; -using Bit.Core.Identity; -using Bit.Core.Context; -using Bit.Core.Settings; -using Bit.Core.Utilities; using Microsoft.Extensions.Logging; namespace Bit.Core.IdentityServer diff --git a/src/Core/IdentityServer/StaticClientStore.cs b/src/Core/IdentityServer/StaticClientStore.cs index c70598a5e..4007488ff 100644 --- a/src/Core/IdentityServer/StaticClientStore.cs +++ b/src/Core/IdentityServer/StaticClientStore.cs @@ -1,8 +1,8 @@ -using IdentityServer4.Models; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using Bit.Core.Settings; using Bit.Core.Enums; +using Bit.Core.Settings; +using IdentityServer4.Models; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/TokenRetrieval.cs b/src/Core/IdentityServer/TokenRetrieval.cs index 137162e79..6ae1b2814 100644 --- a/src/Core/IdentityServer/TokenRetrieval.cs +++ b/src/Core/IdentityServer/TokenRetrieval.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Http; -using System; +using System; using System.Linq; +using Microsoft.AspNetCore.Http; namespace Bit.Core.IdentityServer { diff --git a/src/Core/IdentityServer/VaultCorsPolicyService.cs b/src/Core/IdentityServer/VaultCorsPolicyService.cs index ba964939b..3fd9ffe30 100644 --- a/src/Core/IdentityServer/VaultCorsPolicyService.cs +++ b/src/Core/IdentityServer/VaultCorsPolicyService.cs @@ -1,7 +1,7 @@ -using Bit.Core.Utilities; -using IdentityServer4.Services; -using System.Threading.Tasks; +using System.Threading.Tasks; using Bit.Core.Settings; +using Bit.Core.Utilities; +using IdentityServer4.Services; namespace Bit.Core.IdentityServer { diff --git a/src/Core/Jobs/BaseJobsHostedService.cs b/src/Core/Jobs/BaseJobsHostedService.cs index 57b7b60fd..4bd384664 100644 --- a/src/Core/Jobs/BaseJobsHostedService.cs +++ b/src/Core/Jobs/BaseJobsHostedService.cs @@ -4,12 +4,12 @@ using System.Collections.Specialized; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Bit.Core.Settings; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Quartz; using Quartz.Impl; using Quartz.Impl.Matchers; -using Bit.Core.Settings; namespace Bit.Core.Jobs { diff --git a/src/Core/Models/Api/Request/ICaptchaProtectedModel.cs b/src/Core/Models/Api/Request/ICaptchaProtectedModel.cs index 939c1448b..9084ecc89 100644 --- a/src/Core/Models/Api/Request/ICaptchaProtectedModel.cs +++ b/src/Core/Models/Api/Request/ICaptchaProtectedModel.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Models.Api +namespace Bit.Core.Models.Api { public interface ICaptchaProtectedModel { diff --git a/src/Core/Models/Api/Request/PushRegistrationRequestModel.cs b/src/Core/Models/Api/Request/PushRegistrationRequestModel.cs index b628edc29..fd74b50af 100644 --- a/src/Core/Models/Api/Request/PushRegistrationRequestModel.cs +++ b/src/Core/Models/Api/Request/PushRegistrationRequestModel.cs @@ -1,5 +1,5 @@ -using Bit.Core.Enums; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Bit.Core.Enums; namespace Bit.Core.Models.Api { diff --git a/src/Core/Models/Api/Request/PushSendRequestModel.cs b/src/Core/Models/Api/Request/PushSendRequestModel.cs index fc4f47866..e54465317 100644 --- a/src/Core/Models/Api/Request/PushSendRequestModel.cs +++ b/src/Core/Models/Api/Request/PushSendRequestModel.cs @@ -1,6 +1,6 @@ -using Bit.Core.Enums; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Collections.Generic; +using Bit.Core.Enums; namespace Bit.Core.Models.Api { diff --git a/src/Core/Models/Api/Response/ErrorResponseModel.cs b/src/Core/Models/Api/Response/ErrorResponseModel.cs index bf56c97e3..ec73483f3 100644 --- a/src/Core/Models/Api/Response/ErrorResponseModel.cs +++ b/src/Core/Models/Api/Response/ErrorResponseModel.cs @@ -1,5 +1,5 @@ -using System.Linq; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Bit.Core.Models.Api diff --git a/src/Core/Models/Business/BillingInfo.cs b/src/Core/Models/Business/BillingInfo.cs index 46ea79f3d..fbe0de475 100644 --- a/src/Core/Models/Business/BillingInfo.cs +++ b/src/Core/Models/Business/BillingInfo.cs @@ -1,8 +1,8 @@ -using Bit.Core.Enums; +using System; +using System.Collections.Generic; +using Bit.Core.Enums; using Bit.Core.Models.Table; using Stripe; -using System; -using System.Collections.Generic; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Business/ExpiringToken.cs b/src/Core/Models/Business/ExpiringToken.cs index c2a782de5..3de031a5c 100644 --- a/src/Core/Models/Business/ExpiringToken.cs +++ b/src/Core/Models/Business/ExpiringToken.cs @@ -1,11 +1,11 @@ -using System; +using System; namespace Bit.Core.Models.Business { public class ExpiringToken { - public readonly string Token; - public readonly DateTime ExpirationDate; + public readonly string Token; + public readonly DateTime ExpirationDate; public ExpiringToken(string token, DateTime expirationDate) { diff --git a/src/Core/Models/Business/ImportedGroup.cs b/src/Core/Models/Business/ImportedGroup.cs index d6e967478..f85e03284 100644 --- a/src/Core/Models/Business/ImportedGroup.cs +++ b/src/Core/Models/Business/ImportedGroup.cs @@ -1,5 +1,5 @@ -using Bit.Core.Models.Table; -using System.Collections.Generic; +using System.Collections.Generic; +using Bit.Core.Models.Table; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Business/OrganizationLicense.cs b/src/Core/Models/Business/OrganizationLicense.cs index d493855e6..3f09ce9d1 100644 --- a/src/Core/Models/Business/OrganizationLicense.cs +++ b/src/Core/Models/Business/OrganizationLicense.cs @@ -1,14 +1,14 @@ -using Bit.Core.Enums; -using Bit.Core.Models.Table; -using Bit.Core.Services; -using Bit.Core.Settings; -using Newtonsoft.Json; -using System; +using System; using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; +using Bit.Core.Enums; +using Bit.Core.Models.Table; +using Bit.Core.Services; +using Bit.Core.Settings; +using Newtonsoft.Json; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Business/OrganizationUserInvite.cs b/src/Core/Models/Business/OrganizationUserInvite.cs index 8068495da..425a2ef76 100644 --- a/src/Core/Models/Business/OrganizationUserInvite.cs +++ b/src/Core/Models/Business/OrganizationUserInvite.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Bit.Core.Models.Data; namespace Bit.Core.Models.Business @@ -11,7 +11,7 @@ namespace Bit.Core.Models.Business public Permissions Permissions { get; set; } public IEnumerable Collections { get; set; } - public OrganizationUserInvite() {} + public OrganizationUserInvite() { } public OrganizationUserInvite(OrganizationUserInviteData requestModel) { diff --git a/src/Core/Models/Business/Provider/ProviderUserInvite.cs b/src/Core/Models/Business/Provider/ProviderUserInvite.cs index fc2fe01e0..782f3a2c3 100644 --- a/src/Core/Models/Business/Provider/ProviderUserInvite.cs +++ b/src/Core/Models/Business/Provider/ProviderUserInvite.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Bit.Core.Enums.Provider; diff --git a/src/Core/Models/Business/ReferenceEvent.cs b/src/Core/Models/Business/ReferenceEvent.cs index f4eedde6f..cd87441ac 100644 --- a/src/Core/Models/Business/ReferenceEvent.cs +++ b/src/Core/Models/Business/ReferenceEvent.cs @@ -24,7 +24,7 @@ namespace Bit.Core.Models.Business [JsonConverter(typeof(StringEnumConverter))] public ReferenceEventType Type { get; set; } - + [JsonConverter(typeof(StringEnumConverter))] public ReferenceEventSource Source { get; set; } diff --git a/src/Core/Models/Business/SubscriptionCreateOptions.cs b/src/Core/Models/Business/SubscriptionCreateOptions.cs index 75086c654..fd964dc25 100644 --- a/src/Core/Models/Business/SubscriptionCreateOptions.cs +++ b/src/Core/Models/Business/SubscriptionCreateOptions.cs @@ -1,6 +1,6 @@ +using System.Collections.Generic; using Bit.Core.Models.Table; using Stripe; -using System.Collections.Generic; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Business/SubscriptionInfo.cs b/src/Core/Models/Business/SubscriptionInfo.cs index 57b102ed6..b648dcb57 100644 --- a/src/Core/Models/Business/SubscriptionInfo.cs +++ b/src/Core/Models/Business/SubscriptionInfo.cs @@ -1,7 +1,7 @@ -using Stripe; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Stripe; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Business/SubscriptionUpdate.cs b/src/Core/Models/Business/SubscriptionUpdate.cs index f4c682fd2..aa131b0fe 100644 --- a/src/Core/Models/Business/SubscriptionUpdate.cs +++ b/src/Core/Models/Business/SubscriptionUpdate.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Models.Table; using Stripe; diff --git a/src/Core/Models/Business/UserLicense.cs b/src/Core/Models/Business/UserLicense.cs index 313b7223d..64ec47b0d 100644 --- a/src/Core/Models/Business/UserLicense.cs +++ b/src/Core/Models/Business/UserLicense.cs @@ -1,12 +1,12 @@ -using Bit.Core.Models.Table; -using Bit.Core.Services; -using Newtonsoft.Json; -using System; +using System; using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; +using Bit.Core.Models.Table; +using Bit.Core.Services; +using Newtonsoft.Json; namespace Bit.Core.Models.Business { diff --git a/src/Core/Models/Data/CipherAttachment.cs b/src/Core/Models/Data/CipherAttachment.cs index 29886537b..911180438 100644 --- a/src/Core/Models/Data/CipherAttachment.cs +++ b/src/Core/Models/Data/CipherAttachment.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System; +using System; +using Newtonsoft.Json; namespace Bit.Core.Models.Data { diff --git a/src/Core/Models/Data/EventMessage.cs b/src/Core/Models/Data/EventMessage.cs index 054fdae33..eaae3dfbb 100644 --- a/src/Core/Models/Data/EventMessage.cs +++ b/src/Core/Models/Data/EventMessage.cs @@ -1,6 +1,6 @@ using System; -using Bit.Core.Enums; using Bit.Core.Context; +using Bit.Core.Enums; using Bit.Core.Settings; namespace Bit.Core.Models.Data diff --git a/src/Core/Models/Data/EventTableEntity.cs b/src/Core/Models/Data/EventTableEntity.cs index 3b0f2fe14..7fcff2df4 100644 --- a/src/Core/Models/Data/EventTableEntity.cs +++ b/src/Core/Models/Data/EventTableEntity.cs @@ -143,7 +143,7 @@ namespace Bit.Core.Models.Data { return $"OrganizationId={e.OrganizationId}"; } - + if (e.ProviderId.HasValue) { return $"ProviderId={e.ProviderId}"; diff --git a/src/Core/Models/Data/GroupWithCollections.cs b/src/Core/Models/Data/GroupWithCollections.cs index a3cbe786f..dedd4f1e6 100644 --- a/src/Core/Models/Data/GroupWithCollections.cs +++ b/src/Core/Models/Data/GroupWithCollections.cs @@ -1,4 +1,4 @@ -using System.Data; +using System.Data; using Bit.Core.Models.Table; namespace Bit.Core.Models.Data diff --git a/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs b/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs index 78313c2c2..7adbc274f 100644 --- a/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs +++ b/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs @@ -15,7 +15,7 @@ namespace Bit.Core.Models.Data public bool UseEvents { get; set; } public bool UseTotp { get; set; } public bool Use2fa { get; set; } - public bool UseApi{ get; set; } + public bool UseApi { get; set; } public bool UseResetPassword { get; set; } public bool SelfHost { get; set; } public bool UsersGetPremium { get; set; } diff --git a/src/Core/Models/Data/OrganizationUserResetPasswordDetails.cs b/src/Core/Models/Data/OrganizationUserResetPasswordDetails.cs index 1d4327f8d..e8edf5436 100644 --- a/src/Core/Models/Data/OrganizationUserResetPasswordDetails.cs +++ b/src/Core/Models/Data/OrganizationUserResetPasswordDetails.cs @@ -12,12 +12,12 @@ namespace Bit.Core.Models.Data { throw new ArgumentNullException(nameof(orgUser)); } - + if (user == null) { throw new ArgumentNullException(nameof(user)); } - + if (org == null) { throw new ArgumentNullException(nameof(org)); diff --git a/src/Core/Models/Data/OrganizationUserWithCollections.cs b/src/Core/Models/Data/OrganizationUserWithCollections.cs index f1b7d11f6..7070e009c 100644 --- a/src/Core/Models/Data/OrganizationUserWithCollections.cs +++ b/src/Core/Models/Data/OrganizationUserWithCollections.cs @@ -1,4 +1,4 @@ -using System.Data; +using System.Data; using Bit.Core.Models.Table; namespace Bit.Core.Models.Data diff --git a/src/Core/Models/Data/Permissions.cs b/src/Core/Models/Data/Permissions.cs index ac0bb7613..507c22035 100644 --- a/src/Core/Models/Data/Permissions.cs +++ b/src/Core/Models/Data/Permissions.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Generic; using Newtonsoft.Json; -namespace Bit.Core.Models.Data +namespace Bit.Core.Models.Data { public class Permissions { diff --git a/src/Core/Models/Data/Provider/ProviderUserOrganizationDetails.cs b/src/Core/Models/Data/Provider/ProviderUserOrganizationDetails.cs index 38c5bb210..62a19fabd 100644 --- a/src/Core/Models/Data/Provider/ProviderUserOrganizationDetails.cs +++ b/src/Core/Models/Data/Provider/ProviderUserOrganizationDetails.cs @@ -16,7 +16,7 @@ namespace Bit.Core.Models.Data public bool UseEvents { get; set; } public bool UseTotp { get; set; } public bool Use2fa { get; set; } - public bool UseApi{ get; set; } + public bool UseApi { get; set; } public bool UseResetPassword { get; set; } public bool SelfHost { get; set; } public bool UsersGetPremium { get; set; } diff --git a/src/Core/Models/Data/SendOptionsPolicyData.cs b/src/Core/Models/Data/SendOptionsPolicyData.cs index fe789abb5..d3898fd85 100644 --- a/src/Core/Models/Data/SendOptionsPolicyData.cs +++ b/src/Core/Models/Data/SendOptionsPolicyData.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Bit.Core.Models.Data { diff --git a/src/Core/Models/Data/SsoConfigurationData.cs b/src/Core/Models/Data/SsoConfigurationData.cs index b8745e604..23375a6e0 100644 --- a/src/Core/Models/Data/SsoConfigurationData.cs +++ b/src/Core/Models/Data/SsoConfigurationData.cs @@ -95,19 +95,19 @@ namespace Bit.Core.Models.Data .Where(c => !string.IsNullOrWhiteSpace(c))? .Select(c => c.Trim()) ?? Array.Empty(); - + public IEnumerable GetAdditionalUserIdClaimTypes() => AdditionalUserIdClaimTypes? .Split(',')? .Where(c => !string.IsNullOrWhiteSpace(c))? .Select(c => c.Trim()) ?? Array.Empty(); - + public IEnumerable GetAdditionalEmailClaimTypes() => AdditionalEmailClaimTypes? .Split(',')? .Where(c => !string.IsNullOrWhiteSpace(c))? .Select(c => c.Trim()) ?? Array.Empty(); - + public IEnumerable GetAdditionalNameClaimTypes() => AdditionalNameClaimTypes? .Split(',')? .Where(c => !string.IsNullOrWhiteSpace(c))? diff --git a/src/Core/Models/EntityFramework/Collection.cs b/src/Core/Models/EntityFramework/Collection.cs index 697f724d9..4b4688cef 100644 --- a/src/Core/Models/EntityFramework/Collection.cs +++ b/src/Core/Models/EntityFramework/Collection.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/CollectionCipher.cs b/src/Core/Models/EntityFramework/CollectionCipher.cs index 00650b92d..fcff668a7 100644 --- a/src/Core/Models/EntityFramework/CollectionCipher.cs +++ b/src/Core/Models/EntityFramework/CollectionCipher.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/CollectionGroup.cs b/src/Core/Models/EntityFramework/CollectionGroup.cs index afd714fdf..ba97c366f 100644 --- a/src/Core/Models/EntityFramework/CollectionGroup.cs +++ b/src/Core/Models/EntityFramework/CollectionGroup.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework { diff --git a/src/Core/Models/EntityFramework/CollectionUser.cs b/src/Core/Models/EntityFramework/CollectionUser.cs index ec5a7e62e..f959728df 100644 --- a/src/Core/Models/EntityFramework/CollectionUser.cs +++ b/src/Core/Models/EntityFramework/CollectionUser.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework { diff --git a/src/Core/Models/EntityFramework/Device.cs b/src/Core/Models/EntityFramework/Device.cs index a70e97cc3..b6032c416 100644 --- a/src/Core/Models/EntityFramework/Device.cs +++ b/src/Core/Models/EntityFramework/Device.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/EmergencyAccess.cs b/src/Core/Models/EntityFramework/EmergencyAccess.cs index 950e386b7..3211a8dd2 100644 --- a/src/Core/Models/EntityFramework/EmergencyAccess.cs +++ b/src/Core/Models/EntityFramework/EmergencyAccess.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Event.cs b/src/Core/Models/EntityFramework/Event.cs index db66f3330..f7300d313 100644 --- a/src/Core/Models/EntityFramework/Event.cs +++ b/src/Core/Models/EntityFramework/Event.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework { diff --git a/src/Core/Models/EntityFramework/Folder.cs b/src/Core/Models/EntityFramework/Folder.cs index 6e5bdaf0f..8e8da6874 100644 --- a/src/Core/Models/EntityFramework/Folder.cs +++ b/src/Core/Models/EntityFramework/Folder.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Grant.cs b/src/Core/Models/EntityFramework/Grant.cs index e110233d9..7c349b26b 100644 --- a/src/Core/Models/EntityFramework/Grant.cs +++ b/src/Core/Models/EntityFramework/Grant.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Group.cs b/src/Core/Models/EntityFramework/Group.cs index 122ded667..b40a0f0f6 100644 --- a/src/Core/Models/EntityFramework/Group.cs +++ b/src/Core/Models/EntityFramework/Group.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/GroupUser.cs b/src/Core/Models/EntityFramework/GroupUser.cs index 55f18d8ad..f1635aed2 100644 --- a/src/Core/Models/EntityFramework/GroupUser.cs +++ b/src/Core/Models/EntityFramework/GroupUser.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Installation.cs b/src/Core/Models/EntityFramework/Installation.cs index 6b65fdd29..b50f045c2 100644 --- a/src/Core/Models/EntityFramework/Installation.cs +++ b/src/Core/Models/EntityFramework/Installation.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/OrganizationUser.cs b/src/Core/Models/EntityFramework/OrganizationUser.cs index de75f24d6..74dd98fae 100644 --- a/src/Core/Models/EntityFramework/OrganizationUser.cs +++ b/src/Core/Models/EntityFramework/OrganizationUser.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Policy.cs b/src/Core/Models/EntityFramework/Policy.cs index 3646e58ad..d9f2f1db3 100644 --- a/src/Core/Models/EntityFramework/Policy.cs +++ b/src/Core/Models/EntityFramework/Policy.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Provider/Provider.cs b/src/Core/Models/EntityFramework/Provider/Provider.cs index fc595b449..8f96192e2 100644 --- a/src/Core/Models/EntityFramework/Provider/Provider.cs +++ b/src/Core/Models/EntityFramework/Provider/Provider.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework.Provider { diff --git a/src/Core/Models/EntityFramework/Provider/ProviderOrganization.cs b/src/Core/Models/EntityFramework/Provider/ProviderOrganization.cs index 5f1077d81..f05216946 100644 --- a/src/Core/Models/EntityFramework/Provider/ProviderOrganization.cs +++ b/src/Core/Models/EntityFramework/Provider/ProviderOrganization.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework.Provider { diff --git a/src/Core/Models/EntityFramework/Provider/ProviderUser.cs b/src/Core/Models/EntityFramework/Provider/ProviderUser.cs index 14d22764f..7b4480073 100644 --- a/src/Core/Models/EntityFramework/Provider/ProviderUser.cs +++ b/src/Core/Models/EntityFramework/Provider/ProviderUser.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; namespace Bit.Core.Models.EntityFramework.Provider { diff --git a/src/Core/Models/EntityFramework/Role.cs b/src/Core/Models/EntityFramework/Role.cs index 706e6cbd1..b55a1ddc7 100644 --- a/src/Core/Models/EntityFramework/Role.cs +++ b/src/Core/Models/EntityFramework/Role.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Send.cs b/src/Core/Models/EntityFramework/Send.cs index 517e07749..7343b3216 100644 --- a/src/Core/Models/EntityFramework/Send.cs +++ b/src/Core/Models/EntityFramework/Send.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/SsoConfig.cs b/src/Core/Models/EntityFramework/SsoConfig.cs index 74b83f661..be86fa522 100644 --- a/src/Core/Models/EntityFramework/SsoConfig.cs +++ b/src/Core/Models/EntityFramework/SsoConfig.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/SsoUser.cs b/src/Core/Models/EntityFramework/SsoUser.cs index 616e4d864..c3aef552f 100644 --- a/src/Core/Models/EntityFramework/SsoUser.cs +++ b/src/Core/Models/EntityFramework/SsoUser.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/TaxRate.cs b/src/Core/Models/EntityFramework/TaxRate.cs index 1fe2b499e..bf3605d21 100644 --- a/src/Core/Models/EntityFramework/TaxRate.cs +++ b/src/Core/Models/EntityFramework/TaxRate.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/Transaction.cs b/src/Core/Models/EntityFramework/Transaction.cs index bef6271df..820f8091b 100644 --- a/src/Core/Models/EntityFramework/Transaction.cs +++ b/src/Core/Models/EntityFramework/Transaction.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/EntityFramework/U2f.cs b/src/Core/Models/EntityFramework/U2f.cs index 206baff10..9fee7f35c 100644 --- a/src/Core/Models/EntityFramework/U2f.cs +++ b/src/Core/Models/EntityFramework/U2f.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Text.Json; using AutoMapper; diff --git a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferExistingAccountViewModel.cs b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferExistingAccountViewModel.cs index 8d25a3377..82c86a03d 100644 --- a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferExistingAccountViewModel.cs +++ b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferExistingAccountViewModel.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Models.Mail.FamiliesForEnterprise +namespace Bit.Core.Models.Mail.FamiliesForEnterprise { public class FamiliesForEnterpriseOfferExistingAccountViewModel : BaseMailModel { diff --git a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferNewAccountViewModel.cs b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferNewAccountViewModel.cs index 72999fefd..52462296a 100644 --- a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferNewAccountViewModel.cs +++ b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseOfferNewAccountViewModel.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Models.Mail.FamiliesForEnterprise +namespace Bit.Core.Models.Mail.FamiliesForEnterprise { public class FamiliesForEnterpriseOfferNewAccountViewModel : BaseMailModel { diff --git a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseSponsorshipRevertingViewModel.cs b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseSponsorshipRevertingViewModel.cs index e8185000b..b9de49db8 100644 --- a/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseSponsorshipRevertingViewModel.cs +++ b/src/Core/Models/Mail/FamiliesForEnterprise/FamiliesForEnterpriseSponsorshipRevertingViewModel.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Models.Mail.FamiliesForEnterprise +namespace Bit.Core.Models.Mail.FamiliesForEnterprise { public class FamiliesForEnterpriseSponsorshipRevertingViewModel : BaseMailModel { diff --git a/src/Core/Models/Mail/IMailQueueMessage.cs b/src/Core/Models/Mail/IMailQueueMessage.cs index 89899c0e8..32ec67db4 100644 --- a/src/Core/Models/Mail/IMailQueueMessage.cs +++ b/src/Core/Models/Mail/IMailQueueMessage.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace Bit.Core.Models.Mail { diff --git a/src/Core/Models/Mail/MailQueueMessage.cs b/src/Core/Models/Mail/MailQueueMessage.cs index 2fdc56750..5dd9616b9 100644 --- a/src/Core/Models/Mail/MailQueueMessage.cs +++ b/src/Core/Models/Mail/MailQueueMessage.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using System.Collections.Generic; using Bit.Core.Utilities; +using Newtonsoft.Json; namespace Bit.Core.Models.Mail { diff --git a/src/Core/Models/Mail/OrganizationSeatsAutoscaledViewModel.cs b/src/Core/Models/Mail/OrganizationSeatsAutoscaledViewModel.cs index 8a2f30ee0..4c7df5bbf 100644 --- a/src/Core/Models/Mail/OrganizationSeatsAutoscaledViewModel.cs +++ b/src/Core/Models/Mail/OrganizationSeatsAutoscaledViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Bit.Core.Models.Mail { diff --git a/src/Core/Models/Mail/OrganizationSeatsMaxReachedViewModel.cs b/src/Core/Models/Mail/OrganizationSeatsMaxReachedViewModel.cs index 18ea3b058..44cad6f20 100644 --- a/src/Core/Models/Mail/OrganizationSeatsMaxReachedViewModel.cs +++ b/src/Core/Models/Mail/OrganizationSeatsMaxReachedViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Bit.Core.Models.Mail { diff --git a/src/Core/Models/PushNotification.cs b/src/Core/Models/PushNotification.cs index b5d4d3702..cf11f5a37 100644 --- a/src/Core/Models/PushNotification.cs +++ b/src/Core/Models/PushNotification.cs @@ -1,6 +1,6 @@ -using Bit.Core.Enums; -using System; +using System; using System.Collections.Generic; +using Bit.Core.Enums; namespace Bit.Core.Models { @@ -12,7 +12,7 @@ namespace Bit.Core.Models Payload = payload; ContextId = contextId; } - + public PushType Type { get; set; } public T Payload { get; set; } public string ContextId { get; set; } diff --git a/src/Core/Models/StaticStore/SponsoredPlan.cs b/src/Core/Models/StaticStore/SponsoredPlan.cs index f9c7b2b6b..7624db1e3 100644 --- a/src/Core/Models/StaticStore/SponsoredPlan.cs +++ b/src/Core/Models/StaticStore/SponsoredPlan.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Enums; using Bit.Core.Models.Data; diff --git a/src/Core/Models/Table/Cipher.cs b/src/Core/Models/Table/Cipher.cs index cf9ba9a7e..34efec508 100644 --- a/src/Core/Models/Table/Cipher.cs +++ b/src/Core/Models/Table/Cipher.cs @@ -1,8 +1,8 @@ using System; -using Bit.Core.Utilities; -using Bit.Core.Models.Data; -using Newtonsoft.Json; using System.Collections.Generic; +using Bit.Core.Models.Data; +using Bit.Core.Utilities; +using Newtonsoft.Json; namespace Bit.Core.Models.Table { diff --git a/src/Core/Models/Table/CollectionGroup.cs b/src/Core/Models/Table/CollectionGroup.cs index b510e05e0..4a34e39a4 100644 --- a/src/Core/Models/Table/CollectionGroup.cs +++ b/src/Core/Models/Table/CollectionGroup.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Utilities; namespace Bit.Core.Models.Table diff --git a/src/Core/Models/Table/CollectionUser.cs b/src/Core/Models/Table/CollectionUser.cs index 3bcf15d70..153b130f7 100644 --- a/src/Core/Models/Table/CollectionUser.cs +++ b/src/Core/Models/Table/CollectionUser.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Utilities; namespace Bit.Core.Models.Table diff --git a/src/Core/Models/Table/EmergencyAccess.cs b/src/Core/Models/Table/EmergencyAccess.cs index 0e256cff3..b14729184 100644 --- a/src/Core/Models/Table/EmergencyAccess.cs +++ b/src/Core/Models/Table/EmergencyAccess.cs @@ -25,7 +25,7 @@ namespace Bit.Core.Models.Table { Id = CoreHelpers.GenerateComb(); } - + public EmergencyAccess ToEmergencyAccess() { return new EmergencyAccess diff --git a/src/Core/Models/Table/Installation.cs b/src/Core/Models/Table/Installation.cs index 631fa5bf6..8d8140438 100644 --- a/src/Core/Models/Table/Installation.cs +++ b/src/Core/Models/Table/Installation.cs @@ -1,6 +1,6 @@ -using Bit.Core.Utilities; -using System; +using System; using System.ComponentModel.DataAnnotations; +using Bit.Core.Utilities; namespace Bit.Core.Models.Table { diff --git a/src/Core/Models/Table/Organization.cs b/src/Core/Models/Table/Organization.cs index 644017bac..fb5870236 100644 --- a/src/Core/Models/Table/Organization.cs +++ b/src/Core/Models/Table/Organization.cs @@ -1,10 +1,10 @@ using System; -using Bit.Core.Utilities; -using Bit.Core.Enums; using System.Collections.Generic; -using Newtonsoft.Json; -using System.Linq; using System.ComponentModel.DataAnnotations; +using System.Linq; +using Bit.Core.Enums; +using Bit.Core.Utilities; +using Newtonsoft.Json; namespace Bit.Core.Models.Table { diff --git a/src/Core/Models/Table/OrganizationSponsorship.cs b/src/Core/Models/Table/OrganizationSponsorship.cs index 11be3c66c..4acb7eb88 100644 --- a/src/Core/Models/Table/OrganizationSponsorship.cs +++ b/src/Core/Models/Table/OrganizationSponsorship.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; using Bit.Core.Utilities; diff --git a/src/Core/Models/Table/OrganizationUser.cs b/src/Core/Models/Table/OrganizationUser.cs index 5a275ec75..9019adeb3 100644 --- a/src/Core/Models/Table/OrganizationUser.cs +++ b/src/Core/Models/Table/OrganizationUser.cs @@ -1,7 +1,7 @@ using System; -using Bit.Core.Utilities; -using Bit.Core.Enums; using System.ComponentModel.DataAnnotations; +using Bit.Core.Enums; +using Bit.Core.Utilities; namespace Bit.Core.Models.Table { diff --git a/src/Core/Models/Table/TaxRate.cs b/src/Core/Models/Table/TaxRate.cs index a9a758577..bed82d0df 100644 --- a/src/Core/Models/Table/TaxRate.cs +++ b/src/Core/Models/Table/TaxRate.cs @@ -1,24 +1,24 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Bit.Core.Models.Table { - public class TaxRate: ITableObject - { - [MaxLength(40)] - public string Id { get; set; } - [MaxLength(50)] - public string Country { get; set; } - [MaxLength(2)] - public string State { get; set; } - [MaxLength(10)] - public string PostalCode { get; set; } - public decimal Rate { get; set; } - public bool Active { get; set; } + public class TaxRate : ITableObject + { + [MaxLength(40)] + public string Id { get; set; } + [MaxLength(50)] + public string Country { get; set; } + [MaxLength(2)] + public string State { get; set; } + [MaxLength(10)] + public string PostalCode { get; set; } + public decimal Rate { get; set; } + public bool Active { get; set; } - public void SetNewId() - { - // Id is created by Stripe, should exist before this gets called - return; - } - } + public void SetNewId() + { + // Id is created by Stripe, should exist before this gets called + return; + } + } } diff --git a/src/Core/Models/Table/User.cs b/src/Core/Models/Table/User.cs index 1ad875a1c..beb290dec 100644 --- a/src/Core/Models/Table/User.cs +++ b/src/Core/Models/Table/User.cs @@ -1,10 +1,10 @@ using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; using Bit.Core.Utilities; -using System.Collections.Generic; -using Newtonsoft.Json; using Microsoft.AspNetCore.Identity; -using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; namespace Bit.Core.Models.Table { diff --git a/src/Core/Models/TwoFactorProvider.cs b/src/Core/Models/TwoFactorProvider.cs index c4f786559..2468c6699 100644 --- a/src/Core/Models/TwoFactorProvider.cs +++ b/src/Core/Models/TwoFactorProvider.cs @@ -1,11 +1,11 @@ -using Bit.Core.Enums; +using System; +using System.Collections.Generic; +using System.Security.Cryptography; +using Bit.Core.Enums; using Fido2NetLib.Objects; using Microsoft.Extensions.Options; using Newtonsoft.Json; using PeterO.Cbor; -using System; -using System.Collections.Generic; -using System.Security.Cryptography; using U2F.Core.Utils; namespace Bit.Core.Models diff --git a/src/Core/Repositories/EntityFramework/BaseEntityFrameworkRepository.cs b/src/Core/Repositories/EntityFramework/BaseEntityFrameworkRepository.cs index d1b20764d..2e842fbc9 100644 --- a/src/Core/Repositories/EntityFramework/BaseEntityFrameworkRepository.cs +++ b/src/Core/Repositories/EntityFramework/BaseEntityFrameworkRepository.cs @@ -1,17 +1,17 @@ -using AutoMapper; -using Bit.Core.Models.Table; -using Bit.Core.Repositories.EntityFramework.Queries; -using EfModel = Bit.Core.Models.EntityFramework; -using LinqToDB.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Threading.Tasks; -using System; +using AutoMapper; using Bit.Core.Enums; using Bit.Core.Enums.Provider; +using Bit.Core.Models.Table; +using Bit.Core.Repositories.EntityFramework.Queries; +using LinqToDB.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using EfModel = Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework { @@ -70,7 +70,7 @@ namespace Bit.Core.Repositories.EntityFramework var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher); var users = query.Run(dbContext); - await users.ForEachAsync(e => + await users.ForEachAsync(e => { dbContext.Attach(e); e.RevisionDate = DateTime.UtcNow; @@ -87,7 +87,7 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var query = new UserBumpAccountRevisionDateByOrganizationIdQuery(organizationId); var users = query.Run(dbContext); - await users.ForEachAsync(e => + await users.ForEachAsync(e => { dbContext.Attach(e); e.RevisionDate = DateTime.UtcNow; @@ -107,7 +107,7 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var users = dbContext.Users.Where(u => userIds.Contains(u.Id)); - await users.ForEachAsync(u => + await users.ForEachAsync(u => { dbContext.Attach(u); u.RevisionDate = DateTime.UtcNow; @@ -195,31 +195,31 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from u in dbContext.Users - join ou in dbContext.OrganizationUsers - on u.Id equals ou.UserId - join cu in dbContext.CollectionUsers - on ou.Id equals cu.OrganizationUserId into cu_g - from cu in cu_g.DefaultIfEmpty() - where !ou.AccessAll && cu.CollectionId.Equals(collectionId) - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == default(Guid) && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on gu.GroupId equals cg.GroupId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.CollectionId == collectionId && - (ou.OrganizationId == organizationId && ou.Status == OrganizationUserStatusType.Confirmed && - (cu.CollectionId != default(Guid) || cg.CollectionId != default(Guid) || ou.AccessAll || g.AccessAll)) - select new { u, ou, cu, gu, g, cg }; + join ou in dbContext.OrganizationUsers + on u.Id equals ou.UserId + join cu in dbContext.CollectionUsers + on ou.Id equals cu.OrganizationUserId into cu_g + from cu in cu_g.DefaultIfEmpty() + where !ou.AccessAll && cu.CollectionId.Equals(collectionId) + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == default(Guid) && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on gu.GroupId equals cg.GroupId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.CollectionId == collectionId && + (ou.OrganizationId == organizationId && ou.Status == OrganizationUserStatusType.Confirmed && + (cu.CollectionId != default(Guid) || cg.CollectionId != default(Guid) || ou.AccessAll || g.AccessAll)) + select new { u, ou, cu, gu, g, cg }; var users = query.Select(x => x.u); - await users.ForEachAsync(u => + await users.ForEachAsync(u => { dbContext.Attach(u); - u.RevisionDate = DateTime.UtcNow; + u.RevisionDate = DateTime.UtcNow; }); await dbContext.SaveChangesAsync(); } @@ -231,12 +231,12 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from u in dbContext.Users - join ou in dbContext.OrganizationUsers - on u.Id equals ou.UserId - where ou.Id.Equals(organizationUserId) && ou.Status.Equals(OrganizationUserStatusType.Confirmed) - select new { u, ou }; + join ou in dbContext.OrganizationUsers + on u.Id equals ou.UserId + where ou.Id.Equals(organizationUserId) && ou.Status.Equals(OrganizationUserStatusType.Confirmed) + select new { u, ou }; var users = query.Select(x => x.u); - await users.ForEachAsync(u => + await users.ForEachAsync(u => { dbContext.Attach(u); u.AccountRevisionDate = DateTime.UtcNow; @@ -251,13 +251,14 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from pu in dbContext.ProviderUsers - join u in dbContext.Users - on pu.UserId equals u.Id - where pu.Status.Equals(ProviderUserStatusType.Confirmed) && - providerUserIds.Contains(pu.Id) - select new { pu, u }; + join u in dbContext.Users + on pu.UserId equals u.Id + where pu.Status.Equals(ProviderUserStatusType.Confirmed) && + providerUserIds.Contains(pu.Id) + select new { pu, u }; var users = query.Select(x => x.u); - await users.ForEachAsync(u => { + await users.ForEachAsync(u => + { dbContext.Attach(u); u.AccountRevisionDate = DateTime.UtcNow; }); diff --git a/src/Core/Repositories/EntityFramework/CipherRepository.cs b/src/Core/Repositories/EntityFramework/CipherRepository.cs index f365d0da0..279637d45 100644 --- a/src/Core/Repositories/EntityFramework/CipherRepository.cs +++ b/src/Core/Repositories/EntityFramework/CipherRepository.cs @@ -1,22 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using AutoMapper; +using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework.Queries; using Bit.Core.Utilities; using Core.Models.Data; -using EfModel = Bit.Core.Models.EntityFramework; using LinqToDB.Data; using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using Newtonsoft.Json; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System; +using Newtonsoft.Json.Linq; +using EfModel = Bit.Core.Models.EntityFramework; using TableModel = Bit.Core.Models.Table; -using Bit.Core.Enums; namespace Bit.Core.Repositories.EntityFramework { @@ -85,8 +85,8 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var userIdKey = $"\"{cipher.UserId}\""; cipher.UserId = cipher.OrganizationId.HasValue ? null : cipher.UserId; - cipher.Favorites = cipher.Favorite ? - $"{{{userIdKey}:true}}" : + cipher.Favorites = cipher.Favorite ? + $"{{{userIdKey}:true}}" : null; cipher.Folders = cipher.FolderId.HasValue ? $"{{{userIdKey}:\"{cipher.FolderId}\"}}" : @@ -125,9 +125,9 @@ namespace Bit.Core.Repositories.EntityFramework public async Task CreateAsync(IEnumerable ciphers, IEnumerable collections, IEnumerable collectionCiphers) { - if (!ciphers.Any()) + if (!ciphers.Any()) { - return; + return; } using (var scope = ServiceScopeFactory.CreateScope()) { @@ -201,15 +201,15 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var collectionCiphers = from cc in dbContext.CollectionCiphers - join c in dbContext.Collections - on cc.CollectionId equals c.Id - where c.OrganizationId == organizationId - select cc; + join c in dbContext.Collections + on cc.CollectionId equals c.Id + where c.OrganizationId == organizationId + select cc; dbContext.RemoveRange(collectionCiphers); var ciphers = from c in dbContext.Ciphers - where c.OrganizationId == organizationId - select c; + where c.OrganizationId == organizationId + select c; dbContext.RemoveRange(ciphers); await dbContext.SaveChangesAsync(); @@ -224,12 +224,12 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var ciphers = from c in dbContext.Ciphers - where c.UserId == userId - select c; + where c.UserId == userId + select c; dbContext.RemoveRange(ciphers); var folders = from f in dbContext.Folders - where f.UserId == userId - select f; + where f.UserId == userId + select f; dbContext.RemoveRange(folders); await dbContext.SaveChangesAsync(); await UserUpdateStorage(userId); @@ -287,29 +287,30 @@ namespace Bit.Core.Repositories.EntityFramework using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); - IQueryable cipherDetailsView = withOrganizations ? + IQueryable cipherDetailsView = withOrganizations ? new UserCipherDetailsQuery(userId).Run(dbContext) : new CipherDetailsQuery(userId).Run(dbContext); if (!withOrganizations) { cipherDetailsView = from c in cipherDetailsView - where c.UserId == userId - select new CipherDetails { - Id = c.Id, - UserId = c.UserId, - OrganizationId = c.OrganizationId, - Type= c.Type, - Data = c.Data, - Attachments = c.Attachments, - CreationDate = c.CreationDate, - RevisionDate = c.RevisionDate, - DeletedDate = c.DeletedDate, - Favorite = c.Favorite, - FolderId = c.FolderId, - Edit = true, - ViewPassword = true, - OrganizationUseTotp = false, - }; + where c.UserId == userId + select new CipherDetails + { + Id = c.Id, + UserId = c.UserId, + OrganizationId = c.OrganizationId, + Type = c.Type, + Data = c.Data, + Attachments = c.Attachments, + CreationDate = c.CreationDate, + RevisionDate = c.RevisionDate, + DeletedDate = c.DeletedDate, + Favorite = c.Favorite, + FolderId = c.FolderId, + Edit = true, + ViewPassword = true, + OrganizationUseTotp = false, + }; } var ciphers = await cipherDetailsView.ToListAsync(); return ciphers; @@ -335,13 +336,13 @@ namespace Bit.Core.Repositories.EntityFramework var cipherEntities = dbContext.Ciphers.Where(c => ids.Contains(c.Id)); var userCipherDetails = new UserCipherDetailsQuery(userId).Run(dbContext); var idsToMove = from ucd in userCipherDetails - join c in cipherEntities - on ucd.Id equals c.Id - where ucd.Edit - select c; - await idsToMove.ForEachAsync(cipher => + join c in cipherEntities + on ucd.Id equals c.Id + where ucd.Edit + select c; + await idsToMove.ForEachAsync(cipher => { - var foldersJson = string.IsNullOrWhiteSpace(cipher.Folders) ? + var foldersJson = string.IsNullOrWhiteSpace(cipher.Folders) ? new JObject() : JObject.Parse(cipher.Folders); @@ -356,7 +357,7 @@ namespace Bit.Core.Repositories.EntityFramework } dbContext.Attach(cipher); cipher.Folders = JsonConvert.SerializeObject(foldersJson); - }); + }); await dbContext.SaveChangesAsync(); await UserBumpAccountRevisionDate(userId); } @@ -476,10 +477,10 @@ namespace Bit.Core.Repositories.EntityFramework var userCipherDetailsQuery = new UserCipherDetailsQuery(userId); var cipherEntitiesToCheck = await (dbContext.Ciphers.Where(c => ids.Contains(c.Id))).ToListAsync(); var query = from ucd in await (userCipherDetailsQuery.Run(dbContext)).ToListAsync() - join c in cipherEntitiesToCheck - on ucd.Id equals c.Id - where ucd.Edit && ucd.DeletedDate == null - select c; + join c in cipherEntitiesToCheck + on ucd.Id equals c.Id + where ucd.Edit && ucd.DeletedDate == null + select c; var utcNow = DateTime.UtcNow; var cipherIdsToModify = query.Select(c => c.Id); @@ -488,9 +489,9 @@ namespace Bit.Core.Repositories.EntityFramework { dbContext.RemoveRange(cipherEntitiesToModify); } - else + else { - await cipherEntitiesToModify.ForEachAsync(cipher => + await cipherEntitiesToModify.ForEachAsync(cipher => { dbContext.Attach(cipher); cipher.DeletedDate = action == CipherStateAction.Restore ? null : utcNow; @@ -524,12 +525,12 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var utcNow = DateTime.UtcNow; var ciphers = dbContext.Ciphers.Where(c => ids.Contains(c.Id) && c.OrganizationId == organizationId); - await ciphers.ForEachAsync(cipher => + await ciphers.ForEachAsync(cipher => { dbContext.Attach(cipher); cipher.DeletedDate = utcNow; cipher.RevisionDate = utcNow; - }); + }); await dbContext.SaveChangesAsync(); await OrganizationUpdateStorage(organizationId); await UserBumpAccountRevisionDateByOrganizationId(organizationId); @@ -562,9 +563,9 @@ namespace Bit.Core.Repositories.EntityFramework public async Task UpdateCiphersAsync(Guid userId, IEnumerable ciphers) { - if (!ciphers.Any()) + if (!ciphers.Any()) { - return; + return; } using (var scope = ServiceScopeFactory.CreateScope()) { @@ -591,7 +592,7 @@ namespace Bit.Core.Repositories.EntityFramework { foldersJson[userId] = folderId.Value; } - else + else { foldersJson.Remove(userId.ToString()); } @@ -601,7 +602,7 @@ namespace Bit.Core.Repositories.EntityFramework { favoritesJson.Add(userId.ToString(), favorite); } - else + else { favoritesJson.Remove(userId.ToString()); } diff --git a/src/Core/Repositories/EntityFramework/CollectionCipherRepository.cs b/src/Core/Repositories/EntityFramework/CollectionCipherRepository.cs index e1e788d69..e7f958008 100644 --- a/src/Core/Repositories/EntityFramework/CollectionCipherRepository.cs +++ b/src/Core/Repositories/EntityFramework/CollectionCipherRepository.cs @@ -1,14 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using AutoMapper; using Bit.Core.Enums; using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework.Queries; -using EfModel = Bit.Core.Models.EntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System; +using EfModel = Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework { @@ -41,10 +41,10 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var data = await (from cc in dbContext.CollectionCiphers - join c in dbContext.Collections - on cc.CollectionId equals c.Id - where c.OrganizationId == organizationId - select cc).ToArrayAsync(); + join c in dbContext.Collections + on cc.CollectionId equals c.Id + where c.OrganizationId == organizationId + select cc).ToArrayAsync(); return data; } } @@ -80,45 +80,45 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var organizationId = (await dbContext.Ciphers.FindAsync(cipherId)).OrganizationId; var availableCollectionsCte = from c in dbContext.Collections - join o in dbContext.Organizations - on c.OrganizationId equals o.Id - join ou in dbContext.OrganizationUsers - on o.Id equals ou.OrganizationId - where ou.UserId == userId - join cu in dbContext.CollectionUsers - on ou.Id equals cu.OrganizationUserId into cu_g - from cu in cu_g.DefaultIfEmpty() - where !ou.AccessAll && cu.CollectionId == c.Id - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on gu.GroupId equals cg.GroupId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.CollectionId == c.Id && - (o.Id == organizationId && o.Enabled && ou.Status == OrganizationUserStatusType.Confirmed && ( - ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)) - select new { c, o, cu, gu, g, cg }; + join o in dbContext.Organizations + on c.OrganizationId equals o.Id + join ou in dbContext.OrganizationUsers + on o.Id equals ou.OrganizationId + where ou.UserId == userId + join cu in dbContext.CollectionUsers + on ou.Id equals cu.OrganizationUserId into cu_g + from cu in cu_g.DefaultIfEmpty() + where !ou.AccessAll && cu.CollectionId == c.Id + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on gu.GroupId equals cg.GroupId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.CollectionId == c.Id && + (o.Id == organizationId && o.Enabled && ou.Status == OrganizationUserStatusType.Confirmed && ( + ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)) + select new { c, o, cu, gu, g, cg }; var target = from cc in dbContext.CollectionCiphers - where cc.CipherId == cipherId - select new { cc.CollectionId, cc.CipherId }; + where cc.CipherId == cipherId + select new { cc.CollectionId, cc.CipherId }; var source = collectionIds.Select(x => new { CollectionId = x, CipherId = cipherId }); var merge1 = from t in target - join s in source - on t.CollectionId equals s.CollectionId into s_g - from s in s_g.DefaultIfEmpty() - where t.CipherId == s.CipherId - select new { t, s }; + join s in source + on t.CollectionId equals s.CollectionId into s_g + from s in s_g.DefaultIfEmpty() + where t.CipherId == s.CipherId + select new { t, s }; var merge2 = from s in source - join t in target - on s.CollectionId equals t.CollectionId into t_g - from t in t_g.DefaultIfEmpty() - where t.CipherId == s.CipherId - select new { t, s }; + join t in target + on s.CollectionId equals t.CollectionId into t_g + from t in t_g.DefaultIfEmpty() + where t.CipherId == s.CipherId + select new { t, s }; var union = merge1.Union(merge2).Distinct(); var insert = union .Where(x => x.t == null && collectionIds.Contains(x.s.CollectionId)) @@ -151,28 +151,28 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var availableCollectionsCte = from c in dbContext.Collections - where c.OrganizationId == organizationId - select c; + where c.OrganizationId == organizationId + select c; var target = from cc in dbContext.CollectionCiphers - where cc.CipherId == cipherId - select new { cc.CollectionId, cc.CipherId }; + where cc.CipherId == cipherId + select new { cc.CollectionId, cc.CipherId }; var source = collectionIds.Select(x => new { CollectionId = x, CipherId = cipherId }); var merge1 = from t in target - join s in source - on t.CollectionId equals s.CollectionId into s_g - from s in s_g.DefaultIfEmpty() - where t.CipherId == s.CipherId - select new { t, s }; + join s in source + on t.CollectionId equals s.CollectionId into s_g + from s in s_g.DefaultIfEmpty() + where t.CipherId == s.CipherId + select new { t, s }; var merge2 = from s in source - join t in target - on s.CollectionId equals t.CollectionId into t_g - from t in t_g.DefaultIfEmpty() - where t.CipherId == s.CipherId - select new { t, s }; + join t in target + on s.CollectionId equals t.CollectionId into t_g + from t in t_g.DefaultIfEmpty() + where t.CipherId == s.CipherId + select new { t, s }; var union = merge1.Union(merge2).Distinct(); var insert = union .Where(x => x.t == null && collectionIds.Contains(x.s.CollectionId)) - .Select(x => new EfModel.CollectionCipher + .Select(x => new EfModel.CollectionCipher { CollectionId = x.s.CollectionId, CipherId = x.s.CipherId, @@ -197,29 +197,29 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var availibleCollections = from c in dbContext.Collections - join o in dbContext.Organizations - on c.OrganizationId equals o.Id - join ou in dbContext.OrganizationUsers - on o.Id equals ou.OrganizationId - where ou.UserId == userId - join cu in dbContext.CollectionUsers - on ou.Id equals cu.OrganizationUserId into cu_g - from cu in cu_g.DefaultIfEmpty() - where !ou.AccessAll && cu.CollectionId == c.Id - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on gu.GroupId equals cg.GroupId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.CollectionId == c.Id && - (o.Id == organizationId && o.Enabled && ou.Status == OrganizationUserStatusType.Confirmed && - (ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)) - select new { c, o, ou, cu, gu, g, cg }; + join o in dbContext.Organizations + on c.OrganizationId equals o.Id + join ou in dbContext.OrganizationUsers + on o.Id equals ou.OrganizationId + where ou.UserId == userId + join cu in dbContext.CollectionUsers + on ou.Id equals cu.OrganizationUserId into cu_g + from cu in cu_g.DefaultIfEmpty() + where !ou.AccessAll && cu.CollectionId == c.Id + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on gu.GroupId equals cg.GroupId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.CollectionId == c.Id && + (o.Id == organizationId && o.Enabled && ou.Status == OrganizationUserStatusType.Confirmed && + (ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)) + select new { c, o, ou, cu, gu, g, cg }; var count = await availibleCollections.CountAsync(); if (await availibleCollections.CountAsync() < 1) { @@ -227,13 +227,13 @@ namespace Bit.Core.Repositories.EntityFramework } var insertData = from collectionId in collectionIds - from cipherId in cipherIds - where availibleCollections.Select(x => x.c.Id).Contains(collectionId) - select new EfModel.CollectionCipher - { - CollectionId = collectionId, - CipherId = cipherId, - }; + from cipherId in cipherIds + where availibleCollections.Select(x => x.c.Id).Contains(collectionId) + select new EfModel.CollectionCipher + { + CollectionId = collectionId, + CipherId = cipherId, + }; await dbContext.AddRangeAsync(insertData); await UserBumpAccountRevisionDateByOrganizationId(organizationId); } diff --git a/src/Core/Repositories/EntityFramework/CollectionRepository.cs b/src/Core/Repositories/EntityFramework/CollectionRepository.cs index ab9a075b6..7be9c5fec 100644 --- a/src/Core/Repositories/EntityFramework/CollectionRepository.cs +++ b/src/Core/Repositories/EntityFramework/CollectionRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -33,8 +33,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var availibleGroups = await (from g in dbContext.Groups - where g.OrganizationId == obj.OrganizationId - select g.Id).ToListAsync(); + where g.OrganizationId == obj.OrganizationId + select g.Id).ToListAsync(); var collectionGroups = groups .Where(g => availibleGroups.Contains(g.Id)) .Select(g => new EfModel.CollectionGroup @@ -56,9 +56,9 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from cu in dbContext.CollectionUsers - where cu.CollectionId == collectionId && - cu.OrganizationUserId == organizationUserId - select cu; + where cu.CollectionId == collectionId && + cu.OrganizationUserId == organizationUserId + select cu; dbContext.RemoveRange(await query.ToListAsync()); await dbContext.SaveChangesAsync(); await UserBumpAccountRevisionDateByOrganizationUserId(organizationUserId); @@ -76,14 +76,14 @@ namespace Bit.Core.Repositories.EntityFramework public async Task>> GetByIdWithGroupsAsync(Guid id) { - var collection = await base.GetByIdAsync(id); + var collection = await base.GetByIdAsync(id); using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var collectionGroups = await (from cg in dbContext.CollectionGroups - where cg.CollectionId == id - select cg).ToListAsync(); - var selectionReadOnlys = collectionGroups.Select(cg => new SelectionReadOnly + where cg.CollectionId == id + select cg).ToListAsync(); + var selectionReadOnlys = collectionGroups.Select(cg => new SelectionReadOnly { Id = cg.GroupId, ReadOnly = cg.ReadOnly, @@ -100,13 +100,13 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from cg in dbContext.CollectionGroups - where cg.CollectionId.Equals(id) - select new SelectionReadOnly - { - Id = cg.GroupId, - ReadOnly = cg.ReadOnly, - HidePasswords = cg.HidePasswords, - }; + where cg.CollectionId.Equals(id) + select new SelectionReadOnly + { + Id = cg.GroupId, + ReadOnly = cg.ReadOnly, + HidePasswords = cg.HidePasswords, + }; var configurations = await query.ToArrayAsync(); return new Tuple>(collection, configurations); } @@ -124,8 +124,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from c in dbContext.Collections - where c.OrganizationId == organizationId - select c; + where c.OrganizationId == organizationId + select c; var collections = await query.ToArrayAsync(); return collections; } @@ -158,10 +158,10 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from cu in dbContext.CollectionUsers - where cu.CollectionId == id - select cu; + where cu.CollectionId == id + select cu; var collectionUsers = await query.ToListAsync(); - return collectionUsers.Select(cu => new SelectionReadOnly + return collectionUsers.Select(cu => new SelectionReadOnly { Id = cu.OrganizationUserId, ReadOnly = cu.ReadOnly, @@ -179,25 +179,25 @@ namespace Bit.Core.Repositories.EntityFramework var groupsInOrg = dbContext.Groups.Where(g => g.OrganizationId == collection.OrganizationId); var modifiedGroupEntities = dbContext.Groups.Where(x => groups.Select(x => x.Id).Contains(x.Id)); var target = (from cg in dbContext.CollectionGroups - join g in modifiedGroupEntities - on cg.CollectionId equals collection.Id into s_g - from g in s_g.DefaultIfEmpty() - where g == null || cg.GroupId == g.Id - select new {cg, g}).AsNoTracking(); + join g in modifiedGroupEntities + on cg.CollectionId equals collection.Id into s_g + from g in s_g.DefaultIfEmpty() + where g == null || cg.GroupId == g.Id + select new { cg, g }).AsNoTracking(); var source = (from g in modifiedGroupEntities - from cg in dbContext.CollectionGroups - .Where(cg => cg.CollectionId == collection.Id && cg.GroupId == g.Id).DefaultIfEmpty() - select new {cg, g}).AsNoTracking(); + from cg in dbContext.CollectionGroups + .Where(cg => cg.CollectionId == collection.Id && cg.GroupId == g.Id).DefaultIfEmpty() + select new { cg, g }).AsNoTracking(); var union = await target .Union(source) - .Where(x => + .Where(x => x.cg == null || - ((x.g == null || x.g.Id == x.cg.GroupId) && + ((x.g == null || x.g.Id == x.cg.GroupId) && (x.cg.CollectionId == collection.Id))) .AsNoTracking() .ToListAsync(); var insert = union.Where(x => x.cg == null && groupsInOrg.Any(c => x.g.Id == c.Id)) - .Select(x => new EfModel.CollectionGroup + .Select(x => new EfModel.CollectionGroup { CollectionId = collection.Id, GroupId = x.g.Id, @@ -206,30 +206,30 @@ namespace Bit.Core.Repositories.EntityFramework }).ToList(); var update = union .Where( - x => x.g != null && - x.cg != null && - (x.cg.ReadOnly != groups.FirstOrDefault(g => g.Id == x.g.Id).ReadOnly || + x => x.g != null && + x.cg != null && + (x.cg.ReadOnly != groups.FirstOrDefault(g => g.Id == x.g.Id).ReadOnly || x.cg.HidePasswords != groups.FirstOrDefault(g => g.Id == x.g.Id).HidePasswords) ) - .Select(x => new EfModel.CollectionGroup + .Select(x => new EfModel.CollectionGroup { - CollectionId = collection.Id, + CollectionId = collection.Id, GroupId = x.g.Id, ReadOnly = groups.FirstOrDefault(g => g.Id == x.g.Id).ReadOnly, HidePasswords = groups.FirstOrDefault(g => g.Id == x.g.Id).HidePasswords, }); var delete = union .Where( - x => x.g == null && + x => x.g == null && x.cg.CollectionId == collection.Id ) - .Select(x => new EfModel.CollectionGroup - { - CollectionId = collection.Id, + .Select(x => new EfModel.CollectionGroup + { + CollectionId = collection.Id, GroupId = x.cg.GroupId, }) .ToList(); - + await dbContext.AddRangeAsync(insert); dbContext.UpdateRange(update); dbContext.RemoveRange(delete); @@ -248,7 +248,7 @@ namespace Bit.Core.Repositories.EntityFramework dbContext.UpdateRange(updateData); var insertData = await procedure.Insert.BuildInMemory(dbContext); await dbContext.AddRangeAsync(insertData); - dbContext.RemoveRange(await procedure.Delete.Run(dbContext).ToListAsync()); + dbContext.RemoveRange(await procedure.Delete.Run(dbContext).ToListAsync()); } } } diff --git a/src/Core/Repositories/EntityFramework/DatabaseContext.cs b/src/Core/Repositories/EntityFramework/DatabaseContext.cs index 0131ab1c8..1ba7053ab 100644 --- a/src/Core/Repositories/EntityFramework/DatabaseContext.cs +++ b/src/Core/Repositories/EntityFramework/DatabaseContext.cs @@ -39,7 +39,7 @@ namespace Bit.Core.Repositories.EntityFramework public DbSet Transactions { get; set; } public DbSet U2fs { get; set; } public DbSet Users { get; set; } - + protected override void OnModelCreating(ModelBuilder builder) { var eCipher = builder.Entity(); @@ -95,7 +95,7 @@ namespace Bit.Core.Repositories.EntityFramework eGroupUser.HasKey(gu => new { gu.GroupId, gu.OrganizationUserId }); - if (Database.IsNpgsql()) + if (Database.IsNpgsql()) { // the postgres provider doesn't currently support database level non-deterministic collations. // see https://www.npgsql.org/efcore/misc/collations-and-case-sensitivity.html#database-collation diff --git a/src/Core/Repositories/EntityFramework/DeviceRepository.cs b/src/Core/Repositories/EntityFramework/DeviceRepository.cs index 79f6e8c93..0cb17acba 100644 --- a/src/Core/Repositories/EntityFramework/DeviceRepository.cs +++ b/src/Core/Repositories/EntityFramework/DeviceRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/EmergencyAccessRepository.cs b/src/Core/Repositories/EntityFramework/EmergencyAccessRepository.cs index c8c4ecfaa..e226f09c0 100644 --- a/src/Core/Repositories/EntityFramework/EmergencyAccessRepository.cs +++ b/src/Core/Repositories/EntityFramework/EmergencyAccessRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -31,8 +31,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var view = new EmergencyAccessDetailsViewQuery(); - var query = view.Run(dbContext).Where(ea => - ea.Id == id && + var query = view.Run(dbContext).Where(ea => + ea.Id == id && ea.GrantorId == grantorId ); return await query.FirstOrDefaultAsync(); @@ -45,7 +45,7 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var view = new EmergencyAccessDetailsViewQuery(); - var query = view.Run(dbContext).Where(ea => + var query = view.Run(dbContext).Where(ea => ea.Status == EmergencyAccessStatusType.RecoveryInitiated ); return await query.ToListAsync(); @@ -58,7 +58,7 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var view = new EmergencyAccessDetailsViewQuery(); - var query = view.Run(dbContext).Where(ea => + var query = view.Run(dbContext).Where(ea => ea.GranteeId == granteeId ); return await query.ToListAsync(); @@ -71,7 +71,7 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var view = new EmergencyAccessDetailsViewQuery(); - var query = view.Run(dbContext).Where(ea => + var query = view.Run(dbContext).Where(ea => ea.GrantorId == grantorId ); return await query.ToListAsync(); @@ -84,10 +84,10 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var view = new EmergencyAccessDetailsViewQuery(); - var query = view.Run(dbContext).Where(ea => + var query = view.Run(dbContext).Where(ea => ea.Status == EmergencyAccessStatusType.RecoveryInitiated ); - var notifies = await query.Select(ea => new EmergencyAccessNotify + var notifies = await query.Select(ea => new EmergencyAccessNotify { Id = ea.Id, GrantorId = ea.GrantorId, @@ -104,7 +104,7 @@ namespace Bit.Core.Repositories.EntityFramework GranteeName = ea.GranteeName, GranteeEmail = ea.GranteeEmail, GrantorEmail = ea.GrantorEmail, - }).ToListAsync(); + }).ToListAsync(); return notifies; } } diff --git a/src/Core/Repositories/EntityFramework/EventRepository.cs b/src/Core/Repositories/EntityFramework/EventRepository.cs index 34cfba4fe..bea5ed067 100644 --- a/src/Core/Repositories/EntityFramework/EventRepository.cs +++ b/src/Core/Repositories/EntityFramework/EventRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/FolderRepository.cs b/src/Core/Repositories/EntityFramework/FolderRepository.cs index 823491f35..48d7b29f4 100644 --- a/src/Core/Repositories/EntityFramework/FolderRepository.cs +++ b/src/Core/Repositories/EntityFramework/FolderRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -35,8 +35,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from f in dbContext.Folders - where f.UserId == userId - select f; + where f.UserId == userId + select f; var folders = await query.ToListAsync(); return Mapper.Map>(folders); } diff --git a/src/Core/Repositories/EntityFramework/GrantRepository.cs b/src/Core/Repositories/EntityFramework/GrantRepository.cs index a71aff227..033ce64f0 100644 --- a/src/Core/Repositories/EntityFramework/GrantRepository.cs +++ b/src/Core/Repositories/EntityFramework/GrantRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -24,8 +24,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from g in dbContext.Grants - where g.Key == key - select g; + where g.Key == key + select g; dbContext.Remove(query); await dbContext.SaveChangesAsync(); } @@ -37,11 +37,11 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from g in dbContext.Grants - where g.SubjectId == subjectId && - g.ClientId == clientId && - g.SessionId == sessionId && - g.Type == type - select g; + where g.SubjectId == subjectId && + g.ClientId == clientId && + g.SessionId == sessionId && + g.Type == type + select g; dbContext.Remove(query); await dbContext.SaveChangesAsync(); } @@ -53,8 +53,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from g in dbContext.Grants - where g.Key == key - select g; + where g.Key == key + select g; var grant = await query.FirstOrDefaultAsync(); return grant; } @@ -66,11 +66,11 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from g in dbContext.Grants - where g.SubjectId == subjectId && - g.ClientId == clientId && - g.SessionId == sessionId && - g.Type == type - select g; + where g.SubjectId == subjectId && + g.ClientId == clientId && + g.SessionId == sessionId && + g.Type == type + select g; var grants = await query.ToListAsync(); return (ICollection)grants; } @@ -82,8 +82,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var existingGrant = await (from g in dbContext.Grants - where g.Key == obj.Key - select g).FirstOrDefaultAsync(); + where g.Key == obj.Key + select g).FirstOrDefaultAsync(); if (existingGrant != null) { dbContext.Entry(existingGrant).CurrentValues.SetValues(obj); diff --git a/src/Core/Repositories/EntityFramework/GroupRepository.cs b/src/Core/Repositories/EntityFramework/GroupRepository.cs index 863e3ae6e..416b8e4a8 100644 --- a/src/Core/Repositories/EntityFramework/GroupRepository.cs +++ b/src/Core/Repositories/EntityFramework/GroupRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -48,9 +48,9 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from gu in dbContext.GroupUsers - where gu.GroupId == groupId && - gu.OrganizationUserId == organizationUserId - select gu; + where gu.GroupId == groupId && + gu.OrganizationUserId == organizationUserId + select gu; dbContext.RemoveRange(await query.ToListAsync()); await dbContext.SaveChangesAsync(); } @@ -62,7 +62,7 @@ namespace Bit.Core.Repositories.EntityFramework using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); - var query = await ( + var query = await ( from cg in dbContext.CollectionGroups where cg.GroupId == id select cg).ToListAsync(); @@ -71,7 +71,7 @@ namespace Bit.Core.Repositories.EntityFramework Id = c.CollectionId, ReadOnly = c.ReadOnly, HidePasswords = c.HidePasswords, - }).ToList(); + }).ToList(); return new Tuple>( grp, collections); } @@ -151,23 +151,23 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var orgId = (await dbContext.Groups.FindAsync(groupId)).OrganizationId; var insert = from ou in dbContext.OrganizationUsers - where organizationUserIds.Contains(ou.Id) && - ou.OrganizationId == orgId && - !dbContext.GroupUsers.Any(gu => gu.GroupId == groupId && ou.Id == gu.OrganizationUserId) - select new EfModel.GroupUser - { - GroupId = groupId, - OrganizationUserId = ou.Id, - }; - await dbContext.AddRangeAsync(insert); + where organizationUserIds.Contains(ou.Id) && + ou.OrganizationId == orgId && + !dbContext.GroupUsers.Any(gu => gu.GroupId == groupId && ou.Id == gu.OrganizationUserId) + select new EfModel.GroupUser + { + GroupId = groupId, + OrganizationUserId = ou.Id, + }; + await dbContext.AddRangeAsync(insert); - var delete = from gu in dbContext.GroupUsers - where gu.GroupId == groupId && - !organizationUserIds.Contains(gu.OrganizationUserId) - select gu; - dbContext.RemoveRange(delete); - await dbContext.SaveChangesAsync(); - await UserBumpAccountRevisionDateByOrganizationId(orgId); + var delete = from gu in dbContext.GroupUsers + where gu.GroupId == groupId && + !organizationUserIds.Contains(gu.OrganizationUserId) + select gu; + dbContext.RemoveRange(delete); + await dbContext.SaveChangesAsync(); + await UserBumpAccountRevisionDateByOrganizationId(orgId); } } } diff --git a/src/Core/Repositories/EntityFramework/InstallationRepository.cs b/src/Core/Repositories/EntityFramework/InstallationRepository.cs index f28e7cd2b..d42ad3289 100644 --- a/src/Core/Repositories/EntityFramework/InstallationRepository.cs +++ b/src/Core/Repositories/EntityFramework/InstallationRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/MaintenanceRepository.cs b/src/Core/Repositories/EntityFramework/MaintenanceRepository.cs index 9ad8e8514..988f272de 100644 --- a/src/Core/Repositories/EntityFramework/MaintenanceRepository.cs +++ b/src/Core/Repositories/EntityFramework/MaintenanceRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Threading.Tasks; using AutoMapper; diff --git a/src/Core/Repositories/EntityFramework/OrganizationRepository.cs b/src/Core/Repositories/EntityFramework/OrganizationRepository.cs index 31f31269f..9994c643b 100644 --- a/src/Core/Repositories/EntityFramework/OrganizationRepository.cs +++ b/src/Core/Repositories/EntityFramework/OrganizationRepository.cs @@ -1,13 +1,13 @@ -using AutoMapper; -using Bit.Core.Models.Table; -using DataModel = Bit.Core.Models.Data; -using EFModel = Bit.Core.Models.EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using System; +using AutoMapper; +using Bit.Core.Models.Table; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using DataModel = Bit.Core.Models.Data; +using EFModel = Bit.Core.Models.EntityFramework; using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework @@ -62,7 +62,7 @@ namespace Bit.Core.Repositories.EntityFramework var organizations = await GetDbSet(dbContext) .Where(e => name == null || e.Name.Contains(name)) .Where(e => userEmail == null || e.OrganizationUsers.Any(u => u.Email == userEmail)) - .Where(e => paid == null || + .Where(e => paid == null || (paid == true && !string.IsNullOrWhiteSpace(e.GatewaySubscriptionId)) || (paid == false && e.GatewaySubscriptionId == null)) .OrderBy(e => e.CreationDate) diff --git a/src/Core/Repositories/EntityFramework/OrganizationSponsorshipRepository.cs b/src/Core/Repositories/EntityFramework/OrganizationSponsorshipRepository.cs index 9fed4b0c5..522dae1ea 100644 --- a/src/Core/Repositories/EntityFramework/OrganizationSponsorshipRepository.cs +++ b/src/Core/Repositories/EntityFramework/OrganizationSponsorshipRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -12,7 +12,7 @@ namespace Bit.Core.Repositories.EntityFramework { public class OrganizationSponsorshipRepository : Repository, IOrganizationSponsorshipRepository { - public OrganizationSponsorshipRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) + public OrganizationSponsorshipRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationSponsorships) { } diff --git a/src/Core/Repositories/EntityFramework/OrganizationUserRepository.cs b/src/Core/Repositories/EntityFramework/OrganizationUserRepository.cs index 0c6f49507..11a92ad7f 100644 --- a/src/Core/Repositories/EntityFramework/OrganizationUserRepository.cs +++ b/src/Core/Repositories/EntityFramework/OrganizationUserRepository.cs @@ -1,15 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using AutoMapper; using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework.Queries; -using EfModel = Bit.Core.Models.EntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System; +using EfModel = Bit.Core.Models.EntityFramework; using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework @@ -118,7 +118,7 @@ namespace Bit.Core.Repositories.EntityFramework from ou in dbContext.OrganizationUsers join cu in dbContext.CollectionUsers on ou.Id equals cu.OrganizationUserId - where !ou.AccessAll && + where !ou.AccessAll && ou.Id == id select cu).ToListAsync(); var collections = query.Select(cu => new SelectionReadOnly @@ -126,7 +126,7 @@ namespace Bit.Core.Repositories.EntityFramework Id = cu.CollectionId, ReadOnly = cu.ReadOnly, HidePasswords = cu.HidePasswords, - }); + }); return new Tuple>( organizationUser, collections.ToList()); } @@ -198,14 +198,14 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - join cu in dbContext.CollectionUsers on ou.Id equals cu.OrganizationUserId - where !ou.AccessAll && ou.Id == id - select cu; + join cu in dbContext.CollectionUsers on ou.Id equals cu.OrganizationUserId + where !ou.AccessAll && ou.Id == id + select cu; var collections = await query.Select(cu => new SelectionReadOnly { - Id = cu.CollectionId, - ReadOnly = cu.ReadOnly, - HidePasswords = cu.HidePasswords, + Id = cu.CollectionId, + ReadOnly = cu.ReadOnly, + HidePasswords = cu.HidePasswords, }).ToListAsync(); return new Tuple>(organizationUserUserDetails, collections); } @@ -219,8 +219,8 @@ namespace Bit.Core.Repositories.EntityFramework var view = new OrganizationUserOrganizationDetailsViewQuery(); var t = await (view.Run(dbContext)).ToArrayAsync(); var entity = await view.Run(dbContext) - .FirstOrDefaultAsync(o => o.UserId == userId && - o.OrganizationId == organizationId && + .FirstOrDefaultAsync(o => o.UserId == userId && + o.OrganizationId == organizationId && (status == null || o.Status == status)); return entity; } @@ -232,8 +232,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - where Ids.Contains(ou.Id) - select ou; + where Ids.Contains(ou.Id) + select ou; var data = await query.ToArrayAsync(); return data; } @@ -245,8 +245,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - where userIds.Contains(ou.Id) - select ou; + where userIds.Contains(ou.Id) + select ou; return Mapper.Map>(await query.ToListAsync()); } } @@ -257,9 +257,9 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - where ou.OrganizationId == organizationId && - (type == null || ou.Type == type) - select ou; + where ou.OrganizationId == organizationId && + (type == null || ou.Type == type) + select ou; return Mapper.Map>(await query.ToListAsync()); } } @@ -270,8 +270,8 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - where ou.UserId == userId - select ou; + where ou.UserId == userId + select ou; return Mapper.Map>(await query.ToListAsync()); } } @@ -283,8 +283,8 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var view = new OrganizationUserUserDetailsViewQuery(); var query = from ou in view.Run(dbContext) - where ou.OrganizationId == organizationId - select ou; + where ou.OrganizationId == organizationId + select ou; return await query.ToListAsync(); } } @@ -297,9 +297,9 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var view = new OrganizationUserOrganizationDetailsViewQuery(); var query = from ou in view.Run(dbContext) - where ou.UserId == userId && - (status == null || ou.Status == status) - select ou; + where ou.UserId == userId && + (status == null || ou.Status == status) + select ou; var organizationUsers = await query.ToListAsync(); return organizationUsers; } @@ -311,16 +311,16 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from ou in dbContext.OrganizationUsers - where Ids.Contains(ou.Id) && ou.Status == OrganizationUserStatusType.Accepted - join u in dbContext.Users - on ou.UserId equals u.Id - where ou.OrganizationId == organizationId - select new { ou, u }; + where Ids.Contains(ou.Id) && ou.Status == OrganizationUserStatusType.Accepted + join u in dbContext.Users + on ou.UserId equals u.Id + where ou.OrganizationId == organizationId + select new { ou, u }; var data = await query - .Select(x => new OrganizationUserPublicKey() + .Select(x => new OrganizationUserPublicKey() { - Id = x.ou.Id, - PublicKey = x.u.PublicKey, + Id = x.ou.Id, + PublicKey = x.u.PublicKey, }).ToListAsync(); return data; } @@ -341,7 +341,7 @@ namespace Bit.Core.Repositories.EntityFramework var insert = procedure.Insert.Run(dbContext); await dbContext.AddRangeAsync(await insert.ToListAsync()); - dbContext.RemoveRange(await procedure.Delete.Run(dbContext).ToListAsync()); + dbContext.RemoveRange(await procedure.Delete.Run(dbContext).ToListAsync()); await dbContext.SaveChangesAsync(); } } @@ -365,19 +365,19 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var usersQuery = from ou in dbContext.OrganizationUsers - join u in dbContext.Users - on ou.UserId equals u.Id into u_g - from u in u_g - where ou.OrganizationId == organizationId - select new { ou, u }; + join u in dbContext.Users + on ou.UserId equals u.Id into u_g + from u in u_g + where ou.OrganizationId == organizationId + select new { ou, u }; var ouu = await usersQuery.ToListAsync(); var ouEmails = ouu.Select(x => x.ou.Email); var uEmails = ouu.Select(x => x.u.Email); var knownEmails = from e in emails - where (ouEmails.Contains(e) || uEmails.Contains(e)) && - (!onlyRegisteredUsers && (uEmails.Contains(e) || ouEmails.Contains(e))) || - (onlyRegisteredUsers && uEmails.Contains(e)) - select e; + where (ouEmails.Contains(e) || uEmails.Contains(e)) && + (!onlyRegisteredUsers && (uEmails.Contains(e) || ouEmails.Contains(e))) || + (onlyRegisteredUsers && uEmails.Contains(e)) + select e; return knownEmails; } } @@ -396,7 +396,7 @@ namespace Bit.Core.Repositories.EntityFramework var delete = procedure.Delete.Run(dbContext); var deleteData = await delete.ToListAsync(); - dbContext.RemoveRange(deleteData); + dbContext.RemoveRange(deleteData); await UserBumpAccountRevisionDateByOrganizationUserId(orgUserId); await dbContext.SaveChangesAsync(); } @@ -431,10 +431,11 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var query = dbContext.OrganizationUsers .Include(e => e.User) - .Where(e => e.OrganizationId.Equals(organizationId) && + .Where(e => e.OrganizationId.Equals(organizationId) && e.Type <= minRole && e.Status == OrganizationUserStatusType.Confirmed) - .Select(e => new OrganizationUserUserDetails() { + .Select(e => new OrganizationUserUserDetails() + { Id = e.Id, Email = e.Email ?? e.User.Email }); diff --git a/src/Core/Repositories/EntityFramework/PolicyRepository.cs b/src/Core/Repositories/EntityFramework/PolicyRepository.cs index 9e8c95634..39fdb7a70 100644 --- a/src/Core/Repositories/EntityFramework/PolicyRepository.cs +++ b/src/Core/Repositories/EntityFramework/PolicyRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/ProviderOrganizationRepository.cs b/src/Core/Repositories/EntityFramework/ProviderOrganizationRepository.cs index f4f93f757..77d15b4ad 100644 --- a/src/Core/Repositories/EntityFramework/ProviderOrganizationRepository.cs +++ b/src/Core/Repositories/EntityFramework/ProviderOrganizationRepository.cs @@ -1,19 +1,19 @@ -using System; +using System; using System.Collections.Generic; -using System.Threading.Tasks; using System.Linq; -using TableModel = Bit.Core.Models.Table; -using EfModel = Bit.Core.Models.EntityFramework; -using Microsoft.Extensions.DependencyInjection; +using System.Threading.Tasks; using AutoMapper; using Bit.Core.Models.Data; using Bit.Core.Models.Table.Provider; using Bit.Core.Repositories.EntityFramework.Queries; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using EfModel = Bit.Core.Models.EntityFramework; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework { - public class ProviderOrganizationRepository : + public class ProviderOrganizationRepository : Repository, IProviderOrganizationRepository { public ProviderOrganizationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) diff --git a/src/Core/Repositories/EntityFramework/ProviderRepository.cs b/src/Core/Repositories/EntityFramework/ProviderRepository.cs index 2603d514f..8ff09a5a9 100644 --- a/src/Core/Repositories/EntityFramework/ProviderRepository.cs +++ b/src/Core/Repositories/EntityFramework/ProviderRepository.cs @@ -1,14 +1,14 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Bit.Core.Models.Table.Provider; -using TableModel = Bit.Core.Models.Table; -using EfModel = Bit.Core.Models.EntityFramework; -using Microsoft.Extensions.DependencyInjection; using AutoMapper; -using Microsoft.EntityFrameworkCore; using Bit.Core.Models.Data; +using Bit.Core.Models.Table.Provider; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using EfModel = Bit.Core.Models.EntityFramework; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework { @@ -26,18 +26,18 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var query = !string.IsNullOrWhiteSpace(userEmail) ? (from p in dbContext.Providers - join pu in dbContext.ProviderUsers - on p.Id equals pu.ProviderId - join u in dbContext.Users - on pu.UserId equals u.Id - where (string.IsNullOrWhiteSpace(name) || p.Name.Contains(name)) && - u.Email == userEmail - orderby p.CreationDate descending - select new { p, pu, u }).Skip(skip).Take(take).Select(x => x.p) : + join pu in dbContext.ProviderUsers + on p.Id equals pu.ProviderId + join u in dbContext.Users + on pu.UserId equals u.Id + where (string.IsNullOrWhiteSpace(name) || p.Name.Contains(name)) && + u.Email == userEmail + orderby p.CreationDate descending + select new { p, pu, u }).Skip(skip).Take(take).Select(x => x.p) : (from p in dbContext.Providers - where string.IsNullOrWhiteSpace(name) || p.Name.Contains(name) - orderby p.CreationDate descending - select new { p }).Skip(skip).Take(take).Select(x => x.p); + where string.IsNullOrWhiteSpace(name) || p.Name.Contains(name) + orderby p.CreationDate descending + select new { p }).Skip(skip).Take(take).Select(x => x.p); var providers = await query.ToArrayAsync(); return Mapper.Map>(providers); } diff --git a/src/Core/Repositories/EntityFramework/ProviderUserRepository.cs b/src/Core/Repositories/EntityFramework/ProviderUserRepository.cs index 6ca4f83a9..48ba10753 100644 --- a/src/Core/Repositories/EntityFramework/ProviderUserRepository.cs +++ b/src/Core/Repositories/EntityFramework/ProviderUserRepository.cs @@ -1,20 +1,20 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Bit.Core.Models.Table.Provider; -using TableModel = Bit.Core.Models.Table; -using EfModel = Bit.Core.Models.EntityFramework; -using Microsoft.Extensions.DependencyInjection; using AutoMapper; using Bit.Core.Enums.Provider; -using Microsoft.EntityFrameworkCore; using Bit.Core.Models.Data; +using Bit.Core.Models.Table.Provider; using Bit.Core.Repositories.EntityFramework.Queries; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using EfModel = Bit.Core.Models.EntityFramework; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework { - public class ProviderUserRepository : + public class ProviderUserRepository : Repository, IProviderUserRepository { public ProviderUserRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) @@ -27,13 +27,13 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from pu in dbContext.ProviderUsers - join u in dbContext.Users - on pu.UserId equals u.Id into u_g - from u in u_g.DefaultIfEmpty() - where pu.ProviderId == providerId && - ((!onlyRegisteredUsers && (pu.Email == email || u.Email == email)) || - (onlyRegisteredUsers && u.Email == email)) - select new { pu, u }; + join u in dbContext.Users + on pu.UserId equals u.Id into u_g + from u in u_g.DefaultIfEmpty() + where pu.ProviderId == providerId && + ((!onlyRegisteredUsers && (pu.Email == email || u.Email == email)) || + (onlyRegisteredUsers && u.Email == email)) + select new { pu, u }; return await query.CountAsync(); } } @@ -53,7 +53,7 @@ namespace Bit.Core.Repositories.EntityFramework using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); - var query = dbContext.ProviderUsers.Where(pu => pu.ProviderId.Equals(providerId) && + var query = dbContext.ProviderUsers.Where(pu => pu.ProviderId.Equals(providerId) && (type != null && pu.Type.Equals(type))); return await query.ToArrayAsync(); } @@ -71,14 +71,14 @@ namespace Bit.Core.Repositories.EntityFramework } } - public async Task> GetManyByUserAsync(Guid userId) + public async Task> GetManyByUserAsync(Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = from pu in dbContext.ProviderUsers - where pu.UserId == userId - select pu; + where pu.UserId == userId + select pu; return await query.ToArrayAsync(); } } @@ -88,23 +88,23 @@ namespace Bit.Core.Repositories.EntityFramework { var dbContext = GetDatabaseContext(scope); var query = from pu in dbContext.ProviderUsers - where pu.UserId == userId && - pu.ProviderId == providerId - select pu; + where pu.UserId == userId && + pu.ProviderId == providerId + select pu; return await query.FirstOrDefaultAsync(); } } - public async Task> GetManyDetailsByProviderAsync(Guid providerId) + public async Task> GetManyDetailsByProviderAsync(Guid providerId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var view = from pu in dbContext.ProviderUsers - join u in dbContext.Users - on pu.UserId equals u.Id into u_g - from u in u_g.DefaultIfEmpty() - select new {pu, u}; - var data = await view.Where(e => e.pu.ProviderId == providerId).Select(e => new ProviderUserUserDetails + join u in dbContext.Users + on pu.UserId equals u.Id into u_g + from u in u_g.DefaultIfEmpty() + select new { pu, u }; + var data = await view.Where(e => e.pu.ProviderId == providerId).Select(e => new ProviderUserUserDetails { Id = e.pu.Id, UserId = e.pu.UserId, @@ -130,7 +130,7 @@ namespace Bit.Core.Repositories.EntityFramework } } - public async Task> GetManyPublicKeysByProviderUserAsync(Guid providerId, IEnumerable Ids) + public async Task> GetManyPublicKeysByProviderUserAsync(Guid providerId, IEnumerable Ids) { using (var scope = ServiceScopeFactory.CreateScope()) { @@ -148,9 +148,9 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var view = new ProviderUserOrganizationDetailsViewQuery(); var query = from ou in view.Run(dbContext) - where ou.UserId == userId && - (status == null || ou.Status == status) - select ou; + where ou.UserId == userId && + (status == null || ou.Status == status) + select ou; var organizationUsers = await query.ToListAsync(); return organizationUsers; } diff --git a/src/Core/Repositories/EntityFramework/Queries/CipherDetailsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CipherDetailsQuery.cs index 761dc7471..a2105e018 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CipherDetailsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CipherDetailsQuery.cs @@ -1,8 +1,8 @@ -using System.Linq; -using System; +using System; using System.Collections.Generic; -using Core.Models.Data; +using System.Linq; using Bit.Core.Utilities; +using Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -18,22 +18,22 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Ciphers - select new CipherDetails - { - Id = c.Id, - UserId = c.UserId, - OrganizationId = c.OrganizationId, - Type= c.Type, - Data = c.Data, - Attachments = c.Attachments, - CreationDate = c.CreationDate, - RevisionDate = c.RevisionDate, - DeletedDate = c.DeletedDate, - Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"), - FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.Contains(_userId.Value.ToString())) ? - null : - CoreHelpers.LoadClassFromJsonData>(c.Folders)[_userId.Value], - }; + select new CipherDetails + { + Id = c.Id, + UserId = c.UserId, + OrganizationId = c.OrganizationId, + Type = c.Type, + Data = c.Data, + Attachments = c.Attachments, + CreationDate = c.CreationDate, + RevisionDate = c.RevisionDate, + DeletedDate = c.DeletedDate, + Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"), + FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.Contains(_userId.Value.ToString())) ? + null : + CoreHelpers.LoadClassFromJsonData>(c.Folders)[_userId.Value], + }; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/CipherOrganizationDetailsReadByIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CipherOrganizationDetailsReadByIdQuery.cs index 52566c9e2..e29a8f695 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CipherOrganizationDetailsReadByIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CipherOrganizationDetailsReadByIdQuery.cs @@ -1,5 +1,5 @@ +using System; using System.Linq; -using System; using Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -16,25 +16,25 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Ciphers - join o in dbContext.Organizations - on c.OrganizationId equals o.Id into o_g - from o in o_g.DefaultIfEmpty() - where c.Id == _cipherId - select new CipherOrganizationDetails - { - Id = c.Id, - UserId = c.UserId, - OrganizationId = c.OrganizationId, - Type = c.Type, - Data = c.Data, - Favorites = c.Favorites, - Folders = c.Folders, - Attachments = c.Attachments, - CreationDate = c.CreationDate, - RevisionDate = c.RevisionDate, - DeletedDate = c.DeletedDate, - OrganizationUseTotp = o.UseTotp, - }; + join o in dbContext.Organizations + on c.OrganizationId equals o.Id into o_g + from o in o_g.DefaultIfEmpty() + where c.Id == _cipherId + select new CipherOrganizationDetails + { + Id = c.Id, + UserId = c.UserId, + OrganizationId = c.OrganizationId, + Type = c.Type, + Data = c.Data, + Favorites = c.Favorites, + Folders = c.Folders, + Attachments = c.Attachments, + CreationDate = c.CreationDate, + RevisionDate = c.RevisionDate, + DeletedDate = c.DeletedDate, + OrganizationUseTotp = o.UseTotp, + }; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/CipherReadCanEditByIdUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CipherReadCanEditByIdUserIdQuery.cs index 5187726b2..b742e7e6f 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CipherReadCanEditByIdUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CipherReadCanEditByIdUserIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Enums; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -19,39 +19,39 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Ciphers - join o in dbContext.Organizations - on c.OrganizationId equals o.Id into o_g - from o in o_g.DefaultIfEmpty() - where !c.UserId.HasValue - join ou in dbContext.OrganizationUsers - on o.Id equals ou.OrganizationId into ou_g - from ou in ou_g.DefaultIfEmpty() - where ou.UserId == _userId - join cc in dbContext.CollectionCiphers - on c.Id equals cc.CipherId into cc_g - from cc in cc_g.DefaultIfEmpty() - where !c.UserId.HasValue && !ou.AccessAll - join cu in dbContext.CollectionUsers - on cc.CollectionId equals cu.CollectionId into cu_g - from cu in cu_g.DefaultIfEmpty() - where ou.Id == cu.OrganizationUserId - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where !c.UserId.HasValue && cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on gu.GroupId equals cg.GroupId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.CollectionId == cc.CollectionId && - (c.Id == _cipherId && - (c.UserId == _userId || - (!c.UserId.HasValue && ou.Status == OrganizationUserStatusType.Confirmed && o.Enabled && - (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)))) && - (c.UserId.HasValue || ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly) - select c; + join o in dbContext.Organizations + on c.OrganizationId equals o.Id into o_g + from o in o_g.DefaultIfEmpty() + where !c.UserId.HasValue + join ou in dbContext.OrganizationUsers + on o.Id equals ou.OrganizationId into ou_g + from ou in ou_g.DefaultIfEmpty() + where ou.UserId == _userId + join cc in dbContext.CollectionCiphers + on c.Id equals cc.CipherId into cc_g + from cc in cc_g.DefaultIfEmpty() + where !c.UserId.HasValue && !ou.AccessAll + join cu in dbContext.CollectionUsers + on cc.CollectionId equals cu.CollectionId into cu_g + from cu in cu_g.DefaultIfEmpty() + where ou.Id == cu.OrganizationUserId + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where !c.UserId.HasValue && cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on gu.GroupId equals cg.GroupId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.CollectionId == cc.CollectionId && + (c.Id == _cipherId && + (c.UserId == _userId || + (!c.UserId.HasValue && ou.Status == OrganizationUserStatusType.Confirmed && o.Enabled && + (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)))) && + (c.UserId.HasValue || ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly) + select c; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/CipherUpdateCollectionsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CipherUpdateCollectionsQuery.cs index 8c3fbd507..9ac993203 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CipherUpdateCollectionsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CipherUpdateCollectionsQuery.cs @@ -1,8 +1,8 @@ -using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; -using Bit.Core.Enums; +using System; using System.Collections.Generic; +using System.Linq; +using Bit.Core.Enums; +using Bit.Core.Models.EntityFramework; using Table = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework.Queries diff --git a/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdCipherIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdCipherIdQuery.cs index 00608b3fe..c64c09066 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdCipherIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdCipherIdQuery.cs @@ -1,6 +1,6 @@ +using System; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { diff --git a/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdQuery.cs index 2b1d0d0db..7468b274b 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CollectionCipherReadByUserIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Enums; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -17,30 +17,30 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from cc in dbContext.CollectionCiphers - join c in dbContext.Collections - on cc.CollectionId equals c.Id - join ou in dbContext.OrganizationUsers - on c.OrganizationId equals ou.OrganizationId - where ou.UserId == _userId - join cu in dbContext.CollectionUsers - on c.Id equals cu.CollectionId into cu_g - from cu in cu_g - where ou.AccessAll && cu.OrganizationUserId == ou.Id - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g - where cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g - join cg in dbContext.CollectionGroups - on cc.CollectionId equals cg.CollectionId into cg_g - from cg in cg_g - where g.AccessAll && cg.GroupId == gu.GroupId && - ou.Status == OrganizationUserStatusType.Confirmed && - (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null) - select cc; - return query; + join c in dbContext.Collections + on cc.CollectionId equals c.Id + join ou in dbContext.OrganizationUsers + on c.OrganizationId equals ou.OrganizationId + where ou.UserId == _userId + join cu in dbContext.CollectionUsers + on c.Id equals cu.CollectionId into cu_g + from cu in cu_g + where ou.AccessAll && cu.OrganizationUserId == ou.Id + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g + where cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g + join cg in dbContext.CollectionGroups + on cc.CollectionId equals cg.CollectionId into cg_g + from cg in cg_g + where g.AccessAll && cg.GroupId == gu.GroupId && + ou.Status == OrganizationUserStatusType.Confirmed && + (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null) + select cc; + return query; } } } diff --git a/src/Core/Repositories/EntityFramework/Queries/CollectionReadCountByOrganizationIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CollectionReadCountByOrganizationIdQuery.cs index 64f62682f..9856a5ac9 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CollectionReadCountByOrganizationIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CollectionReadCountByOrganizationIdQuery.cs @@ -1,6 +1,6 @@ +using System; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -16,8 +16,8 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Collections - where c.OrganizationId == _organizationId - select c; + where c.OrganizationId == _organizationId + select c; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/CollectionUserUpdateUsersQuery.cs b/src/Core/Repositories/EntityFramework/Queries/CollectionUserUpdateUsersQuery.cs index 24b4ca9d1..cbd456e0e 100644 --- a/src/Core/Repositories/EntityFramework/Queries/CollectionUserUpdateUsersQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/CollectionUserUpdateUsersQuery.cs @@ -1,10 +1,10 @@ +using System; using System.Collections.Generic; using System.Linq; -using EfModel = Bit.Core.Models.EntityFramework; -using Bit.Core.Models.Data; -using System; using System.Threading.Tasks; +using Bit.Core.Models.Data; using Microsoft.EntityFrameworkCore; +using EfModel = Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -16,7 +16,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public CollectionUserUpdateUsersQuery(Guid collectionId, IEnumerable users) { - Insert = new CollectionUserUpdateUsersInsertQuery(collectionId, users); + Insert = new CollectionUserUpdateUsersInsertQuery(collectionId, users); Update = new CollectionUserUpdateUsersUpdateQuery(collectionId, users); Delete = new CollectionUserUpdateUsersDeleteQuery(collectionId, users); } @@ -38,12 +38,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId; var organizationUserIds = _users.Select(u => u.Id); var insertQuery = from ou in dbContext.OrganizationUsers - where - organizationUserIds.Contains(ou.Id) && - ou.OrganizationId == orgId && - !dbContext.CollectionUsers.Any( - x => x.CollectionId != _collectionId && x.OrganizationUserId == ou.Id) - select ou; + where + organizationUserIds.Contains(ou.Id) && + ou.OrganizationId == orgId && + !dbContext.CollectionUsers.Any( + x => x.CollectionId != _collectionId && x.OrganizationUserId == ou.Id) + select ou; return insertQuery; } @@ -51,7 +51,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries { var data = await Run(dbContext).ToListAsync(); var collectionUsers = data.Select(x => new EfModel.CollectionUser() - { + { CollectionId = _collectionId, OrganizationUserId = x.Id, ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.Id)).ReadOnly, @@ -61,7 +61,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries } } - public class CollectionUserUpdateUsersUpdateQuery: IQuery + public class CollectionUserUpdateUsersUpdateQuery : IQuery { private readonly Guid _collectionId; private readonly IEnumerable _users; @@ -77,9 +77,9 @@ namespace Bit.Core.Repositories.EntityFramework.Queries var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId; var ids = _users.Select(x => x.Id); var updateQuery = from target in dbContext.CollectionUsers - where target.CollectionId == _collectionId && - ids.Contains(target.OrganizationUserId) - select target; + where target.CollectionId == _collectionId && + ids.Contains(target.OrganizationUserId) + select target; return updateQuery; } @@ -87,7 +87,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries { var data = await Run(dbContext).ToListAsync(); var collectionUsers = data.Select(x => new EfModel.CollectionUser - { + { CollectionId = _collectionId, OrganizationUserId = x.OrganizationUserId, ReadOnly = _users.FirstOrDefault(u => u.Id.Equals(x.OrganizationUserId)).ReadOnly, @@ -97,7 +97,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries } } - public class CollectionUserUpdateUsersDeleteQuery: IQuery + public class CollectionUserUpdateUsersDeleteQuery : IQuery { private readonly Guid _collectionId; private readonly IEnumerable _users; @@ -112,9 +112,9 @@ namespace Bit.Core.Repositories.EntityFramework.Queries { var orgId = dbContext.Collections.FirstOrDefault(c => c.Id == _collectionId)?.OrganizationId; var deleteQuery = from cu in dbContext.CollectionUsers - where !dbContext.Users.Any( - u => u.Id == cu.OrganizationUserId) - select cu; + where !dbContext.Users.Any( + u => u.Id == cu.OrganizationUserId) + select cu; return deleteQuery; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessDetailsViewQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessDetailsViewQuery.cs index f2818b504..ed24b0ab3 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessDetailsViewQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessDetailsViewQuery.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Bit.Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -8,14 +8,14 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ea in dbContext.EmergencyAccesses - join grantee in dbContext.Users - on ea.GranteeId equals grantee.Id into grantee_g - from grantee in grantee_g.DefaultIfEmpty() - join grantor in dbContext.Users - on ea.GrantorId equals grantor.Id into grantor_g - from grantor in grantor_g.DefaultIfEmpty() - select new {ea, grantee, grantor}; - return query.Select(x => new EmergencyAccessDetails + join grantee in dbContext.Users + on ea.GranteeId equals grantee.Id into grantee_g + from grantee in grantee_g.DefaultIfEmpty() + join grantor in dbContext.Users + on ea.GrantorId equals grantor.Id into grantor_g + from grantor in grantor_g.DefaultIfEmpty() + select new { ea, grantee, grantor }; + return query.Select(x => new EmergencyAccessDetails { Id = x.ea.Id, GrantorId = x.ea.GrantorId, diff --git a/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs index b1007d56f..eb68797d3 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs @@ -1,6 +1,6 @@ +using System; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -20,13 +20,13 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ea in dbContext.EmergencyAccesses - join u in dbContext.Users - on ea.GranteeId equals u.Id into u_g - from u in u_g.DefaultIfEmpty() - where ea.GrantorId == _grantorId && - ((!_onlyRegisteredUsers && (ea.Email == _email || u.Email == _email)) - || (_onlyRegisteredUsers && u.Email == _email)) - select ea; + join u in dbContext.Users + on ea.GranteeId equals u.Id into u_g + from u in u_g.DefaultIfEmpty() + where ea.GrantorId == _grantorId && + ((!_onlyRegisteredUsers && (ea.Email == _email || u.Email == _email)) + || (_onlyRegisteredUsers && u.Email == _email)) + select ea; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByCipherIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByCipherIdQuery.cs index 47d5a0253..9bbba0387 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByCipherIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByCipherIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; using Table = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -35,15 +35,15 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate == null || e.Date < _beforeDate.Value) && - ((!_cipher.OrganizationId.HasValue && !e.OrganizationId.HasValue) || - (_cipher.OrganizationId.HasValue && _cipher.OrganizationId == e.OrganizationId)) && - ((!_cipher.UserId.HasValue && !e.UserId.HasValue) || - (_cipher.UserId.HasValue && _cipher.UserId == e.UserId)) && - _cipher.Id == e.CipherId - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate == null || e.Date < _beforeDate.Value) && + ((!_cipher.OrganizationId.HasValue && !e.OrganizationId.HasValue) || + (_cipher.OrganizationId.HasValue && _cipher.OrganizationId == e.OrganizationId)) && + ((!_cipher.UserId.HasValue && !e.UserId.HasValue) || + (_cipher.UserId.HasValue && _cipher.UserId == e.UserId)) && + _cipher.Id == e.CipherId + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdActingUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdActingUserIdQuery.cs index 207b8435b..bb47ac359 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdActingUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdActingUserIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -28,13 +28,13 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate != null || e.Date <= _endDate) && - (_beforeDate == null || e.Date < _beforeDate.Value) && - e.OrganizationId == _organizationId && - e.ActingUserId == _actingUserId - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate != null || e.Date <= _endDate) && + (_beforeDate == null || e.Date < _beforeDate.Value) && + e.OrganizationId == _organizationId && + e.ActingUserId == _actingUserId + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdQuery.cs index 95ac7d59e..f01d88f8c 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByOrganizationIdQuery.cs @@ -1,11 +1,11 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { - public class EventReadPageByOrganizationIdQuery: IQuery + public class EventReadPageByOrganizationIdQuery : IQuery { private readonly Guid _organizationId; private readonly DateTime _startDate; @@ -26,12 +26,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate != null || e.Date <= _endDate) && - (_beforeDate == null || e.Date < _beforeDate.Value) && - e.OrganizationId == _organizationId - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate != null || e.Date <= _endDate) && + (_beforeDate == null || e.Date < _beforeDate.Value) && + e.OrganizationId == _organizationId + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdActingUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdActingUserIdQuery.cs index 37c5e2b0a..07ccd9fb6 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdActingUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdActingUserIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -28,13 +28,13 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate != null || e.Date <= _endDate) && - (_beforeDate == null || e.Date < _beforeDate.Value) && - e.ProviderId == _providerId && - e.ActingUserId == _actingUserId - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate != null || e.Date <= _endDate) && + (_beforeDate == null || e.Date < _beforeDate.Value) && + e.ProviderId == _providerId && + e.ActingUserId == _actingUserId + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdQuery.cs index 12690b7b8..3df12ad2e 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByProviderIdQuery.cs @@ -1,11 +1,11 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { - public class EventReadPageByProviderIdQuery: IQuery + public class EventReadPageByProviderIdQuery : IQuery { private readonly Guid _providerId; private readonly DateTime _startDate; @@ -26,12 +26,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate != null || e.Date <= _endDate) && - (_beforeDate == null || e.Date < _beforeDate.Value) && - e.ProviderId == _providerId && e.OrganizationId == null - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate != null || e.Date <= _endDate) && + (_beforeDate == null || e.Date < _beforeDate.Value) && + e.ProviderId == _providerId && e.OrganizationId == null + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByUserIdQuery.cs index d434e10f6..293d02e07 100644 --- a/src/Core/Repositories/EntityFramework/Queries/EventReadPageByUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/EventReadPageByUserIdQuery.cs @@ -1,11 +1,11 @@ +using System; using System.Linq; -using Bit.Core.Models.EntityFramework; -using System; using Bit.Core.Models.Data; +using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries { - public class EventReadPageByUserIdQuery: IQuery + public class EventReadPageByUserIdQuery : IQuery { private readonly Guid _userId; private readonly DateTime _startDate; @@ -26,13 +26,13 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var q = from e in dbContext.Events - where e.Date >= _startDate && - (_beforeDate != null || e.Date <= _endDate) && - (_beforeDate == null || e.Date < _beforeDate.Value) && - !e.OrganizationId.HasValue && - e.ActingUserId == _userId - orderby e.Date descending - select e; + where e.Date >= _startDate && + (_beforeDate != null || e.Date <= _endDate) && + (_beforeDate == null || e.Date < _beforeDate.Value) && + !e.OrganizationId.HasValue && + e.ActingUserId == _userId + orderby e.Date descending + select e; return q.Skip(0).Take(_pageOptions.PageSize); } } diff --git a/src/Core/Repositories/EntityFramework/Queries/GroupUserUpdateGroupsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/GroupUserUpdateGroupsQuery.cs index 6b61533a7..cf60a0259 100644 --- a/src/Core/Repositories/EntityFramework/Queries/GroupUserUpdateGroupsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/GroupUserUpdateGroupsQuery.cs @@ -1,8 +1,8 @@ +using System; +using System.Collections.Generic; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -13,7 +13,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public GroupUserUpdateGroupsQuery(Guid organizationUserId, IEnumerable groupIds) { - Insert = new GroupUserUpdateGroupsInsertQuery(organizationUserId, groupIds); + Insert = new GroupUserUpdateGroupsInsertQuery(organizationUserId, groupIds); Delete = new GroupUserUpdateGroupsDeleteQuery(organizationUserId, groupIds); } } @@ -32,17 +32,17 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var orgUser = from ou in dbContext.OrganizationUsers - where ou.Id == _organizationUserId - select ou; + where ou.Id == _organizationUserId + select ou; var groupIdEntities = dbContext.Groups.Where(x => _groupIds.Contains(x.Id)); var query = from g in dbContext.Groups - join ou in orgUser - on g.OrganizationId equals ou.OrganizationId - join gie in groupIdEntities - on g.Id equals gie.Id - where !dbContext.GroupUsers.Any(gu => _groupIds.Contains(gu.GroupId) && gu.OrganizationUserId == _organizationUserId) - select g; - return query.Select(x => new GroupUser + join ou in orgUser + on g.OrganizationId equals ou.OrganizationId + join gie in groupIdEntities + on g.Id equals gie.Id + where !dbContext.GroupUsers.Any(gu => _groupIds.Contains(gu.GroupId) && gu.OrganizationUserId == _organizationUserId) + select g; + return query.Select(x => new GroupUser { GroupId = x.Id, OrganizationUserId = _organizationUserId, @@ -64,9 +64,9 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var deleteQuery = from gu in dbContext.GroupUsers - where gu.OrganizationUserId == _organizationUserId && - !_groupIds.Any(x => gu.GroupId == x) - select gu; + where gu.OrganizationUserId == _organizationUserId && + !_groupIds.Any(x => gu.GroupId == x) + select gu; return deleteQuery; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/IQuery.cs b/src/Core/Repositories/EntityFramework/Queries/IQuery.cs index de6c12903..d0e235431 100644 --- a/src/Core/Repositories/EntityFramework/Queries/IQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/IQuery.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; namespace Bit.Core.Repositories.EntityFramework.Queries { diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserOrganizationDetailsViewQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserOrganizationDetailsViewQuery.cs index 2442191d3..43619f8ea 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserOrganizationDetailsViewQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserOrganizationDetailsViewQuery.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Models.Data; using Microsoft.Azure.Documents.SystemFunctions; @@ -10,21 +10,21 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ou in dbContext.OrganizationUsers - join o in dbContext.Organizations on ou.OrganizationId equals o.Id - join su in dbContext.SsoUsers on ou.UserId equals su.UserId into su_g - from su in su_g.DefaultIfEmpty() - join po in dbContext.ProviderOrganizations on o.Id equals po.OrganizationId into po_g - from po in po_g.DefaultIfEmpty() - join p in dbContext.Providers on po.ProviderId equals p.Id into p_g - from p in p_g.DefaultIfEmpty() - join os in dbContext.OrganizationSponsorships on ou.Id equals os.SponsoringOrganizationUserId into os_g - from os in os_g.DefaultIfEmpty() - join ss in dbContext.SsoConfigs on ou.OrganizationId equals ss.OrganizationId into ss_g - from ss in ss_g.DefaultIfEmpty() - where ((su == null || !su.OrganizationId.HasValue) || su.OrganizationId == ou.OrganizationId) - select new { ou, o, su, p, ss, os }; - - return query.Select(x => new OrganizationUserOrganizationDetails + join o in dbContext.Organizations on ou.OrganizationId equals o.Id + join su in dbContext.SsoUsers on ou.UserId equals su.UserId into su_g + from su in su_g.DefaultIfEmpty() + join po in dbContext.ProviderOrganizations on o.Id equals po.OrganizationId into po_g + from po in po_g.DefaultIfEmpty() + join p in dbContext.Providers on po.ProviderId equals p.Id into p_g + from p in p_g.DefaultIfEmpty() + join os in dbContext.OrganizationSponsorships on ou.Id equals os.SponsoringOrganizationUserId into os_g + from os in os_g.DefaultIfEmpty() + join ss in dbContext.SsoConfigs on ou.OrganizationId equals ss.OrganizationId into ss_g + from ss in ss_g.DefaultIfEmpty() + where ((su == null || !su.OrganizationId.HasValue) || su.OrganizationId == ou.OrganizationId) + select new { ou, o, su, p, ss, os }; + + return query.Select(x => new OrganizationUserOrganizationDetails { OrganizationId = x.ou.OrganizationId, UserId = x.ou.UserId, diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByFreeOrganizationAdminUserQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByFreeOrganizationAdminUserQuery.cs index c2f0c32e1..15b7ad620 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByFreeOrganizationAdminUserQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByFreeOrganizationAdminUserQuery.cs @@ -1,8 +1,8 @@ +using System; using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -18,14 +18,14 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ou in dbContext.OrganizationUsers - join o in dbContext.Organizations - on ou.OrganizationId equals o.Id - where ou.UserId == _userId && - (ou.Type == OrganizationUserType.Owner || ou.Type == OrganizationUserType.Admin) && - o.PlanType == PlanType.Free && - ou.Status == OrganizationUserStatusType.Confirmed - select ou; - + join o in dbContext.Organizations + on ou.OrganizationId equals o.Id + where ou.UserId == _userId && + (ou.Type == OrganizationUserType.Owner || ou.Type == OrganizationUserType.Admin) && + o.PlanType == PlanType.Free && + ou.Status == OrganizationUserStatusType.Confirmed + select ou; + return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOnlyOwnerQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOnlyOwnerQuery.cs index 23be161fd..73d54550d 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOnlyOwnerQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOnlyOwnerQuery.cs @@ -1,8 +1,8 @@ +using System; using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -18,22 +18,22 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var owners = from ou in dbContext.OrganizationUsers - where ou.Type == OrganizationUserType.Owner && - ou.Status == OrganizationUserStatusType.Confirmed - group ou by ou.OrganizationId into g - select new - { - OrgUser = g.Select(x => new {x.UserId, x.Id}).FirstOrDefault(), - ConfirmedOwnerCount = g.Count(), - }; - + where ou.Type == OrganizationUserType.Owner && + ou.Status == OrganizationUserStatusType.Confirmed + group ou by ou.OrganizationId into g + select new + { + OrgUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(), + ConfirmedOwnerCount = g.Count(), + }; + var query = from owner in owners - join ou in dbContext.OrganizationUsers - on owner.OrgUser.Id equals ou.Id - where owner.OrgUser.UserId == _userId && - owner.ConfirmedOwnerCount == 1 - select ou; - + join ou in dbContext.OrganizationUsers + on owner.OrgUser.Id equals ou.Id + where owner.OrgUser.UserId == _userId && + owner.ConfirmedOwnerCount == 1 + select ou; + return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdEmailQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdEmailQuery.cs index 17da7814e..aec5b2b3c 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdEmailQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdEmailQuery.cs @@ -1,6 +1,6 @@ +using System; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -20,13 +20,13 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ou in dbContext.OrganizationUsers - join u in dbContext.Users - on ou.UserId equals u.Id into u_g - from u in u_g.DefaultIfEmpty() - where ou.OrganizationId == _organizationId && - ((!_onlyUsers && (ou.Email == _email || u.Email == _email)) - || (_onlyUsers && u.Email == _email)) - select ou; + join u in dbContext.Users + on ou.UserId equals u.Id into u_g + from u in u_g.DefaultIfEmpty() + where ou.OrganizationId == _organizationId && + ((!_onlyUsers && (ou.Email == _email || u.Email == _email)) + || (_onlyUsers && u.Email == _email)) + select ou; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdQuery.cs index 3a4777237..a8f72532c 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserReadCountByOrganizationIdQuery.cs @@ -1,6 +1,6 @@ +using System; using System.Linq; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -16,8 +16,8 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ou in dbContext.OrganizationUsers - where ou.OrganizationId == _organizationId - select ou; + where ou.OrganizationId == _organizationId + select ou; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUpdateWithCollectionsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUpdateWithCollectionsQuery.cs index de2e519c5..dc55912bf 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUpdateWithCollectionsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUpdateWithCollectionsQuery.cs @@ -1,9 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; using Bit.Core.Models.Data; using Bit.Core.Models.EntityFramework; using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System.Linq; -using System; using Table = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -17,7 +17,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public OrganizationUserUpdateWithCollectionsQuery(Table.OrganizationUser organizationUser, IEnumerable collections) { - Insert = new OrganizationUserUpdateWithCollectionsInsertQuery(organizationUser, collections); + Insert = new OrganizationUserUpdateWithCollectionsInsertQuery(organizationUser, collections); Update = new OrganizationUserUpdateWithCollectionsUpdateQuery(organizationUser, collections); Delete = new OrganizationUserUpdateWithCollectionsDeleteQuery(organizationUser, collections); } @@ -38,16 +38,16 @@ namespace Bit.Core.Repositories.EntityFramework.Queries { var collectionIds = _collections.Select(c => c.Id).ToArray(); var t = (from cu in dbContext.CollectionUsers - where collectionIds.Contains(cu.CollectionId) && - cu.OrganizationUserId == _organizationUser.Id - select cu).AsEnumerable(); + where collectionIds.Contains(cu.CollectionId) && + cu.OrganizationUserId == _organizationUser.Id + select cu).AsEnumerable(); var insertQuery = (from c in dbContext.Collections - where collectionIds.Contains(c.Id) && - c.OrganizationId == _organizationUser.OrganizationId && - !t.Any() - select c).AsEnumerable(); + where collectionIds.Contains(c.Id) && + c.OrganizationId == _organizationUser.OrganizationId && + !t.Any() + select c).AsEnumerable(); return insertQuery.Select(x => new CollectionUser - { + { CollectionId = x.Id, OrganizationUserId = _organizationUser.Id, ReadOnly = _collections.FirstOrDefault(c => c.Id == x.Id).ReadOnly, @@ -56,7 +56,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries } } - public class OrganizationUserUpdateWithCollectionsUpdateQuery: IQuery + public class OrganizationUserUpdateWithCollectionsUpdateQuery : IQuery { private readonly Table.OrganizationUser _organizationUser; private readonly IEnumerable _collections; @@ -71,14 +71,14 @@ namespace Bit.Core.Repositories.EntityFramework.Queries { var collectionIds = _collections.Select(c => c.Id).ToArray(); var updateQuery = (from target in dbContext.CollectionUsers - where collectionIds.Contains(target.CollectionId) && - target.OrganizationUserId == _organizationUser.Id - select new { target }).AsEnumerable(); - updateQuery = updateQuery.Where(cu => + where collectionIds.Contains(target.CollectionId) && + target.OrganizationUserId == _organizationUser.Id + select new { target }).AsEnumerable(); + updateQuery = updateQuery.Where(cu => cu.target.ReadOnly == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).ReadOnly && cu.target.HidePasswords == _collections.FirstOrDefault(u => u.Id == cu.target.CollectionId).HidePasswords); return updateQuery.Select(x => new CollectionUser - { + { CollectionId = x.target.CollectionId, OrganizationUserId = _organizationUser.Id, ReadOnly = x.target.ReadOnly, @@ -87,7 +87,7 @@ namespace Bit.Core.Repositories.EntityFramework.Queries } } - public class OrganizationUserUpdateWithCollectionsDeleteQuery: IQuery + public class OrganizationUserUpdateWithCollectionsDeleteQuery : IQuery { private readonly Table.OrganizationUser _organizationUser; private readonly IEnumerable _collections; @@ -101,9 +101,9 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var deleteQuery = from cu in dbContext.CollectionUsers - where !_collections.Any( - c => c.Id == cu.CollectionId) - select cu; + where !_collections.Any( + c => c.Id == cu.CollectionId) + select cu; return deleteQuery; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUserViewQuery.cs b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUserViewQuery.cs index 49c8274e7..7d01bf7c7 100644 --- a/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUserViewQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/OrganizationUserUserViewQuery.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Bit.Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -8,12 +8,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from ou in dbContext.OrganizationUsers - join u in dbContext.Users on ou.UserId equals u.Id into u_g - from u in u_g.DefaultIfEmpty() - join su in dbContext.SsoUsers on u.Id equals su.UserId into su_g - from su in su_g.DefaultIfEmpty() - select new { ou, u, su }; - return query.Select(x => new OrganizationUserUserDetails + join u in dbContext.Users on ou.UserId equals u.Id into u_g + from u in u_g.DefaultIfEmpty() + join su in dbContext.SsoUsers on u.Id equals su.UserId into su_g + from su in su_g.DefaultIfEmpty() + select new { ou, u, su }; + return query.Select(x => new OrganizationUserUserDetails { Id = x.ou.Id, OrganizationId = x.ou.OrganizationId, diff --git a/src/Core/Repositories/EntityFramework/Queries/PolicyReadByTypeApplicableToUserQuery.cs b/src/Core/Repositories/EntityFramework/Queries/PolicyReadByTypeApplicableToUserQuery.cs index 8253b9de0..538c65431 100644 --- a/src/Core/Repositories/EntityFramework/Queries/PolicyReadByTypeApplicableToUserQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/PolicyReadByTypeApplicableToUserQuery.cs @@ -1,8 +1,8 @@ +using System; using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -22,10 +22,10 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var providerOrganizations = from pu in dbContext.ProviderUsers - where pu.UserId == _userId - join po in dbContext.ProviderOrganizations - on pu.ProviderId equals po.ProviderId - select po; + where pu.UserId == _userId + join po in dbContext.ProviderOrganizations + on pu.ProviderId equals po.ProviderId + select po; string userEmail = null; if (_minimumStatus == OrganizationUserStatusType.Invited) @@ -35,19 +35,19 @@ namespace Bit.Core.Repositories.EntityFramework.Queries } var query = from p in dbContext.Policies - join ou in dbContext.OrganizationUsers - on p.OrganizationId equals ou.OrganizationId - where - ((_minimumStatus > OrganizationUserStatusType.Invited && ou.UserId == _userId) || - (_minimumStatus == OrganizationUserStatusType.Invited && ou.Email == userEmail)) && - p.Type == _policyType && - p.Enabled && - ou.Status >= _minimumStatus && - ou.Type >= OrganizationUserType.User && - (ou.Permissions == null || - ou.Permissions.Contains($"\"managePolicies\":false")) && - !providerOrganizations.Any(po => po.OrganizationId == p.OrganizationId) - select p; + join ou in dbContext.OrganizationUsers + on p.OrganizationId equals ou.OrganizationId + where + ((_minimumStatus > OrganizationUserStatusType.Invited && ou.UserId == _userId) || + (_minimumStatus == OrganizationUserStatusType.Invited && ou.Email == userEmail)) && + p.Type == _policyType && + p.Enabled && + ou.Status >= _minimumStatus && + ou.Type >= OrganizationUserType.User && + (ou.Permissions == null || + ou.Permissions.Contains($"\"managePolicies\":false")) && + !providerOrganizations.Any(po => po.OrganizationId == p.OrganizationId) + select p; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/PolicyReadByUserIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/PolicyReadByUserIdQuery.cs index 09532e101..5ef6e86bb 100644 --- a/src/Core/Repositories/EntityFramework/Queries/PolicyReadByUserIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/PolicyReadByUserIdQuery.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; using Bit.Core.Models.EntityFramework; -using System; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -18,15 +18,15 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from p in dbContext.Policies - join ou in dbContext.OrganizationUsers - on p.OrganizationId equals ou.OrganizationId - join o in dbContext.Organizations - on ou.OrganizationId equals o.Id - where ou.UserId == _userId && - ou.Status == OrganizationUserStatusType.Confirmed && - o.Enabled == true - select p; - + join ou in dbContext.OrganizationUsers + on p.OrganizationId equals ou.OrganizationId + join o in dbContext.Organizations + on ou.OrganizationId equals o.Id + where ou.UserId == _userId && + ou.Status == OrganizationUserStatusType.Confirmed && + o.Enabled == true + select p; + return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs index 3919fae59..6261f6150 100644 --- a/src/Core/Repositories/EntityFramework/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Bit.Core.Models.Data; @@ -15,15 +15,15 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from po in dbContext.ProviderOrganizations - join o in dbContext.Organizations - on po.OrganizationId equals o.Id - where po.ProviderId == _providerId - select new { po, o }; - return query.Select(x => new ProviderOrganizationOrganizationDetails() + join o in dbContext.Organizations + on po.OrganizationId equals o.Id + where po.ProviderId == _providerId + select new { po, o }; + return query.Select(x => new ProviderOrganizationOrganizationDetails() { Id = x.po.Id, ProviderId = x.po.ProviderId, - OrganizationId = x.po.OrganizationId, + OrganizationId = x.po.OrganizationId, OrganizationName = x.o.Name, Key = x.po.Key, Settings = x.po.Settings, diff --git a/src/Core/Repositories/EntityFramework/Queries/ProviderUserOrganizationDetailsViewQuery.cs b/src/Core/Repositories/EntityFramework/Queries/ProviderUserOrganizationDetailsViewQuery.cs index c21c68fcc..0ac54059e 100644 --- a/src/Core/Repositories/EntityFramework/Queries/ProviderUserOrganizationDetailsViewQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/ProviderUserOrganizationDetailsViewQuery.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Models.Data; @@ -9,10 +9,10 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from pu in dbContext.ProviderUsers - join po in dbContext.ProviderOrganizations on pu.ProviderId equals po.ProviderId - join o in dbContext.Organizations on po.OrganizationId equals o.Id - join p in dbContext.Providers on pu.ProviderId equals p.Id - select new { pu, po, o, p }; + join po in dbContext.ProviderOrganizations on pu.ProviderId equals po.ProviderId + join o in dbContext.Organizations on po.OrganizationId equals o.Id + join p in dbContext.Providers on pu.ProviderId equals p.Id + select new { pu, po, o, p }; return query.Select(x => new ProviderUserOrganizationDetails { OrganizationId = x.po.OrganizationId, diff --git a/src/Core/Repositories/EntityFramework/Queries/ProviderUserProviderDetailsReadByUserIdStatusQuery.cs b/src/Core/Repositories/EntityFramework/Queries/ProviderUserProviderDetailsReadByUserIdStatusQuery.cs index 9dd2f6bd6..3d2dd8419 100644 --- a/src/Core/Repositories/EntityFramework/Queries/ProviderUserProviderDetailsReadByUserIdStatusQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/ProviderUserProviderDetailsReadByUserIdStatusQuery.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Bit.Core.Enums.Provider; using Bit.Core.Models.Data; @@ -18,16 +18,16 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from pu in dbContext.ProviderUsers - join p in dbContext.Providers - on pu.ProviderId equals p.Id into p_g - from p in p_g.DefaultIfEmpty() - where pu.UserId == _userId && p.Status != ProviderStatusType.Pending && (_status == null || pu.Status == _status) - select new { pu, p }; - return query.Select(x => new ProviderUserProviderDetails() + join p in dbContext.Providers + on pu.ProviderId equals p.Id into p_g + from p in p_g.DefaultIfEmpty() + where pu.UserId == _userId && p.Status != ProviderStatusType.Pending && (_status == null || pu.Status == _status) + select new { pu, p }; + return query.Select(x => new ProviderUserProviderDetails() { UserId = x.pu.UserId, ProviderId = x.pu.ProviderId, - Name = x.p.Name, + Name = x.p.Name, Key = x.pu.Key, Status = x.pu.Status, Type = x.pu.Type, diff --git a/src/Core/Repositories/EntityFramework/Queries/ProviderUserReadCountByOnlyOwnerQuery.cs b/src/Core/Repositories/EntityFramework/Queries/ProviderUserReadCountByOnlyOwnerQuery.cs index 86e5296c3..b1cb35065 100644 --- a/src/Core/Repositories/EntityFramework/Queries/ProviderUserReadCountByOnlyOwnerQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/ProviderUserReadCountByOnlyOwnerQuery.cs @@ -1,5 +1,5 @@ +using System; using System.Linq; -using System; using Bit.Core.Enums.Provider; using Bit.Core.Models.EntityFramework.Provider; @@ -17,21 +17,21 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var owners = from pu in dbContext.ProviderUsers - where pu.Type == ProviderUserType.ProviderAdmin && - pu.Status == ProviderUserStatusType.Confirmed - group pu by pu.ProviderId into g - select new - { - ProviderUser = g.Select(x => new {x.UserId, x.Id}).FirstOrDefault(), - ConfirmedOwnerCount = g.Count(), - }; + where pu.Type == ProviderUserType.ProviderAdmin && + pu.Status == ProviderUserStatusType.Confirmed + group pu by pu.ProviderId into g + select new + { + ProviderUser = g.Select(x => new { x.UserId, x.Id }).FirstOrDefault(), + ConfirmedOwnerCount = g.Count(), + }; var query = from owner in owners - join pu in dbContext.ProviderUsers - on owner.ProviderUser.Id equals pu.Id - where owner.ProviderUser.UserId == _userId && - owner.ConfirmedOwnerCount == 1 - select pu; + join pu in dbContext.ProviderUsers + on owner.ProviderUser.Id equals pu.Id + where owner.ProviderUser.UserId == _userId && + owner.ConfirmedOwnerCount == 1 + select pu; return query; } diff --git a/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByCipherIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByCipherIdQuery.cs index 38bc0cf50..0827bef01 100644 --- a/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByCipherIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByCipherIdQuery.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; using Bit.Core.Models.EntityFramework; @@ -18,36 +18,36 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from u in dbContext.Users - join ou in dbContext.OrganizationUsers - on u.Id equals ou.UserId - join collectionCipher in dbContext.CollectionCiphers - on _cipher.Id equals collectionCipher.CipherId into cc_g - from cc in cc_g.DefaultIfEmpty() - join collectionUser in dbContext.CollectionUsers - on cc.CollectionId equals collectionUser.CollectionId into cu_g - from cu in cu_g.DefaultIfEmpty() - where ou.AccessAll && - cu.OrganizationUserId == ou.Id - join groupUser in dbContext.GroupUsers - on ou.Id equals groupUser.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == null && - !ou.AccessAll - join grp in dbContext.Groups - on gu.GroupId equals grp.Id into g_g - from g in g_g.DefaultIfEmpty() - join collectionGroup in dbContext.CollectionGroups - on cc.CollectionId equals collectionGroup.CollectionId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && - cg.GroupId == gu.GroupId - where ou.OrganizationId == _cipher.OrganizationId && - ou.Status == OrganizationUserStatusType.Confirmed && - (cu.CollectionId != null || - cg.CollectionId != null || - ou.AccessAll || - g.AccessAll) - select u; + join ou in dbContext.OrganizationUsers + on u.Id equals ou.UserId + join collectionCipher in dbContext.CollectionCiphers + on _cipher.Id equals collectionCipher.CipherId into cc_g + from cc in cc_g.DefaultIfEmpty() + join collectionUser in dbContext.CollectionUsers + on cc.CollectionId equals collectionUser.CollectionId into cu_g + from cu in cu_g.DefaultIfEmpty() + where ou.AccessAll && + cu.OrganizationUserId == ou.Id + join groupUser in dbContext.GroupUsers + on ou.Id equals groupUser.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == null && + !ou.AccessAll + join grp in dbContext.Groups + on gu.GroupId equals grp.Id into g_g + from g in g_g.DefaultIfEmpty() + join collectionGroup in dbContext.CollectionGroups + on cc.CollectionId equals collectionGroup.CollectionId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && + cg.GroupId == gu.GroupId + where ou.OrganizationId == _cipher.OrganizationId && + ou.Status == OrganizationUserStatusType.Confirmed && + (cu.CollectionId != null || + cg.CollectionId != null || + ou.AccessAll || + g.AccessAll) + select u; return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByOrganizationIdQuery.cs b/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByOrganizationIdQuery.cs index 4145d2719..4ed4fdaff 100644 --- a/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByOrganizationIdQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/UserBumpAccountRevisionDateByOrganizationIdQuery.cs @@ -1,7 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; using Bit.Core.Enums; -using System; using Bit.Core.Models.EntityFramework; namespace Bit.Core.Repositories.EntityFramework.Queries @@ -18,12 +18,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public IQueryable Run(DatabaseContext dbContext) { var query = from u in dbContext.Users - join ou in dbContext.OrganizationUsers - on u.Id equals ou.UserId - where ou.OrganizationId == _organizationId && - ou.Status == OrganizationUserStatusType.Confirmed - select u; - + join ou in dbContext.OrganizationUsers + on u.Id equals ou.UserId + where ou.OrganizationId == _organizationId && + ou.Status == OrganizationUserStatusType.Confirmed + select u; + return query; } } diff --git a/src/Core/Repositories/EntityFramework/Queries/UserCipherDetailsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/UserCipherDetailsQuery.cs index 8254b091c..02ae9d3a4 100644 --- a/src/Core/Repositories/EntityFramework/Queries/UserCipherDetailsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/UserCipherDetailsQuery.cs @@ -1,16 +1,16 @@ -using System.Linq; -using System; -using Bit.Core.Enums; +using System; using System.Collections.Generic; -using Core.Models.Data; +using System.Linq; +using Bit.Core.Enums; using Bit.Core.Utilities; +using Core.Models.Data; using Newtonsoft.Json.Linq; namespace Bit.Core.Repositories.EntityFramework.Queries { public class UserCipherDetailsQuery : IQuery { - private readonly Guid? _userId; + private readonly Guid? _userId; public UserCipherDetailsQuery(Guid? userId) { _userId = userId; @@ -18,53 +18,53 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Ciphers - join ou in dbContext.OrganizationUsers - on c.OrganizationId equals ou.OrganizationId - where ou.UserId == _userId && - ou.Status == OrganizationUserStatusType.Confirmed - join o in dbContext.Organizations - on c.OrganizationId equals o.Id - where o.Id == ou.OrganizationId && o.Enabled - join cc in dbContext.CollectionCiphers - on c.Id equals cc.CipherId into cc_g - from cc in cc_g.DefaultIfEmpty() - where ou.AccessAll - join cu in dbContext.CollectionUsers - on cc.CollectionId equals cu.CollectionId into cu_g - from cu in cu_g.DefaultIfEmpty() - where cu.OrganizationUserId == ou.Id - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on cc.CollectionId equals cg.CollectionId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.GroupId == gu.GroupId && - ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null - select new {c, ou, o, cc, cu, gu, g, cg}.c; + join ou in dbContext.OrganizationUsers + on c.OrganizationId equals ou.OrganizationId + where ou.UserId == _userId && + ou.Status == OrganizationUserStatusType.Confirmed + join o in dbContext.Organizations + on c.OrganizationId equals o.Id + where o.Id == ou.OrganizationId && o.Enabled + join cc in dbContext.CollectionCiphers + on c.Id equals cc.CipherId into cc_g + from cc in cc_g.DefaultIfEmpty() + where ou.AccessAll + join cu in dbContext.CollectionUsers + on cc.CollectionId equals cu.CollectionId into cu_g + from cu in cu_g.DefaultIfEmpty() + where cu.OrganizationUserId == ou.Id + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on cc.CollectionId equals cg.CollectionId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.GroupId == gu.GroupId && + ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null + select new { c, ou, o, cc, cu, gu, g, cg }.c; var query2 = from c in dbContext.Ciphers - where c.UserId == _userId - select c; + where c.UserId == _userId + select c; var union = query.Union(query2).Select(c => new CipherDetails { Id = c.Id, UserId = c.UserId, OrganizationId = c.OrganizationId, - Type= c.Type, + Type = c.Type, Data = c.Data, Attachments = c.Attachments, CreationDate = c.CreationDate, RevisionDate = c.RevisionDate, DeletedDate = c.DeletedDate, Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"), - FolderId = _userId.HasValue && !string.IsNullOrWhiteSpace(c.Folders) ? - Guid.Parse(JObject.Parse(c.Folders)[_userId.Value.ToString()].Value()) : + FolderId = _userId.HasValue && !string.IsNullOrWhiteSpace(c.Folders) ? + Guid.Parse(JObject.Parse(c.Folders)[_userId.Value.ToString()].Value()) : null, Edit = true, ViewPassword = true, diff --git a/src/Core/Repositories/EntityFramework/Queries/UserCollectionDetailsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/UserCollectionDetailsQuery.cs index 9c56239d2..ef218bb82 100644 --- a/src/Core/Repositories/EntityFramework/Queries/UserCollectionDetailsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/UserCollectionDetailsQuery.cs @@ -1,14 +1,14 @@ -using System.Linq; -using System; -using Bit.Core.Enums; +using System; using System.Collections.Generic; +using System.Linq; +using Bit.Core.Enums; using Bit.Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries { public class UserCollectionDetailsQuery : IQuery { - private readonly Guid? _userId; + private readonly Guid? _userId; public UserCollectionDetailsQuery(Guid? userId) { _userId = userId; @@ -16,31 +16,31 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from c in dbContext.Collections - join ou in dbContext.OrganizationUsers - on c.OrganizationId equals ou.OrganizationId - join o in dbContext.Organizations - on c.OrganizationId equals o.Id - join cu in dbContext.CollectionUsers - on c.Id equals cu.CollectionId into cu_g - from cu in cu_g.DefaultIfEmpty() - where ou.AccessAll && cu.OrganizationUserId == ou.Id - join gu in dbContext.GroupUsers - on ou.Id equals gu.OrganizationUserId into gu_g - from gu in gu_g.DefaultIfEmpty() - where cu.CollectionId == null && !ou.AccessAll - join g in dbContext.Groups - on gu.GroupId equals g.Id into g_g - from g in g_g.DefaultIfEmpty() - join cg in dbContext.CollectionGroups - on gu.GroupId equals cg.GroupId into cg_g - from cg in cg_g.DefaultIfEmpty() - where !g.AccessAll && cg.CollectionId == c.Id && - ou.UserId == _userId && - ou.Status == OrganizationUserStatusType.Confirmed && - o.Enabled && - (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null) - select new { c, ou, o, cu, gu, g, cg }; - return query.Select(x => new CollectionDetails + join ou in dbContext.OrganizationUsers + on c.OrganizationId equals ou.OrganizationId + join o in dbContext.Organizations + on c.OrganizationId equals o.Id + join cu in dbContext.CollectionUsers + on c.Id equals cu.CollectionId into cu_g + from cu in cu_g.DefaultIfEmpty() + where ou.AccessAll && cu.OrganizationUserId == ou.Id + join gu in dbContext.GroupUsers + on ou.Id equals gu.OrganizationUserId into gu_g + from gu in gu_g.DefaultIfEmpty() + where cu.CollectionId == null && !ou.AccessAll + join g in dbContext.Groups + on gu.GroupId equals g.Id into g_g + from g in g_g.DefaultIfEmpty() + join cg in dbContext.CollectionGroups + on gu.GroupId equals cg.GroupId into cg_g + from cg in cg_g.DefaultIfEmpty() + where !g.AccessAll && cg.CollectionId == c.Id && + ou.UserId == _userId && + ou.Status == OrganizationUserStatusType.Confirmed && + o.Enabled && + (ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null) + select new { c, ou, o, cu, gu, g, cg }; + return query.Select(x => new CollectionDetails { Id = x.c.Id, OrganizationId = x.c.OrganizationId, diff --git a/src/Core/Repositories/EntityFramework/Queries/UserReadPublicKeysByProviderUserIdsQuery.cs b/src/Core/Repositories/EntityFramework/Queries/UserReadPublicKeysByProviderUserIdsQuery.cs index d3b629f6d..5b9a63add 100644 --- a/src/Core/Repositories/EntityFramework/Queries/UserReadPublicKeysByProviderUserIdsQuery.cs +++ b/src/Core/Repositories/EntityFramework/Queries/UserReadPublicKeysByProviderUserIdsQuery.cs @@ -1,10 +1,10 @@ -using System.Linq; -using System; +using System; using System.Collections.Generic; -using Core.Models.Data; -using Bit.Core.Utilities; -using Bit.Core.Models.Data; +using System.Linq; using Bit.Core.Enums.Provider; +using Bit.Core.Models.Data; +using Bit.Core.Utilities; +using Core.Models.Data; namespace Bit.Core.Repositories.EntityFramework.Queries { @@ -22,12 +22,12 @@ namespace Bit.Core.Repositories.EntityFramework.Queries public virtual IQueryable Run(DatabaseContext dbContext) { var query = from pu in dbContext.ProviderUsers - join u in dbContext.Users - on pu.UserId equals u.Id - where _ids.Contains(pu.Id) && - pu.Status == ProviderUserStatusType.Accepted && - pu.ProviderId == _providerId - select new { pu, u }; + join u in dbContext.Users + on pu.UserId equals u.Id + where _ids.Contains(pu.Id) && + pu.Status == ProviderUserStatusType.Accepted && + pu.ProviderId == _providerId + select new { pu, u }; return query.Select(x => new ProviderUserPublicKey { Id = x.pu.Id, diff --git a/src/Core/Repositories/EntityFramework/Repository.cs b/src/Core/Repositories/EntityFramework/Repository.cs index 4f29ed621..9e9817958 100644 --- a/src/Core/Repositories/EntityFramework/Repository.cs +++ b/src/Core/Repositories/EntityFramework/Repository.cs @@ -1,12 +1,12 @@ using System; -using System.Threading.Tasks; -using Bit.Core.Models.Table; -using AutoMapper; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework.Queries; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.Repositories.EntityFramework { diff --git a/src/Core/Repositories/EntityFramework/SendRepository.cs b/src/Core/Repositories/EntityFramework/SendRepository.cs index 151c4e67a..fd3d011e9 100644 --- a/src/Core/Repositories/EntityFramework/SendRepository.cs +++ b/src/Core/Repositories/EntityFramework/SendRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -20,13 +20,13 @@ namespace Bit.Core.Repositories.EntityFramework public override async Task CreateAsync(Send send) { - send = await base.CreateAsync(send); - if (send.UserId.HasValue) - { + send = await base.CreateAsync(send); + if (send.UserId.HasValue) + { await UserUpdateStorage(send.UserId.Value); await UserBumpAccountRevisionDate(send.UserId.Value); - } - return send; + } + return send; } public async Task> GetManyByDeletionDateAsync(DateTime deletionDateBefore) diff --git a/src/Core/Repositories/EntityFramework/SsoConfigRepository.cs b/src/Core/Repositories/EntityFramework/SsoConfigRepository.cs index e96bb6485..cda75d2cf 100644 --- a/src/Core/Repositories/EntityFramework/SsoConfigRepository.cs +++ b/src/Core/Repositories/EntityFramework/SsoConfigRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/SsoUserRepository.cs b/src/Core/Repositories/EntityFramework/SsoUserRepository.cs index e8ad2b736..b1521448d 100644 --- a/src/Core/Repositories/EntityFramework/SsoUserRepository.cs +++ b/src/Core/Repositories/EntityFramework/SsoUserRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using AutoMapper; using Microsoft.EntityFrameworkCore; diff --git a/src/Core/Repositories/EntityFramework/TaxRateRepository.cs b/src/Core/Repositories/EntityFramework/TaxRateRepository.cs index f2180002c..c1e0ab1d9 100644 --- a/src/Core/Repositories/EntityFramework/TaxRateRepository.cs +++ b/src/Core/Repositories/EntityFramework/TaxRateRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/TransactionRepository.cs b/src/Core/Repositories/EntityFramework/TransactionRepository.cs index 07ceebe0f..d2a540dac 100644 --- a/src/Core/Repositories/EntityFramework/TransactionRepository.cs +++ b/src/Core/Repositories/EntityFramework/TransactionRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Repositories/EntityFramework/U2fRepository.cs b/src/Core/Repositories/EntityFramework/U2fRepository.cs index 1afe000e0..f2e567f3b 100644 --- a/src/Core/Repositories/EntityFramework/U2fRepository.cs +++ b/src/Core/Repositories/EntityFramework/U2fRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -38,7 +38,7 @@ namespace Bit.Core.Repositories.EntityFramework await dbContext.SaveChangesAsync(); } } - + public override Task ReplaceAsync(U2f obj) { throw new NotSupportedException(); diff --git a/src/Core/Repositories/EntityFramework/UserRepository.cs b/src/Core/Repositories/EntityFramework/UserRepository.cs index 38c432131..04177bd48 100644 --- a/src/Core/Repositories/EntityFramework/UserRepository.cs +++ b/src/Core/Repositories/EntityFramework/UserRepository.cs @@ -1,15 +1,15 @@ using System; -using TableModel = Bit.Core.Models.Table; -using EFModel = Bit.Core.Models.EntityFramework; -using DataModel = Bit.Core.Models.Data; -using AutoMapper; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using Bit.Core.Models.Table; using System.Text.Json; +using System.Threading.Tasks; +using AutoMapper; +using Bit.Core.Models.Table; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using DataModel = Bit.Core.Models.Data; +using EFModel = Bit.Core.Models.EntityFramework; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Repositories.EntityFramework { @@ -52,13 +52,14 @@ namespace Bit.Core.Repositories.EntityFramework if (dbContext.Database.IsNpgsql()) { users = await GetDbSet(dbContext) - .Where(e => e.Email == null || + .Where(e => e.Email == null || EF.Functions.ILike(EF.Functions.Collate(e.Email, "default"), "a%")) .OrderBy(e => e.Email) .Skip(skip).Take(take) .ToListAsync(); } - else { + else + { users = await GetDbSet(dbContext) .Where(e => email == null || e.Email.StartsWith(email)) .OrderBy(e => e.Email) @@ -127,7 +128,7 @@ namespace Bit.Core.Repositories.EntityFramework var dbContext = GetDatabaseContext(scope); var ssoUser = await dbContext.SsoUsers.SingleOrDefaultAsync(e => e.OrganizationId == organizationId && e.ExternalId == externalId); - + if (ssoUser == null) { return null; diff --git a/src/Core/Repositories/ICipherRepository.cs b/src/Core/Repositories/ICipherRepository.cs index 5a5e1ede7..e1b423dad 100644 --- a/src/Core/Repositories/ICipherRepository.cs +++ b/src/Core/Repositories/ICipherRepository.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Core.Models.Data; -using Bit.Core.Models.Data; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ICollectionCipherRepository.cs b/src/Core/Repositories/ICollectionCipherRepository.cs index 03409baf1..f518603d3 100644 --- a/src/Core/Repositories/ICollectionCipherRepository.cs +++ b/src/Core/Repositories/ICollectionCipherRepository.cs @@ -1,7 +1,7 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Table; -using System.Collections.Generic; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ICollectionRepository.cs b/src/Core/Repositories/ICollectionRepository.cs index 7ebf4d2dc..f0cd4cd4b 100644 --- a/src/Core/Repositories/ICollectionRepository.cs +++ b/src/Core/Repositories/ICollectionRepository.cs @@ -1,8 +1,8 @@ using System; -using System.Threading.Tasks; -using Bit.Core.Models.Table; using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IFolderRepository.cs b/src/Core/Repositories/IFolderRepository.cs index 3056c3121..2760d8556 100644 --- a/src/Core/Repositories/IFolderRepository.cs +++ b/src/Core/Repositories/IFolderRepository.cs @@ -1,7 +1,7 @@ using System; -using Bit.Core.Models.Table; -using System.Threading.Tasks; using System.Collections.Generic; +using System.Threading.Tasks; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IGrantRepository.cs b/src/Core/Repositories/IGrantRepository.cs index 86730040a..5f4f3d723 100644 --- a/src/Core/Repositories/IGrantRepository.cs +++ b/src/Core/Repositories/IGrantRepository.cs @@ -1,7 +1,7 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Table; -using System.Collections.Generic; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IGroupRepository.cs b/src/Core/Repositories/IGroupRepository.cs index 4d3302f26..2e11b4cc4 100644 --- a/src/Core/Repositories/IGroupRepository.cs +++ b/src/Core/Repositories/IGroupRepository.cs @@ -1,8 +1,8 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IOrganizationSponsorshipRepository.cs b/src/Core/Repositories/IOrganizationSponsorshipRepository.cs index 9d81cae91..3c9f57d26 100644 --- a/src/Core/Repositories/IOrganizationSponsorshipRepository.cs +++ b/src/Core/Repositories/IOrganizationSponsorshipRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; diff --git a/src/Core/Repositories/IOrganizationUserRepository.cs b/src/Core/Repositories/IOrganizationUserRepository.cs index 2c12d9712..e4085480e 100644 --- a/src/Core/Repositories/IOrganizationUserRepository.cs +++ b/src/Core/Repositories/IOrganizationUserRepository.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Bit.Core.Models.Table; -using Bit.Core.Models.Data; using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IPolicyRepository.cs b/src/Core/Repositories/IPolicyRepository.cs index cf80d32b5..54ceed605 100644 --- a/src/Core/Repositories/IPolicyRepository.cs +++ b/src/Core/Repositories/IPolicyRepository.cs @@ -1,8 +1,8 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/IRepository.cs b/src/Core/Repositories/IRepository.cs index 9402e22e1..6cb1a7951 100644 --- a/src/Core/Repositories/IRepository.cs +++ b/src/Core/Repositories/IRepository.cs @@ -1,6 +1,6 @@ -using Bit.Core.Models.Table; -using System; +using System; using System.Threading.Tasks; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ISendRepository.cs b/src/Core/Repositories/ISendRepository.cs index 761781dcb..a7179ea21 100644 --- a/src/Core/Repositories/ISendRepository.cs +++ b/src/Core/Repositories/ISendRepository.cs @@ -1,7 +1,7 @@ using System; -using Bit.Core.Models.Table; -using System.Threading.Tasks; using System.Collections.Generic; +using System.Threading.Tasks; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ISsoConfigRepository.cs b/src/Core/Repositories/ISsoConfigRepository.cs index 7f5c9169e..763cb2f0b 100644 --- a/src/Core/Repositories/ISsoConfigRepository.cs +++ b/src/Core/Repositories/ISsoConfigRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Table; diff --git a/src/Core/Repositories/ISsoUserRepository.cs b/src/Core/Repositories/ISsoUserRepository.cs index 350c15387..7d466ed00 100644 --- a/src/Core/Repositories/ISsoUserRepository.cs +++ b/src/Core/Repositories/ISsoUserRepository.cs @@ -1,6 +1,6 @@ -using Bit.Core.Models.Table; -using System; +using System; using System.Threading.Tasks; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ITaxRateRepository.cs b/src/Core/Repositories/ITaxRateRepository.cs index b507e3b31..7916a3137 100644 --- a/src/Core/Repositories/ITaxRateRepository.cs +++ b/src/Core/Repositories/ITaxRateRepository.cs @@ -1,6 +1,6 @@ -using Bit.Core.Models.Table; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/ITransactionRepository.cs b/src/Core/Repositories/ITransactionRepository.cs index 242dcfa3c..e47c68b8c 100644 --- a/src/Core/Repositories/ITransactionRepository.cs +++ b/src/Core/Repositories/ITransactionRepository.cs @@ -1,8 +1,8 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Repositories { diff --git a/src/Core/Repositories/SqlServer/CipherRepository.cs b/src/Core/Repositories/SqlServer/CipherRepository.cs index ed7f65757..0b37e2dca 100644 --- a/src/Core/Repositories/SqlServer/CipherRepository.cs +++ b/src/Core/Repositories/SqlServer/CipherRepository.cs @@ -1,16 +1,16 @@ using System; -using System.Linq; using System.Collections.Generic; -using System.Data.SqlClient; -using System.Threading.Tasks; -using Bit.Core.Models.Table; using System.Data; -using Dapper; -using Core.Models.Data; -using Bit.Core.Utilities; -using Newtonsoft.Json; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Core.Models.Data; +using Dapper; +using Newtonsoft.Json; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/CollectionCipherRepository.cs b/src/Core/Repositories/SqlServer/CollectionCipherRepository.cs index 34e962028..8d3f5e03e 100644 --- a/src/Core/Repositories/SqlServer/CollectionCipherRepository.cs +++ b/src/Core/Repositories/SqlServer/CollectionCipherRepository.cs @@ -1,13 +1,13 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; -using System.Threading.Tasks; -using System.Data.SqlClient; using System.Data; -using Dapper; +using System.Data.SqlClient; using System.Linq; -using Bit.Core.Utilities; +using System.Threading.Tasks; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/CollectionRepository.cs b/src/Core/Repositories/SqlServer/CollectionRepository.cs index c7de1c7c7..b41706e28 100644 --- a/src/Core/Repositories/SqlServer/CollectionRepository.cs +++ b/src/Core/Repositories/SqlServer/CollectionRepository.cs @@ -1,15 +1,15 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; -using System.Threading.Tasks; -using System.Data.SqlClient; using System.Data; -using Dapper; +using System.Data.SqlClient; using System.Linq; -using Newtonsoft.Json; -using Bit.Core.Utilities; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Dapper; +using Newtonsoft.Json; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/DeviceRepository.cs b/src/Core/Repositories/SqlServer/DeviceRepository.cs index 9838dbebc..961edc247 100644 --- a/src/Core/Repositories/SqlServer/DeviceRepository.cs +++ b/src/Core/Repositories/SqlServer/DeviceRepository.cs @@ -1,11 +1,11 @@ using System; -using System.Linq; using System.Collections.Generic; +using System.Data; using System.Data.SqlClient; +using System.Linq; using System.Threading.Tasks; using Bit.Core.Models.Table; using Bit.Core.Settings; -using System.Data; using Dapper; namespace Bit.Core.Repositories.SqlServer diff --git a/src/Core/Repositories/SqlServer/EmergencyAccessRepository.cs b/src/Core/Repositories/SqlServer/EmergencyAccessRepository.cs index e35b8a9f4..38d4c0125 100644 --- a/src/Core/Repositories/SqlServer/EmergencyAccessRepository.cs +++ b/src/Core/Repositories/SqlServer/EmergencyAccessRepository.cs @@ -1,13 +1,13 @@ using System; -using Bit.Core.Models.Table; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using System.Threading.Tasks; -using Dapper; using System.Linq; -using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/EventRepository.cs b/src/Core/Repositories/SqlServer/EventRepository.cs index b3cf43b11..8ce19f64b 100644 --- a/src/Core/Repositories/SqlServer/EventRepository.cs +++ b/src/Core/Repositories/SqlServer/EventRepository.cs @@ -1,12 +1,12 @@ using System; -using Bit.Core.Models.Table; -using System.Threading.Tasks; using System.Collections.Generic; -using Bit.Core.Models.Data; -using Bit.Core.Settings; +using System.Data; using System.Data.SqlClient; using System.Linq; -using System.Data; +using System.Threading.Tasks; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Settings; using Dapper; namespace Bit.Core.Repositories.SqlServer diff --git a/src/Core/Repositories/SqlServer/FolderRepository.cs b/src/Core/Repositories/SqlServer/FolderRepository.cs index 74634dfc6..7a91b13c8 100644 --- a/src/Core/Repositories/SqlServer/FolderRepository.cs +++ b/src/Core/Repositories/SqlServer/FolderRepository.cs @@ -1,12 +1,12 @@ using System; -using Bit.Core.Models.Table; -using Bit.Core.Settings; -using System.Threading.Tasks; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using Dapper; using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Models.Table; +using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/GroupRepository.cs b/src/Core/Repositories/SqlServer/GroupRepository.cs index a41777057..7c7f8e5fe 100644 --- a/src/Core/Repositories/SqlServer/GroupRepository.cs +++ b/src/Core/Repositories/SqlServer/GroupRepository.cs @@ -1,15 +1,15 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; -using System.Threading.Tasks; -using Dapper; using System.Data; using System.Data.SqlClient; using System.Linq; -using Newtonsoft.Json; -using Bit.Core.Utilities; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Dapper; +using Newtonsoft.Json; namespace Bit.Core.Repositories.SqlServer { @@ -126,7 +126,7 @@ namespace Bit.Core.Repositories.SqlServer { var results = await connection.ExecuteAsync( $"[{Schema}].[GroupUser_Delete]", - new { GroupId = groupId, OrganizationUserId = organizationUserId }, + new { GroupId = groupId, OrganizationUserId = organizationUserId }, commandType: CommandType.StoredProcedure); } } diff --git a/src/Core/Repositories/SqlServer/MaintenanceRepository.cs b/src/Core/Repositories/SqlServer/MaintenanceRepository.cs index dec3444ec..060038170 100644 --- a/src/Core/Repositories/SqlServer/MaintenanceRepository.cs +++ b/src/Core/Repositories/SqlServer/MaintenanceRepository.cs @@ -1,8 +1,8 @@ using System.Data; using System.Data.SqlClient; using System.Threading.Tasks; -using Dapper; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/OrganizationRepository.cs b/src/Core/Repositories/SqlServer/OrganizationRepository.cs index 84c882ad9..a545741b6 100644 --- a/src/Core/Repositories/SqlServer/OrganizationRepository.cs +++ b/src/Core/Repositories/SqlServer/OrganizationRepository.cs @@ -1,13 +1,13 @@ using System; -using Bit.Core.Models.Table; -using System.Threading.Tasks; -using System.Data.SqlClient; -using System.Data; -using Dapper; -using System.Linq; using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/OrganizationSponsorshipRepository.cs b/src/Core/Repositories/SqlServer/OrganizationSponsorshipRepository.cs index c759e906b..70b55d0d8 100644 --- a/src/Core/Repositories/SqlServer/OrganizationSponsorshipRepository.cs +++ b/src/Core/Repositories/SqlServer/OrganizationSponsorshipRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Data; using System.Data.SqlClient; using System.Linq; diff --git a/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs b/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs index c0a3632be..84f247f5f 100644 --- a/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs +++ b/src/Core/Repositories/SqlServer/OrganizationUserRepository.cs @@ -1,15 +1,15 @@ using System; -using Bit.Core.Models.Table; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using System.Threading.Tasks; -using Dapper; using System.Linq; -using Bit.Core.Models.Data; -using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Enums; -using Bit.Core.Utilities; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Dapper; using Newtonsoft.Json; namespace Bit.Core.Repositories.SqlServer @@ -214,8 +214,8 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - - public async Task GetDetailsByUserAsync(Guid userId, + + public async Task GetDetailsByUserAsync(Guid userId, Guid organizationId, OrganizationUserStatusType? status = null) { using (var connection = new SqlConnection(ConnectionString)) @@ -285,7 +285,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task> GetManyAsync(IEnumerable Ids) { using (var connection = new SqlConnection(ConnectionString)) @@ -298,7 +298,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task GetByOrganizationEmailAsync(Guid organizationId, string email) { using (var connection = new SqlConnection(ConnectionString)) @@ -348,7 +348,7 @@ namespace Bit.Core.Repositories.SqlServer return default; } - foreach(var organizationUser in organizationUsers) + foreach (var organizationUser in organizationUsers) { organizationUser.SetNewId(); } diff --git a/src/Core/Repositories/SqlServer/PolicyRepository.cs b/src/Core/Repositories/SqlServer/PolicyRepository.cs index c95f63cff..4d5a9fe28 100644 --- a/src/Core/Repositories/SqlServer/PolicyRepository.cs +++ b/src/Core/Repositories/SqlServer/PolicyRepository.cs @@ -1,13 +1,13 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; -using System.Threading.Tasks; -using System.Data.SqlClient; using System.Data; -using Dapper; +using System.Data.SqlClient; using System.Linq; +using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { @@ -60,7 +60,7 @@ namespace Bit.Core.Repositories.SqlServer } public async Task> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType, - OrganizationUserStatusType minStatus) + OrganizationUserStatusType minStatus) { using (var connection = new SqlConnection(ConnectionString)) { @@ -74,7 +74,7 @@ namespace Bit.Core.Repositories.SqlServer } public async Task GetCountByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType, - OrganizationUserStatusType minStatus) + OrganizationUserStatusType minStatus) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Core/Repositories/SqlServer/ProviderOrganizationRepository.cs b/src/Core/Repositories/SqlServer/ProviderOrganizationRepository.cs index f6f21d791..c7060bf83 100644 --- a/src/Core/Repositories/SqlServer/ProviderOrganizationRepository.cs +++ b/src/Core/Repositories/SqlServer/ProviderOrganizationRepository.cs @@ -20,7 +20,7 @@ namespace Bit.Core.Repositories.SqlServer public ProviderOrganizationRepository(string connectionString, string readOnlyConnectionString) : base(connectionString, readOnlyConnectionString) { } - + public async Task> GetManyDetailsByProviderAsync(Guid providerId) { using (var connection = new SqlConnection(ConnectionString)) diff --git a/src/Core/Repositories/SqlServer/ProviderRepository.cs b/src/Core/Repositories/SqlServer/ProviderRepository.cs index 61736ba9a..1740e8efd 100644 --- a/src/Core/Repositories/SqlServer/ProviderRepository.cs +++ b/src/Core/Repositories/SqlServer/ProviderRepository.cs @@ -1,13 +1,13 @@ using System; -using System.Threading.Tasks; -using System.Data.SqlClient; -using System.Data; -using Dapper; -using System.Linq; using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Models.Data; using Bit.Core.Models.Table.Provider; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { @@ -20,7 +20,7 @@ namespace Bit.Core.Repositories.SqlServer public ProviderRepository(string connectionString, string readOnlyConnectionString) : base(connectionString, readOnlyConnectionString) { } - + public async Task> SearchAsync(string name, string userEmail, int skip, int take) { using (var connection = new SqlConnection(ReadOnlyConnectionString)) @@ -34,7 +34,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task> GetManyAbilitiesAsync() { using (var connection = new SqlConnection(ConnectionString)) diff --git a/src/Core/Repositories/SqlServer/ProviderUserRepository.cs b/src/Core/Repositories/SqlServer/ProviderUserRepository.cs index 9c7da61ad..0ba023396 100644 --- a/src/Core/Repositories/SqlServer/ProviderUserRepository.cs +++ b/src/Core/Repositories/SqlServer/ProviderUserRepository.cs @@ -35,7 +35,7 @@ namespace Bit.Core.Repositories.SqlServer return result; } } - + public async Task> GetManyAsync(IEnumerable ids) { using (var connection = new SqlConnection(ConnectionString)) @@ -48,7 +48,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task> GetManyByUserAsync(Guid userId) { using (var connection = new SqlConnection(ConnectionString)) @@ -61,7 +61,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task GetByProviderUserAsync(Guid providerId, Guid userId) { using (var connection = new SqlConnection(ConnectionString)) @@ -74,7 +74,7 @@ namespace Bit.Core.Repositories.SqlServer return results.SingleOrDefault(); } } - + public async Task> GetManyByProviderAsync(Guid providerId, ProviderUserType? type) { using (var connection = new SqlConnection(ConnectionString)) @@ -87,7 +87,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task> GetManyDetailsByProviderAsync(Guid providerId) { using (var connection = new SqlConnection(ConnectionString)) diff --git a/src/Core/Repositories/SqlServer/Repository.cs b/src/Core/Repositories/SqlServer/Repository.cs index 2d6714651..ba3cb3e04 100644 --- a/src/Core/Repositories/SqlServer/Repository.cs +++ b/src/Core/Repositories/SqlServer/Repository.cs @@ -3,8 +3,8 @@ using System.Data; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; -using Dapper; using Bit.Core.Models.Table; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/SendRepository.cs b/src/Core/Repositories/SqlServer/SendRepository.cs index 7e61f6040..f9aeee828 100644 --- a/src/Core/Repositories/SqlServer/SendRepository.cs +++ b/src/Core/Repositories/SqlServer/SendRepository.cs @@ -1,12 +1,12 @@ using System; -using Bit.Core.Models.Table; -using Bit.Core.Settings; -using System.Threading.Tasks; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using Dapper; using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Models.Table; +using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/SsoConfigRepository.cs b/src/Core/Repositories/SqlServer/SsoConfigRepository.cs index a9319774b..940c48aa1 100644 --- a/src/Core/Repositories/SqlServer/SsoConfigRepository.cs +++ b/src/Core/Repositories/SqlServer/SsoConfigRepository.cs @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Models.Table; using Bit.Core.Settings; -using System.Threading.Tasks; -using System.Data.SqlClient; -using System.Data; using Dapper; -using System.Linq; -using System.Collections.Generic; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/SsoUserRepository.cs b/src/Core/Repositories/SqlServer/SsoUserRepository.cs index 4f68c25a3..38ce2c95d 100644 --- a/src/Core/Repositories/SqlServer/SsoUserRepository.cs +++ b/src/Core/Repositories/SqlServer/SsoUserRepository.cs @@ -1,11 +1,11 @@ -using Bit.Core.Models.Table; +using System; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Models.Table; using Bit.Core.Settings; using Dapper; -using System; -using System.Threading.Tasks; -using System.Data.SqlClient; -using System.Data; -using System.Linq; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/TaxRateRepository.cs b/src/Core/Repositories/SqlServer/TaxRateRepository.cs index 552b7dd2e..288cc94d7 100644 --- a/src/Core/Repositories/SqlServer/TaxRateRepository.cs +++ b/src/Core/Repositories/SqlServer/TaxRateRepository.cs @@ -1,11 +1,11 @@ -using Bit.Core.Models.Table; -using Bit.Core.Settings; -using System.Threading.Tasks; -using System.Collections.Generic; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using Dapper; using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Models.Table; +using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { @@ -31,7 +31,7 @@ namespace Bit.Core.Repositories.SqlServer return results.ToList(); } } - + public async Task> GetAllActiveAsync() { using (var connection = new SqlConnection(ConnectionString)) diff --git a/src/Core/Repositories/SqlServer/TransactionRepository.cs b/src/Core/Repositories/SqlServer/TransactionRepository.cs index 4f0828758..a5be77de2 100644 --- a/src/Core/Repositories/SqlServer/TransactionRepository.cs +++ b/src/Core/Repositories/SqlServer/TransactionRepository.cs @@ -1,13 +1,13 @@ using System; -using Bit.Core.Models.Table; using System.Collections.Generic; -using System.Threading.Tasks; -using Dapper; using System.Data; using System.Data.SqlClient; using System.Linq; +using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Table; using Bit.Core.Settings; +using Dapper; namespace Bit.Core.Repositories.SqlServer { diff --git a/src/Core/Repositories/SqlServer/U2fRepository.cs b/src/Core/Repositories/SqlServer/U2fRepository.cs index 55335bcc8..6f997c050 100644 --- a/src/Core/Repositories/SqlServer/U2fRepository.cs +++ b/src/Core/Repositories/SqlServer/U2fRepository.cs @@ -1,11 +1,11 @@ using System; -using System.Linq; using System.Collections.Generic; +using System.Data; using System.Data.SqlClient; +using System.Linq; using System.Threading.Tasks; using Bit.Core.Models.Table; using Bit.Core.Settings; -using System.Data; using Dapper; namespace Bit.Core.Repositories.SqlServer diff --git a/src/Core/Repositories/TableStorage/EventRepository.cs b/src/Core/Repositories/TableStorage/EventRepository.cs index 5057e33e1..a2df9d9b1 100644 --- a/src/Core/Repositories/TableStorage/EventRepository.cs +++ b/src/Core/Repositories/TableStorage/EventRepository.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Threading.Tasks; using Bit.Core.Models.Data; using Bit.Core.Models.Table; +using Bit.Core.Settings; using Bit.Core.Utilities; using Microsoft.Azure.Cosmos.Table; -using Bit.Core.Settings; namespace Bit.Core.Repositories.TableStorage { diff --git a/src/Core/Services/IAttachmentStorageService.cs b/src/Core/Services/IAttachmentStorageService.cs index e4a265480..66775e601 100644 --- a/src/Core/Services/IAttachmentStorageService.cs +++ b/src/Core/Services/IAttachmentStorageService.cs @@ -1,9 +1,9 @@ -using Bit.Core.Models.Data; -using Bit.Core.Models.Table; -using Bit.Core.Enums; -using System; +using System; using System.IO; using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/ICipherService.cs b/src/Core/Services/ICipherService.cs index fa6b9080e..e0b69a63b 100644 --- a/src/Core/Services/ICipherService.cs +++ b/src/Core/Services/ICipherService.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Core.Models.Data; -using System; -using System.IO; -using Bit.Core.Models.Data; namespace Bit.Core.Services { diff --git a/src/Core/Services/ICollectionService.cs b/src/Core/Services/ICollectionService.cs index 557e2f83f..e5f22287d 100644 --- a/src/Core/Services/ICollectionService.cs +++ b/src/Core/Services/ICollectionService.cs @@ -1,8 +1,8 @@ -using System.Threading.Tasks; -using Bit.Core.Models.Table; +using System; using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Models.Data; -using System; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/IGroupService.cs b/src/Core/Services/IGroupService.cs index ce7696021..3dbe953d1 100644 --- a/src/Core/Services/IGroupService.cs +++ b/src/Core/Services/IGroupService.cs @@ -1,8 +1,8 @@ -using System.Threading.Tasks; -using Bit.Core.Models.Table; +using System; using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Models.Data; -using System; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/ILicensingService.cs b/src/Core/Services/ILicensingService.cs index 384b9cd15..84e7978f0 100644 --- a/src/Core/Services/ILicensingService.cs +++ b/src/Core/Services/ILicensingService.cs @@ -1,6 +1,6 @@ -using Bit.Core.Models.Business; +using System.Threading.Tasks; +using Bit.Core.Models.Business; using Bit.Core.Models.Table; -using System.Threading.Tasks; namespace Bit.Core.Services { diff --git a/src/Core/Services/IMailEnqueuingService.cs b/src/Core/Services/IMailEnqueuingService.cs index 3f763e0f4..00229b015 100644 --- a/src/Core/Services/IMailEnqueuingService.cs +++ b/src/Core/Services/IMailEnqueuingService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Mail; diff --git a/src/Core/Services/IMailService.cs b/src/Core/Services/IMailService.cs index 50f954049..3615da1de 100644 --- a/src/Core/Services/IMailService.cs +++ b/src/Core/Services/IMailService.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; -using Bit.Core.Models.Table; +using System; using System.Collections.Generic; -using System; -using Bit.Core.Models.Mail; -using Bit.Core.Models.Table.Provider; +using System.Threading.Tasks; using Bit.Core.Models.Business; +using Bit.Core.Models.Mail; +using Bit.Core.Models.Table; +using Bit.Core.Models.Table.Provider; namespace Bit.Core.Services { diff --git a/src/Core/Services/IOrganizationService.cs b/src/Core/Services/IOrganizationService.cs index cde873882..a6f35537f 100644 --- a/src/Core/Services/IOrganizationService.cs +++ b/src/Core/Services/IOrganizationService.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; -using Bit.Core.Models.Business; -using Bit.Core.Models.Table; -using System; +using System; using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Business; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/IOrganizationSponsorshipService.cs b/src/Core/Services/IOrganizationSponsorshipService.cs index 06391b9ca..a72e4e592 100644 --- a/src/Core/Services/IOrganizationSponsorshipService.cs +++ b/src/Core/Services/IOrganizationSponsorshipService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Bit.Core.Enums; using Bit.Core.Models.Table; diff --git a/src/Core/Services/IPaymentService.cs b/src/Core/Services/IPaymentService.cs index 2bb515a21..36b4889f6 100644 --- a/src/Core/Services/IPaymentService.cs +++ b/src/Core/Services/IPaymentService.cs @@ -1,9 +1,9 @@ using System; using System.Threading.Tasks; -using Bit.Core.Models.Table; +using Bit.Core.Enums; using Bit.Core.Models.Business; using Bit.Core.Models.StaticStore; -using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/IProviderService.cs b/src/Core/Services/IProviderService.cs index 8cef1bcf8..7214e6cf8 100644 --- a/src/Core/Services/IProviderService.cs +++ b/src/Core/Services/IProviderService.cs @@ -1,9 +1,9 @@ -using System.Threading.Tasks; -using Bit.Core.Models.Table; +using System; using System.Collections.Generic; -using System; +using System.Threading.Tasks; using Bit.Core.Models.Business; using Bit.Core.Models.Business.Provider; +using Bit.Core.Models.Table; using Bit.Core.Models.Table.Provider; namespace Bit.Core.Services diff --git a/src/Core/Services/IPushNotificationService.cs b/src/Core/Services/IPushNotificationService.cs index 799fd1a53..1bfd16018 100644 --- a/src/Core/Services/IPushNotificationService.cs +++ b/src/Core/Services/IPushNotificationService.cs @@ -1,8 +1,8 @@ using System; -using System.Threading.Tasks; -using Bit.Core.Models.Table; -using Bit.Core.Enums; using System.Collections.Generic; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/ISendStorageService.cs b/src/Core/Services/ISendStorageService.cs index 474e856e2..03b601675 100644 --- a/src/Core/Services/ISendStorageService.cs +++ b/src/Core/Services/ISendStorageService.cs @@ -1,8 +1,8 @@ -using Bit.Core.Enums; -using Bit.Core.Models.Table; -using System; +using System; using System.IO; using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Services/IUserService.cs b/src/Core/Services/IUserService.cs index 8b697b6e3..52b0bfc92 100644 --- a/src/Core/Services/IUserService.cs +++ b/src/Core/Services/IUserService.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Bit.Core.Models.Table; using System.Security.Claims; +using System.Threading.Tasks; using Bit.Core.Enums; using Bit.Core.Models; using Bit.Core.Models.Business; +using Bit.Core.Models.Table; using Fido2NetLib; +using Microsoft.AspNetCore.Identity; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs b/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs index bdfde40d5..41d682b72 100644 --- a/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs +++ b/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Amazon; +using Amazon.SimpleEmail; +using Amazon.SimpleEmail.Model; using Bit.Core.Models.Mail; using Bit.Core.Settings; using Bit.Core.Utilities; -using System.Linq; -using Amazon.SimpleEmail; -using Amazon; -using Amazon.SimpleEmail.Model; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Logging; diff --git a/src/Core/Services/Implementations/AmazonSqsBlockIpService.cs b/src/Core/Services/Implementations/AmazonSqsBlockIpService.cs index f1ba51ca7..cf0202334 100644 --- a/src/Core/Services/Implementations/AmazonSqsBlockIpService.cs +++ b/src/Core/Services/Implementations/AmazonSqsBlockIpService.cs @@ -1,7 +1,7 @@ -using System.Threading.Tasks; -using System; -using Amazon.SQS; +using System; +using System.Threading.Tasks; using Amazon; +using Amazon.SQS; using Bit.Core.Settings; namespace Bit.Core.Services diff --git a/src/Core/Services/Implementations/AzureAttachmentStorageService.cs b/src/Core/Services/Implementations/AzureAttachmentStorageService.cs index c4147a01a..c9e836091 100644 --- a/src/Core/Services/Implementations/AzureAttachmentStorageService.cs +++ b/src/Core/Services/Implementations/AzureAttachmentStorageService.cs @@ -1,13 +1,13 @@ -using System.Threading.Tasks; -using Microsoft.Azure.Storage; -using Microsoft.Azure.Storage.Blob; +using System; +using System.Collections.Generic; using System.IO; -using System; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Settings; -using System.Collections.Generic; -using Bit.Core.Enums; +using Microsoft.Azure.Storage; +using Microsoft.Azure.Storage.Blob; namespace Bit.Core.Services { @@ -28,15 +28,20 @@ namespace Bit.Core.Services attachmentData.AttachmentId ); - public static (string cipherId, string organizationId, string attachmentId) IdentifiersFromBlobName(string blobName) { + public static (string cipherId, string organizationId, string attachmentId) IdentifiersFromBlobName(string blobName) + { var parts = blobName.Split('/'); - switch (parts.Length) { + switch (parts.Length) + { case 4: return (parts[1], parts[2], parts[3]); case 3: - if (parts[0] == "temp") { + if (parts[0] == "temp") + { return (parts[1], null, parts[2]); - } else { + } + else + { return (parts[0], parts[1], parts[2]); } case 2: diff --git a/src/Core/Services/Implementations/AzureQueueBlockIpService.cs b/src/Core/Services/Implementations/AzureQueueBlockIpService.cs index 8baa67344..02d60aa69 100644 --- a/src/Core/Services/Implementations/AzureQueueBlockIpService.cs +++ b/src/Core/Services/Implementations/AzureQueueBlockIpService.cs @@ -1,5 +1,5 @@ -using System.Threading.Tasks; -using System; +using System; +using System.Threading.Tasks; using Azure.Storage.Queues; using Bit.Core.Settings; diff --git a/src/Core/Services/Implementations/AzureQueueEventWriteService.cs b/src/Core/Services/Implementations/AzureQueueEventWriteService.cs index 107df5ecd..47dfaa1e7 100644 --- a/src/Core/Services/Implementations/AzureQueueEventWriteService.cs +++ b/src/Core/Services/Implementations/AzureQueueEventWriteService.cs @@ -1,11 +1,11 @@ -using System.Threading.Tasks; -using System.Collections.Generic; -using Azure.Storage.Queues; -using Newtonsoft.Json; -using Bit.Core.Models.Data; -using Bit.Core.Settings; +using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; +using Azure.Storage.Queues; +using Bit.Core.Models.Data; +using Bit.Core.Settings; +using Newtonsoft.Json; namespace Bit.Core.Services { @@ -13,7 +13,7 @@ namespace Bit.Core.Services { public AzureQueueEventWriteService(GlobalSettings globalSettings) : base( new QueueClient(globalSettings.Events.ConnectionString, "event"), - new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }) + new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }) { } } } diff --git a/src/Core/Services/Implementations/AzureQueueMailService.cs b/src/Core/Services/Implementations/AzureQueueMailService.cs index c7fc28afc..05d91d323 100644 --- a/src/Core/Services/Implementations/AzureQueueMailService.cs +++ b/src/Core/Services/Implementations/AzureQueueMailService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs b/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs index 90137a6b4..989136b73 100644 --- a/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs +++ b/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs @@ -1,14 +1,14 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; +using Azure.Storage.Queues; using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Models; using Bit.Core.Models.Table; using Bit.Core.Settings; -using Newtonsoft.Json; -using Azure.Storage.Queues; using Microsoft.AspNetCore.Http; -using System.Collections.Generic; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs b/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs index 740126868..a8caad81d 100644 --- a/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs +++ b/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using System.Threading.Tasks; using Azure.Storage.Queues; @@ -19,7 +19,7 @@ namespace Bit.Core.Services NullValueHandling = NullValueHandling.Ignore, }; - public AzureQueueReferenceEventService ( + public AzureQueueReferenceEventService( GlobalSettings globalSettings) { _queueClient = new QueueClient(globalSettings.Events.ConnectionString, _queueName); diff --git a/src/Core/Services/Implementations/AzureQueueService.cs b/src/Core/Services/Implementations/AzureQueueService.cs index a8162c5e1..844f8d700 100644 --- a/src/Core/Services/Implementations/AzureQueueService.cs +++ b/src/Core/Services/Implementations/AzureQueueService.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -53,7 +53,7 @@ namespace Bit.Core.Services var messagesList = new List(); var messagesListSize = 0; - + int calculateByteSize(int totalSize, int toAdd) => // Calculate the total length this would be w/ "[]" and commas getBase64Size(totalSize + toAdd + messagesList.Count + 2); @@ -68,7 +68,7 @@ namespace Bit.Core.Services return CoreHelpers.Base64EncodeString( string.Concat("[", string.Join(',', messagesList), "]")); } - + var serializedMessages = messages.Select(message => JsonConvert.SerializeObject(message, jsonSettings)); diff --git a/src/Core/Services/Implementations/AzureSendFileStorageService.cs b/src/Core/Services/Implementations/AzureSendFileStorageService.cs index 7009878c9..9e536503b 100644 --- a/src/Core/Services/Implementations/AzureSendFileStorageService.cs +++ b/src/Core/Services/Implementations/AzureSendFileStorageService.cs @@ -1,11 +1,11 @@ -using System.Threading.Tasks; -using Microsoft.Azure.Storage; -using Microsoft.Azure.Storage.Blob; +using System; using System.IO; -using System; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Table; using Bit.Core.Settings; -using Bit.Core.Enums; +using Microsoft.Azure.Storage; +using Microsoft.Azure.Storage.Blob; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/BaseIdentityClientService.cs b/src/Core/Services/Implementations/BaseIdentityClientService.cs index cfb5a172b..26abf21fc 100644 --- a/src/Core/Services/Implementations/BaseIdentityClientService.cs +++ b/src/Core/Services/Implementations/BaseIdentityClientService.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using System.Net.Http; -using Newtonsoft.Json; -using System.Text; -using System; -using Newtonsoft.Json.Linq; -using Bit.Core.Utilities; +using System; +using System.Collections.Generic; using System.Net; +using System.Net.Http; using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using Bit.Core.Utilities; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/BlockingMailQueueService.cs b/src/Core/Services/Implementations/BlockingMailQueueService.cs index 58e03df6e..f8bc24c15 100644 --- a/src/Core/Services/Implementations/BlockingMailQueueService.cs +++ b/src/Core/Services/Implementations/BlockingMailQueueService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; @@ -15,7 +15,7 @@ namespace Bit.Core.Services public async Task EnqueueManyAsync(IEnumerable messages, Func fallback) { - foreach(var message in messages) + foreach (var message in messages) { await fallback(message); } diff --git a/src/Core/Services/Implementations/CipherService.cs b/src/Core/Services/Implementations/CipherService.cs index a85ae2a74..f1a5a8e38 100644 --- a/src/Core/Services/Implementations/CipherService.cs +++ b/src/Core/Services/Implementations/CipherService.cs @@ -1,18 +1,18 @@ using System; -using System.Linq; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Business; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using Core.Models.Data; -using Bit.Core.Exceptions; -using Bit.Core.Models.Data; -using Newtonsoft.Json; -using System.IO; -using Bit.Core.Enums; -using Bit.Core.Utilities; using Bit.Core.Settings; -using Bit.Core.Models.Business; +using Bit.Core.Utilities; +using Core.Models.Data; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/CollectionService.cs b/src/Core/Services/Implementations/CollectionService.cs index 829cdead2..d0105908a 100644 --- a/src/Core/Services/Implementations/CollectionService.cs +++ b/src/Core/Services/Implementations/CollectionService.cs @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Exceptions; +using Bit.Core.Models.Business; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using System.Collections.Generic; -using Bit.Core.Models.Data; -using Bit.Core.Models.Business; -using Bit.Core.Enums; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/EmergencyAccessService.cs b/src/Core/Services/Implementations/EmergencyAccessService.cs index 28ff8e66c..b51bfbf28 100644 --- a/src/Core/Services/Implementations/EmergencyAccessService.cs +++ b/src/Core/Services/Implementations/EmergencyAccessService.cs @@ -8,8 +8,8 @@ using Bit.Core.Models; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Identity; @@ -69,7 +69,7 @@ namespace Bit.Core.Services { throw new BadRequestException("You cannot use Emergency Access Takeover because you are using Key Connector."); } - + var emergencyAccess = new EmergencyAccess { GrantorId = invitingUser.Id, @@ -248,7 +248,7 @@ namespace Bit.Core.Services emergencyAccess.Status = EmergencyAccessStatusType.RecoveryApproved; await _emergencyAccessRepository.ReplaceAsync(emergencyAccess); - + var grantee = await _userRepository.GetByIdAsync(emergencyAccess.GranteeId.Value); await _mailService.SendEmergencyAccessRecoveryApproved(emergencyAccess, NameOrEmail(approvingUser), grantee.Email); } @@ -263,10 +263,10 @@ namespace Bit.Core.Services { throw new BadRequestException("Emergency Access not valid."); } - + emergencyAccess.Status = EmergencyAccessStatusType.Confirmed; await _emergencyAccessRepository.ReplaceAsync(emergencyAccess); - + var grantee = await _userRepository.GetByIdAsync(emergencyAccess.GranteeId.Value); await _mailService.SendEmergencyAccessRecoveryRejected(emergencyAccess, NameOrEmail(rejectingUser), grantee.Email); } @@ -381,7 +381,8 @@ namespace Bit.Core.Services var ciphers = await _cipherRepository.GetManyByUserIdAsync(emergencyAccess.GrantorId, false); - return new EmergencyAccessViewData { + return new EmergencyAccessViewData + { EmergencyAccess = emergencyAccess, Ciphers = ciphers, }; @@ -412,11 +413,12 @@ namespace Bit.Core.Services return string.IsNullOrWhiteSpace(user.Name) ? user.Email : user.Name; } - private bool IsValidRequest(EmergencyAccess availibleAccess, User requestingUser, EmergencyAccessType requestedAccessType) { - return availibleAccess != null && - availibleAccess.GranteeId == requestingUser.Id && - availibleAccess.Status == EmergencyAccessStatusType.RecoveryApproved && - availibleAccess.Type == requestedAccessType; + private bool IsValidRequest(EmergencyAccess availibleAccess, User requestingUser, EmergencyAccessType requestedAccessType) + { + return availibleAccess != null && + availibleAccess.GranteeId == requestingUser.Id && + availibleAccess.Status == EmergencyAccessStatusType.RecoveryApproved && + availibleAccess.Type == requestedAccessType; } } } diff --git a/src/Core/Services/Implementations/EventService.cs b/src/Core/Services/Implementations/EventService.cs index 3c272eb01..1a1d016ec 100644 --- a/src/Core/Services/Implementations/EventService.cs +++ b/src/Core/Services/Implementations/EventService.cs @@ -1,13 +1,13 @@ -using System.Threading.Tasks; -using System; -using Bit.Core.Enums; -using Bit.Core.Repositories; -using Bit.Core.Models.Data; -using System.Linq; +using System; using System.Collections.Generic; -using Bit.Core.Models.Table; +using System.Linq; +using System.Threading.Tasks; using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Models.Table.Provider; +using Bit.Core.Repositories; using Bit.Core.Settings; namespace Bit.Core.Services @@ -61,7 +61,7 @@ namespace Bit.Core.Services Type = type, Date = DateTime.UtcNow }); - + var providerAbilities = await _applicationCacheService.GetProviderAbilitiesAsync(); var providers = await _currentContext.ProviderMembershipAsync(_providerUserRepository, userId); var providerEvents = providers.Where(o => CanUseProviderEvents(providerAbilities, o.Id)) @@ -310,7 +310,7 @@ namespace Bit.Core.Services return orgAbilities != null && orgAbilities.ContainsKey(orgId) && orgAbilities[orgId].Enabled && orgAbilities[orgId].UseEvents; } - + private bool CanUseProviderEvents(IDictionary providerAbilities, Guid providerId) { return providerAbilities != null && providerAbilities.ContainsKey(providerId) && diff --git a/src/Core/Services/Implementations/GroupService.cs b/src/Core/Services/Implementations/GroupService.cs index 869609b76..96f242fa1 100644 --- a/src/Core/Services/Implementations/GroupService.cs +++ b/src/Core/Services/Implementations/GroupService.cs @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Exceptions; +using Bit.Core.Models.Business; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using System.Collections.Generic; -using Bit.Core.Models.Data; -using Bit.Core.Models.Business; -using Bit.Core.Enums; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/HandlebarsMailService.cs b/src/Core/Services/Implementations/HandlebarsMailService.cs index d8264431b..c8e5dd121 100644 --- a/src/Core/Services/Implementations/HandlebarsMailService.cs +++ b/src/Core/Services/Implementations/HandlebarsMailService.cs @@ -1,19 +1,19 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; -using Bit.Core.Models.Table; -using Bit.Core.Models.Mail; -using Bit.Core.Settings; using System.IO; -using System.Net; -using Bit.Core.Utilities; using System.Linq; +using System.Net; using System.Reflection; +using System.Threading.Tasks; +using Bit.Core.Models.Business; +using Bit.Core.Models.Mail; using Bit.Core.Models.Mail.FamiliesForEnterprise; using Bit.Core.Models.Mail.Provider; +using Bit.Core.Models.Table; using Bit.Core.Models.Table.Provider; +using Bit.Core.Settings; +using Bit.Core.Utilities; using HandlebarsDotNet; -using Bit.Core.Models.Business; namespace Bit.Core.Services { @@ -327,7 +327,7 @@ namespace Bit.Core.Services message.Category = "AddedCredit"; await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendLicenseExpiredAsync(IEnumerable emails, string organizationName = null) { var message = CreateDefaultMessage("License Expired", emails); @@ -397,7 +397,7 @@ namespace Bit.Core.Services await AddMessageContentAsync(message, queueMessage.TemplateName, queueMessage.Model); await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendAdminResetPasswordEmailAsync(string email, string userName, string orgName) { var message = CreateDefaultMessage("Master Password Has Been Changed", email); @@ -615,7 +615,7 @@ namespace Bit.Core.Services public async Task SendEmergencyAccessRecoveryInitiated(EmergencyAccess emergencyAccess, string initiatingName, string email) { var message = CreateDefaultMessage("Emergency Access Initiated", email); - + var remainingTime = DateTime.UtcNow - emergencyAccess.RecoveryInitiatedDate.GetValueOrDefault(); var model = new EmergencyAccessRecoveryViewModel @@ -628,7 +628,7 @@ namespace Bit.Core.Services message.Category = "EmergencyAccessRecovery"; await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendEmergencyAccessRecoveryApproved(EmergencyAccess emergencyAccess, string approvingName, string email) { var message = CreateDefaultMessage("Emergency Access Approved", email); @@ -658,7 +658,7 @@ namespace Bit.Core.Services var message = CreateDefaultMessage("Pending Emergency Access Request", email); var remainingTime = DateTime.UtcNow - emergencyAccess.RecoveryInitiatedDate.GetValueOrDefault(); - + var model = new EmergencyAccessRecoveryViewModel { Name = CoreHelpers.SanitizeForEmail(initiatingName), @@ -682,7 +682,7 @@ namespace Bit.Core.Services message.Category = "EmergencyAccessRecoveryTimedOut"; await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendProviderSetupInviteEmailAsync(Provider provider, string token, string email) { var message = CreateDefaultMessage($"Create a Provider", email); @@ -745,7 +745,7 @@ namespace Bit.Core.Services message.Category = "ProviderUserRemoved"; await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendUpdatedTempPasswordEmailAsync(string email, string userName) { var message = CreateDefaultMessage("Master Password Has Been Changed", email); @@ -829,7 +829,7 @@ namespace Bit.Core.Services message.Category = "FamiliesForEnterpriseSponsorshipReverting"; await _mailDeliveryService.SendEmailAsync(message); } - + public async Task SendOTPEmailAsync(string email, string token) { var message = CreateDefaultMessage("Your Bitwarden Verification Code", email); diff --git a/src/Core/Services/Implementations/InMemoryApplicationCacheService.cs b/src/Core/Services/Implementations/InMemoryApplicationCacheService.cs index d02417c01..fc9ba2aec 100644 --- a/src/Core/Services/Implementations/InMemoryApplicationCacheService.cs +++ b/src/Core/Services/Implementations/InMemoryApplicationCacheService.cs @@ -37,7 +37,7 @@ namespace Bit.Core.Services await InitProviderAbilitiesAsync(); return _providerAbilities; } - + public virtual async Task UpsertProviderAbilityAsync(Provider provider) { await InitProviderAbilitiesAsync(); @@ -88,7 +88,7 @@ namespace Bit.Core.Services _lastOrgAbilityRefresh = now; } } - + private async Task InitProviderAbilitiesAsync() { var now = DateTime.UtcNow; diff --git a/src/Core/Services/Implementations/InMemoryServiceBusApplicationCacheService.cs b/src/Core/Services/Implementations/InMemoryServiceBusApplicationCacheService.cs index 6a28a9077..f08cccae3 100644 --- a/src/Core/Services/Implementations/InMemoryServiceBusApplicationCacheService.cs +++ b/src/Core/Services/Implementations/InMemoryServiceBusApplicationCacheService.cs @@ -3,8 +3,8 @@ using System.Threading.Tasks; using Bit.Core.Enums; using Bit.Core.Models.Table; using Bit.Core.Repositories; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; using Microsoft.Azure.ServiceBus; namespace Bit.Core.Services diff --git a/src/Core/Services/Implementations/LicensingService.cs b/src/Core/Services/Implementations/LicensingService.cs index ef29bd55e..6254646ee 100644 --- a/src/Core/Services/Implementations/LicensingService.cs +++ b/src/Core/Services/Implementations/LicensingService.cs @@ -1,20 +1,20 @@ -using Bit.Core.Models.Business; -using Bit.Core.Models.Table; -using Bit.Core.Repositories; -using Bit.Core.Utilities; -using Bit.Core.Settings; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.Azure.Storage; -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; +using Bit.Core.Models.Business; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Azure.Storage; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/LocalAttachmentStorageService.cs b/src/Core/Services/Implementations/LocalAttachmentStorageService.cs index d742931a5..e226284f2 100644 --- a/src/Core/Services/Implementations/LocalAttachmentStorageService.cs +++ b/src/Core/Services/Implementations/LocalAttachmentStorageService.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; +using System; using System.IO; -using System; -using Bit.Core.Models.Table; -using Bit.Core.Models.Data; -using Bit.Core.Settings; +using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Settings; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/LocalSendStorageService.cs b/src/Core/Services/Implementations/LocalSendStorageService.cs index 26339f343..c9d65f67c 100644 --- a/src/Core/Services/Implementations/LocalSendStorageService.cs +++ b/src/Core/Services/Implementations/LocalSendStorageService.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; +using System; using System.IO; -using System; +using System.Linq; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Table; using Bit.Core.Settings; -using System.Linq; -using Bit.Core.Enums; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/MailKitSmtpMailDeliveryService.cs b/src/Core/Services/Implementations/MailKitSmtpMailDeliveryService.cs index 96ea2e0cb..6ded88b0b 100644 --- a/src/Core/Services/Implementations/MailKitSmtpMailDeliveryService.cs +++ b/src/Core/Services/Implementations/MailKitSmtpMailDeliveryService.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -using Bit.Core.Utilities; using Bit.Core.Settings; +using Bit.Core.Utilities; using MailKit.Net.Smtp; using Microsoft.Extensions.Logging; using MimeKit; diff --git a/src/Core/Services/Implementations/MultiServiceMailDeliveryService.cs b/src/Core/Services/Implementations/MultiServiceMailDeliveryService.cs index b54e59564..ee419cb46 100644 --- a/src/Core/Services/Implementations/MultiServiceMailDeliveryService.cs +++ b/src/Core/Services/Implementations/MultiServiceMailDeliveryService.cs @@ -1,10 +1,10 @@ using System; +using System.Net.Http; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; +using Bit.Core.Models.Mail; using Bit.Core.Settings; using Microsoft.AspNetCore.Hosting; -using System.Net.Http; -using Bit.Core.Models.Mail; +using Microsoft.Extensions.Logging; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/MultiServicePushNotificationService.cs b/src/Core/Services/Implementations/MultiServicePushNotificationService.cs index 64b2106cc..d55092732 100644 --- a/src/Core/Services/Implementations/MultiServicePushNotificationService.cs +++ b/src/Core/Services/Implementations/MultiServicePushNotificationService.cs @@ -1,13 +1,13 @@ using System; -using System.Threading.Tasks; -using Bit.Core.Models.Table; -using Bit.Core.Enums; using System.Collections.Generic; -using Microsoft.AspNetCore.Http; -using Bit.Core.Utilities; -using Microsoft.Extensions.Logging; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; namespace Bit.Core.Services { @@ -53,7 +53,7 @@ namespace Bit.Core.Services _services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor)); } } - + _logger = logger; } diff --git a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs index 24ece972b..2504125c6 100644 --- a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs @@ -1,17 +1,17 @@ using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; using System.Threading.Tasks; -using Bit.Core.Models.Table; -using Microsoft.Azure.NotificationHubs; using Bit.Core.Context; using Bit.Core.Enums; -using Newtonsoft.Json; -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; using Bit.Core.Models; using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Settings; -using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.Azure.NotificationHubs; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs index 7b8cbdbd4..7822cf6da 100644 --- a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Azure.NotificationHubs; -using Bit.Core.Enums; +using System; +using System.Collections.Generic; using System.Linq; -using System; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Repositories; using Bit.Core.Settings; +using Microsoft.Azure.NotificationHubs; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs b/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs index 2790179b4..f0c10e11a 100644 --- a/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs +++ b/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs @@ -1,15 +1,15 @@ using System; +using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; using Bit.Core.Context; -using Bit.Core.Models.Table; using Bit.Core.Enums; -using Bit.Core.Settings; -using Newtonsoft.Json; using Bit.Core.Models; +using Bit.Core.Models.Table; +using Bit.Core.Settings; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using System.Net.Http; -using System.Collections.Generic; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index b3d06ca23..058a60424 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -1,22 +1,22 @@ using System; -using System.Linq; -using System.Threading.Tasks; -using Bit.Core.Repositories; -using Bit.Core.Models.Business; -using Bit.Core.Models.Table; -using Bit.Core.Utilities; -using Bit.Core.Exceptions; using System.Collections.Generic; -using Microsoft.AspNetCore.DataProtection; -using Stripe; -using Bit.Core.Enums; -using Bit.Core.Models.Data; -using Bit.Core.Settings; using System.IO; -using Newtonsoft.Json; +using System.Linq; using System.Text.Json; +using System.Threading.Tasks; using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Business; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Settings; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Stripe; namespace Bit.Core.Services { @@ -1262,7 +1262,7 @@ namespace Bit.Core.Services { string MakeToken(OrganizationUser orgUser) => _dataProtector.Protect($"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}"); - + await _mailService.BulkSendOrganizationInviteEmailAsync(organization.Name, CheckOrganizationCanSponsor(organization), orgUsers.Select(o => (o, new ExpiringToken(MakeToken(o), DateTime.UtcNow.AddDays(5))))); } @@ -1273,7 +1273,7 @@ namespace Bit.Core.Services var nowMillis = CoreHelpers.ToEpocMilliseconds(now); var token = _dataProtector.Protect( $"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {nowMillis}"); - + await _mailService.SendOrganizationInviteEmailAsync(organization.Name, CheckOrganizationCanSponsor(organization), orgUser, new ExpiringToken(token, now.AddDays(5))); } diff --git a/src/Core/Services/Implementations/OrganizationSponsorshipService.cs b/src/Core/Services/Implementations/OrganizationSponsorshipService.cs index 8dbd07e38..eb704d77a 100644 --- a/src/Core/Services/Implementations/OrganizationSponsorshipService.cs +++ b/src/Core/Services/Implementations/OrganizationSponsorshipService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Bit.Core.Enums; using Bit.Core.Exceptions; @@ -250,7 +250,7 @@ namespace Bit.Core.Services { throw new BadRequestException("You are not currently sponsoring an organization."); } - + if (sponsorship.SponsoredOrganizationId == null) { await DoRemoveSponsorshipAsync(null, sponsorship); diff --git a/src/Core/Services/Implementations/PolicyService.cs b/src/Core/Services/Implementations/PolicyService.cs index 8f7fbf130..19831a991 100644 --- a/src/Core/Services/Implementations/PolicyService.cs +++ b/src/Core/Services/Implementations/PolicyService.cs @@ -47,9 +47,9 @@ namespace Bit.Core.Services { throw new BadRequestException("This organization cannot use policies."); } - + // Handle dependent policy checks - switch(policy.Type) + switch (policy.Type) { case PolicyType.SingleOrg: if (!policy.Enabled) @@ -59,9 +59,9 @@ namespace Bit.Core.Services await RequiredByKeyConnectorAsync(org); } break; - - case PolicyType.RequireSso: - if (policy.Enabled) + + case PolicyType.RequireSso: + if (policy.Enabled) { await DependsOnSingleOrgAsync(org); } @@ -71,12 +71,12 @@ namespace Bit.Core.Services } break; - case PolicyType.MaximumVaultTimeout: - if (policy.Enabled) - { + case PolicyType.MaximumVaultTimeout: + if (policy.Enabled) + { await DependsOnSingleOrgAsync(org); - } - break; + } + break; } var now = DateTime.UtcNow; @@ -93,7 +93,7 @@ namespace Bit.Core.Services policy.OrganizationId); var removableOrgUsers = orgUsers.Where(ou => ou.Status != Enums.OrganizationUserStatusType.Invited && - ou.Type != Enums.OrganizationUserType.Owner && ou.Type != Enums.OrganizationUserType.Admin && + ou.Type != Enums.OrganizationUserType.Owner && ou.Type != Enums.OrganizationUserType.Admin && ou.UserId != savingUserId); switch (currentPolicy.Type) { @@ -108,14 +108,14 @@ namespace Bit.Core.Services org.Name, orgUser.Email); } } - break; + break; case Enums.PolicyType.SingleOrg: var userOrgs = await _organizationUserRepository.GetManyByManyUsersAsync( removableOrgUsers.Select(ou => ou.UserId.Value)); foreach (var orgUser in removableOrgUsers) { - if (userOrgs.Any(ou => ou.UserId == orgUser.UserId - && ou.OrganizationId != org.Id + if (userOrgs.Any(ou => ou.UserId == orgUser.UserId + && ou.OrganizationId != org.Id && ou.Status != OrganizationUserStatusType.Invited)) { await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id, @@ -124,9 +124,9 @@ namespace Bit.Core.Services org.Name, orgUser.Email); } } - break; + break; default: - break; + break; } } } diff --git a/src/Core/Services/Implementations/PostalMailDeliveryService.cs b/src/Core/Services/Implementations/PostalMailDeliveryService.cs index 2bd6429ad..e6e278348 100644 --- a/src/Core/Services/Implementations/PostalMailDeliveryService.cs +++ b/src/Core/Services/Implementations/PostalMailDeliveryService.cs @@ -1,13 +1,13 @@ using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; using System.Threading.Tasks; using Bit.Core.Settings; -using Microsoft.Extensions.Logging; -using System.Net.Http; -using System.Collections.Generic; -using Newtonsoft.Json; -using Microsoft.AspNetCore.Hosting; -using System.Text; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/RelayPushNotificationService.cs b/src/Core/Services/Implementations/RelayPushNotificationService.cs index ec492a0ab..dcdd921ad 100644 --- a/src/Core/Services/Implementations/RelayPushNotificationService.cs +++ b/src/Core/Services/Implementations/RelayPushNotificationService.cs @@ -1,16 +1,16 @@ using System; +using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; using Bit.Core.Context; -using Bit.Core.Models.Table; using Bit.Core.Enums; -using Microsoft.AspNetCore.Http; using Bit.Core.Models; -using System.Net.Http; -using Microsoft.Extensions.Logging; -using System.Collections.Generic; using Bit.Core.Models.Api; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Settings; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/RelayPushRegistrationService.cs b/src/Core/Services/Implementations/RelayPushRegistrationService.cs index 2c589be16..9a77885bc 100644 --- a/src/Core/Services/Implementations/RelayPushRegistrationService.cs +++ b/src/Core/Services/Implementations/RelayPushRegistrationService.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; -using System.Threading.Tasks; -using System.Net.Http; -using Bit.Core.Enums; -using Bit.Core.Settings; using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Models.Api; +using Bit.Core.Settings; using Microsoft.Extensions.Logging; namespace Bit.Core.Services diff --git a/src/Core/Services/Implementations/RepositoryEventWriteService.cs b/src/Core/Services/Implementations/RepositoryEventWriteService.cs index 9551f89e8..294f7ee91 100644 --- a/src/Core/Services/Implementations/RepositoryEventWriteService.cs +++ b/src/Core/Services/Implementations/RepositoryEventWriteService.cs @@ -1,7 +1,7 @@ -using System.Threading.Tasks; -using Bit.Core.Repositories; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Threading.Tasks; using Bit.Core.Models.Data; +using Bit.Core.Repositories; namespace Bit.Core.Services { diff --git a/src/Core/Services/Implementations/SsoConfigService.cs b/src/Core/Services/Implementations/SsoConfigService.cs index 40fe6a87e..dd6f9b305 100644 --- a/src/Core/Services/Implementations/SsoConfigService.cs +++ b/src/Core/Services/Implementations/SsoConfigService.cs @@ -82,7 +82,8 @@ namespace Bit.Core.Services throw new BadRequestException("Key Connector requires the Single Sign-On Authentication policy to be enabled."); } - if (!config.Enabled) { + if (!config.Enabled) + { throw new BadRequestException("You must enable SSO to use Key Connector."); } } diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index ec9759d9c..e891235c5 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1,16 +1,16 @@ using System; -using System.Threading.Tasks; -using Bit.Core.Models.Table; using System.Collections.Generic; -using Bit.Core.Exceptions; using System.Linq; +using System.Threading.Tasks; using Bit.Billing.Models; -using Bit.Core.Models.Business; using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Business; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Microsoft.Extensions.Logging; -using TaxRate = Bit.Core.Models.Table.TaxRate; using StaticStore = Bit.Core.Models.StaticStore; +using TaxRate = Bit.Core.Models.Table.TaxRate; namespace Bit.Core.Services { diff --git a/src/Core/Services/NoopImplementations/NoopLicensingService.cs b/src/Core/Services/NoopImplementations/NoopLicensingService.cs index 65f879027..52f8d1edd 100644 --- a/src/Core/Services/NoopImplementations/NoopLicensingService.cs +++ b/src/Core/Services/NoopImplementations/NoopLicensingService.cs @@ -1,9 +1,9 @@ -using Bit.Core.Models.Table; -using Microsoft.AspNetCore.Hosting; -using System; -using Bit.Core.Models.Business; -using Bit.Core.Settings; +using System; using System.Threading.Tasks; +using Bit.Core.Models.Business; +using Bit.Core.Models.Table; +using Bit.Core.Settings; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; namespace Bit.Core.Services diff --git a/src/Core/Services/NoopImplementations/NoopMailService.cs b/src/Core/Services/NoopImplementations/NoopMailService.cs index 62d1d4a1c..55ff400b5 100644 --- a/src/Core/Services/NoopImplementations/NoopMailService.cs +++ b/src/Core/Services/NoopImplementations/NoopMailService.cs @@ -195,7 +195,7 @@ namespace Bit.Core.Services { return Task.FromResult(0); } - + public Task SendUpdatedTempPasswordEmailAsync(string email, string userName) { return Task.FromResult(0); @@ -215,7 +215,7 @@ namespace Bit.Core.Services { return Task.FromResult(0); } - + public Task SendOTPEmailAsync(string email, string token) { return Task.FromResult(0); diff --git a/src/Core/Services/NoopImplementations/NoopProviderService.cs b/src/Core/Services/NoopImplementations/NoopProviderService.cs index 24b575360..5d29c93bf 100644 --- a/src/Core/Services/NoopImplementations/NoopProviderService.cs +++ b/src/Core/Services/NoopImplementations/NoopProviderService.cs @@ -29,13 +29,13 @@ namespace Bit.Core.Services public Task>> DeleteUsersAsync(Guid providerId, IEnumerable providerUserIds, Guid deletingUserId) => throw new NotImplementedException(); public Task AddOrganization(Guid providerId, Guid organizationId, Guid addingUserId, string key) => throw new NotImplementedException(); - + public Task CreateOrganizationAsync(Guid providerId, OrganizationSignup organizationSignup, string clientOwnerEmail, User user) => throw new NotImplementedException(); public Task RemoveOrganizationAsync(Guid providerId, Guid providerOrganizationId, Guid removingUserId) => throw new NotImplementedException(); - + public Task LogProviderAccessToOrganizationAsync(Guid organizationId) => throw new NotImplementedException(); - + public Task ResendProviderSetupInviteEmailAsync(Guid providerId, Guid userId) => throw new NotImplementedException(); } } diff --git a/src/Core/Services/NoopImplementations/NoopSendFileStorageService.cs b/src/Core/Services/NoopImplementations/NoopSendFileStorageService.cs index 819e42c88..bc4b63142 100644 --- a/src/Core/Services/NoopImplementations/NoopSendFileStorageService.cs +++ b/src/Core/Services/NoopImplementations/NoopSendFileStorageService.cs @@ -1,8 +1,8 @@ -using System.Threading.Tasks; +using System; using System.IO; -using System; -using Bit.Core.Models.Table; +using System.Threading.Tasks; using Bit.Core.Enums; +using Bit.Core.Models.Table; namespace Bit.Core.Services { diff --git a/src/Core/Settings/IFileStorageSettings.cs b/src/Core/Settings/IFileStorageSettings.cs index a243b265a..45e44802d 100644 --- a/src/Core/Settings/IFileStorageSettings.cs +++ b/src/Core/Settings/IFileStorageSettings.cs @@ -1,4 +1,4 @@ -namespace Bit.Core.Settings +namespace Bit.Core.Settings { public interface IFileStorageSettings { diff --git a/src/Core/Settings/IGlobalSettings.cs b/src/Core/Settings/IGlobalSettings.cs index 23b75d61f..e286d7c2b 100644 --- a/src/Core/Settings/IGlobalSettings.cs +++ b/src/Core/Settings/IGlobalSettings.cs @@ -1,4 +1,4 @@ -using static Bit.Core.Settings.GlobalSettings; +using static Bit.Core.Settings.GlobalSettings; namespace Bit.Core.Settings { diff --git a/src/Core/Utilities/BillingHelpers.cs b/src/Core/Utilities/BillingHelpers.cs index 9c79ba5ca..25505b7ff 100644 --- a/src/Core/Utilities/BillingHelpers.cs +++ b/src/Core/Utilities/BillingHelpers.cs @@ -1,8 +1,8 @@ -using Bit.Core.Exceptions; +using System; +using System.Threading.Tasks; +using Bit.Core.Exceptions; using Bit.Core.Models.Table; using Bit.Core.Services; -using System; -using System.Threading.Tasks; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/CaptchaProtectedAttribute.cs b/src/Core/Utilities/CaptchaProtectedAttribute.cs index dec7bd7af..27dabb3bb 100644 --- a/src/Core/Utilities/CaptchaProtectedAttribute.cs +++ b/src/Core/Utilities/CaptchaProtectedAttribute.cs @@ -1,4 +1,4 @@ -using Bit.Core.Context; +using Bit.Core.Context; using Bit.Core.Exceptions; using Bit.Core.Models.Api; using Bit.Core.Services; diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index a6aed7150..42202227e 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -1,33 +1,33 @@ -using Bit.Core.Models.Data; -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; -using System.Text.RegularExpressions; -using Dapper; -using System.Globalization; -using System.Web; -using Microsoft.AspNetCore.DataProtection; -using Bit.Core.Settings; -using Bit.Core.Enums; -using Bit.Core.Context; -using System.Threading.Tasks; -using Microsoft.Azure.Storage; -using Microsoft.Azure.Storage.Blob; -using Bit.Core.Models.Table; -using IdentityModel; using System.Text.Json; -using Bit.Core.Enums.Provider; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web; using Azure.Storage.Queues; using Azure.Storage.Queues.Models; -using System.Threading; +using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Enums.Provider; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; +using Bit.Core.Settings; +using Dapper; +using IdentityModel; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.Azure.Storage; +using Microsoft.Azure.Storage.Blob; using MimeKit; +using Newtonsoft.Json; namespace Bit.Core.Utilities { @@ -854,7 +854,7 @@ namespace Bit.Core.Utilities } } } - + if (providers.Any()) { foreach (var group in providers.GroupBy(o => o.Type)) @@ -876,7 +876,7 @@ namespace Bit.Core.Utilities } } } - + return claims; } diff --git a/src/Core/Utilities/CurrentContextMiddleware.cs b/src/Core/Utilities/CurrentContextMiddleware.cs index 268f64675..3e733ad00 100644 --- a/src/Core/Utilities/CurrentContextMiddleware.cs +++ b/src/Core/Utilities/CurrentContextMiddleware.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Http; -using System.Threading.Tasks; +using System.Threading.Tasks; using Bit.Core.Context; using Bit.Core.Settings; +using Microsoft.AspNetCore.Http; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/CustomIpRateLimitMiddleware.cs b/src/Core/Utilities/CustomIpRateLimitMiddleware.cs index c7d31f64d..3101fd84b 100644 --- a/src/Core/Utilities/CustomIpRateLimitMiddleware.cs +++ b/src/Core/Utilities/CustomIpRateLimitMiddleware.cs @@ -1,13 +1,13 @@ -using AspNetCoreRateLimit; +using System; +using System.Threading.Tasks; +using AspNetCoreRateLimit; +using Bit.Core.Models.Api; using Bit.Core.Services; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using System.Threading.Tasks; -using System; -using Bit.Core.Models.Api; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/DuoApi.cs b/src/Core/Utilities/DuoApi.cs index 75584eb73..472df506d 100644 --- a/src/Core/Utilities/DuoApi.cs +++ b/src/Core/Utilities/DuoApi.cs @@ -10,13 +10,13 @@ All rights reserved using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Net; using System.Security.Cryptography; -using System.Text.RegularExpressions; using System.Text; +using System.Text.RegularExpressions; using System.Web; -using System.Globalization; using Newtonsoft.Json; namespace Bit.Core.Utilities.Duo diff --git a/src/Core/Utilities/EnumKeyResolver.cs b/src/Core/Utilities/EnumKeyResolver.cs index c99b1240a..92029008f 100644 --- a/src/Core/Utilities/EnumKeyResolver.cs +++ b/src/Core/Utilities/EnumKeyResolver.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Serialization; -using System; +using System; +using Newtonsoft.Json.Serialization; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/ExpandoObjectJsonConverter.cs b/src/Core/Utilities/ExpandoObjectJsonConverter.cs index 78a1ce87b..9cade71f9 100644 --- a/src/Core/Utilities/ExpandoObjectJsonConverter.cs +++ b/src/Core/Utilities/ExpandoObjectJsonConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Dynamic; using Newtonsoft.Json; diff --git a/src/Core/Utilities/LoggerFactoryExtensions.cs b/src/Core/Utilities/LoggerFactoryExtensions.cs index 0ccf3d615..a62f1ab24 100644 --- a/src/Core/Utilities/LoggerFactoryExtensions.cs +++ b/src/Core/Utilities/LoggerFactoryExtensions.cs @@ -1,4 +1,8 @@ -using Microsoft.AspNetCore.Builder; +using System; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using Bit.Core.Settings; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -6,10 +10,6 @@ using Microsoft.Extensions.Logging; using Serilog; using Serilog.Events; using Serilog.Sinks.Syslog; -using System; -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; -using Bit.Core.Settings; namespace Bit.Core.Utilities { @@ -83,7 +83,7 @@ namespace Bit.Core.Utilities { config.WriteTo.LocalSyslog(appName); } - else if (Uri.TryCreate(globalSettings.Syslog.Destination,UriKind.Absolute, out var syslogAddress)) + else if (Uri.TryCreate(globalSettings.Syslog.Destination, UriKind.Absolute, out var syslogAddress)) { // Syslog's standard port is 514 (both UDP and TCP). TLS does not have a standard port, so assume 514. int port = syslogAddress.Port >= 0 @@ -107,7 +107,7 @@ namespace Bit.Core.Utilities { config.WriteTo.TcpSyslog(syslogAddress.Host, port, appName, secureProtocols: protocols, - certProvider: new CertificateStoreProvider(StoreName.My, StoreLocation.CurrentUser, + certProvider: new CertificateStoreProvider(StoreName.My, StoreLocation.CurrentUser, globalSettings.Syslog.CertificateThumbprint)); } else diff --git a/src/Core/Utilities/SelfHostedAttribute.cs b/src/Core/Utilities/SelfHostedAttribute.cs index 41300e8e1..13dc83fa7 100644 --- a/src/Core/Utilities/SelfHostedAttribute.cs +++ b/src/Core/Utilities/SelfHostedAttribute.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; -using Bit.Core.Exceptions; +using Bit.Core.Exceptions; using Bit.Core.Settings; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/ServiceCollectionExtensions.cs b/src/Core/Utilities/ServiceCollectionExtensions.cs index f37412963..c9bf1f8a7 100644 --- a/src/Core/Utilities/ServiceCollectionExtensions.cs +++ b/src/Core/Utilities/ServiceCollectionExtensions.cs @@ -84,7 +84,7 @@ namespace Bit.Core.Utilities if (provider == SupportedDatabaseProviders.Postgres) { options.UseNpgsql(connectionString); - } + } else if (provider == SupportedDatabaseProviders.MySql) { options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); diff --git a/src/Core/Utilities/StaticStore.cs b/src/Core/Utilities/StaticStore.cs index 3de47c1c8..0a9a786f1 100644 --- a/src/Core/Utilities/StaticStore.cs +++ b/src/Core/Utilities/StaticStore.cs @@ -1,8 +1,8 @@ -using Bit.Core.Enums; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Models.StaticStore; -using System.Collections.Generic; -using System.Linq; namespace Bit.Core.Utilities { diff --git a/src/Core/Utilities/StrictEmailAddressAttribute.cs b/src/Core/Utilities/StrictEmailAddressAttribute.cs index d0c2b06f9..cb0ab8969 100644 --- a/src/Core/Utilities/StrictEmailAddressAttribute.cs +++ b/src/Core/Utilities/StrictEmailAddressAttribute.cs @@ -8,8 +8,8 @@ namespace Bit.Core.Utilities { public StrictEmailAddressAttribute() : base("The {0} field is not a supported e-mail address format.") - {} - + { } + public override bool IsValid(object value) { var emailAddress = value?.ToString(); diff --git a/src/Core/Utilities/StrictEmailAddressListAttribute.cs b/src/Core/Utilities/StrictEmailAddressListAttribute.cs index 16611d58e..994151f8b 100644 --- a/src/Core/Utilities/StrictEmailAddressListAttribute.cs +++ b/src/Core/Utilities/StrictEmailAddressListAttribute.cs @@ -15,7 +15,7 @@ namespace Bit.Core.Utilities { return new ValidationResult("An email is required."); } - + if (emails.Count() > 20) { return new ValidationResult("You can only submit up to 20 emails at a time."); diff --git a/src/Events/Controllers/CollectController.cs b/src/Events/Controllers/CollectController.cs index 5a5293d79..bed3030ec 100644 --- a/src/Events/Controllers/CollectController.cs +++ b/src/Events/Controllers/CollectController.cs @@ -33,7 +33,7 @@ namespace Bit.Events.Controllers } [HttpPost] - public async Task Post([FromBody]IEnumerable model) + public async Task Post([FromBody] IEnumerable model) { if (model == null || !model.Any()) { diff --git a/src/Events/Controllers/InfoController.cs b/src/Events/Controllers/InfoController.cs index abd939c8e..3a14ea6f7 100644 --- a/src/Events/Controllers/InfoController.cs +++ b/src/Events/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Events.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Events.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Events/Program.cs b/src/Events/Program.cs index ddc7fb017..9e234d007 100644 --- a/src/Events/Program.cs +++ b/src/Events/Program.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore; +using Bit.Core.Utilities; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Bit.Core.Utilities; -using Serilog.Events; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.Events { diff --git a/src/EventsProcessor/AzureQueueHostedService.cs b/src/EventsProcessor/AzureQueueHostedService.cs index a5d86d661..b72ae224f 100644 --- a/src/EventsProcessor/AzureQueueHostedService.cs +++ b/src/EventsProcessor/AzureQueueHostedService.cs @@ -3,16 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure.Storage.Queues; using Bit.Core; using Bit.Core.Models.Data; using Bit.Core.Services; +using Bit.Core.Utilities; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Azure.Storage.Queues; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Bit.Core.Utilities; namespace Bit.EventsProcessor { diff --git a/src/EventsProcessor/Program.cs b/src/EventsProcessor/Program.cs index 0f4176e10..66f2192bc 100644 --- a/src/EventsProcessor/Program.cs +++ b/src/EventsProcessor/Program.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Hosting; -using Bit.Core.Utilities; -using Serilog.Events; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.EventsProcessor { diff --git a/src/EventsProcessor/Startup.cs b/src/EventsProcessor/Startup.cs index fad3cc85b..fd437b96f 100644 --- a/src/EventsProcessor/Startup.cs +++ b/src/EventsProcessor/Startup.cs @@ -48,7 +48,7 @@ namespace Bit.EventsProcessor app.UseRouting(); app.UseEndpoints(endpoints => { - endpoints.MapGet("/alive", + endpoints.MapGet("/alive", async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow)); endpoints.MapGet("/now", async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow)); diff --git a/src/Icons/Controllers/InfoController.cs b/src/Icons/Controllers/InfoController.cs index c61dce1b1..7897569e8 100644 --- a/src/Icons/Controllers/InfoController.cs +++ b/src/Icons/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Icons.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Icons.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Icons/Program.cs b/src/Icons/Program.cs index e5ffb8179..0fba98111 100644 --- a/src/Icons/Program.cs +++ b/src/Icons/Program.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Hosting; -using Bit.Core.Utilities; -using Serilog.Events; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.Icons { diff --git a/src/Icons/Services/IconFetchingService.cs b/src/Icons/Services/IconFetchingService.cs index 181ab4edb..6450f7489 100644 --- a/src/Icons/Services/IconFetchingService.cs +++ b/src/Icons/Services/IconFetchingService.cs @@ -4,11 +4,11 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Text; using System.Threading.Tasks; +using AngleSharp.Html.Parser; using Bit.Icons.Models; using Microsoft.Extensions.Logging; -using System.Text; -using AngleSharp.Html.Parser; namespace Bit.Icons.Services { diff --git a/src/Identity/Controllers/AccountController.cs b/src/Identity/Controllers/AccountController.cs index 57e7d9a10..b01ca2c07 100644 --- a/src/Identity/Controllers/AccountController.cs +++ b/src/Identity/Controllers/AccountController.cs @@ -1,4 +1,11 @@ -using Bit.Core.Models.Table; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Security.Claims; +using System.Threading.Tasks; +using Bit.Core.Models.Api; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Identity.Models; using IdentityModel; @@ -10,13 +17,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Security.Claims; -using System.Threading.Tasks; -using Bit.Core.Models.Api; namespace Bit.Identity.Controllers { @@ -47,7 +47,7 @@ namespace Bit.Identity.Controllers _organizationRepository = organizationRepository; _clientFactory = clientFactory; } - + [HttpGet] public async Task PreValidate(string domainHint) { @@ -91,7 +91,7 @@ namespace Bit.Identity.Controllers { var context = await _interaction.GetAuthorizationContextAsync(returnUrl); - var domainHint = context.Parameters.AllKeys.Contains("domain_hint") ? + var domainHint = context.Parameters.AllKeys.Contains("domain_hint") ? context.Parameters["domain_hint"] : null; if (string.IsNullOrWhiteSpace(domainHint)) @@ -99,7 +99,7 @@ namespace Bit.Identity.Controllers throw new Exception("No domain_hint provided"); } - var userIdentifier = context.Parameters.AllKeys.Contains("user_identifier") ? + var userIdentifier = context.Parameters.AllKeys.Contains("user_identifier") ? context.Parameters["user_identifier"] : null; return RedirectToAction(nameof(ExternalChallenge), new diff --git a/src/Identity/Controllers/InfoController.cs b/src/Identity/Controllers/InfoController.cs index bf1b3b6c4..9824ac93a 100644 --- a/src/Identity/Controllers/InfoController.cs +++ b/src/Identity/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Identity.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Identity.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Identity/Program.cs b/src/Identity/Program.cs index cbaf19cdd..a1397cd4c 100644 --- a/src/Identity/Program.cs +++ b/src/Identity/Program.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Hosting; +using AspNetCoreRateLimit; using Bit.Core.Utilities; -using Serilog.Events; -using AspNetCoreRateLimit; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.Identity { diff --git a/src/Identity/Startup.cs b/src/Identity/Startup.cs index 1c27df676..10761df29 100644 --- a/src/Identity/Startup.cs +++ b/src/Identity/Startup.cs @@ -1,21 +1,21 @@ using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Configuration; +using System.Globalization; +using System.IdentityModel.Tokens.Jwt; +using System.Threading.Tasks; +using AspNetCoreRateLimit; using Bit.Core; using Bit.Core.Context; using Bit.Core.Settings; using Bit.Core.Utilities; -using AspNetCoreRateLimit; -using System.Globalization; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Hosting; -using Microsoft.IdentityModel.Logging; -using System.IdentityModel.Tokens.Jwt; -using System.Threading.Tasks; using Bit.Identity.Utilities; using IdentityServer4.Extensions; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.IdentityModel.Logging; namespace Bit.Identity { diff --git a/src/Notifications/AzureQueueHostedService.cs b/src/Notifications/AzureQueueHostedService.cs index e90203f27..87a4347fd 100644 --- a/src/Notifications/AzureQueueHostedService.cs +++ b/src/Notifications/AzureQueueHostedService.cs @@ -2,12 +2,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure.Storage.Queues; using Bit.Core.Settings; +using Bit.Core.Utilities; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Azure.Storage.Queues; -using Bit.Core.Utilities; namespace Bit.Notifications { diff --git a/src/Notifications/Controllers/InfoController.cs b/src/Notifications/Controllers/InfoController.cs index b743e7073..d91697243 100644 --- a/src/Notifications/Controllers/InfoController.cs +++ b/src/Notifications/Controllers/InfoController.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Mvc; using Bit.Core.Utilities; +using Microsoft.AspNetCore.Mvc; namespace Bit.Notifications.Controllers { @@ -12,7 +12,7 @@ namespace Bit.Notifications.Controllers { return DateTime.UtcNow; } - + [HttpGet("~/version")] public JsonResult GetVersion() { diff --git a/src/Notifications/Program.cs b/src/Notifications/Program.cs index 098ace19b..b5c3f941d 100644 --- a/src/Notifications/Program.cs +++ b/src/Notifications/Program.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Hosting; -using Bit.Core.Utilities; -using Serilog.Events; +using Bit.Core.Utilities; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Serilog.Events; namespace Bit.Notifications { diff --git a/test/Api.Test/AutoFixture/Attributes/ControllerCustomizeAttribute.cs b/test/Api.Test/AutoFixture/Attributes/ControllerCustomizeAttribute.cs index fa5f764b9..951f0d582 100644 --- a/test/Api.Test/AutoFixture/Attributes/ControllerCustomizeAttribute.cs +++ b/test/Api.Test/AutoFixture/Attributes/ControllerCustomizeAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; diff --git a/test/Api.Test/AutoFixture/ControllerCustomization.cs b/test/Api.Test/AutoFixture/ControllerCustomization.cs index 137cadb89..0c4179388 100644 --- a/test/Api.Test/AutoFixture/ControllerCustomization.cs +++ b/test/Api.Test/AutoFixture/ControllerCustomization.cs @@ -1,10 +1,10 @@ +using System; using AutoFixture; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc; -using Bit.Api.Controllers; using AutoFixture.Kernel; -using System; +using Bit.Api.Controllers; using Bit.Test.Common.AutoFixture; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; using Org.BouncyCastle.Security; namespace Bit.Api.Test.AutoFixture diff --git a/test/Api.Test/Controllers/AccountsControllerTests.cs b/test/Api.Test/Controllers/AccountsControllerTests.cs index 365cb4917..4149479b2 100644 --- a/test/Api.Test/Controllers/AccountsControllerTests.cs +++ b/test/Api.Test/Controllers/AccountsControllerTests.cs @@ -1,4 +1,8 @@ +using System; +using System.Security.Claims; +using System.Threading.Tasks; using Bit.Api.Controllers; +using Bit.Api.Models.Request.Accounts; using Bit.Core; using Bit.Core.Enums; using Bit.Core.Exceptions; @@ -9,10 +13,6 @@ using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.AspNetCore.Identity; using NSubstitute; -using System; -using System.Security.Claims; -using System.Threading.Tasks; -using Bit.Api.Models.Request.Accounts; using Xunit; namespace Bit.Api.Test.Controllers diff --git a/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs b/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs index 3c97499c6..b24c7c0c1 100644 --- a/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs +++ b/test/Api.Test/Controllers/OrganizationSponsorshipsControllerTests.cs @@ -1,21 +1,21 @@ -using Xunit; -using Bit.Test.Common.AutoFixture.Attributes; -using System.Threading.Tasks; -using System; -using Bit.Core.Enums; -using System.Linq; +using System; using System.Collections.Generic; -using Bit.Core.Models.Table; -using Bit.Test.Common.AutoFixture; +using System.Linq; +using System.Threading.Tasks; using Bit.Api.Controllers; using Bit.Api.Models.Request.Organizations; -using Bit.Core.Context; -using NSubstitute; -using Bit.Core.Exceptions; using Bit.Api.Test.AutoFixture.Attributes; +using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Utilities; +using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using NSubstitute; +using Xunit; namespace Bit.Api.Test.Controllers { diff --git a/test/Api.Test/Controllers/OrganizationsControllerTests.cs b/test/Api.Test/Controllers/OrganizationsControllerTests.cs index ba3096e96..1a2b79ce4 100644 --- a/test/Api.Test/Controllers/OrganizationsControllerTests.cs +++ b/test/Api.Test/Controllers/OrganizationsControllerTests.cs @@ -1,21 +1,21 @@ +using System; +using System.Security.Claims; +using System.Threading.Tasks; using AutoFixture.Xunit2; using Bit.Api.Controllers; using Bit.Core.Context; using Bit.Core.Exceptions; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; using NSubstitute; -using System.Threading.Tasks; -using System.Security.Claims; -using System; -using Bit.Core.Models.Data; using Xunit; namespace Bit.Api.Test.Controllers { - public class OrganizationsControllerTests: IDisposable + public class OrganizationsControllerTests : IDisposable { private readonly GlobalSettings _globalSettings; private readonly ICurrentContext _currentContext; diff --git a/test/Api.Test/Controllers/SendsControllerTests.cs b/test/Api.Test/Controllers/SendsControllerTests.cs index 0b2c8fa74..0eaad4c84 100644 --- a/test/Api.Test/Controllers/SendsControllerTests.cs +++ b/test/Api.Test/Controllers/SendsControllerTests.cs @@ -1,5 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using AutoFixture.Xunit2; using Bit.Api.Controllers; +using Bit.Api.Models.Request; +using Bit.Api.Models.Response; using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Models.Table; @@ -11,11 +16,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NSubstitute; -using System.Collections.Generic; -using System.Threading.Tasks; -using System; -using Bit.Api.Models.Request; -using Bit.Api.Models.Response; using Xunit; namespace Bit.Api.Test.Controllers diff --git a/test/Common/AutoFixture/Attributes/BitAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/BitAutoDataAttribute.cs index dfb06a254..4f93f7752 100644 --- a/test/Common/AutoFixture/Attributes/BitAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/BitAutoDataAttribute.cs @@ -1,9 +1,9 @@ -using System; -using Xunit.Sdk; -using AutoFixture; -using System.Reflection; +using System; using System.Collections.Generic; +using System.Reflection; +using AutoFixture; using Bit.Test.Common.Helpers; +using Xunit.Sdk; namespace Bit.Test.Common.AutoFixture.Attributes { diff --git a/test/Common/AutoFixture/Attributes/BitCustomizeAttribute.cs b/test/Common/AutoFixture/Attributes/BitCustomizeAttribute.cs index 32910ef53..f599308bf 100644 --- a/test/Common/AutoFixture/Attributes/BitCustomizeAttribute.cs +++ b/test/Common/AutoFixture/Attributes/BitCustomizeAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using AutoFixture; namespace Bit.Test.Common.AutoFixture.Attributes diff --git a/test/Common/AutoFixture/Attributes/CustomAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/CustomAutoDataAttribute.cs index cd2feebca..d6c5863b1 100644 --- a/test/Common/AutoFixture/Attributes/CustomAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/CustomAutoDataAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using AutoFixture; using AutoFixture.Xunit2; diff --git a/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs index d36f963a4..9a9a6730a 100644 --- a/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs @@ -1,8 +1,8 @@ -using System; +using System; +using AutoFixture; +using AutoFixture.Xunit2; using Xunit; using Xunit.Sdk; -using AutoFixture.Xunit2; -using AutoFixture; namespace Bit.Test.Common.AutoFixture.Attributes { diff --git a/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs index 89eebad8c..cc04e062a 100644 --- a/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using AutoFixture; diff --git a/test/Common/AutoFixture/Attributes/MemberAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/MemberAutoDataAttribute.cs index a154128ae..fd68f2759 100644 --- a/test/Common/AutoFixture/Attributes/MemberAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/MemberAutoDataAttribute.cs @@ -1,9 +1,9 @@ -using System; -using Xunit; -using AutoFixture; -using System.Reflection; +using System; using System.Linq; +using System.Reflection; +using AutoFixture; using Bit.Test.Common.Helpers; +using Xunit; namespace Bit.Test.Common.AutoFixture.Attributes { diff --git a/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs index 1c8bd089b..6bb3b92ce 100644 --- a/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Reflection; using AutoFixture; diff --git a/test/Common/AutoFixture/BuilderWithoutAutoProperties.cs b/test/Common/AutoFixture/BuilderWithoutAutoProperties.cs index 81df3206a..e5902b8a4 100644 --- a/test/Common/AutoFixture/BuilderWithoutAutoProperties.cs +++ b/test/Common/AutoFixture/BuilderWithoutAutoProperties.cs @@ -1,4 +1,4 @@ -using System; +using System; using AutoFixture; using AutoFixture.Dsl; using AutoFixture.Kernel; diff --git a/test/Common/AutoFixture/FixtureExtensions.cs b/test/Common/AutoFixture/FixtureExtensions.cs index 7249e8e41..a78b2f4bf 100644 --- a/test/Common/AutoFixture/FixtureExtensions.cs +++ b/test/Common/AutoFixture/FixtureExtensions.cs @@ -1,4 +1,4 @@ -using AutoFixture; +using AutoFixture; using AutoFixture.AutoNSubstitute; namespace Bit.Test.Common.AutoFixture diff --git a/test/Common/AutoFixture/GlobalSettingsFixtures.cs b/test/Common/AutoFixture/GlobalSettingsFixtures.cs index 8df15b107..4d0e7e0aa 100644 --- a/test/Common/AutoFixture/GlobalSettingsFixtures.cs +++ b/test/Common/AutoFixture/GlobalSettingsFixtures.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AutoFixture; using AutoFixture.Kernel; diff --git a/test/Common/AutoFixture/ISutProvider.cs b/test/Common/AutoFixture/ISutProvider.cs index c72dc4a27..cbd8c6e6f 100644 --- a/test/Common/AutoFixture/ISutProvider.cs +++ b/test/Common/AutoFixture/ISutProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Bit.Test.Common.AutoFixture { diff --git a/test/Common/AutoFixture/SutProvider.cs b/test/Common/AutoFixture/SutProvider.cs index 0846655a7..e7fc10449 100644 --- a/test/Common/AutoFixture/SutProvider.cs +++ b/test/Common/AutoFixture/SutProvider.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; using AutoFixture; using AutoFixture.Kernel; -using System.Reflection; -using System.Linq; namespace Bit.Test.Common.AutoFixture { diff --git a/test/Common/AutoFixture/SutProviderCustomization.cs b/test/Common/AutoFixture/SutProviderCustomization.cs index f6041e91e..b72ff0329 100644 --- a/test/Common/AutoFixture/SutProviderCustomization.cs +++ b/test/Common/AutoFixture/SutProviderCustomization.cs @@ -1,4 +1,4 @@ -using System; +using System; using AutoFixture; using AutoFixture.Kernel; diff --git a/test/Common/Helpers/AssertHelper.cs b/test/Common/Helpers/AssertHelper.cs index 5d65dc515..a2bfbfcb5 100644 --- a/test/Common/Helpers/AssertHelper.cs +++ b/test/Common/Helpers/AssertHelper.cs @@ -1,9 +1,9 @@ -using System.Reflection; +using System; using System.IO; using System.Linq; -using Xunit; -using System; +using System.Reflection; using Newtonsoft.Json; +using Xunit; namespace Bit.Test.Common.Helpers { diff --git a/test/Common/Helpers/BitAutoDataAttributeHelpers.cs b/test/Common/Helpers/BitAutoDataAttributeHelpers.cs index 635d99671..0e9d6112b 100644 --- a/test/Common/Helpers/BitAutoDataAttributeHelpers.cs +++ b/test/Common/Helpers/BitAutoDataAttributeHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/test/Common/Helpers/Factories.cs b/test/Common/Helpers/Factories.cs index 5067662d2..ecd0cfe85 100644 --- a/test/Common/Helpers/Factories.cs +++ b/test/Common/Helpers/Factories.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Settings; using Microsoft.EntityFrameworkCore; diff --git a/test/Core.Test/AutoFixture/Attributes/CiSkippedTheory.cs b/test/Core.Test/AutoFixture/Attributes/CiSkippedTheory.cs index 446ee3197..8db3742ab 100644 --- a/test/Core.Test/AutoFixture/Attributes/CiSkippedTheory.cs +++ b/test/Core.Test/AutoFixture/Attributes/CiSkippedTheory.cs @@ -1,13 +1,13 @@ -using System; +using System; namespace Bit.Core.Test.AutoFixture.Attributes { public sealed class CiSkippedTheory : Xunit.TheoryAttribute { - private static bool IsGithubActions() => Environment.GetEnvironmentVariable("CI") != null; - public CiSkippedTheory() + private static bool IsGithubActions() => Environment.GetEnvironmentVariable("CI") != null; + public CiSkippedTheory() { - if(IsGithubActions()) + if (IsGithubActions()) { Skip = "Ignore during CI builds"; } diff --git a/test/Core.Test/AutoFixture/CipherAttachmentMetaDataFixtures.cs b/test/Core.Test/AutoFixture/CipherAttachmentMetaDataFixtures.cs index d5f961ff6..972614f56 100644 --- a/test/Core.Test/AutoFixture/CipherAttachmentMetaDataFixtures.cs +++ b/test/Core.Test/AutoFixture/CipherAttachmentMetaDataFixtures.cs @@ -1,4 +1,4 @@ -using AutoFixture; +using AutoFixture; using AutoFixture.Dsl; using Bit.Core.Models.Data; diff --git a/test/Core.Test/AutoFixture/CipherFixtures.cs b/test/Core.Test/AutoFixture/CipherFixtures.cs index 23730fe9d..145c9bfcb 100644 --- a/test/Core.Test/AutoFixture/CipherFixtures.cs +++ b/test/Core.Test/AutoFixture/CipherFixtures.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; @@ -46,12 +46,12 @@ namespace Bit.Core.Test.AutoFixture.CipherFixtures } } - internal class CipherBuilder: ISpecimenBuilder + internal class CipherBuilder : ISpecimenBuilder { public bool OrganizationOwned { get; set; } public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -78,11 +78,12 @@ namespace Bit.Core.Test.AutoFixture.CipherFixtures .Without(e => e.Favorites) .Without(e => e.Folders)); // - var serializerOptions = new JsonSerializerOptions(){ + var serializerOptions = new JsonSerializerOptions() + { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; - if(type == typeof(Cipher)) + if (type == typeof(Cipher)) { var obj = fixture.WithAutoNSubstitutions().Create(); var cipherData = fixture.WithAutoNSubstitutions().Create(); @@ -92,10 +93,10 @@ namespace Bit.Core.Test.AutoFixture.CipherFixtures return obj; } - if (type == typeof(List)) + if (type == typeof(List)) { var ciphers = fixture.WithAutoNSubstitutions().CreateMany().ToArray(); - for (var i = 0; i < ciphers.Count(); i++ ) + for (var i = 0; i < ciphers.Count(); i++) { var cipherData = fixture.WithAutoNSubstitutions().Create(); var cipherAttachements = fixture.WithAutoNSubstitutions().Create>(); @@ -110,14 +111,15 @@ namespace Bit.Core.Test.AutoFixture.CipherFixtures } } - internal class EfCipher: ICustomization + internal class EfCipher : ICustomization { public bool OrganizationOwned { get; set; } public void Customize(IFixture fixture) { fixture.Customizations.Add(new GlobalSettingsBuilder()); - fixture.Customizations.Add(new CipherBuilder(){ - OrganizationOwned = OrganizationOwned + fixture.Customizations.Add(new CipherBuilder() + { + OrganizationOwned = OrganizationOwned }); fixture.Customizations.Add(new UserBuilder()); fixture.Customizations.Add(new OrganizationBuilder()); @@ -172,9 +174,10 @@ namespace Bit.Core.Test.AutoFixture.CipherFixtures internal class EfOrganizationCipherAutoDataAttribute : CustomAutoDataAttribute { - public EfOrganizationCipherAutoDataAttribute() : base(new SutProviderCustomization(), new EfCipher(){ - OrganizationOwned = true, - }) + public EfOrganizationCipherAutoDataAttribute() : base(new SutProviderCustomization(), new EfCipher() + { + OrganizationOwned = true, + }) { } } diff --git a/test/Core.Test/AutoFixture/CollectionCipherFixtures.cs b/test/Core.Test/AutoFixture/CollectionCipherFixtures.cs index 79a3cd38a..607a6ca50 100644 --- a/test/Core.Test/AutoFixture/CollectionCipherFixtures.cs +++ b/test/Core.Test/AutoFixture/CollectionCipherFixtures.cs @@ -1,23 +1,23 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; +using Bit.Core.Test.AutoFixture.CipherFixtures; +using Bit.Core.Test.AutoFixture.CollectionFixtures; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; -using Bit.Core.Test.AutoFixture.CollectionFixtures; -using Bit.Core.Test.AutoFixture.CipherFixtures; using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.CollectionCipherFixtures { - internal class CollectionCipherBuilder: ISpecimenBuilder + internal class CollectionCipherBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -35,7 +35,7 @@ namespace Bit.Core.Test.AutoFixture.CollectionCipherFixtures } } - internal class EfCollectionCipher: ICustomization + internal class EfCollectionCipher : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/CollectionFixtures.cs b/test/Core.Test/AutoFixture/CollectionFixtures.cs index fd1d91b5c..9eb7bc60f 100644 --- a/test/Core.Test/AutoFixture/CollectionFixtures.cs +++ b/test/Core.Test/AutoFixture/CollectionFixtures.cs @@ -1,21 +1,21 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.CollectionFixtures { - internal class CollectionBuilder: ISpecimenBuilder + internal class CollectionBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,7 @@ namespace Bit.Core.Test.AutoFixture.CollectionFixtures } } - internal class EfCollection: ICustomization + internal class EfCollection : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/CurrentContextFixtures.cs b/test/Core.Test/AutoFixture/CurrentContextFixtures.cs index 8dcaeb646..13d6ed1ed 100644 --- a/test/Core.Test/AutoFixture/CurrentContextFixtures.cs +++ b/test/Core.Test/AutoFixture/CurrentContextFixtures.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using AutoFixture; using AutoFixture.Kernel; diff --git a/test/Core.Test/AutoFixture/DeviceFixtures.cs b/test/Core.Test/AutoFixture/DeviceFixtures.cs index 4fac109b0..f16e608f2 100644 --- a/test/Core.Test/AutoFixture/DeviceFixtures.cs +++ b/test/Core.Test/AutoFixture/DeviceFixtures.cs @@ -1,21 +1,21 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Core.Test.AutoFixture.Relays; +using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.DeviceFixtures { - internal class DeviceBuilder: ISpecimenBuilder + internal class DeviceBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,7 @@ namespace Bit.Core.Test.AutoFixture.DeviceFixtures } } - internal class EfDevice: ICustomization + internal class EfDevice : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/EmergencyAccessFixtures.cs b/test/Core.Test/AutoFixture/EmergencyAccessFixtures.cs index 760a92a1e..fcbf49bf7 100644 --- a/test/Core.Test/AutoFixture/EmergencyAccessFixtures.cs +++ b/test/Core.Test/AutoFixture/EmergencyAccessFixtures.cs @@ -1,21 +1,21 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Core.Test.AutoFixture.Relays; +using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.EmergencyAccessFixtures { - internal class EmergencyAccessBuilder: ISpecimenBuilder + internal class EmergencyAccessBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,7 @@ namespace Bit.Core.Test.AutoFixture.EmergencyAccessFixtures } } - internal class EfEmergencyAccess: ICustomization + internal class EfEmergencyAccess : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/EntityFrameworkRepositoryFixtures.cs b/test/Core.Test/AutoFixture/EntityFrameworkRepositoryFixtures.cs index 0d82ef9b4..92ba4423d 100644 --- a/test/Core.Test/AutoFixture/EntityFrameworkRepositoryFixtures.cs +++ b/test/Core.Test/AutoFixture/EntityFrameworkRepositoryFixtures.cs @@ -1,24 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Reflection; using AutoFixture; +using AutoFixture.Kernel; using AutoMapper; using Bit.Core.Models.EntityFramework; using Bit.Core.Models.EntityFramework.Provider; -using System.Collections.Generic; -using AutoFixture.Kernel; -using System; -using Moq; -using Microsoft.Extensions.DependencyInjection; -using System.Reflection; using Bit.Core.Repositories.EntityFramework; -using Microsoft.EntityFrameworkCore; using Bit.Core.Settings; using Bit.Core.Test.Helpers.Factories; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Moq; namespace Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures { - internal class ServiceScopeFactoryBuilder: ISpecimenBuilder + internal class ServiceScopeFactoryBuilder : ISpecimenBuilder { private DbContextOptions _options { get; set; } - public ServiceScopeFactoryBuilder(DbContextOptions options) { + public ServiceScopeFactoryBuilder(DbContextOptions options) + { _options = options; } @@ -42,11 +43,11 @@ namespace Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures } } - public class EfRepositoryListBuilder: ISpecimenBuilder where T: BaseEntityFrameworkRepository + public class EfRepositoryListBuilder : ISpecimenBuilder where T : BaseEntityFrameworkRepository { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -62,8 +63,9 @@ namespace Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures { var fixture = new Fixture(); fixture.Customize(x => x.FromFactory(new ServiceScopeFactoryBuilder(option))); - fixture.Customize(x => x.FromFactory(() => - new MapperConfiguration(cfg => { + fixture.Customize(x => x.FromFactory(() => + new MapperConfiguration(cfg => + { cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); diff --git a/test/Core.Test/AutoFixture/EventFixtures.cs b/test/Core.Test/AutoFixture/EventFixtures.cs index f5674ddd4..e0569e4fb 100644 --- a/test/Core.Test/AutoFixture/EventFixtures.cs +++ b/test/Core.Test/AutoFixture/EventFixtures.cs @@ -1,20 +1,20 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.EventFixtures { - internal class EventBuilder: ISpecimenBuilder + internal class EventBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -32,7 +32,7 @@ namespace Bit.Core.Test.AutoFixture.EventFixtures } } - internal class EfEvent: ICustomization + internal class EfEvent : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/FolderFixtures.cs b/test/Core.Test/AutoFixture/FolderFixtures.cs index f46de2f75..cfc0d0723 100644 --- a/test/Core.Test/AutoFixture/FolderFixtures.cs +++ b/test/Core.Test/AutoFixture/FolderFixtures.cs @@ -1,21 +1,21 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.FolderFixtures { - internal class FolderBuilder: ISpecimenBuilder + internal class FolderBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,7 @@ namespace Bit.Core.Test.AutoFixture.FolderFixtures } } - internal class EfFolder: ICustomization + internal class EfFolder : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/GrantFixtures.cs b/test/Core.Test/AutoFixture/GrantFixtures.cs index 2c837f216..18846e86e 100644 --- a/test/Core.Test/AutoFixture/GrantFixtures.cs +++ b/test/Core.Test/AutoFixture/GrantFixtures.cs @@ -1,20 +1,20 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.GrantFixtures { - internal class GrantBuilder: ISpecimenBuilder + internal class GrantBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -32,7 +32,7 @@ namespace Bit.Core.Test.AutoFixture.GrantFixtures } } - internal class EfGrant: ICustomization + internal class EfGrant : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/GroupFixtures.cs b/test/Core.Test/AutoFixture/GroupFixtures.cs index b13a1c063..4f2891cc9 100644 --- a/test/Core.Test/AutoFixture/GroupFixtures.cs +++ b/test/Core.Test/AutoFixture/GroupFixtures.cs @@ -1,14 +1,14 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Test.AutoFixture.Relays; -using Fixtures = Bit.Core.Test.AutoFixture.OrganizationFixtures; -using Bit.Test.Common.AutoFixture.Attributes; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using Fixtures = Bit.Core.Test.AutoFixture.OrganizationFixtures; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.GroupFixtures { @@ -26,11 +26,11 @@ namespace Bit.Core.Test.AutoFixture.GroupFixtures { } } - internal class GroupBuilder: ISpecimenBuilder + internal class GroupBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -48,7 +48,7 @@ namespace Bit.Core.Test.AutoFixture.GroupFixtures } } - internal class EfGroup: ICustomization + internal class EfGroup : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/GroupUserFixtures.cs b/test/Core.Test/AutoFixture/GroupUserFixtures.cs index 6a44d7c81..5ec1e9062 100644 --- a/test/Core.Test/AutoFixture/GroupUserFixtures.cs +++ b/test/Core.Test/AutoFixture/GroupUserFixtures.cs @@ -1,19 +1,19 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.GroupUserFixtures { - internal class GroupUserBuilder: ISpecimenBuilder + internal class GroupUserBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -30,7 +30,7 @@ namespace Bit.Core.Test.AutoFixture.GroupUserFixtures } } - internal class EfGroupUser: ICustomization + internal class EfGroupUser : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/InstallationFixtures.cs b/test/Core.Test/AutoFixture/InstallationFixtures.cs index 87980fa82..91657ba55 100644 --- a/test/Core.Test/AutoFixture/InstallationFixtures.cs +++ b/test/Core.Test/AutoFixture/InstallationFixtures.cs @@ -1,19 +1,19 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.InstallationFixtures { - internal class InstallationBuilder: ISpecimenBuilder + internal class InstallationBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -30,7 +30,7 @@ namespace Bit.Core.Test.AutoFixture.InstallationFixtures } } - internal class EfInstallation: ICustomization + internal class EfInstallation : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/OrganizationFixtures.cs b/test/Core.Test/AutoFixture/OrganizationFixtures.cs index 819ebeb85..c674e50ea 100644 --- a/test/Core.Test/AutoFixture/OrganizationFixtures.cs +++ b/test/Core.Test/AutoFixture/OrganizationFixtures.cs @@ -3,17 +3,17 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json; using AutoFixture; +using AutoFixture.Kernel; using Bit.Core.Enums; +using Bit.Core.Models; using Bit.Core.Models.Business; using Bit.Core.Models.Data; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Utilities; -using AutoFixture.Kernel; -using Bit.Core.Models; -using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Repositories.EntityFramework; -using Bit.Test.Common.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; +using Bit.Core.Utilities; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.OrganizationFixtures { @@ -39,11 +39,11 @@ namespace Bit.Core.Test.AutoFixture.OrganizationFixtures } } - internal class OrganizationBuilder: ISpecimenBuilder + internal class OrganizationBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -74,7 +74,7 @@ namespace Bit.Core.Test.AutoFixture.OrganizationFixtures fixture.Customize(composer => composer .With(o => o.PlanType, CheckedPlanType)); fixture.Customize(composer => composer - .With(ou => ou.Plan, validUpgradePlans.First())) ; + .With(ou => ou.Plan, validUpgradePlans.First())); } } @@ -129,7 +129,7 @@ namespace Bit.Core.Test.AutoFixture.OrganizationFixtures } } - internal class EfOrganization: ICustomization + internal class EfOrganization : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/OrganizationSponsorshipFixtures.cs b/test/Core.Test/AutoFixture/OrganizationSponsorshipFixtures.cs index 7c39ca097..8ef89252b 100644 --- a/test/Core.Test/AutoFixture/OrganizationSponsorshipFixtures.cs +++ b/test/Core.Test/AutoFixture/OrganizationSponsorshipFixtures.cs @@ -1,13 +1,13 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; -using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.OrganizationSponsorshipFixtures { diff --git a/test/Core.Test/AutoFixture/OrganizationUserFixtures.cs b/test/Core.Test/AutoFixture/OrganizationUserFixtures.cs index 1a083c2f3..828bc953a 100644 --- a/test/Core.Test/AutoFixture/OrganizationUserFixtures.cs +++ b/test/Core.Test/AutoFixture/OrganizationUserFixtures.cs @@ -1,28 +1,28 @@ -using AutoFixture; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Models; +using System; using System.Collections.Generic; -using Bit.Core.Enums; +using System.Reflection; +using System.Text.Json; +using AutoFixture; using AutoFixture.Kernel; -using System; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using AutoFixture.Xunit2; +using Bit.Core.Enums; +using Bit.Core.Models; +using Bit.Core.Models.Data; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using Bit.Core.Models.Data; -using System.Text.Json; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Test.AutoFixture.UserFixtures; -using AutoFixture.Xunit2; -using System.Reflection; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures { - internal class OrganizationUserBuilder: ISpecimenBuilder + internal class OrganizationUserBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,8 @@ namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures var fixture = new Fixture(); var orgUser = fixture.WithAutoNSubstitutions().Create(); var orgUserPermissions = fixture.WithAutoNSubstitutions().Create(); - orgUser.Permissions = JsonSerializer.Serialize(orgUserPermissions, new JsonSerializerOptions() { + orgUser.Permissions = JsonSerializer.Serialize(orgUserPermissions, new JsonSerializerOptions() + { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }); return orgUser; @@ -46,7 +47,8 @@ namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures { var providers = fixture.Create>(); var orgUserPermissions = fixture.WithAutoNSubstitutions().Create(); - orgUser.Permissions = JsonSerializer.Serialize(orgUserPermissions, new JsonSerializerOptions() { + orgUser.Permissions = JsonSerializer.Serialize(orgUserPermissions, new JsonSerializerOptions() + { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }); } @@ -55,7 +57,7 @@ namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures return new NoSpecimen(); } } - + internal class OrganizationUser : ICustomization { public OrganizationUserStatusType Status { get; set; } @@ -66,7 +68,7 @@ namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures Status = status; Type = type; } - + public void Customize(IFixture fixture) { fixture.Customize(composer => composer @@ -94,20 +96,20 @@ namespace Bit.Core.Test.AutoFixture.OrganizationUserFixtures } } - internal class EfOrganizationUser: ICustomization - { - public void Customize(IFixture fixture) - { - fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); - fixture.Customizations.Add(new GlobalSettingsBuilder()); - fixture.Customizations.Add(new OrganizationUserBuilder()); - fixture.Customizations.Add(new OrganizationBuilder()); - fixture.Customizations.Add(new UserBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - } - } + internal class EfOrganizationUser : ICustomization + { + public void Customize(IFixture fixture) + { + fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); + fixture.Customizations.Add(new GlobalSettingsBuilder()); + fixture.Customizations.Add(new OrganizationUserBuilder()); + fixture.Customizations.Add(new OrganizationBuilder()); + fixture.Customizations.Add(new UserBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + } + } internal class EfOrganizationUserAutoDataAttribute : CustomAutoDataAttribute { diff --git a/test/Core.Test/AutoFixture/PolicyFixtures.cs b/test/Core.Test/AutoFixture/PolicyFixtures.cs index 71b2e30a7..ceb493a7d 100644 --- a/test/Core.Test/AutoFixture/PolicyFixtures.cs +++ b/test/Core.Test/AutoFixture/PolicyFixtures.cs @@ -1,15 +1,15 @@ using System; using System.Reflection; using AutoFixture; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Enums; using AutoFixture.Kernel; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using AutoFixture.Xunit2; +using Bit.Core.Enums; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using AutoFixture.Xunit2; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.PolicyFixtures { @@ -21,7 +21,7 @@ namespace Bit.Core.Test.AutoFixture.PolicyFixtures { Type = type; } - + public void Customize(IFixture fixture) { fixture.Customize(composer => composer @@ -45,12 +45,12 @@ namespace Bit.Core.Test.AutoFixture.PolicyFixtures return new Policy(_type); } } - - internal class PolicyBuilder: ISpecimenBuilder + + internal class PolicyBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -67,7 +67,7 @@ namespace Bit.Core.Test.AutoFixture.PolicyFixtures } } - internal class EfPolicy: ICustomization + internal class EfPolicy : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/Relays/MaxLengthStringRelay.cs b/test/Core.Test/AutoFixture/Relays/MaxLengthStringRelay.cs index 38e3a1a9c..bf55cd276 100644 --- a/test/Core.Test/AutoFixture/Relays/MaxLengthStringRelay.cs +++ b/test/Core.Test/AutoFixture/Relays/MaxLengthStringRelay.cs @@ -1,15 +1,15 @@ -using AutoFixture.Kernel; -using System; +using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; +using AutoFixture.Kernel; namespace Bit.Core.Test.AutoFixture.Relays { // Creates a string the same length as any availible MaxLength data annotation // Modified version of the StringLenfthRelay provided by AutoFixture // https://github.com/AutoFixture/AutoFixture/blob/master/Src/AutoFixture/DataAnnotations/StringLengthAttributeRelay.cs - internal class MaxLengthStringRelay: ISpecimenBuilder + internal class MaxLengthStringRelay : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { diff --git a/test/Core.Test/AutoFixture/SendFixtures.cs b/test/Core.Test/AutoFixture/SendFixtures.cs index 17dee60ed..c6ff9a457 100644 --- a/test/Core.Test/AutoFixture/SendFixtures.cs +++ b/test/Core.Test/AutoFixture/SendFixtures.cs @@ -1,4 +1,4 @@ -using System; +using System; using AutoFixture; using AutoFixture.Kernel; using Bit.Core.Models.Table; @@ -70,12 +70,12 @@ namespace Bit.Core.Test.AutoFixture.SendFixtures { } } - internal class SendBuilder: ISpecimenBuilder + internal class SendBuilder : ISpecimenBuilder { public bool OrganizationOwned { get; set; } public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -98,7 +98,7 @@ namespace Bit.Core.Test.AutoFixture.SendFixtures } } - internal class EfSend: ICustomization + internal class EfSend : ICustomization { public bool OrganizationOwned { get; set; } public void Customize(IFixture fixture) @@ -122,9 +122,10 @@ namespace Bit.Core.Test.AutoFixture.SendFixtures internal class EfOrganizationSendAutoDataAttribute : CustomAutoDataAttribute { - public EfOrganizationSendAutoDataAttribute() : base(new SutProviderCustomization(), new EfSend(){ - OrganizationOwned = true, - }) + public EfOrganizationSendAutoDataAttribute() : base(new SutProviderCustomization(), new EfSend() + { + OrganizationOwned = true, + }) { } } } diff --git a/test/Core.Test/AutoFixture/SsoConfigFixtures.cs b/test/Core.Test/AutoFixture/SsoConfigFixtures.cs index 5ecbc247c..95938272b 100644 --- a/test/Core.Test/AutoFixture/SsoConfigFixtures.cs +++ b/test/Core.Test/AutoFixture/SsoConfigFixtures.cs @@ -1,22 +1,22 @@ -using System; +using System; +using System.Text.Json; using AutoFixture; using AutoFixture.Kernel; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Models.Data; -using System.Text.Json; -using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Repositories.EntityFramework; +using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.SsoConfigFixtures { - internal class SsoConfigBuilder: ISpecimenBuilder + internal class SsoConfigBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -35,18 +35,18 @@ namespace Bit.Core.Test.AutoFixture.SsoConfigFixtures } } - internal class EfSsoConfig: ICustomization - { - public void Customize(IFixture fixture) - { - fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); - fixture.Customizations.Add(new GlobalSettingsBuilder()); - fixture.Customizations.Add(new OrganizationBuilder()); - fixture.Customizations.Add(new SsoConfigBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - } - } + internal class EfSsoConfig : ICustomization + { + public void Customize(IFixture fixture) + { + fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); + fixture.Customizations.Add(new GlobalSettingsBuilder()); + fixture.Customizations.Add(new OrganizationBuilder()); + fixture.Customizations.Add(new SsoConfigBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + } + } internal class EfSsoConfigAutoDataAttribute : CustomAutoDataAttribute { diff --git a/test/Core.Test/AutoFixture/SsoUserFixtures.cs b/test/Core.Test/AutoFixture/SsoUserFixtures.cs index 9dc452466..e28f7ac64 100644 --- a/test/Core.Test/AutoFixture/SsoUserFixtures.cs +++ b/test/Core.Test/AutoFixture/SsoUserFixtures.cs @@ -1,4 +1,4 @@ -using AutoFixture; +using AutoFixture; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.OrganizationFixtures; @@ -11,18 +11,18 @@ namespace Bit.Core.Test.AutoFixture.SsoUserFixtures { internal class EfSsoUser : ICustomization { - public void Customize(IFixture fixture) - { - fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); - fixture.Customizations.Add(new GlobalSettingsBuilder()); - fixture.Customizations.Add(new UserBuilder()); - fixture.Customizations.Add(new OrganizationBuilder()); - fixture.Customize(composer => composer.Without(ou => ou.Id)); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - fixture.Customizations.Add(new EfRepositoryListBuilder()); - } - } + public void Customize(IFixture fixture) + { + fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); + fixture.Customizations.Add(new GlobalSettingsBuilder()); + fixture.Customizations.Add(new UserBuilder()); + fixture.Customizations.Add(new OrganizationBuilder()); + fixture.Customize(composer => composer.Without(ou => ou.Id)); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + fixture.Customizations.Add(new EfRepositoryListBuilder()); + } + } internal class EfSsoUserAutoDataAttribute : CustomAutoDataAttribute { diff --git a/test/Core.Test/AutoFixture/TaxRateFixtures.cs b/test/Core.Test/AutoFixture/TaxRateFixtures.cs index d1e89fa5d..af42e224f 100644 --- a/test/Core.Test/AutoFixture/TaxRateFixtures.cs +++ b/test/Core.Test/AutoFixture/TaxRateFixtures.cs @@ -1,20 +1,20 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.TaxRateFixtures { - internal class TaxRateBuilder: ISpecimenBuilder + internal class TaxRateBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -32,7 +32,7 @@ namespace Bit.Core.Test.AutoFixture.TaxRateFixtures } } - internal class EfTaxRate: ICustomization + internal class EfTaxRate : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/TransactionFixutres.cs b/test/Core.Test/AutoFixture/TransactionFixutres.cs index 0610ced02..107c27a19 100644 --- a/test/Core.Test/AutoFixture/TransactionFixutres.cs +++ b/test/Core.Test/AutoFixture/TransactionFixutres.cs @@ -1,24 +1,24 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Models.EntityFramework; using AutoFixture.Kernel; -using System; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using Bit.Core.Models.EntityFramework; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using Bit.Core.Test.AutoFixture.UserFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Test.AutoFixture.Relays; +using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.TransactionFixtures { - internal class TransactionBuilder: ISpecimenBuilder + internal class TransactionBuilder : ISpecimenBuilder { public bool OrganizationOwned { get; set; } public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -41,7 +41,7 @@ namespace Bit.Core.Test.AutoFixture.TransactionFixtures } } - internal class EfTransaction: ICustomization + internal class EfTransaction : ICustomization { public bool OrganizationOwned { get; set; } public void Customize(IFixture fixture) @@ -65,9 +65,10 @@ namespace Bit.Core.Test.AutoFixture.TransactionFixtures internal class EfOrganizationTransactionAutoDataAttribute : CustomAutoDataAttribute { - public EfOrganizationTransactionAutoDataAttribute() : base(new SutProviderCustomization(), new EfTransaction(){ - OrganizationOwned = true, - }) + public EfOrganizationTransactionAutoDataAttribute() : base(new SutProviderCustomization(), new EfTransaction() + { + OrganizationOwned = true, + }) { } } } diff --git a/test/Core.Test/AutoFixture/U2fFixtures.cs b/test/Core.Test/AutoFixture/U2fFixtures.cs index 78fac0c4d..51c5d619d 100644 --- a/test/Core.Test/AutoFixture/U2fFixtures.cs +++ b/test/Core.Test/AutoFixture/U2fFixtures.cs @@ -1,21 +1,21 @@ +using System; using AutoFixture; -using TableModel = Bit.Core.Models.Table; using AutoFixture.Kernel; -using System; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Core.Test.AutoFixture.Relays; using Bit.Core.Test.AutoFixture.UserFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.U2fFixtures { - internal class U2fBuilder: ISpecimenBuilder + internal class U2fBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - if (context == null) + if (context == null) { throw new ArgumentNullException(nameof(context)); } @@ -33,7 +33,7 @@ namespace Bit.Core.Test.AutoFixture.U2fFixtures } } - internal class EfU2f: ICustomization + internal class EfU2f : ICustomization { public void Customize(IFixture fixture) { diff --git a/test/Core.Test/AutoFixture/UserFixtures.cs b/test/Core.Test/AutoFixture/UserFixtures.cs index 1608db151..ddc32f854 100644 --- a/test/Core.Test/AutoFixture/UserFixtures.cs +++ b/test/Core.Test/AutoFixture/UserFixtures.cs @@ -1,15 +1,15 @@ -using AutoFixture; -using TableModel = Bit.Core.Models.Table; -using Bit.Core.Models; +using System; using System.Collections.Generic; -using Bit.Core.Enums; +using AutoFixture; using AutoFixture.Kernel; -using System; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using Bit.Core.Enums; +using Bit.Core.Models; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; -using Bit.Test.Common.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.AutoFixture.UserFixtures { diff --git a/test/Core.Test/Helpers/Factories.cs b/test/Core.Test/Helpers/Factories.cs index 56092122d..0ca18e7c7 100644 --- a/test/Core.Test/Helpers/Factories.cs +++ b/test/Core.Test/Helpers/Factories.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Settings; using Bit.Test.Common.Helpers.Factories; diff --git a/test/Core.Test/Models/Business/TaxInfoTests.cs b/test/Core.Test/Models/Business/TaxInfoTests.cs index 20ccf4a3d..e6d96c670 100644 --- a/test/Core.Test/Models/Business/TaxInfoTests.cs +++ b/test/Core.Test/Models/Business/TaxInfoTests.cs @@ -1,4 +1,4 @@ -using Bit.Core.Models.Business; +using Bit.Core.Models.Business; using NSubstitute; using Xunit; @@ -16,7 +16,7 @@ namespace Bit.Core.Test.Models.Business [InlineData("AU", "PH", null, "au_abn")] [InlineData("BR", "PH", null, "br_cnpj")] [InlineData("CA", "PH", "bec", "ca_qst")] - [InlineData("CA", "PH", null, "ca_bn")] + [InlineData("CA", "PH", null, "ca_bn")] [InlineData("CL", "PH", null, "cl_tin")] [InlineData("AT", "PH", null, "eu_vat")] [InlineData("BE", "PH", null, "eu_vat")] @@ -63,8 +63,8 @@ namespace Bit.Core.Test.Models.Business [InlineData("US", "PH", null, "us_ein")] [InlineData("ZA", "PH", null, "za_vat")] [InlineData("ABCDEF", "PH", null, null)] - public void GetTaxIdType_Success(string billingAddressCountry, - string taxIdNumber, + public void GetTaxIdType_Success(string billingAddressCountry, + string taxIdNumber, string billingAddressState, string expectedTaxIdType) { diff --git a/test/Core.Test/Models/PermissionsTests.cs b/test/Core.Test/Models/PermissionsTests.cs index 909d0fb29..090bc72a6 100644 --- a/test/Core.Test/Models/PermissionsTests.cs +++ b/test/Core.Test/Models/PermissionsTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text.Json; using AutoFixture.Xunit2; using Bit.Core.Models.Data; diff --git a/test/Core.Test/Models/Tables/UserTests.cs b/test/Core.Test/Models/Tables/UserTests.cs index 05a34c00f..851174e05 100644 --- a/test/Core.Test/Models/Tables/UserTests.cs +++ b/test/Core.Test/Models/Tables/UserTests.cs @@ -1,4 +1,4 @@ -using Bit.Core.Models.Table; +using Bit.Core.Models.Table; using Xunit; namespace Bit.Core.Test.Models.Tables diff --git a/test/Core.Test/Repositories/EntityFramework/CipherRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/CipherRepositoryTests.cs index 63cd2d051..f1fbb11e9 100644 --- a/test/Core.Test/Repositories/EntityFramework/CipherRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/CipherRepositoryTests.cs @@ -1,6 +1,9 @@ +using System; using System.Collections.Generic; using System.Linq; +using Bit.Core.Models.Data; using Bit.Core.Models.Table; +using Bit.Core.Repositories.EntityFramework.Queries; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.CipherFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; @@ -8,15 +11,12 @@ using Microsoft.EntityFrameworkCore; using Xunit; using EfRepo = Bit.Core.Repositories.EntityFramework; using SqlRepo = Bit.Core.Repositories.SqlServer; -using Bit.Core.Repositories.EntityFramework.Queries; -using Bit.Core.Models.Data; -using System; namespace Bit.Core.Test.Repositories.EntityFramework { public class CipherRepositoryTests { - [Theory (Skip = "Run ad-hoc"), EfUserCipherAutoData] + [Theory(Skip = "Run ad-hoc"), EfUserCipherAutoData] public async void RefreshDb(List suts) { foreach (var sut in suts) @@ -28,7 +28,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework [CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData] public async void CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org, CipherCompare equalityComparer, List suts, List efUserRepos, - List efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo, + List efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo) { var savedCiphers = new List(); @@ -56,7 +56,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework var sqlUser = await sqlUserRepo.CreateAsync(user); cipher.UserId = sqlUser.Id; - + if (cipher.OrganizationId.HasValue) { var sqlOrg = await sqlOrgRepo.CreateAsync(org); @@ -69,7 +69,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedCiphers.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); - } + } [CiSkippedTheory, EfUserCipherAutoData] public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user, @@ -93,8 +93,8 @@ namespace Bit.Core.Test.Repositories.EntityFramework bumpedUsers.Add(bumpedUser); } - Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString() )); - } + Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString())); + } [CiSkippedTheory, EfOrganizationCipherAutoData] public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, List users, @@ -118,7 +118,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework var efCollection = await efCollectionRepos[i].CreateAsync(collection); efCollectionRepos[i].ClearChangeTracking(); - IEnumerable[] lists = {efUsers, orgUsers}; + IEnumerable[] lists = { efUsers, orgUsers }; var maxOrgUsers = lists.Min(l => l.Count()); orgUsers = orgUsers.Take(maxOrgUsers).ToList(); @@ -140,7 +140,8 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var ou in orgUsers) { - var collectionUser = new CollectionUser() { + var collectionUser = new CollectionUser() + { CollectionId = efCollection.Id, OrganizationUserId = ou.Id }; @@ -153,10 +154,10 @@ namespace Bit.Core.Test.Repositories.EntityFramework var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher); var modifiedUsers = await sut.Run(query).ToListAsync(); Assert.True(modifiedUsers - .All(u => u.AccountRevisionDate.ToShortDateString() == + .All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString())); } - } + } [CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData] public async void DeleteAsync_CipherIsDeleted( @@ -171,7 +172,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var i = suts.IndexOf(sut); - + var postEfOrg = await efOrgRepos[i].CreateAsync(org); efOrgRepos[i].ClearChangeTracking(); var postEfUser = await efUserRepos[i].CreateAsync(user); diff --git a/test/Core.Test/Repositories/EntityFramework/CollectionRepository.cs b/test/Core.Test/Repositories/EntityFramework/CollectionRepository.cs index b29d265af..eadac57aa 100644 --- a/test/Core.Test/Repositories/EntityFramework/CollectionRepository.cs +++ b/test/Core.Test/Repositories/EntityFramework/CollectionRepository.cs @@ -1,15 +1,15 @@ +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.CollectionFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Microsoft.EntityFrameworkCore; using Xunit; -using Bit.Core.Models.Table; -using System.Collections.Generic; -using SqlRepo = Bit.Core.Repositories.SqlServer; using EfRepo = Bit.Core.Repositories.EntityFramework; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; -using Bit.Core.Test.AutoFixture.CollectionFixtures; -using System.Linq; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -50,6 +50,6 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedCollections.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); - } + } } } diff --git a/test/Core.Test/Repositories/EntityFramework/DeviceRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/DeviceRepositoryTests.cs index 33d3bf66a..c62b70eda 100644 --- a/test/Core.Test/Repositories/EntityFramework/DeviceRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/DeviceRepositoryTests.cs @@ -1,12 +1,12 @@ -using Bit.Core.Test.AutoFixture.Attributes; -using Xunit; -using SqlRepo = Bit.Core.Repositories.SqlServer; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using System.Collections.Generic; -using Bit.Core.Models.Table; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using System.Collections.Generic; using System.Linq; +using Bit.Core.Models.Table; +using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.DeviceFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -44,6 +44,6 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedDevices.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); } - + } } diff --git a/test/Core.Test/Repositories/EntityFramework/EmergencyAccessRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/EmergencyAccessRepositoryTests.cs index aaf00bbfd..4f8007a63 100644 --- a/test/Core.Test/Repositories/EntityFramework/EmergencyAccessRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/EmergencyAccessRepositoryTests.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; +using AutoFixture; +using AutoFixture.DataAnnotations; +using AutoFixture.Kernel; using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.EmergencyAccessFixtures; +using Bit.Core.Test.AutoFixture.Relays; +using Bit.Core.Test.AutoFixture.TransactionFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Xunit; -using SqlRepo = Bit.Core.Repositories.SqlServer; using EfRepo = Bit.Core.Repositories.EntityFramework; -using System.Linq; -using AutoFixture; -using Bit.Core.Test.AutoFixture.TransactionFixtures; -using AutoFixture.DataAnnotations; -using AutoFixture.Kernel; -using Bit.Core.Test.AutoFixture.Relays; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CipherCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CipherCompare.cs index 979ea7e7b..f396bdf7b 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CipherCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CipherCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class CipherCompare: IEqualityComparer + public class CipherCompare : IEqualityComparer { public bool Equals(Cipher x, Cipher y) { - return x.Type == y.Type && + return x.Type == y.Type && x.Data == y.Data && x.Favorites == y.Favorites && x.Attachments == y.Attachments; diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CollectionCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CollectionCompare.cs index 99aaa4e6b..eeced8b66 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CollectionCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/CollectionCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class CollectionCompare: IEqualityComparer + public class CollectionCompare : IEqualityComparer { public bool Equals(Collection x, Collection y) { - return x.Name == y.Name && + return x.Name == y.Name && x.ExternalId == y.ExternalId; } diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/DeviceCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/DeviceCompare.cs index ae4defa0f..f793a784d 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/DeviceCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/DeviceCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class DeviceCompare: IEqualityComparer + public class DeviceCompare : IEqualityComparer { public bool Equals(Device x, Device y) { - return x.Name == y.Name && + return x.Name == y.Name && x.Type == y.Type && x.Identifier == y.Identifier && x.PushToken == y.PushToken; diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EmergencyAccessCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EmergencyAccessCompare.cs index 2564f418c..36bce9b6e 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EmergencyAccessCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EmergencyAccessCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class EmergencyAccessCompare: IEqualityComparer + public class EmergencyAccessCompare : IEqualityComparer { public bool Equals(EmergencyAccess x, EmergencyAccess y) { - return x.Email == y.Email && + return x.Email == y.Email && x.KeyEncrypted == y.KeyEncrypted && x.Type == y.Type && x.Status == y.Status && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EventCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EventCompare.cs index ea278388c..3c1733483 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EventCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/EventCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class EventCompare: IEqualityComparer + public class EventCompare : IEqualityComparer { public bool Equals(Event x, Event y) { - return x.Date.ToShortDateString() == y.Date.ToShortDateString() && + return x.Date.ToShortDateString() == y.Date.ToShortDateString() && x.Type == y.Type && x.IpAddress == y.IpAddress; } diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/FolderCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/FolderCompare.cs index 1f0a832e6..41f25dc26 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/FolderCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/FolderCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class FolderCompare: IEqualityComparer + public class FolderCompare : IEqualityComparer { public bool Equals(Folder x, Folder y) { - return x.Name == y.Name; + return x.Name == y.Name; } public int GetHashCode([DisallowNull] Folder obj) diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GrantCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GrantCompare.cs index 09d8f0181..f0b07da30 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GrantCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GrantCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class GrantCompare: IEqualityComparer + public class GrantCompare : IEqualityComparer { public bool Equals(Grant x, Grant y) { - return x.Key == y.Key && + return x.Key == y.Key && x.Type == y.Type && x.SubjectId == y.SubjectId && x.ClientId == y.ClientId && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GroupCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GroupCompare.cs index 1b06b3fbf..3604368cf 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GroupCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/GroupCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class GroupCompare: IEqualityComparer + public class GroupCompare : IEqualityComparer { public bool Equals(Group x, Group y) { - return x.Name == y.Name && + return x.Name == y.Name && x.AccessAll == y.AccessAll && x.ExternalId == y.ExternalId; } diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/InstallationCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/InstallationCompare.cs index 380a348e7..496b71cb6 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/InstallationCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/InstallationCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class InstallationCompare: IEqualityComparer + public class InstallationCompare : IEqualityComparer { public bool Equals(Installation x, Installation y) { - return x.Email == y.Email && + return x.Email == y.Email && x.Key == y.Key && x.Enabled == y.Enabled; } diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationCompare.cs index 04fa1b10a..91ef9f3bc 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationCompare.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class OrganizationCompare: IEqualityComparer + public class OrganizationCompare : IEqualityComparer { public bool Equals(Organization x, Organization y) { diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationSponsorshipCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationSponsorshipCompare.cs index cd1c29262..c9698e07f 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationSponsorshipCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationSponsorshipCompare.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationUserCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationUserCompare.cs index 7bad31122..3684b2077 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationUserCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/OrganizationUserCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class OrganizationUserCompare: IEqualityComparer + public class OrganizationUserCompare : IEqualityComparer { public bool Equals(OrganizationUser x, OrganizationUser y) { - return x.Email == y.Email && + return x.Email == y.Email && x.Status == y.Status && x.Type == y.Type && x.AccessAll == y.AccessAll && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/PolicyCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/PolicyCompare.cs index ee54af9cc..a192502f1 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/PolicyCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/PolicyCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class PolicyCompare: IEqualityComparer + public class PolicyCompare : IEqualityComparer { public bool Equals(Policy x, Policy y) { - return x.Type == y.Type && + return x.Type == y.Type && x.Data == y.Data && x.Enabled == y.Enabled; } @@ -19,7 +19,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers } } - public class PolicyCompareIncludingOrganization: PolicyCompare + public class PolicyCompareIncludingOrganization : PolicyCompare { public new bool Equals(Policy x, Policy y) { diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SendCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SendCompare.cs index 9a590c548..917ee30a3 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SendCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SendCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class SendCompare: IEqualityComparer + public class SendCompare : IEqualityComparer { public bool Equals(Send x, Send y) { - return x.Type == y.Type && + return x.Type == y.Type && x.Data == y.Data && x.Key == y.Key && x.Password == y.Password && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoConfigCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoConfigCompare.cs index fbffd9cb0..47c24bc3a 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoConfigCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoConfigCompare.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class SsoConfigCompare: IEqualityComparer + public class SsoConfigCompare : IEqualityComparer { public bool Equals(SsoConfig x, SsoConfig y) { diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoUserCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoUserCompare.cs index 7b6dabd8b..d11c2e518 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoUserCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/SsoUserCompare.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class SsoUserCompare: IEqualityComparer + public class SsoUserCompare : IEqualityComparer { public bool Equals(SsoUser x, SsoUser y) { diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TaxRateCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TaxRateCompare.cs index 88127de4d..13d7a29bc 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TaxRateCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TaxRateCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class TaxRateCompare: IEqualityComparer + public class TaxRateCompare : IEqualityComparer { public bool Equals(TaxRate x, TaxRate y) { - return x.Country == y.Country && + return x.Country == y.Country && x.State == y.State && x.PostalCode == y.PostalCode && x.Rate == y.Rate && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TransactionCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TransactionCompare.cs index fbf0d981b..5de0c4c33 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TransactionCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/TransactionCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class TransactionCompare: IEqualityComparer + public class TransactionCompare : IEqualityComparer { public bool Equals(Transaction x, Transaction y) { - return x.Type == y.Type && + return x.Type == y.Type && x.Amount == y.Amount && x.Refunded == y.Refunded && x.Details == y.Details && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/U2fCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/U2fCompare.cs index 3cf4d154b..09687b7d8 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/U2fCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/U2fCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class U2fCompare: IEqualityComparer + public class U2fCompare : IEqualityComparer { public bool Equals(U2f x, U2f y) { - return x.KeyHandle == y.KeyHandle && + return x.KeyHandle == y.KeyHandle && x.Challenge == y.Challenge && x.AppId == y.AppId && x.Version == y.Version; diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserCompare.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserCompare.cs index 552dfc7d8..1388ea96b 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserCompare.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserCompare.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class UserCompare: IEqualityComparer + public class UserCompare : IEqualityComparer { public bool Equals(User x, User y) { - return x.Name == y.Name && + return x.Name == y.Name && x.Email == y.Email && x.EmailVerified == y.EmailVerified && x.MasterPassword == y.MasterPassword && diff --git a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserKdfInformation.cs b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserKdfInformation.cs index d69c76713..f8d0c8acc 100644 --- a/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserKdfInformation.cs +++ b/test/Core.Test/Repositories/EntityFramework/EqualityComparers/UserKdfInformation.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Bit.Core.Models.Data; namespace Bit.Core.Test.Repositories.EntityFramework.EqualityComparers { - public class UserKdfInformationCompare: IEqualityComparer + public class UserKdfInformationCompare : IEqualityComparer { public bool Equals(UserKdfInformation x, UserKdfInformation y) { - return x.Kdf == y.Kdf && + return x.Kdf == y.Kdf && x.KdfIterations == y.KdfIterations; } diff --git a/test/Core.Test/Repositories/EntityFramework/FolderRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/FolderRepositoryTests.cs index 717b42286..4dd478e17 100644 --- a/test/Core.Test/Repositories/EntityFramework/FolderRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/FolderRepositoryTests.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; -using Bit.Core.Models.Table; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.FolderFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; @@ -7,7 +8,6 @@ using Microsoft.EntityFrameworkCore; using Xunit; using EfRepo = Bit.Core.Repositories.EntityFramework; using SqlRepo = Bit.Core.Repositories.SqlServer; -using System.Linq; namespace Bit.Core.Test.Repositories.EntityFramework { diff --git a/test/Core.Test/Repositories/EntityFramework/InstallationRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/InstallationRepositoryTests.cs index 70f70f325..45991d7e9 100644 --- a/test/Core.Test/Repositories/EntityFramework/InstallationRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/InstallationRepositoryTests.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; -using Bit.Core.Models.Table; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.InstallationFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Xunit; using EfRepo = Bit.Core.Repositories.EntityFramework; using SqlRepo = Bit.Core.Repositories.SqlServer; -using System.Linq; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -36,6 +36,6 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedInstallations.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); - } + } } } diff --git a/test/Core.Test/Repositories/EntityFramework/OrganizationRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/OrganizationRepositoryTests.cs index 7f6a2a19f..dc6c3e0d1 100644 --- a/test/Core.Test/Repositories/EntityFramework/OrganizationRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/OrganizationRepositoryTests.cs @@ -1,15 +1,15 @@ +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Data; using Bit.Core.Test.AutoFixture; +using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Test.Helpers.Factories; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; using EfRepo = Bit.Core.Repositories.EntityFramework; using SqlRepo = Bit.Core.Repositories.SqlServer; -using System.Collections.Generic; -using System.Linq; using TableModel = Bit.Core.Models.Table; -using Bit.Core.Models.Data; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; -using Bit.Core.Test.AutoFixture.Attributes; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -68,7 +68,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework [CiSkippedTheory, EfOrganizationAutoData] public async void DeleteAsync_Works_DataMatches(TableModel.Organization organization, - SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, + SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, List suts) { foreach (var sut in suts) @@ -98,7 +98,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework [CiSkippedTheory, EfOrganizationAutoData] public async void GetByIdentifierAsync_Works_DataMatches(TableModel.Organization organization, - SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, + SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, List suts) { var returnedOrgs = new List(); @@ -120,7 +120,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework [CiSkippedTheory, EfOrganizationAutoData] public async void GetManyByEnabledAsync_Works_DataMatches(TableModel.Organization organization, - SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityCompare, + SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityCompare, List suts) { var returnedOrgs = new List(); @@ -142,7 +142,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework // testing data matches here would require manipulating all organization abilities in the db [CiSkippedTheory, EfOrganizationAutoData] public async void GetManyAbilitiesAsync_Works(TableModel.Organization organization, - SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, + SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer, List suts) { var list = new List(); diff --git a/test/Core.Test/Repositories/EntityFramework/OrganizationSponsorshipRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/OrganizationSponsorshipRepositoryTests.cs index 67b7ab409..3fc9dbb6b 100644 --- a/test/Core.Test/Repositories/EntityFramework/OrganizationSponsorshipRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/OrganizationSponsorshipRepositoryTests.cs @@ -1,12 +1,12 @@ -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using TableModel = Bit.Core.Models.Table; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.OrganizationSponsorshipFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework { diff --git a/test/Core.Test/Repositories/EntityFramework/OrganizationUserRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/OrganizationUserRepositoryTests.cs index 0d6b44bb2..c7bb0dbf7 100644 --- a/test/Core.Test/Repositories/EntityFramework/OrganizationUserRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/OrganizationUserRepositoryTests.cs @@ -1,14 +1,14 @@ -using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; +using System; using System.Collections.Generic; using System.Linq; -using TableModel = Bit.Core.Models.Table; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Bit.Core.Models.Data; -using System; using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -125,10 +125,10 @@ namespace Bit.Core.Test.Repositories.EntityFramework var savedEfOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id); Assert.True(savedEfOrgUser != null); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); await sut.DeleteAsync(savedEfOrgUser); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); savedEfOrgUser = await sut.GetByIdAsync(savedEfOrgUser.Id); Assert.True(savedEfOrgUser == null); diff --git a/test/Core.Test/Repositories/EntityFramework/PolicyRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/PolicyRepositoryTests.cs index 1c8fefa21..d929a026f 100644 --- a/test/Core.Test/Repositories/EntityFramework/PolicyRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/PolicyRepositoryTests.cs @@ -1,21 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Repositories; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; -using Bit.Core.Test.AutoFixture.PolicyFixtures; using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; +using Bit.Core.Test.AutoFixture.PolicyFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Microsoft.EntityFrameworkCore; using Xunit; -using TableModel = Bit.Core.Models.Table; -using System.Linq; -using System.Collections.Generic; using EfRepo = Bit.Core.Repositories.EntityFramework; using SqlRepo = Bit.Core.Repositories.SqlServer; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; -using Bit.Core.Models.Data; -using System.Text.Json; -using Bit.Core.Enums; -using Bit.Core.Repositories; -using System.Threading.Tasks; +using TableModel = Bit.Core.Models.Table; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -193,7 +193,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework // Assert var distinctItems = results.Distinct(equalityComparer); - + Assert.True(results.All(r => r == null) || !distinctItems.Skip(1).Any()); } diff --git a/test/Core.Test/Repositories/EntityFramework/SendRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/SendRepositoryTests.cs index 5f3e9fec6..9b2660cdf 100644 --- a/test/Core.Test/Repositories/EntityFramework/SendRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/SendRepositoryTests.cs @@ -1,34 +1,34 @@ -using System.Collections.Generic; -using Bit.Core.Models.Table; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.SendFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Xunit; -using SqlRepo = Bit.Core.Repositories.SqlServer; using EfRepo = Bit.Core.Repositories.EntityFramework; -using System.Linq; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { public class SendRepositoryTests { - [CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData] - public async void CreateAsync_Works_DataMatches( - Send send, - User user, - Organization org, - SendCompare equalityComparer, - List suts, - List efUserRepos, - List efOrgRepos, - SqlRepo.SendRepository sqlSendRepo, - SqlRepo.UserRepository sqlUserRepo, - SqlRepo.OrganizationRepository sqlOrgRepo - ) - { - var savedSends = new List(); - foreach (var sut in suts) - { + [CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData] + public async void CreateAsync_Works_DataMatches( + Send send, + User user, + Organization org, + SendCompare equalityComparer, + List suts, + List efUserRepos, + List efOrgRepos, + SqlRepo.SendRepository sqlSendRepo, + SqlRepo.UserRepository sqlUserRepo, + SqlRepo.OrganizationRepository sqlOrgRepo + ) + { + var savedSends = new List(); + foreach (var sut in suts) + { var i = suts.IndexOf(sut); if (send.OrganizationId.HasValue) @@ -46,7 +46,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework var savedSend = await sut.GetByIdAsync(postEfSend.Id); savedSends.Add(savedSend); - } + } var sqlUser = await sqlUserRepo.CreateAsync(user); if (send.OrganizationId.HasValue) @@ -62,6 +62,6 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedSends.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); - } + } } } diff --git a/test/Core.Test/Repositories/EntityFramework/SsoConfigRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/SsoConfigRepositoryTests.cs index 584ac56b6..3b2e00435 100644 --- a/test/Core.Test/Repositories/EntityFramework/SsoConfigRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/SsoConfigRepositoryTests.cs @@ -1,15 +1,15 @@ -using Bit.Core.Test.AutoFixture; -using Bit.Core.Test.Helpers.Factories; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; +using System; using System.Collections.Generic; using System.Linq; using Bit.Core.Models.Table; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; -using Bit.Core.Test.AutoFixture.SsoConfigFixtures; -using System; +using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.SsoConfigFixtures; +using Bit.Core.Test.Helpers.Factories; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -52,7 +52,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework } [CiSkippedTheory, EfSsoConfigAutoData] - public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig, + public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig, Organization org, SsoConfigCompare equalityComparer, List suts, List efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo, SqlRepo.OrganizationRepository sqlOrganizationRepo) @@ -118,7 +118,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework sut.ClearChangeTracking(); await sut.DeleteAsync(savedEfSsoConfig); - var deletedEfSsoConfig= await sut.GetByIdAsync(savedEfSsoConfig.Id); + var deletedEfSsoConfig = await sut.GetByIdAsync(savedEfSsoConfig.Id); Assert.True(deletedEfSsoConfig == null); } diff --git a/test/Core.Test/Repositories/EntityFramework/SsoUserRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/SsoUserRepositoryTests.cs index 3e772ab5e..0562f8d4b 100644 --- a/test/Core.Test/Repositories/EntityFramework/SsoUserRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/SsoUserRepositoryTests.cs @@ -1,14 +1,14 @@ -using Bit.Core.Test.AutoFixture; -using Bit.Core.Test.Helpers.Factories; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Bit.Core.Models.Table; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; -using Bit.Core.Test.AutoFixture.SsoUserFixtures; +using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.SsoUserFixtures; +using Bit.Core.Test.Helpers.Factories; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -53,7 +53,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework } [CiSkippedTheory, EfSsoUserAutoData] - public async void ReplaceAsync_Works_DataMatches(SsoUser postSsoUser, SsoUser replaceSsoUser, + public async void ReplaceAsync_Works_DataMatches(SsoUser postSsoUser, SsoUser replaceSsoUser, Organization org, User user, SsoUserCompare equalityComparer, List suts, List efUserRepos, List efOrgRepos, SqlRepo.SsoUserRepository sqlSsoUserRepo, diff --git a/test/Core.Test/Repositories/EntityFramework/TaxRateRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/TaxRateRepositoryTests.cs index 594c6e2dc..892032002 100644 --- a/test/Core.Test/Repositories/EntityFramework/TaxRateRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/TaxRateRepositoryTests.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using Bit.Core.Models.Table; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; +using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture.TaxRateFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -37,6 +37,6 @@ namespace Bit.Core.Test.Repositories.EntityFramework var distinctItems = savedTaxRates.Distinct(equalityComparer); Assert.True(!distinctItems.Skip(1).Any()); - } + } } } diff --git a/test/Core.Test/Repositories/EntityFramework/TransactionRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/TransactionRepositoryTests.cs index 43458eac5..c25c48254 100644 --- a/test/Core.Test/Repositories/EntityFramework/TransactionRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/TransactionRepositoryTests.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; -using Bit.Core.Models.Table; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; @@ -7,15 +8,14 @@ using Bit.Core.Test.AutoFixture.TransactionFixtures; using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Microsoft.EntityFrameworkCore; using Xunit; -using SqlRepo = Bit.Core.Repositories.SqlServer; using EfRepo = Bit.Core.Repositories.EntityFramework; -using System.Linq; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { public class TransactionRepositoryTests { - + [CiSkippedTheory, EfUserTransactionAutoData, EfOrganizationTransactionAutoData] public async void CreateAsync_Works_DataMatches( Transaction transaction, diff --git a/test/Core.Test/Repositories/EntityFramework/U2fRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/U2fRepositoryTests.cs index 906438827..3ea666ee3 100644 --- a/test/Core.Test/Repositories/EntityFramework/U2fRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/U2fRepositoryTests.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using Bit.Core.Models.Table; +using Bit.Core.Models.Table; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture; using Bit.Core.Test.AutoFixture.Attributes; @@ -15,7 +15,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework { public class U2fRepositoryTests { - + [CiSkippedTheory, EfU2fAutoData] public async void CreateAsync_Works_DataMatches( U2f u2f, diff --git a/test/Core.Test/Repositories/EntityFramework/UserRepositoryTests.cs b/test/Core.Test/Repositories/EntityFramework/UserRepositoryTests.cs index 8b4623f52..e6545e4fb 100644 --- a/test/Core.Test/Repositories/EntityFramework/UserRepositoryTests.cs +++ b/test/Core.Test/Repositories/EntityFramework/UserRepositoryTests.cs @@ -1,14 +1,14 @@ -using Bit.Core.Test.AutoFixture.UserFixtures; -using EfRepo = Bit.Core.Repositories.EntityFramework; -using SqlRepo = Bit.Core.Repositories.SqlServer; +using System; using System.Collections.Generic; using System.Linq; -using Bit.Core.Models.Table; -using Xunit; -using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; using Bit.Core.Models.Data; -using System; +using Bit.Core.Models.Table; using Bit.Core.Test.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.UserFixtures; +using Bit.Core.Test.Repositories.EntityFramework.EqualityComparers; +using Xunit; +using EfRepo = Bit.Core.Repositories.EntityFramework; +using SqlRepo = Bit.Core.Repositories.SqlServer; namespace Bit.Core.Test.Repositories.EntityFramework { @@ -71,14 +71,14 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var savedEfUser = await sut.GetByIdAsync(postEfUser.Id); Assert.True(savedEfUser != null); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); await sut.DeleteAsync(savedEfUser); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); savedEfUser = await sut.GetByIdAsync(savedEfUser.Id); Assert.True(savedEfUser == null); @@ -122,7 +122,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var kdfInformation = await sut.GetKdfInformationByEmailAsync(postEfUser.Email.ToUpperInvariant()); savedKdfInformation.Add(kdfInformation); } @@ -136,15 +136,15 @@ namespace Bit.Core.Test.Repositories.EntityFramework } [CiSkippedTheory, EfUserAutoData] - public async void SearchAsync_Works_DataMatches(User user, int skip, int take, - UserCompare equalityCompare, List suts, + public async void SearchAsync_Works_DataMatches(User user, int skip, int take, + UserCompare equalityCompare, List suts, SqlRepo.UserRepository sqlUserRepo) { var searchedEfUsers = new List(); foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var searchedEfUsersCollection = await sut.SearchAsync(postEfUser.Email.ToUpperInvariant(), skip, take); searchedEfUsers.Concat(searchedEfUsersCollection.ToList()); @@ -165,7 +165,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var searchedEfUsers = await sut.GetManyByPremiumAsync(user.Premium); returnedUsers.Concat(searchedEfUsers.ToList()); @@ -186,7 +186,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var efKey = await sut.GetPublicKeyAsync(postEfUser.Id); returnedKeys.Add(efKey); @@ -207,7 +207,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework foreach (var sut in suts) { var postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var efKey = await sut.GetPublicKeyAsync(postEfUser.Id); returnedKeys.Add(efKey); @@ -230,10 +230,10 @@ namespace Bit.Core.Test.Repositories.EntityFramework { var postEfUser = user; postEfUser = await sut.CreateAsync(user); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); await sut.UpdateRenewalReminderDateAsync(postEfUser.Id, updatedReminderDate); - sut.ClearChangeTracking(); + sut.ClearChangeTracking(); var replacedUser = await sut.GetByIdAsync(postEfUser.Id); savedDates.Add(replacedUser.RenewalReminderDate); @@ -250,7 +250,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework } [CiSkippedTheory, EfUserAutoData] - public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org, + public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org, SsoUser ssoUser, UserCompare equalityComparer, List suts, List ssoUserRepos, List orgRepos, SqlRepo.UserRepository sqlUserRepo, SqlRepo.SsoUserRepository sqlSsoUserRepo, @@ -282,7 +282,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework ssoUser.UserId = sqlUser.Id; ssoUser.OrganizationId = sqlOrganization.Id; var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser); - + var returnedSqlUser = await sqlUserRepo .GetBySsoUserAsync(postSqlSsoUser.ExternalId, sqlOrganization.Id); returnedList.Add(returnedSqlUser); diff --git a/test/Core.Test/Services/AmazonSqsBlockIpServiceTests.cs b/test/Core.Test/Services/AmazonSqsBlockIpServiceTests.cs index 10a7dba29..fab9b2fda 100644 --- a/test/Core.Test/Services/AmazonSqsBlockIpServiceTests.cs +++ b/test/Core.Test/Services/AmazonSqsBlockIpServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Amazon.SQS; using Bit.Core.Services; diff --git a/test/Core.Test/Services/AzureAttachmentStorageServiceTests.cs b/test/Core.Test/Services/AzureAttachmentStorageServiceTests.cs index b7bc73a4e..788c6f0e4 100644 --- a/test/Core.Test/Services/AzureAttachmentStorageServiceTests.cs +++ b/test/Core.Test/Services/AzureAttachmentStorageServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using NSubstitute; diff --git a/test/Core.Test/Services/AzureQueueBlockIpServiceTests.cs b/test/Core.Test/Services/AzureQueueBlockIpServiceTests.cs index dbc8a8106..295a77adf 100644 --- a/test/Core.Test/Services/AzureQueueBlockIpServiceTests.cs +++ b/test/Core.Test/Services/AzureQueueBlockIpServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using NSubstitute; diff --git a/test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs b/test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs index 7b304c215..62fca9f1d 100644 --- a/test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs +++ b/test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.AspNetCore.Http; diff --git a/test/Core.Test/Services/CipherServiceTests.cs b/test/Core.Test/Services/CipherServiceTests.cs index 45e1f189f..fe5fb2da0 100644 --- a/test/Core.Test/Services/CipherServiceTests.cs +++ b/test/Core.Test/Services/CipherServiceTests.cs @@ -1,17 +1,17 @@ -using System; -using System.Threading.Tasks; -using Bit.Core.Repositories; -using Bit.Core.Services; -using NSubstitute; -using Xunit; -using Bit.Core.Exceptions; -using Bit.Core.Models.Table; -using Core.Models.Data; -using Bit.Core.Test.AutoFixture.CipherFixtures; +using System; using System.Collections.Generic; using System.Linq; -using Castle.Core.Internal; +using System.Threading.Tasks; +using Bit.Core.Exceptions; +using Bit.Core.Models.Table; +using Bit.Core.Repositories; +using Bit.Core.Services; +using Bit.Core.Test.AutoFixture.CipherFixtures; using Bit.Test.Common.AutoFixture; +using Castle.Core.Internal; +using Core.Models.Data; +using NSubstitute; +using Xunit; namespace Bit.Core.Test.Services { diff --git a/test/Core.Test/Services/EmergencyAccessServiceTests.cs b/test/Core.Test/Services/EmergencyAccessServiceTests.cs index 9493238e9..f010ec993 100644 --- a/test/Core.Test/Services/EmergencyAccessServiceTests.cs +++ b/test/Core.Test/Services/EmergencyAccessServiceTests.cs @@ -1,14 +1,14 @@ -using Bit.Core.Exceptions; +using System; +using System.Threading.Tasks; +using Bit.Core.Exceptions; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; -using Bit.Core.Test.AutoFixture.Attributes; using Bit.Core.Test.AutoFixture; +using Bit.Core.Test.AutoFixture.Attributes; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; -using System.Threading.Tasks; -using System; using Xunit; namespace Bit.Core.Test.Services @@ -63,7 +63,7 @@ namespace Bit.Core.Test.Services }; sutProvider.GetDependency().GetUserByIdAsync(savingUser.Id).Returns(savingUser); - + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.SaveAsync(emergencyAccess, savingUser.Id)); diff --git a/test/Core.Test/Services/EventServiceTests.cs b/test/Core.Test/Services/EventServiceTests.cs index 3476a2565..c4282cee3 100644 --- a/test/Core.Test/Services/EventServiceTests.cs +++ b/test/Core.Test/Services/EventServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Context; using Bit.Core.Repositories; using Bit.Core.Services; diff --git a/test/Core.Test/Services/GroupServiceTests.cs b/test/Core.Test/Services/GroupServiceTests.cs index 04ddf20ce..824e4d2bb 100644 --- a/test/Core.Test/Services/GroupServiceTests.cs +++ b/test/Core.Test/Services/GroupServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Enums; diff --git a/test/Core.Test/Services/HandlebarsMailServiceTests.cs b/test/Core.Test/Services/HandlebarsMailServiceTests.cs index d5de7a684..a531ecb11 100644 --- a/test/Core.Test/Services/HandlebarsMailServiceTests.cs +++ b/test/Core.Test/Services/HandlebarsMailServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -44,7 +44,7 @@ namespace Bit.Core.Test.Services { // TODO: Swith to use env variable { ("email", typeof(string)), "test@bitwarden.com" }, - { ("user", typeof(User)), new User + { ("user", typeof(User)), new User { Id = Guid.NewGuid(), Email = "test@bitwarden.com", @@ -151,8 +151,8 @@ namespace Bit.Core.Test.Services { var parameters = method.GetParameters(); var args = new object[parameters.Length]; - - for(var i = 0; i < parameters.Length; i++) + + for (var i = 0; i < parameters.Length; i++) { if (!namedParameters.TryGetValue((parameters[i].Name, parameters[i].ParameterType), out var value)) { diff --git a/test/Core.Test/Services/InMemoryApplicationCacheServiceTests.cs b/test/Core.Test/Services/InMemoryApplicationCacheServiceTests.cs index 97c609d2a..042fe40dc 100644 --- a/test/Core.Test/Services/InMemoryApplicationCacheServiceTests.cs +++ b/test/Core.Test/Services/InMemoryApplicationCacheServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using NSubstitute; diff --git a/test/Core.Test/Services/InMemoryServiceBusApplicationCacheServiceTests.cs b/test/Core.Test/Services/InMemoryServiceBusApplicationCacheServiceTests.cs index 17ff55c03..0cfbe47d2 100644 --- a/test/Core.Test/Services/InMemoryServiceBusApplicationCacheServiceTests.cs +++ b/test/Core.Test/Services/InMemoryServiceBusApplicationCacheServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; diff --git a/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs b/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs index 386bc2bee..846b9784b 100644 --- a/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs +++ b/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs @@ -1,18 +1,18 @@ -using System; +using System; +using System.IO; +using System.Threading.Tasks; +using AutoFixture; +using Bit.Core.Models.Data; +using Bit.Core.Models.Table; using Bit.Core.Services; using Bit.Core.Settings; -using NSubstitute; -using Xunit; -using System.IO; -using Bit.Core.Test.AutoFixture.CipherFixtures; -using Bit.Core.Models.Data; -using System.Threading.Tasks; -using Bit.Core.Models.Table; -using U2F.Core.Utils; using Bit.Core.Test.AutoFixture.CipherAttachmentMetaData; -using AutoFixture; -using Bit.Test.Common.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.CipherFixtures; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using NSubstitute; +using U2F.Core.Utils; +using Xunit; namespace Bit.Core.Test.Services { diff --git a/test/Core.Test/Services/MailKitSmtpMailDeliveryServiceTests.cs b/test/Core.Test/Services/MailKitSmtpMailDeliveryServiceTests.cs index d2853d259..7a99a4b53 100644 --- a/test/Core.Test/Services/MailKitSmtpMailDeliveryServiceTests.cs +++ b/test/Core.Test/Services/MailKitSmtpMailDeliveryServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.Extensions.Logging; diff --git a/test/Core.Test/Services/MultiServicePushNotificationServiceTests.cs b/test/Core.Test/Services/MultiServicePushNotificationServiceTests.cs index 0ac9d2b0e..c99347546 100644 --- a/test/Core.Test/Services/MultiServicePushNotificationServiceTests.cs +++ b/test/Core.Test/Services/MultiServicePushNotificationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; diff --git a/test/Core.Test/Services/NotificationHubPushNotificationServiceTests.cs b/test/Core.Test/Services/NotificationHubPushNotificationServiceTests.cs index cbca82b1e..969f23b61 100644 --- a/test/Core.Test/Services/NotificationHubPushNotificationServiceTests.cs +++ b/test/Core.Test/Services/NotificationHubPushNotificationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; diff --git a/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs b/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs index 336e524a5..b8c847e27 100644 --- a/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs +++ b/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; diff --git a/test/Core.Test/Services/NotificationsApiPushNotificationServiceTests.cs b/test/Core.Test/Services/NotificationsApiPushNotificationServiceTests.cs index 3b103a4e5..b685e4fc6 100644 --- a/test/Core.Test/Services/NotificationsApiPushNotificationServiceTests.cs +++ b/test/Core.Test/Services/NotificationsApiPushNotificationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.AspNetCore.Http; diff --git a/test/Core.Test/Services/OrganizationServiceTests.cs b/test/Core.Test/Services/OrganizationServiceTests.cs index 1324fb7b8..ab3d9ee7d 100644 --- a/test/Core.Test/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/Services/OrganizationServiceTests.cs @@ -1,27 +1,27 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; +using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Models.Business; using Bit.Core.Models.Data; using Bit.Core.Models.Table; -using Bit.Core.Models.Business; using Bit.Core.Repositories; using Bit.Core.Services; +using Bit.Core.Settings; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; +using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; +using Bit.Core.Test.AutoFixture.PolicyFixtures; +using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; using Xunit; -using Bit.Core.Exceptions; -using Bit.Core.Enums; -using Bit.Core.Test.AutoFixture.OrganizationFixtures; -using System.Text.Json; -using Bit.Core.Context; -using Bit.Core.Test.AutoFixture.OrganizationUserFixtures; using Organization = Bit.Core.Models.Table.Organization; using OrganizationUser = Bit.Core.Models.Table.OrganizationUser; using Policy = Bit.Core.Models.Table.Policy; -using Bit.Core.Test.AutoFixture.PolicyFixtures; -using Bit.Core.Settings; -using Bit.Test.Common.AutoFixture; -using Bit.Test.Common.AutoFixture.Attributes; namespace Bit.Core.Test.Services { @@ -68,7 +68,7 @@ namespace Bit.Core.Test.Services .BulkSendOrganizationInviteEmailAsync(org.Name, Arg.Any(), Arg.Is>(messages => messages.Count() == expectedNewUsersCount)); - + // Send events await sutProvider.GetDependency().Received(1) .LogOrganizationUserEventsAsync(Arg.Is>(events => @@ -133,8 +133,8 @@ namespace Bit.Core.Test.Services .LogOrganizationUserEventsAsync(Arg.Is>(events => events.Where(e => e.Item2 == EventType.OrganizationUser_Invited).Count() == expectedNewUsersCount)); await sutProvider.GetDependency().Received(1) - .RaiseEventAsync(Arg.Is(referenceEvent => - referenceEvent.Type == ReferenceEventType.InvitedUsers && referenceEvent.Id == org.Id && + .RaiseEventAsync(Arg.Is(referenceEvent => + referenceEvent.Type == ReferenceEventType.InvitedUsers && referenceEvent.Id == org.Id && referenceEvent.Users == expectedNewUsersCount)); } @@ -199,7 +199,7 @@ namespace Bit.Core.Test.Services await Assert.ThrowsAsync( () => sutProvider.Sut.InviteUsersAsync(organization.Id, invitor.UserId, new (OrganizationUserInvite, string)[] { (invite, null) })); } - + [Theory] [OrganizationInviteAutoData( inviteeUserType: (int)OrganizationUserType.Admin, @@ -322,7 +322,7 @@ namespace Bit.Core.Test.Services organizationRepository.GetByIdAsync(organization.Id).Returns(organization); organizationUserRepository.GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner) - .Returns(new [] {invitor}); + .Returns(new[] { invitor }); currentContext.OrganizationOwner(organization.Id).Returns(true); currentContext.ManageUsers(organization.Id).Returns(true); @@ -336,7 +336,7 @@ namespace Bit.Core.Test.Services )] public async Task InviteUser_Passes(Organization organization, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, OrganizationUser invitor, - [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)]OrganizationUser owner, + [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser owner, SutProvider sutProvider) { // Autofixture will add collections for all of the invites, remove the first and for all the rest set all access false @@ -356,7 +356,7 @@ namespace Bit.Core.Test.Services organizationRepository.GetByIdAsync(organization.Id).Returns(organization); organizationUserRepository.GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner) - .Returns(new [] {owner}); + .Returns(new[] { owner }); currentContext.ManageUsers(organization.Id).Returns(true); await sutProvider.Sut.InviteUsersAsync(organization.Id, invitor.UserId, invites); @@ -392,7 +392,7 @@ namespace Bit.Core.Test.Services OrganizationUser oldUserData, OrganizationUser newUserData, IEnumerable collections, - [OrganizationUser(type: OrganizationUserType.Owner)]OrganizationUser savingUser, + [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser savingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -408,7 +408,7 @@ namespace Bit.Core.Test.Services await sutProvider.Sut.SaveUserAsync(newUserData, savingUser.UserId, collections); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUser_InvalidUser(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) @@ -421,28 +421,28 @@ namespace Bit.Core.Test.Services () => sutProvider.Sut.DeleteUserAsync(Guid.NewGuid(), organizationUser.Id, deletingUser.UserId)); Assert.Contains("User not valid.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUser_RemoveYourself(OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); - + organizationUserRepository.GetByIdAsync(deletingUser.Id).Returns(deletingUser); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, deletingUser.Id, deletingUser.UserId)); Assert.Contains("You cannot remove yourself.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUser_NonOwnerRemoveOwner( - [OrganizationUser(type: OrganizationUserType.Owner)]OrganizationUser organizationUser, - [OrganizationUser(type: OrganizationUserType.Admin)]OrganizationUser deletingUser, + [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, + [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); var currentContext = sutProvider.GetDependency(); - + organizationUser.OrganizationId = deletingUser.OrganizationId; organizationUserRepository.GetByIdAsync(organizationUser.Id).Returns(organizationUser); currentContext.OrganizationAdmin(deletingUser.OrganizationId).Returns(true); @@ -454,12 +454,12 @@ namespace Bit.Core.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUser_LastOwner( - [OrganizationUser(type: OrganizationUserType.Owner)]OrganizationUser organizationUser, + [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); - + organizationUser.OrganizationId = deletingUser.OrganizationId; organizationUserRepository.GetByIdAsync(organizationUser.Id).Returns(organizationUser); organizationUserRepository.GetManyByOrganizationAsync(deletingUser.OrganizationId, OrganizationUserType.Owner) @@ -473,22 +473,22 @@ namespace Bit.Core.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUser_Success( OrganizationUser organizationUser, - [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)]OrganizationUser deletingUser, + [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); var currentContext = sutProvider.GetDependency(); - + organizationUser.OrganizationId = deletingUser.OrganizationId; organizationUserRepository.GetByIdAsync(organizationUser.Id).Returns(organizationUser); organizationUserRepository.GetByIdAsync(deletingUser.Id).Returns(deletingUser); organizationUserRepository.GetManyByOrganizationAsync(deletingUser.OrganizationId, OrganizationUserType.Owner) - .Returns(new[] {deletingUser, organizationUser}); + .Returns(new[] { deletingUser, organizationUser }); currentContext.OrganizationOwner(deletingUser.OrganizationId).Returns(true); await sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsers_FilterInvalid(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) @@ -502,10 +502,10 @@ namespace Bit.Core.Test.Services () => sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId)); Assert.Contains("Users invalid.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsers_RemoveYourself( - [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)]OrganizationUser orgUser, + [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, OrganizationUser deletingUser, SutProvider sutProvider) { @@ -513,34 +513,34 @@ namespace Bit.Core.Test.Services var organizationUsers = new[] { deletingUser }; var organizationUserIds = organizationUsers.Select(u => u.Id); organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); - organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] {orgUser}); + organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] { orgUser }); var result = await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); Assert.Contains("You cannot remove yourself.", result[0].Item2); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsers_NonOwnerRemoveOwner( - [OrganizationUser(type: OrganizationUserType.Admin)]OrganizationUser deletingUser, - [OrganizationUser(type: OrganizationUserType.Owner)]OrganizationUser orgUser1, - [OrganizationUser(OrganizationUserStatusType.Confirmed)]OrganizationUser orgUser2, + [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, + [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, + [OrganizationUser(OrganizationUserStatusType.Confirmed)] OrganizationUser orgUser2, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); - + orgUser1.OrganizationId = orgUser2.OrganizationId = deletingUser.OrganizationId; var organizationUsers = new[] { orgUser1 }; var organizationUserIds = organizationUsers.Select(u => u.Id); organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); - organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] {orgUser2}); + organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] { orgUser2 }); var result = await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); Assert.Contains("Only owners can delete other owners.", result[0].Item2); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsers_LastOwner( - [OrganizationUser(status: OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)]OrganizationUser orgUser, + [OrganizationUser(status: OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -557,8 +557,8 @@ namespace Bit.Core.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task DeleteUsers_Success( - [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)]OrganizationUser deletingUser, - [OrganizationUser(type: OrganizationUserType.Owner)]OrganizationUser orgUser1, OrganizationUser orgUser2, + [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, + [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -570,15 +570,15 @@ namespace Bit.Core.Test.Services organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); organizationUserRepository.GetByIdAsync(deletingUser.Id).Returns(deletingUser); organizationUserRepository.GetManyByOrganizationAsync(deletingUser.OrganizationId, OrganizationUserType.Owner) - .Returns(new[] {deletingUser, orgUser1}); + .Returns(new[] { deletingUser, orgUser1 }); currentContext.OrganizationOwner(deletingUser.OrganizationId).Returns(true); await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUser_InvalidStatus(OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Invited)]OrganizationUser orgUser, string key, + [OrganizationUser(OrganizationUserStatusType.Invited)] OrganizationUser orgUser, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -593,7 +593,7 @@ namespace Bit.Core.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUser_WrongOrganization(OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser, string key, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -622,10 +622,10 @@ namespace Bit.Core.Test.Services orgUser.OrganizationId = confirmingUser.OrganizationId = org.Id; orgUser.UserId = user.Id; orgUser.Type = userType; - organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {orgUser}); + organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { orgUser }); organizationUserRepository.GetCountByFreeOrganizationAdminUserAsync(orgUser.UserId.Value).Returns(1); organizationRepository.GetByIdAsync(org.Id).Returns(org); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {user}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { user }); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.ConfirmUserAsync(orgUser.OrganizationId, orgUser.Id, key, confirmingUser.Id, userService)); @@ -683,8 +683,8 @@ namespace Bit.Core.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUser_SingleOrgPolicy(Organization org, OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser, User user, - OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.SingleOrg)]Policy singleOrgPolicy, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, + OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.SingleOrg)] Policy singleOrgPolicy, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -697,21 +697,21 @@ namespace Bit.Core.Test.Services orgUser.Status = OrganizationUserStatusType.Accepted; orgUser.OrganizationId = confirmingUser.OrganizationId = org.Id; orgUser.UserId = orgUserAnotherOrg.UserId = user.Id; - organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {orgUser}); - organizationUserRepository.GetManyByManyUsersAsync(default).ReturnsForAnyArgs(new[] {orgUserAnotherOrg}); + organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { orgUser }); + organizationUserRepository.GetManyByManyUsersAsync(default).ReturnsForAnyArgs(new[] { orgUserAnotherOrg }); organizationRepository.GetByIdAsync(org.Id).Returns(org); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {user}); - policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] {singleOrgPolicy}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { user }); + policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] { singleOrgPolicy }); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.ConfirmUserAsync(orgUser.OrganizationId, orgUser.Id, key, confirmingUser.Id, userService)); Assert.Contains("User is a member of another organization.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUser_TwoFactorPolicy(Organization org, OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser, User user, - OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.TwoFactorAuthentication)]Policy twoFactorPolicy, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, + OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.TwoFactorAuthentication)] Policy twoFactorPolicy, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -723,22 +723,22 @@ namespace Bit.Core.Test.Services org.PlanType = PlanType.EnterpriseAnnually; orgUser.OrganizationId = confirmingUser.OrganizationId = org.Id; orgUser.UserId = orgUserAnotherOrg.UserId = user.Id; - organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {orgUser}); - organizationUserRepository.GetManyByManyUsersAsync(default).ReturnsForAnyArgs(new[] {orgUserAnotherOrg}); + organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { orgUser }); + organizationUserRepository.GetManyByManyUsersAsync(default).ReturnsForAnyArgs(new[] { orgUserAnotherOrg }); organizationRepository.GetByIdAsync(org.Id).Returns(org); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {user}); - policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] {twoFactorPolicy}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { user }); + policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] { twoFactorPolicy }); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.ConfirmUserAsync(orgUser.OrganizationId, orgUser.Id, key, confirmingUser.Id, userService)); Assert.Contains("User does not have two-step login enabled.", exception.Message); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUser_Success(Organization org, OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser, User user, - [Policy(PolicyType.TwoFactorAuthentication)]Policy twoFactorPolicy, - [Policy(PolicyType.SingleOrg)]Policy singleOrgPolicy, string key, SutProvider sutProvider) + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, + [Policy(PolicyType.TwoFactorAuthentication)] Policy twoFactorPolicy, + [Policy(PolicyType.SingleOrg)] Policy singleOrgPolicy, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); var organizationRepository = sutProvider.GetDependency(); @@ -749,24 +749,24 @@ namespace Bit.Core.Test.Services org.PlanType = PlanType.EnterpriseAnnually; orgUser.OrganizationId = confirmingUser.OrganizationId = org.Id; orgUser.UserId = user.Id; - organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {orgUser}); + organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { orgUser }); organizationRepository.GetByIdAsync(org.Id).Returns(org); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {user}); - policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] {twoFactorPolicy, singleOrgPolicy}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { user }); + policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] { twoFactorPolicy, singleOrgPolicy }); userService.TwoFactorIsEnabledAsync(user).Returns(true); await sutProvider.Sut.ConfirmUserAsync(orgUser.OrganizationId, orgUser.Id, key, confirmingUser.Id, userService); } - + [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task ConfirmUsers_Success(Organization org, OrganizationUser confirmingUser, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser1, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser2, - [OrganizationUser(OrganizationUserStatusType.Accepted)]OrganizationUser orgUser3, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser1, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser2, + [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser3, OrganizationUser anotherOrgUser, User user1, User user2, User user3, - [Policy(PolicyType.TwoFactorAuthentication)]Policy twoFactorPolicy, - [Policy(PolicyType.SingleOrg)]Policy singleOrgPolicy, string key, SutProvider sutProvider) + [Policy(PolicyType.TwoFactorAuthentication)] Policy twoFactorPolicy, + [Policy(PolicyType.SingleOrg)] Policy singleOrgPolicy, string key, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); var organizationRepository = sutProvider.GetDependency(); @@ -780,16 +780,16 @@ namespace Bit.Core.Test.Services orgUser2.UserId = user2.Id; orgUser3.UserId = user3.Id; anotherOrgUser.UserId = user3.Id; - var orgUsers = new[] {orgUser1, orgUser2, orgUser3}; + var orgUsers = new[] { orgUser1, orgUser2, orgUser3 }; organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(orgUsers); organizationRepository.GetByIdAsync(org.Id).Returns(org); - userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] {user1, user2, user3}); - policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] {twoFactorPolicy, singleOrgPolicy}); + userRepository.GetManyAsync(default).ReturnsForAnyArgs(new[] { user1, user2, user3 }); + policyRepository.GetManyByOrganizationIdAsync(org.Id).Returns(new[] { twoFactorPolicy, singleOrgPolicy }); userService.TwoFactorIsEnabledAsync(user1).Returns(true); userService.TwoFactorIsEnabledAsync(user2).Returns(false); userService.TwoFactorIsEnabledAsync(user3).Returns(true); organizationUserRepository.GetManyByManyUsersAsync(default) - .ReturnsForAnyArgs(new[] {orgUser1, orgUser2, orgUser3, anotherOrgUser}); + .ReturnsForAnyArgs(new[] { orgUser1, orgUser2, orgUser3, anotherOrgUser }); var keys = orgUsers.ToDictionary(ou => ou.Id, _ => key); var result = await sutProvider.Sut.ConfirmUsersAsync(confirmingUser.OrganizationId, keys, confirmingUser.Id, userService); diff --git a/test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs b/test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs index ebd1c05a0..cde45af20 100644 --- a/test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs +++ b/test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/test/Core.Test/Services/PolicyServiceTests.cs b/test/Core.Test/Services/PolicyServiceTests.cs index ac83d0ff7..c5932190b 100644 --- a/test/Core.Test/Services/PolicyServiceTests.cs +++ b/test/Core.Test/Services/PolicyServiceTests.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Models.Data; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; -using PolicyFixtures = Bit.Core.Test.AutoFixture.PolicyFixtures; +using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; using Xunit; -using Bit.Core.Enums; -using Bit.Test.Common.AutoFixture.Attributes; -using Bit.Test.Common.AutoFixture; +using PolicyFixtures = Bit.Core.Test.AutoFixture.PolicyFixtures; namespace Bit.Core.Test.Services { @@ -44,7 +44,7 @@ namespace Bit.Core.Test.Services { var orgId = Guid.NewGuid(); - SetupOrg(sutProvider, policy.OrganizationId, new Organization + SetupOrg(sutProvider, policy.OrganizationId, new Organization { UsePolicies = false, }); @@ -270,7 +270,7 @@ namespace Bit.Core.Test.Services sutProvider.GetDependency() .GetByIdAsync(policy.Id) .Returns(new Core.Models.Table.Policy - { + { Id = policy.Id, Type = PolicyType.TwoFactorAuthentication, Enabled = false, diff --git a/test/Core.Test/Services/RelayPushNotificationServiceTests.cs b/test/Core.Test/Services/RelayPushNotificationServiceTests.cs index e53508d47..1dffd5cd1 100644 --- a/test/Core.Test/Services/RelayPushNotificationServiceTests.cs +++ b/test/Core.Test/Services/RelayPushNotificationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; diff --git a/test/Core.Test/Services/RelayPushRegistrationServiceTests.cs b/test/Core.Test/Services/RelayPushRegistrationServiceTests.cs index 3d6fd03b7..dfe69fc66 100644 --- a/test/Core.Test/Services/RelayPushRegistrationServiceTests.cs +++ b/test/Core.Test/Services/RelayPushRegistrationServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.Extensions.Logging; diff --git a/test/Core.Test/Services/RepositoryEventWriteServiceTests.cs b/test/Core.Test/Services/RepositoryEventWriteServiceTests.cs index 6b02a2ceb..c82e02569 100644 --- a/test/Core.Test/Services/RepositoryEventWriteServiceTests.cs +++ b/test/Core.Test/Services/RepositoryEventWriteServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Bit.Core.Repositories; using Bit.Core.Services; using NSubstitute; diff --git a/test/Core.Test/Services/SendServiceTests.cs b/test/Core.Test/Services/SendServiceTests.cs index 7c08f6d00..974e0e674 100644 --- a/test/Core.Test/Services/SendServiceTests.cs +++ b/test/Core.Test/Services/SendServiceTests.cs @@ -1,5 +1,8 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Text.Json; using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Models.Data; @@ -7,13 +10,10 @@ using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Test.AutoFixture.SendFixtures; +using Bit.Test.Common.AutoFixture; using Microsoft.AspNetCore.Identity; using NSubstitute; using Xunit; -using System.Text.Json; -using Bit.Test.Common.AutoFixture; -using System.IO; -using System.Text; namespace Bit.Core.Test.Services { @@ -509,7 +509,7 @@ namespace Bit.Core.Test.Services var utcNow = DateTime.UtcNow; - var exception = await Assert.ThrowsAsync(() => + var exception = await Assert.ThrowsAsync(() => sutProvider.Sut.SaveFileSendAsync(send, data, 1 * Models.Tables.UserTests.Multiplier) ); @@ -530,7 +530,7 @@ namespace Bit.Core.Test.Services await sutProvider.GetDependency() .Received(1) - .DeleteFileAsync(send, Arg.Any()); + .DeleteFileAsync(send, Arg.Any()); } [Theory] @@ -573,7 +573,7 @@ namespace Bit.Core.Test.Services [Theory] [InlineUserSendAutoData] - public async void UpdateFileToExistingSendAsync_Success(SutProvider sutProvider, + public async void UpdateFileToExistingSendAsync_Success(SutProvider sutProvider, Send send) { var fileContents = "Test file content"; @@ -635,7 +635,7 @@ namespace Bit.Core.Test.Services .VerifyHashedPassword(Arg.Any(), send.Password, "TEST") .Returns(PasswordVerificationResult.Success); - var (grant, passwordRequiredError, passwordInvalidError) + var (grant, passwordRequiredError, passwordInvalidError) = sutProvider.Sut.SendCanBeAccessed(send, "TEST"); Assert.True(grant); @@ -710,7 +710,7 @@ namespace Bit.Core.Test.Services [Theory] [InlineUserSendAutoData] - public void SendCanBeAccessed_RehashNeeded_RehashesPassword(SutProvider sutProvider, + public void SendCanBeAccessed_RehashNeeded_RehashesPassword(SutProvider sutProvider, Send send) { var now = DateTime.UtcNow; @@ -739,7 +739,7 @@ namespace Bit.Core.Test.Services [Theory] [InlineUserSendAutoData] - public void SendCanBeAccessed_VerifyFailed_PasswordInvalidReturnsTrue(SutProvider sutProvider, + public void SendCanBeAccessed_VerifyFailed_PasswordInvalidReturnsTrue(SutProvider sutProvider, Send send) { var now = DateTime.UtcNow; diff --git a/test/Core.Test/Services/SsoConfigServiceTests.cs b/test/Core.Test/Services/SsoConfigServiceTests.cs index 77eeb5675..310859e60 100644 --- a/test/Core.Test/Services/SsoConfigServiceTests.cs +++ b/test/Core.Test/Services/SsoConfigServiceTests.cs @@ -270,9 +270,9 @@ namespace Bit.Core.Test.Services sutProvider.GetDependency().GetByOrganizationIdTypeAsync( Arg.Any(), Arg.Any()).Returns(new Policy - { - Enabled = true, - }); + { + Enabled = true, + }); var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.SaveAsync(ssoConfig, organization)); @@ -305,9 +305,9 @@ namespace Bit.Core.Test.Services sutProvider.GetDependency().GetByOrganizationIdTypeAsync( Arg.Any(), Arg.Any()).Returns(new Policy - { - Enabled = true, - }); + { + Enabled = true, + }); await sutProvider.Sut.SaveAsync(ssoConfig, organization); diff --git a/test/Core.Test/Services/UserServiceTests.cs b/test/Core.Test/Services/UserServiceTests.cs index 0f375ec78..18cc63f1d 100644 --- a/test/Core.Test/Services/UserServiceTests.cs +++ b/test/Core.Test/Services/UserServiceTests.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; +using Bit.Core.Context; using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Settings; +using Fido2NetLib; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using NSubstitute; using Xunit; -using Fido2NetLib; -using Bit.Core.Context; namespace Bit.Core.Test.Services { diff --git a/test/Core.Test/TempDirectory.cs b/test/Core.Test/TempDirectory.cs index c87c9863a..61ae6f8d1 100644 --- a/test/Core.Test/TempDirectory.cs +++ b/test/Core.Test/TempDirectory.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Bit.Core.Test diff --git a/test/Core.Test/Utilities/CoreHelpersTests.cs b/test/Core.Test/Utilities/CoreHelpersTests.cs index 2d0a13d46..36e0515b1 100644 --- a/test/Core.Test/Utilities/CoreHelpersTests.cs +++ b/test/Core.Test/Utilities/CoreHelpersTests.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; -using Bit.Core.Utilities; -using Xunit; -using Bit.Core.Test.AutoFixture.UserFixtures; -using IdentityModel; +using AutoFixture; +using Bit.Core.Context; +using Bit.Core.Enums; using Bit.Core.Enums.Provider; using Bit.Core.Models.Table; -using Bit.Core.Context; -using AutoFixture; -using Bit.Core.Enums; -using Bit.Test.Common.AutoFixture.Attributes; +using Bit.Core.Test.AutoFixture.UserFixtures; +using Bit.Core.Utilities; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; +using IdentityModel; +using Xunit; namespace Bit.Core.Test.Utilities { @@ -35,7 +35,7 @@ namespace Bit.Core.Test.Utilities } [Theory] - [InlineData(2, 5, new[] { 1, 2, 3, 4, 5, 6, 7, 8 , 9, 0 })] + [InlineData(2, 5, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })] [InlineData(2, 3, new[] { 1, 2, 3, 4, 5 })] [InlineData(2, 1, new[] { 1, 2 })] [InlineData(1, 1, new[] { 1 })] diff --git a/test/Core.Test/Utilities/EncryptedStringAttributeTests.cs b/test/Core.Test/Utilities/EncryptedStringAttributeTests.cs index f2c8ce816..09ee18847 100644 --- a/test/Core.Test/Utilities/EncryptedStringAttributeTests.cs +++ b/test/Core.Test/Utilities/EncryptedStringAttributeTests.cs @@ -1,4 +1,4 @@ -using Bit.Core.Utilities; +using Bit.Core.Utilities; using Xunit; namespace Bit.Core.Test.Utilities @@ -15,10 +15,10 @@ namespace Bit.Core.Test.Utilities var sut = new EncryptedStringAttribute(); var actual = sut.IsValid(input); - + Assert.True(actual); } - + [Theory] [InlineData("")] [InlineData(".")] @@ -36,7 +36,7 @@ namespace Bit.Core.Test.Utilities var sut = new EncryptedStringAttribute(); var actual = sut.IsValid(input); - + Assert.False(actual); } } diff --git a/test/Core.Test/Utilities/SelfHostedAttributeTests.cs b/test/Core.Test/Utilities/SelfHostedAttributeTests.cs index 13937451a..c64794b82 100644 --- a/test/Core.Test/Utilities/SelfHostedAttributeTests.cs +++ b/test/Core.Test/Utilities/SelfHostedAttributeTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Bit.Core.Exceptions; using Bit.Core.Settings; using Bit.Core.Utilities; @@ -82,12 +82,12 @@ namespace Bit.Core.Test.Utilities var context = Substitute.For( Substitute.For(httpContext, new RouteData(), - Substitute.For()), - new List(), - new Dictionary(), + Substitute.For()), + new List(), + new Dictionary(), Substitute.For()); return context; } } -} \ No newline at end of file +} diff --git a/test/Core.Test/Utilities/StrictEmailAddressAttributeTests.cs b/test/Core.Test/Utilities/StrictEmailAddressAttributeTests.cs index be7648f6f..8a2909730 100644 --- a/test/Core.Test/Utilities/StrictEmailAddressAttributeTests.cs +++ b/test/Core.Test/Utilities/StrictEmailAddressAttributeTests.cs @@ -17,10 +17,10 @@ namespace Bit.Core.Test.Utilities var sut = new StrictEmailAddressAttribute(); var actual = sut.IsValid(email); - + Assert.True(actual); } - + [Theory] [InlineData(null)] // null [InlineData("hello@world.com\t")] // trailing tab char @@ -51,7 +51,7 @@ namespace Bit.Core.Test.Utilities var sut = new StrictEmailAddressAttribute(); var actual = sut.IsValid(email); - + Assert.False(actual); } } diff --git a/test/Icons.Test/Services/IconFetchingServiceTests.cs b/test/Icons.Test/Services/IconFetchingServiceTests.cs index c1a6b702e..303494e45 100644 --- a/test/Icons.Test/Services/IconFetchingServiceTests.cs +++ b/test/Icons.Test/Services/IconFetchingServiceTests.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using Bit.Icons.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/util/MySqlMigrations/Factories.cs b/util/MySqlMigrations/Factories.cs index 2077c9fb0..935299777 100644 --- a/util/MySqlMigrations/Factories.cs +++ b/util/MySqlMigrations/Factories.cs @@ -1,11 +1,11 @@ +using System; using System.Collections.Generic; +using Bit.Core.Enums; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Settings; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Bit.Core.Enums; using Microsoft.EntityFrameworkCore.Design; -using System; +using Microsoft.Extensions.Configuration; namespace MySqlMigrations { @@ -20,7 +20,7 @@ namespace MySqlMigrations } } - public class DatabaseContextFactory : IDesignTimeDbContextFactory + public class DatabaseContextFactory : IDesignTimeDbContextFactory { public DatabaseContext CreateDbContext(string[] args) { @@ -32,7 +32,7 @@ namespace MySqlMigrations throw new Exception("No MySql connection string found."); } optionsBuilder.UseMySql( - connectionString, + connectionString, ServerVersion.AutoDetect(connectionString), b => b.MigrationsAssembly("MySqlMigrations")); return new DatabaseContext(optionsBuilder.Options); diff --git a/util/PostgresMigrations/Factories.cs b/util/PostgresMigrations/Factories.cs index 39e2fbe22..5c0cd79d0 100644 --- a/util/PostgresMigrations/Factories.cs +++ b/util/PostgresMigrations/Factories.cs @@ -1,11 +1,11 @@ +using System; using System.Collections.Generic; +using Bit.Core.Enums; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Settings; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Bit.Core.Enums; using Microsoft.EntityFrameworkCore.Design; -using System; +using Microsoft.Extensions.Configuration; namespace MySqlMigrations { @@ -20,19 +20,19 @@ namespace MySqlMigrations } } - public class DatabaseContextFactory : IDesignTimeDbContextFactory + public class DatabaseContextFactory : IDesignTimeDbContextFactory { public DatabaseContext CreateDbContext(string[] args) { var globalSettings = GlobalSettingsFactory.GlobalSettings; var optionsBuilder = new DbContextOptionsBuilder(); var connectionString = globalSettings.PostgreSql?.ConnectionString; - if (string.IsNullOrWhiteSpace(connectionString)) + if (string.IsNullOrWhiteSpace(connectionString)) { throw new Exception("No Postgres connection string found."); } optionsBuilder.UseNpgsql( - connectionString, + connectionString, b => b.MigrationsAssembly("PostgresMigrations")); return new DatabaseContext(optionsBuilder.Options); } diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index fa8a4e2f9..470da9845 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -1,10 +1,10 @@ -using Bit.Migrator; -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Globalization; using System.Net.Http; +using Bit.Migrator; +using Newtonsoft.Json; namespace Bit.Setup { @@ -137,7 +137,7 @@ namespace Bit.Setup // a new cert and bag to replace the old Identity.pfx. This fixes an issue that came up as a result of // moving the project to .NET 5. _context.Install.IdentityCertPassword = Helpers.GetValueFromEnvFile("global", "globalSettings__identityServer__certificatePassword"); - var certCountString = Helpers.Exec("openssl pkcs12 -nokeys -info -in /bitwarden/identity/identity.pfx " + + var certCountString = Helpers.Exec("openssl pkcs12 -nokeys -info -in /bitwarden/identity/identity.pfx " + $"-passin pass:{_context.Install.IdentityCertPassword} 2> /dev/null | grep -c \"\\-----BEGIN CERTIFICATE----\"", true); if (int.TryParse(certCountString, out var certCount) && certCount > 1) { @@ -291,7 +291,7 @@ namespace Bit.Setup var environmentFileBuilder = new EnvironmentFileBuilder(_context); environmentFileBuilder.BuildForUpdater(); - + var certBuilder = new CertBuilder(_context); certBuilder.BuildForUpdater();