1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-26 12:55:17 +01:00

Run dotnet format (#1764)

This commit is contained in:
Oscar Hinton 2021-12-16 15:35:09 +01:00 committed by GitHub
parent 61dc65aa59
commit 23b0a1f9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
531 changed files with 3024 additions and 3000 deletions

1
.gitattributes vendored
View File

@ -1,3 +1,4 @@
*.sh eol=lf *.sh eol=lf
*.cs eol=lf
.dockerignore eol=lf .dockerignore eol=lf
dockerfile eol=lf dockerfile eol=lf

View File

@ -72,9 +72,9 @@ jobs:
run: dotnet tool restore run: dotnet tool restore
shell: pwsh shell: pwsh
# - name: Verify Format - name: Verify Format
# run: dotnet tool run dotnet-format --check run: dotnet tool run dotnet-format --check
# shell: pwsh shell: pwsh
- name: Test OSS solution - name: Test OSS solution
run: dotnet test ./test --configuration Debug --no-build run: dotnet test ./test --configuration Debug --no-build

View File

@ -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.Enums;
using Bit.Core.Models;
using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.Sso.Models; using Bit.Sso.Models;
using Bit.Sso.Utilities; using Bit.Sso.Utilities;
using IdentityModel; using IdentityModel;
@ -11,20 +21,10 @@ using IdentityServer4.Extensions;
using IdentityServer4.Services; using IdentityServer4.Services;
using IdentityServer4.Stores; using IdentityServer4.Stores;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using Microsoft.Extensions.Logging;
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;
namespace Bit.Sso.Controllers namespace Bit.Sso.Controllers
{ {
@ -83,7 +83,7 @@ namespace Bit.Sso.Controllers
_eventService = eventService; _eventService = eventService;
_globalSettings = globalSettings; _globalSettings = globalSettings;
} }
[HttpGet] [HttpGet]
public async Task<IActionResult> PreValidate(string domainHint) public async Task<IActionResult> PreValidate(string domainHint)
{ {
@ -382,7 +382,7 @@ namespace Bit.Sso.Controllers
{ {
email = providerUserId; email = providerUserId;
} }
if (!Guid.TryParse(provider, out var orgId)) if (!Guid.TryParse(provider, out var orgId))
{ {
// TODO: support non-org (server-wide) SSO in the future? // 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)); throw new Exception(_i18nService.T("CouldNotFindOrganization", orgId));
} }
// Try to find OrgUser via existing User Id (accepted/confirmed user) // Try to find OrgUser via existing User Id (accepted/confirmed user)
if (existingUser != null) 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 // If no Org User found by Existing User Id - search all organization users via email
orgUser ??= await _organizationUserRepository.GetByOrganizationEmailAsync(orgId, email); orgUser ??= await _organizationUserRepository.GetByOrganizationEmailAsync(orgId, email);
// All Existing User flows handled below // All Existing User flows handled below
if (existingUser != null) if (existingUser != null)
{ {
@ -457,11 +457,11 @@ namespace Bit.Sso.Controllers
// Org User is not created - no invite has been sent // Org User is not created - no invite has been sent
throw new Exception(_i18nService.T("UserAlreadyExistsInviteProcess")); throw new Exception(_i18nService.T("UserAlreadyExistsInviteProcess"));
} }
if (orgUser.Status == OrganizationUserStatusType.Invited) if (orgUser.Status == OrganizationUserStatusType.Invited)
{ {
// Org User is invited - they must manually accept the invite via email and authenticate with MP // 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; // Accepted or Confirmed - create SSO link and return;
@ -507,7 +507,7 @@ namespace Bit.Sso.Controllers
ApiKey = CoreHelpers.SecureRandomString(30) ApiKey = CoreHelpers.SecureRandomString(30)
}; };
await _userService.RegisterUserAsync(user); await _userService.RegisterUserAsync(user);
// If the organization has 2fa policy enabled, make sure to default jit user 2fa to email // If the organization has 2fa policy enabled, make sure to default jit user 2fa to email
var twoFactorPolicy = var twoFactorPolicy =
await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.TwoFactorAuthentication); await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.TwoFactorAuthentication);
@ -516,14 +516,14 @@ namespace Bit.Sso.Controllers
user.SetTwoFactorProviders(new Dictionary<TwoFactorProviderType, TwoFactorProvider> user.SetTwoFactorProviders(new Dictionary<TwoFactorProviderType, TwoFactorProvider>
{ {
[TwoFactorProviderType.Email] = new TwoFactorProvider [TwoFactorProviderType.Email] = new TwoFactorProvider
{ {
MetaData = new Dictionary<string, object> { ["Email"] = user.Email.ToLowerInvariant() }, MetaData = new Dictionary<string, object> { ["Email"] = user.Email.ToLowerInvariant() },
Enabled = true Enabled = true
} }
}); });
await _userService.UpdateTwoFactorProviderAsync(user, TwoFactorProviderType.Email); await _userService.UpdateTwoFactorProviderAsync(user, TwoFactorProviderType.Email);
} }
// Create Org User if null or else update existing Org User // Create Org User if null or else update existing Org User
if (orgUser == null) if (orgUser == null)
{ {
@ -541,10 +541,10 @@ namespace Bit.Sso.Controllers
orgUser.UserId = user.Id; orgUser.UserId = user.Id;
await _organizationUserRepository.ReplaceAsync(orgUser); await _organizationUserRepository.ReplaceAsync(orgUser);
} }
// Create sso user record // Create sso user record
await CreateSsoUserRecord(providerUserId, user.Id, orgId, orgUser); await CreateSsoUserRecord(providerUserId, user.Id, orgId, orgUser);
return user; return user;
} }

View File

@ -1,11 +1,11 @@
using System; using System;
using Microsoft.AspNetCore.Mvc; using System.Diagnostics;
using Microsoft.AspNetCore.Authorization;
using IdentityServer4.Services;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Sso.Models; using Bit.Sso.Models;
using System.Diagnostics; using IdentityServer4.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Sso.Controllers namespace Bit.Sso.Controllers
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Sso.Controllers namespace Bit.Sso.Controllers
{ {
@ -12,7 +12,7 @@ namespace Bit.Sso.Controllers
{ {
return DateTime.UtcNow; return DateTime.UtcNow;
} }
[HttpGet("~/version")] [HttpGet("~/version")]
public JsonResult GetVersion() public JsonResult GetVersion()
{ {

View File

@ -9,8 +9,8 @@ using Bit.Core.Enums;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Utilities;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.Sso.Models; using Bit.Sso.Models;
using Bit.Sso.Utilities; using Bit.Sso.Utilities;
using IdentityModel; using IdentityModel;
@ -136,7 +136,7 @@ namespace Bit.Core.Business.Sso
await LoadAllDynamicSchemesIntoCacheAsync(); await LoadAllDynamicSchemesIntoCacheAsync();
schemes.AddRange(_handlerSchemesCopy); schemes.AddRange(_handlerSchemesCopy);
return schemes.ToArray(); return schemes.ToArray();
} }

View File

@ -1,6 +1,6 @@
using Microsoft.Extensions.Options; using System;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Microsoft.Extensions.Options;
namespace Bit.Sso.Utilities namespace Bit.Sso.Utilities
{ {
@ -35,4 +35,4 @@ namespace Bit.Sso.Utilities
return _cache.TryRemove(name ?? Options.DefaultName, out _); return _cache.TryRemove(name ?? Options.DefaultName, out _);
} }
} }
} }

View File

@ -6,4 +6,4 @@ namespace Bit.Sso.Utilities
{ {
void AddOrUpdate(string name, TOptions options); void AddOrUpdate(string name, TOptions options);
} }
} }

View File

@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using Bit.Core.Business.Sso; using Bit.Core.Business.Sso;
using Bit.Core.IdentityServer; using Bit.Core.IdentityServer;
using Bit.Core.Utilities;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.Sso.Models; using Bit.Sso.Models;
using IdentityServer4.Models; using IdentityServer4.Models;
using IdentityServer4.ResponseHandling; using IdentityServer4.ResponseHandling;

View File

@ -12,7 +12,7 @@ namespace Bit.Sso.Utilities
public class SsoAuthenticationMiddleware public class SsoAuthenticationMiddleware
{ {
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
public SsoAuthenticationMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes) public SsoAuthenticationMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes)
{ {
_next = next ?? throw new ArgumentNullException(nameof(next)); _next = next ?? throw new ArgumentNullException(nameof(next));

View File

@ -15,7 +15,7 @@ namespace Bit.CommCore.Test.AutoFixture.ProviderUserFixtures
Status = status; Status = status;
Type = type; Type = type;
} }
public void Customize(IFixture fixture) public void Customize(IFixture fixture)
{ {
fixture.Customize<Core.Models.Table.Provider.ProviderUser>(composer => composer fixture.Customize<Core.Models.Table.Provider.ProviderUser>(composer => composer

View File

@ -2,8 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.CommCore.Test.AutoFixture.ProviderUserFixtures;
using Bit.CommCore.Services; using Bit.CommCore.Services;
using Bit.CommCore.Test.AutoFixture.ProviderUserFixtures;
using Bit.Core.Context;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Enums.Provider; using Bit.Core.Enums.Provider;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
@ -14,14 +15,13 @@ using Bit.Core.Models.Table.Provider;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using NSubstitute; using NSubstitute;
using NSubstitute.ReturnsExtensions; using NSubstitute.ReturnsExtensions;
using Xunit; using Xunit;
using ProviderUser = Bit.Core.Models.Table.Provider.ProviderUser; 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 namespace Bit.CommCore.Test.Services
{ {
@ -34,19 +34,19 @@ namespace Bit.CommCore.Test.Services
() => sutProvider.Sut.CreateAsync(default)); () => sutProvider.Sut.CreateAsync(default));
Assert.Contains("Invalid owner.", exception.Message); Assert.Contains("Invalid owner.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task CreateAsync_Success(User user, SutProvider<ProviderService> sutProvider) public async Task CreateAsync_Success(User user, SutProvider<ProviderService> sutProvider)
{ {
var userRepository = sutProvider.GetDependency<IUserRepository>(); var userRepository = sutProvider.GetDependency<IUserRepository>();
userRepository.GetByEmailAsync(user.Email).Returns(user); userRepository.GetByEmailAsync(user.Email).Returns(user);
await sutProvider.Sut.CreateAsync(user.Email); await sutProvider.Sut.CreateAsync(user.Email);
await sutProvider.GetDependency<IProviderRepository>().ReceivedWithAnyArgs().CreateAsync(default); await sutProvider.GetDependency<IProviderRepository>().ReceivedWithAnyArgs().CreateAsync(default);
await sutProvider.GetDependency<IMailService>().ReceivedWithAnyArgs().SendProviderSetupInviteEmailAsync(default, default, default); await sutProvider.GetDependency<IMailService>().ReceivedWithAnyArgs().SendProviderSetupInviteEmailAsync(default, default, default);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task CompleteSetupAsync_UserIdIsInvalid_Throws(SutProvider<ProviderService> sutProvider) public async Task CompleteSetupAsync_UserIdIsInvalid_Throws(SutProvider<ProviderService> sutProvider)
{ {
@ -54,13 +54,13 @@ namespace Bit.CommCore.Test.Services
() => sutProvider.Sut.CompleteSetupAsync(default, default, default, default)); () => sutProvider.Sut.CompleteSetupAsync(default, default, default, default));
Assert.Contains("Invalid owner.", exception.Message); Assert.Contains("Invalid owner.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task CompleteSetupAsync_TokenIsInvalid_Throws(User user, Provider provider, public async Task CompleteSetupAsync_TokenIsInvalid_Throws(User user, Provider provider,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var userService = sutProvider.GetDependency<IUserService>(); var userService = sutProvider.GetDependency<IUserService>();
userService.GetUserByIdAsync(user.Id).Returns(user); userService.GetUserByIdAsync(user.Id).Returns(user);
var exception = await Assert.ThrowsAsync<BadRequestException>( var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.CompleteSetupAsync(provider, user.Id, default, default)); () => sutProvider.Sut.CompleteSetupAsync(provider, user.Id, default, default));
@ -69,7 +69,7 @@ namespace Bit.CommCore.Test.Services
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task CompleteSetupAsync_Success(User user, Provider provider, string key, 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<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
providerUser.ProviderId = provider.Id; providerUser.ProviderId = provider.Id;
@ -85,7 +85,7 @@ namespace Bit.CommCore.Test.Services
sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector") sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector")
.Returns(protector); .Returns(protector);
sutProvider.Create(); sutProvider.Create();
var token = protector.Protect($"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}"); var token = protector.Protect($"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}");
await sutProvider.Sut.CompleteSetupAsync(provider, user.Id, token, key); await sutProvider.Sut.CompleteSetupAsync(provider, user.Id, token, key);
@ -94,23 +94,23 @@ namespace Bit.CommCore.Test.Services
await sutProvider.GetDependency<IProviderUserRepository>().Received() await sutProvider.GetDependency<IProviderUserRepository>().Received()
.ReplaceAsync(Arg.Is<ProviderUser>(pu => pu.UserId == user.Id && pu.ProviderId == provider.Id && pu.Key == key)); .ReplaceAsync(Arg.Is<ProviderUser>(pu => pu.UserId == user.Id && pu.ProviderId == provider.Id && pu.Key == key));
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task UpdateAsync_ProviderIdIsInvalid_Throws(Provider provider, SutProvider<ProviderService> sutProvider) public async Task UpdateAsync_ProviderIdIsInvalid_Throws(Provider provider, SutProvider<ProviderService> sutProvider)
{ {
provider.Id = default; provider.Id = default;
var exception = await Assert.ThrowsAsync<ArgumentException>( var exception = await Assert.ThrowsAsync<ArgumentException>(
() => sutProvider.Sut.UpdateAsync(provider)); () => sutProvider.Sut.UpdateAsync(provider));
Assert.Contains("Cannot create provider this way.", exception.Message); Assert.Contains("Cannot create provider this way.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task UpdateAsync_Success(Provider provider, SutProvider<ProviderService> sutProvider) public async Task UpdateAsync_Success(Provider provider, SutProvider<ProviderService> sutProvider)
{ {
await sutProvider.Sut.UpdateAsync(provider); await sutProvider.Sut.UpdateAsync(provider);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task InviteUserAsync_ProviderIdIsInvalid_Throws(ProviderUserInvite<string> invite, SutProvider<ProviderService> sutProvider) public async Task InviteUserAsync_ProviderIdIsInvalid_Throws(ProviderUserInvite<string> invite, SutProvider<ProviderService> sutProvider)
{ {
@ -125,7 +125,7 @@ namespace Bit.CommCore.Test.Services
sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(invite.ProviderId).Returns(false); sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(invite.ProviderId).Returns(false);
await Assert.ThrowsAsync<InvalidOperationException>(() => sutProvider.Sut.InviteUserAsync(invite)); await Assert.ThrowsAsync<InvalidOperationException>(() => sutProvider.Sut.InviteUserAsync(invite));
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task InviteUserAsync_EmailsInvalid_Throws(Provider provider, ProviderUserInvite<string> providerUserInvite, public async Task InviteUserAsync_EmailsInvalid_Throws(Provider provider, ProviderUserInvite<string> providerUserInvite,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
@ -135,10 +135,10 @@ namespace Bit.CommCore.Test.Services
sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true); sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true);
providerUserInvite.UserIdentifiers = null; providerUserInvite.UserIdentifiers = null;
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.InviteUserAsync(providerUserInvite)); await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.InviteUserAsync(providerUserInvite));
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task InviteUserAsync_AlreadyInvited(Provider provider, ProviderUserInvite<string> providerUserInvite, public async Task InviteUserAsync_AlreadyInvited(Provider provider, ProviderUserInvite<string> providerUserInvite,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
@ -152,7 +152,7 @@ namespace Bit.CommCore.Test.Services
var result = await sutProvider.Sut.InviteUserAsync(providerUserInvite); var result = await sutProvider.Sut.InviteUserAsync(providerUserInvite);
Assert.Empty(result); Assert.Empty(result);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task InviteUserAsync_Success(Provider provider, ProviderUserInvite<string> providerUserInvite, public async Task InviteUserAsync_Success(Provider provider, ProviderUserInvite<string> providerUserInvite,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> 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.Status == ProviderUserStatusType.Invited), "Status must be invited");
Assert.True(result.TrueForAll(pu => pu.ProviderId == providerUserInvite.ProviderId), "Provider Id must be correct"); Assert.True(result.TrueForAll(pu => pu.ProviderId == providerUserInvite.ProviderId), "Provider Id must be correct");
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task ResendInviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite<Guid> invite, SutProvider<ProviderService> sutProvider) public async Task ResendInviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite<Guid> invite, SutProvider<ProviderService> sutProvider)
{ {
sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(invite.ProviderId).Returns(false); sutProvider.GetDependency<ICurrentContext>().ProviderManageUsers(invite.ProviderId).Returns(false);
await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ResendInvitesAsync(invite)); await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ResendInvitesAsync(invite));
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task ResendInvitesAsync_Errors(Provider provider, public async Task ResendInvitesAsync_Errors(Provider provider,
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1,
[ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2,
[ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3,
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu4, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu4,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUsers = new[] {pu1, pu2, pu3, pu4}; var providerUsers = new[] { pu1, pu2, pu3, pu4 };
pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id; pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id;
var invite = new ProviderUserInvite<Guid> var invite = new ProviderUserInvite<Guid>
@ -205,7 +205,7 @@ namespace Bit.CommCore.Test.Services
Assert.Equal("User invalid.", result[2].Item2); Assert.Equal("User invalid.", result[2].Item2);
Assert.Equal("User invalid.", result[3].Item2); Assert.Equal("User invalid.", result[3].Item2);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task ResendInvitesAsync_Success(Provider provider, IEnumerable<ProviderUser> providerUsers, public async Task ResendInvitesAsync_Success(Provider provider, IEnumerable<ProviderUser> providerUsers,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
@ -240,62 +240,62 @@ namespace Bit.CommCore.Test.Services
() => sutProvider.Sut.AcceptUserAsync(default, default, default)); () => sutProvider.Sut.AcceptUserAsync(default, default, default));
Assert.Equal("User invalid.", exception.Message); Assert.Equal("User invalid.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task AcceptUserAsync_AlreadyAccepted_Throws( public async Task AcceptUserAsync_AlreadyAccepted_Throws(
[ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser providerUser, User user, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser providerUser, User user,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser);
var exception = await Assert.ThrowsAsync<BadRequestException>( var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default)); () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default));
Assert.Equal("Already accepted.", exception.Message); Assert.Equal("Already accepted.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task AcceptUserAsync_TokenIsInvalid_Throws( public async Task AcceptUserAsync_TokenIsInvalid_Throws(
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser);
var exception = await Assert.ThrowsAsync<BadRequestException>( var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default)); () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, default));
Assert.Equal("Invalid token.", exception.Message); Assert.Equal("Invalid token.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task AcceptUserAsync_WrongEmail_Throws( public async Task AcceptUserAsync_WrongEmail_Throws(
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser);
var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName"); var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName");
var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector"); var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector");
sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector") sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector")
.Returns(protector); .Returns(protector);
sutProvider.Create(); sutProvider.Create();
var token = protector.Protect($"ProviderUserInvite {providerUser.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}"); var token = protector.Protect($"ProviderUserInvite {providerUser.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}");
var exception = await Assert.ThrowsAsync<BadRequestException>( var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, token)); () => sutProvider.Sut.AcceptUserAsync(providerUser.Id, user, token));
Assert.Equal("User email does not match invite.", exception.Message); Assert.Equal("User email does not match invite.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task AcceptUserAsync_Success( public async Task AcceptUserAsync_Success(
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser providerUser, User user, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser); providerUserRepository.GetByIdAsync(providerUser.Id).Returns(providerUser);
var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName"); var dataProtectionProvider = DataProtectionProvider.Create("ApplicationName");
var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector"); var protector = dataProtectionProvider.CreateProtector("ProviderServiceDataProtector");
sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector") sutProvider.GetDependency<IDataProtectionProvider>().CreateProtector("ProviderServiceDataProtector")
@ -310,53 +310,53 @@ namespace Bit.CommCore.Test.Services
Assert.Equal(ProviderUserStatusType.Accepted, pu.Status); Assert.Equal(ProviderUserStatusType.Accepted, pu.Status);
Assert.Equal(user.Id, pu.UserId); Assert.Equal(user.Id, pu.UserId);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task ConfirmUsersAsync_NoValid( public async Task ConfirmUsersAsync_NoValid(
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1,
[ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2,
[ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
pu1.ProviderId = pu3.ProviderId; pu1.ProviderId = pu3.ProviderId;
var providerUsers = new[] {pu1, pu2, pu3}; var providerUsers = new[] { pu1, pu2, pu3 };
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers);
var dict = providerUsers.ToDictionary(pu => pu.Id, _ => "key"); var dict = providerUsers.ToDictionary(pu => pu.Id, _ => "key");
var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, default); var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, default);
Assert.Empty(result); Assert.Empty(result);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task ConfirmUsersAsync_Success( public async Task ConfirmUsersAsync_Success(
[ProviderUser(ProviderUserStatusType.Invited)]ProviderUser pu1, User u1, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, User u1,
[ProviderUser(ProviderUserStatusType.Accepted)]ProviderUser pu2, User u2, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, User u2,
[ProviderUser(ProviderUserStatusType.Confirmed)]ProviderUser pu3, User u3, [ProviderUser(ProviderUserStatusType.Confirmed)] ProviderUser pu3, User u3,
Provider provider, User user, SutProvider<ProviderService> sutProvider) Provider provider, User user, SutProvider<ProviderService> sutProvider)
{ {
pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id; pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id;
pu1.UserId = u1.Id; pu1.UserId = u1.Id;
pu2.UserId = u2.Id; pu2.UserId = u2.Id;
pu3.UserId = u3.Id; pu3.UserId = u3.Id;
var providerUsers = new[] {pu1, pu2, pu3}; var providerUsers = new[] { pu1, pu2, pu3 };
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers);
var providerRepository = sutProvider.GetDependency<IProviderRepository>(); var providerRepository = sutProvider.GetDependency<IProviderRepository>();
providerRepository.GetByIdAsync(provider.Id).Returns(provider); providerRepository.GetByIdAsync(provider.Id).Returns(provider);
var userRepository = sutProvider.GetDependency<IUserRepository>(); var userRepository = sutProvider.GetDependency<IUserRepository>();
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 dict = providerUsers.ToDictionary(pu => pu.Id, _ => "key");
var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, user.Id); var result = await sutProvider.Sut.ConfirmUsersAsync(pu1.ProviderId, dict, user.Id);
Assert.Equal("Invalid user.", result[0].Item2); Assert.Equal("Invalid user.", result[0].Item2);
Assert.Equal("", result[1].Item2); Assert.Equal("", result[1].Item2);
Assert.Equal("Invalid user.", result[2].Item2); Assert.Equal("Invalid user.", result[2].Item2);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task SaveUserAsync_UserIdIsInvalid_Throws(ProviderUser providerUser, public async Task SaveUserAsync_UserIdIsInvalid_Throws(ProviderUser providerUser,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
@ -369,7 +369,7 @@ namespace Bit.CommCore.Test.Services
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task SaveUserAsync_Success( public async Task SaveUserAsync_Success(
[ProviderUser(type: ProviderUserType.ProviderAdmin)]ProviderUser providerUser, User savingUser, [ProviderUser(type: ProviderUserType.ProviderAdmin)] ProviderUser providerUser, User savingUser,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
@ -380,7 +380,7 @@ namespace Bit.CommCore.Test.Services
await sutProvider.GetDependency<IEventService>().Received() await sutProvider.GetDependency<IEventService>().Received()
.LogProviderUserEventAsync(providerUser, EventType.ProviderUser_Updated, null); .LogProviderUserEventAsync(providerUser, EventType.ProviderUser_Updated, null);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task DeleteUsersAsync_NoRemainingOwner_Throws(Provider provider, User deletingUser, public async Task DeleteUsersAsync_NoRemainingOwner_Throws(Provider provider, User deletingUser,
ICollection<ProviderUser> providerUsers, SutProvider<ProviderService> sutProvider) ICollection<ProviderUser> providerUsers, SutProvider<ProviderService> sutProvider)
@ -397,16 +397,16 @@ namespace Bit.CommCore.Test.Services
sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider); sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider);
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers);
providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new ProviderUser[] {}); providerUserRepository.GetManyByProviderAsync(default, default).ReturnsForAnyArgs(new ProviderUser[] { });
var exception = await Assert.ThrowsAsync<BadRequestException>( var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.DeleteUsersAsync(provider.Id, userIds, deletingUser.Id)); () => sutProvider.Sut.DeleteUsersAsync(provider.Id, userIds, deletingUser.Id));
Assert.Equal("Provider must have at least one confirmed ProviderAdmin.", exception.Message); Assert.Equal("Provider must have at least one confirmed ProviderAdmin.", exception.Message);
} }
[Theory, CustomAutoData(typeof(SutProviderCustomization))] [Theory, CustomAutoData(typeof(SutProviderCustomization))]
public async Task DeleteUsersAsync_Success(Provider provider, User deletingUser, ICollection<ProviderUser> providerUsers, public async Task DeleteUsersAsync_Success(Provider provider, User deletingUser, ICollection<ProviderUser> providerUsers,
[ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)]ProviderUser remainingOwner, [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser remainingOwner,
SutProvider<ProviderService> sutProvider) SutProvider<ProviderService> sutProvider)
{ {
var userIds = providerUsers.Select(pu => pu.Id); var userIds = providerUsers.Select(pu => pu.Id);
@ -421,10 +421,10 @@ namespace Bit.CommCore.Test.Services
sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider); sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider);
var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>(); var providerUserRepository = sutProvider.GetDependency<IProviderUserRepository>();
providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers); 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); var result = await sutProvider.Sut.DeleteUsersAsync(provider.Id, userIds, deletingUser.Id);
Assert.NotEmpty(result); Assert.NotEmpty(result);
Assert.Equal("You cannot remove yourself.", result[0].Item2); Assert.Equal("You cannot remove yourself.", result[0].Item2);
Assert.Equal("", result[1].Item2); Assert.Equal("", result[1].Item2);

View File

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Bit.Admin.Controllers namespace Bit.Admin.Controllers

View File

@ -1,10 +1,10 @@
using System.Diagnostics; 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.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Admin.Models;
using Bit.Core.Settings;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace Bit.Admin.Controllers namespace Bit.Admin.Controllers

View File

@ -1,6 +1,6 @@
using System; using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Admin.Controllers namespace Bit.Admin.Controllers
{ {
@ -12,7 +12,7 @@ namespace Bit.Admin.Controllers
{ {
return DateTime.UtcNow; return DateTime.UtcNow;
} }
[HttpGet("~/version")] [HttpGet("~/version")]
public JsonResult GetVersion() public JsonResult GetVersion()
{ {

View File

@ -41,7 +41,7 @@ namespace Bit.Admin.Controllers
}, },
continuationToken: cursor continuationToken: cursor
).AsQueryable(); ).AsQueryable();
if (level.HasValue) if (level.HasValue)
{ {
query = query.Where(l => l.Level == level.Value.ToString()); query = query.Where(l => l.Level == level.Value.ToString());
@ -84,7 +84,7 @@ namespace Bit.Admin.Controllers
var query = cosmosContainer.GetItemLinqQueryable<LogDetailsModel>() var query = cosmosContainer.GetItemLinqQueryable<LogDetailsModel>()
.AsQueryable() .AsQueryable()
.Where(l => l.Id == id.ToString()); .Where(l => l.Id == id.ToString());
var response = await query.ToFeedIterator().ReadNextAsync(); var response = await query.ToFeedIterator().ReadNextAsync();
if (response == null || response.Count == 0) if (response == null || response.Count == 0)
{ {

View File

@ -1,16 +1,16 @@
using System; using System;
using Microsoft.AspNetCore.Mvc; using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Repositories;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Admin.Models; 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.Models.Table;
using Bit.Core.Utilities; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Models.Business; using Bit.Core.Utilities;
using Bit.Core.Enums; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Admin.Controllers namespace Bit.Admin.Controllers
{ {
@ -143,7 +143,8 @@ namespace Bit.Admin.Controllers
model.ToOrganization(organization); model.ToOrganization(organization);
await _organizationRepository.ReplaceAsync(organization); await _organizationRepository.ReplaceAsync(organization);
await _applicationCacheService.UpsertOrganizationAbilityAsync(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), EventRaisedByUser = _userService.GetUserName(User),
SalesAssistedTrialStarted = model.SalesAssistedTrialStarted, SalesAssistedTrialStarted = model.SalesAssistedTrialStarted,
}); });

View File

@ -319,8 +319,8 @@ namespace Bit.Admin.Controllers
}; };
return View(model); return View(model);
} }
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> TaxRateUpload(IFormFile file) public async Task<IActionResult> TaxRateUpload(IFormFile file)
{ {
@ -332,7 +332,7 @@ namespace Bit.Admin.Controllers
// Build rates and validate them first before updating DB & Stripe // Build rates and validate them first before updating DB & Stripe
var taxRateUpdates = new List<TaxRate>(); var taxRateUpdates = new List<TaxRate>();
var currentTaxRates = await _taxRateRepository.GetAllActiveAsync(); var currentTaxRates = await _taxRateRepository.GetAllActiveAsync();
using var reader = new StreamReader(file.OpenReadStream()); using var reader = new StreamReader(file.OpenReadStream());
while (!reader.EndOfStream) while (!reader.EndOfStream)
{ {
var line = await reader.ReadLineAsync(); var line = await reader.ReadLineAsync();
@ -370,8 +370,8 @@ namespace Bit.Admin.Controllers
taxRate.Rate = rate; taxRate.Rate = rate;
taxRate.State = state ?? taxRate.State; taxRate.State = state ?? taxRate.State;
taxRateUpdates.Add(taxRate); taxRateUpdates.Add(taxRate);
} }
foreach (var taxRate in taxRateUpdates) foreach (var taxRate in taxRateUpdates)
{ {
if (!string.IsNullOrWhiteSpace(taxRate.Id)) if (!string.IsNullOrWhiteSpace(taxRate.Id))
@ -384,17 +384,17 @@ namespace Bit.Admin.Controllers
} }
} }
return RedirectToAction("TaxRate"); return RedirectToAction("TaxRate");
} }
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> TaxRateAddEdit(TaxRateAddEditModel model) public async Task<IActionResult> TaxRateAddEdit(TaxRateAddEditModel model)
{ {
var existingRateCheck = await _taxRateRepository.GetByLocationAsync(new TaxRate() { Country = model.Country, PostalCode = model.PostalCode }); 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) if (!ModelState.IsValid)
@ -423,7 +423,7 @@ namespace Bit.Admin.Controllers
return RedirectToAction("TaxRate"); return RedirectToAction("TaxRate");
} }
public async Task<IActionResult> TaxRateArchive(string stripeTaxRateId) public async Task<IActionResult> TaxRateArchive(string stripeTaxRateId)
{ {
if (!string.IsNullOrWhiteSpace(stripeTaxRateId)) if (!string.IsNullOrWhiteSpace(stripeTaxRateId))
{ {

View File

@ -1,14 +1,14 @@
using System; using System;
using Microsoft.AspNetCore.Mvc; using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Repositories;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Admin.Models; using Bit.Admin.Models;
using System.Collections.Generic;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Utilities; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Admin.Controllers namespace Bit.Admin.Controllers
{ {

View File

@ -2,10 +2,10 @@
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Azure.Storage.Queues;
using Bit.Core.Settings; using Bit.Core.Settings;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Azure.Storage.Queues;
namespace Bit.Admin.HostedServices namespace Bit.Admin.HostedServices
{ {

View File

@ -1,18 +1,18 @@
using System; 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.Collections.Generic; 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 Bit.Core.Utilities;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Bit.Admin.HostedServices namespace Bit.Admin.HostedServices
{ {
@ -30,7 +30,7 @@ namespace Bit.Admin.HostedServices
ILogger<AzureQueueMailHostedService> logger, ILogger<AzureQueueMailHostedService> logger,
IMailService mailService, IMailService mailService,
GlobalSettings globalSettings) GlobalSettings globalSettings)
{ {
_logger = logger; _logger = logger;
_mailService = mailService; _mailService = mailService;
_globalSettings = globalSettings; _globalSettings = globalSettings;
@ -89,7 +89,7 @@ namespace Bit.Admin.HostedServices
_logger.LogError(e, "Failed to send email"); _logger.LogError(e, "Failed to send email");
// TODO: retries? // TODO: retries?
} }
await _mailQueueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt); await _mailQueueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt);
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Threading.Tasks;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Bit.Core; using Bit.Core;
using Bit.Core.Context; using Bit.Core.Context;
using Bit.Core.Jobs; using Bit.Core.Jobs;

View File

@ -5,7 +5,7 @@ namespace Bit.Admin.Models
public class CreateProviderModel public class CreateProviderModel
{ {
public CreateProviderModel() { } public CreateProviderModel() { }
[Display(Name = "Owner Email")] [Display(Name = "Owner Email")]
[Required] [Required]
public string OwnerEmail { get; set; } public string OwnerEmail { get; set; }

View File

@ -5,8 +5,8 @@ using Bit.Core.Enums;
using Bit.Core.Models.Business; using Bit.Core.Models.Business;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
namespace Bit.Admin.Models namespace Bit.Admin.Models
{ {
@ -92,7 +92,7 @@ namespace Bit.Admin.Models
[Display(Name = "2FA")] [Display(Name = "2FA")]
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
[Display(Name = "API")] [Display(Name = "API")]
public bool UseApi{ get; set; } public bool UseApi { get; set; }
[Display(Name = "Reset Password")] [Display(Name = "Reset Password")]
public bool UseResetPassword { get; set; } public bool UseResetPassword { get; set; }
[Display(Name = "Self Host")] [Display(Name = "Self Host")]

View File

@ -25,11 +25,11 @@ namespace Bit.Admin.Models
CollectionCount = collections.Count(); CollectionCount = collections.Count();
GroupCount = groups?.Count() ?? 0; GroupCount = groups?.Count() ?? 0;
PolicyCount = policies?.Count() ?? 0; PolicyCount = policies?.Count() ?? 0;
Owners = string.Join(", ", Owners = string.Join(", ",
orgUsers orgUsers
.Where(u => u.Type == OrganizationUserType.Owner && u.Status == OrganizationUserStatusType.Confirmed) .Where(u => u.Type == OrganizationUserType.Owner && u.Status == OrganizationUserStatusType.Confirmed)
.Select(u => u.Email)); .Select(u => u.Email));
Admins = string.Join(", ", Admins = string.Join(", ",
orgUsers orgUsers
.Where(u => u.Type == OrganizationUserType.Admin && u.Status == OrganizationUserStatusType.Confirmed) .Where(u => u.Type == OrganizationUserType.Admin && u.Status == OrganizationUserStatusType.Confirmed)
.Select(u => u.Email)); .Select(u => u.Email));

View File

@ -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 StripeTaxRateId { get; set; }
public string Country { get; set; } public string Country { get; set; }

View File

@ -1,8 +1,8 @@
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
namespace Bit.Admin.Models namespace Bit.Admin.Models
{ {
public class TaxRatesModel: PagedModel<TaxRate> public class TaxRatesModel : PagedModel<TaxRate>
{ {
public string Message { get; set; } public string Message { get; set; }
} }

View File

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Business; using Bit.Core.Models.Business;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
namespace Bit.Admin.Models namespace Bit.Admin.Models
{ {
@ -30,7 +30,7 @@ namespace Bit.Admin.Models
LicenseKey = user.LicenseKey; LicenseKey = user.LicenseKey;
PremiumExpirationDate = user.PremiumExpirationDate; PremiumExpirationDate = user.PremiumExpirationDate;
} }
public BillingInfo BillingInfo { get; set; } public BillingInfo BillingInfo { get; set; }
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20); public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm"); public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm");

View File

@ -70,12 +70,12 @@ namespace Bit.Admin
// Services // Services
services.AddBaseServices(); services.AddBaseServices();
services.AddDefaultServices(globalSettings); services.AddDefaultServices(globalSettings);
#if OSS #if OSS
services.AddOosServices(); services.AddOosServices();
#else #else
services.AddCommCoreServices(); services.AddCommCoreServices();
#endif #endif
// Mvc // Mvc
services.AddMvc(config => services.AddMvc(config =>

View File

@ -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;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Enums.Provider;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Models.Business; using Bit.Core.Models.Business;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
@ -11,14 +19,6 @@ using Bit.Core.Settings;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; 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 namespace Bit.Api.Controllers
{ {
@ -66,7 +66,7 @@ namespace Bit.Api.Controllers
[HttpPost("prelogin")] [HttpPost("prelogin")]
[AllowAnonymous] [AllowAnonymous]
public async Task<PreloginResponseModel> PostPrelogin([FromBody]PreloginRequestModel model) public async Task<PreloginResponseModel> PostPrelogin([FromBody] PreloginRequestModel model)
{ {
var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email); var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email);
if (kdfInformation == null) if (kdfInformation == null)
@ -83,7 +83,7 @@ namespace Bit.Api.Controllers
[HttpPost("register")] [HttpPost("register")]
[AllowAnonymous] [AllowAnonymous]
[CaptchaProtected] [CaptchaProtected]
public async Task PostRegister([FromBody]RegisterRequestModel model) public async Task PostRegister([FromBody] RegisterRequestModel model)
{ {
var result = await _userService.RegisterUserAsync(model.ToUser(), model.MasterPasswordHash, var result = await _userService.RegisterUserAsync(model.ToUser(), model.MasterPasswordHash,
model.Token, model.OrganizationUserId); model.Token, model.OrganizationUserId);
@ -103,13 +103,13 @@ namespace Bit.Api.Controllers
[HttpPost("password-hint")] [HttpPost("password-hint")]
[AllowAnonymous] [AllowAnonymous]
public async Task PostPasswordHint([FromBody]PasswordHintRequestModel model) public async Task PostPasswordHint([FromBody] PasswordHintRequestModel model)
{ {
await _userService.SendMasterPasswordHintAsync(model.Email); await _userService.SendMasterPasswordHintAsync(model.Email);
} }
[HttpPost("email-token")] [HttpPost("email-token")]
public async Task PostEmailToken([FromBody]EmailTokenRequestModel model) public async Task PostEmailToken([FromBody] EmailTokenRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -132,7 +132,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("email")] [HttpPost("email")]
public async Task PostEmail([FromBody]EmailRequestModel model) public async Task PostEmail([FromBody] EmailRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -175,7 +175,7 @@ namespace Bit.Api.Controllers
[HttpPost("verify-email-token")] [HttpPost("verify-email-token")]
[AllowAnonymous] [AllowAnonymous]
public async Task PostVerifyEmailToken([FromBody]VerifyEmailRequestModel model) public async Task PostVerifyEmailToken([FromBody] VerifyEmailRequestModel model)
{ {
var user = await _userService.GetUserByIdAsync(new Guid(model.UserId)); var user = await _userService.GetUserByIdAsync(new Guid(model.UserId));
if (user == null) if (user == null)
@ -198,7 +198,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("password")] [HttpPost("password")]
public async Task PostPassword([FromBody]PasswordRequestModel model) public async Task PostPassword([FromBody] PasswordRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -223,7 +223,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("set-password")] [HttpPost("set-password")]
public async Task PostSetPasswordAsync([FromBody]SetPasswordRequestModel model) public async Task PostSetPasswordAsync([FromBody] SetPasswordRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -231,7 +231,7 @@ namespace Bit.Api.Controllers
throw new UnauthorizedAccessException(); 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); model.OrgIdentifier);
if (result.Succeeded) if (result.Succeeded)
{ {
@ -247,7 +247,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("verify-password")] [HttpPost("verify-password")]
public async Task PostVerifyPassword([FromBody]SecretVerificationRequestModel model) public async Task PostVerifyPassword([FromBody] SecretVerificationRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -266,7 +266,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("set-key-connector-key")] [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); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -312,7 +312,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("kdf")] [HttpPost("kdf")]
public async Task PostKdf([FromBody]KdfRequestModel model) public async Task PostKdf([FromBody] KdfRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -337,7 +337,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("key")] [HttpPost("key")]
public async Task PostKey([FromBody]UpdateKeyRequestModel model) public async Task PostKey([FromBody] UpdateKeyRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -393,7 +393,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("security-stamp")] [HttpPost("security-stamp")]
public async Task PostSecurityStamp([FromBody]SecretVerificationRequestModel model) public async Task PostSecurityStamp([FromBody] SecretVerificationRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -449,7 +449,7 @@ namespace Bit.Api.Controllers
[HttpPut("profile")] [HttpPut("profile")]
[HttpPost("profile")] [HttpPost("profile")]
public async Task<ProfileResponseModel> PutProfile([FromBody]UpdateProfileRequestModel model) public async Task<ProfileResponseModel> PutProfile([FromBody] UpdateProfileRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -477,7 +477,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("keys")] [HttpPost("keys")]
public async Task<KeysResponseModel> PostKeys([FromBody]KeysRequestModel model) public async Task<KeysResponseModel> PostKeys([FromBody] KeysRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -503,7 +503,7 @@ namespace Bit.Api.Controllers
[HttpDelete] [HttpDelete]
[HttpPost("delete")] [HttpPost("delete")]
public async Task Delete([FromBody]SecretVerificationRequestModel model) public async Task Delete([FromBody] SecretVerificationRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -535,14 +535,14 @@ namespace Bit.Api.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost("delete-recover")] [HttpPost("delete-recover")]
public async Task PostDeleteRecover([FromBody]DeleteRecoverRequestModel model) public async Task PostDeleteRecover([FromBody] DeleteRecoverRequestModel model)
{ {
await _userService.SendDeleteConfirmationAsync(model.Email); await _userService.SendDeleteConfirmationAsync(model.Email);
} }
[HttpPost("delete-recover-token")] [HttpPost("delete-recover-token")]
[AllowAnonymous] [AllowAnonymous]
public async Task PostDeleteRecoverToken([FromBody]VerifyDeleteRecoverRequestModel model) public async Task PostDeleteRecoverToken([FromBody] VerifyDeleteRecoverRequestModel model)
{ {
var user = await _userService.GetUserByIdAsync(new Guid(model.UserId)); var user = await _userService.GetUserByIdAsync(new Guid(model.UserId));
if (user == null) if (user == null)
@ -566,7 +566,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("iap-check")] [HttpPost("iap-check")]
public async Task PostIapCheck([FromBody]IapCheckRequestModel model) public async Task PostIapCheck([FromBody] IapCheckRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -660,7 +660,7 @@ namespace Bit.Api.Controllers
[HttpPost("payment")] [HttpPost("payment")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task PostPayment([FromBody]PaymentRequestModel model) public async Task PostPayment([FromBody] PaymentRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -678,7 +678,7 @@ namespace Bit.Api.Controllers
[HttpPost("storage")] [HttpPost("storage")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<PaymentResponseModel> PostStorage([FromBody]StorageRequestModel model) public async Task<PaymentResponseModel> PostStorage([FromBody] StorageRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -755,7 +755,7 @@ namespace Bit.Api.Controllers
[HttpPut("tax")] [HttpPut("tax")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task PutTaxInfo([FromBody]TaxInfoUpdateRequestModel model) public async Task PutTaxInfo([FromBody] TaxInfoUpdateRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -793,7 +793,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("api-key")] [HttpPost("api-key")]
public async Task<ApiKeyResponseModel> ApiKey([FromBody]SecretVerificationRequestModel model) public async Task<ApiKeyResponseModel> ApiKey([FromBody] SecretVerificationRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -811,7 +811,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("rotate-api-key")] [HttpPost("rotate-api-key")]
public async Task<ApiKeyResponseModel> RotateApiKey([FromBody]SecretVerificationRequestModel model) public async Task<ApiKeyResponseModel> RotateApiKey([FromBody] SecretVerificationRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -829,9 +829,9 @@ namespace Bit.Api.Controllers
var response = new ApiKeyResponseModel(user); var response = new ApiKeyResponseModel(user);
return response; return response;
} }
[HttpPut("update-temp-password")] [HttpPut("update-temp-password")]
public async Task PutUpdateTempPasswordAsync([FromBody]UpdateTempPasswordRequestModel model) public async Task PutUpdateTempPasswordAsync([FromBody] UpdateTempPasswordRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -866,7 +866,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("verify-otp")] [HttpPost("verify-otp")]
public async Task VerifyOTP([FromBody]VerifyOTPRequestModel model) public async Task VerifyOTP([FromBody] VerifyOTPRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user is not { UsesKeyConnector: true }) if (user is not { UsesKeyConnector: true })

View File

@ -1,27 +1,27 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; 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 Azure.Messaging.EventGrid;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response; 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.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 Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Bit.Core;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -123,7 +123,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("")] [HttpPost("")]
public async Task<CipherResponseModel> Post([FromBody]CipherRequestModel model) public async Task<CipherResponseModel> Post([FromBody] CipherRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var cipher = model.ToCipherDetails(userId); var cipher = model.ToCipherDetails(userId);
@ -138,7 +138,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("create")] [HttpPost("create")]
public async Task<CipherResponseModel> PostCreate([FromBody]CipherCreateRequestModel model) public async Task<CipherResponseModel> PostCreate([FromBody] CipherCreateRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var cipher = model.Cipher.ToCipherDetails(userId); var cipher = model.Cipher.ToCipherDetails(userId);
@ -153,7 +153,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("admin")] [HttpPost("admin")]
public async Task<CipherMiniResponseModel> PostAdmin([FromBody]CipherCreateRequestModel model) public async Task<CipherMiniResponseModel> PostAdmin([FromBody] CipherCreateRequestModel model)
{ {
var cipher = model.Cipher.ToOrganizationCipher(); var cipher = model.Cipher.ToOrganizationCipher();
if (!await _currentContext.EditAnyCollection(cipher.OrganizationId.Value)) if (!await _currentContext.EditAnyCollection(cipher.OrganizationId.Value))
@ -170,7 +170,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<CipherResponseModel> Put(string id, [FromBody]CipherRequestModel model) public async Task<CipherResponseModel> Put(string id, [FromBody] CipherRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
@ -179,7 +179,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ?
(Guid?)null : new Guid(model.OrganizationId); (Guid?)null : new Guid(model.OrganizationId);
if (cipher.OrganizationId != modelOrgId) if (cipher.OrganizationId != modelOrgId)
{ {
@ -195,7 +195,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/admin")] [HttpPut("{id}/admin")]
[HttpPost("{id}/admin")] [HttpPost("{id}/admin")]
public async Task<CipherMiniResponseModel> PutAdmin(string id, [FromBody]CipherRequestModel model) public async Task<CipherMiniResponseModel> PutAdmin(string id, [FromBody] CipherRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id)); var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id));
@ -241,7 +241,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("import")] [HttpPost("import")]
public async Task PostImport([FromBody]ImportCiphersRequestModel model) public async Task PostImport([FromBody] ImportCiphersRequestModel model)
{ {
if (!_globalSettings.SelfHosted && if (!_globalSettings.SelfHosted &&
(model.Ciphers.Count() > 6000 || model.FolderRelationships.Count() > 6000 || (model.Ciphers.Count() > 6000 || model.FolderRelationships.Count() > 6000 ||
@ -257,8 +257,8 @@ namespace Bit.Api.Controllers
} }
[HttpPost("import-organization")] [HttpPost("import-organization")]
public async Task PostImport([FromQuery]string organizationId, public async Task PostImport([FromQuery] string organizationId,
[FromBody]ImportOrganizationCiphersRequestModel model) [FromBody] ImportOrganizationCiphersRequestModel model)
{ {
if (!_globalSettings.SelfHosted && if (!_globalSettings.SelfHosted &&
(model.Ciphers.Count() > 6000 || model.CollectionRelationships.Count() > 12000 || (model.Ciphers.Count() > 6000 || model.CollectionRelationships.Count() > 12000 ||
@ -281,7 +281,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/partial")] [HttpPut("{id}/partial")]
[HttpPost("{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 userId = _userService.GetProperUserId(User).Value;
var folderId = string.IsNullOrWhiteSpace(model.FolderId) ? null : (Guid?)new Guid(model.FolderId); var folderId = string.IsNullOrWhiteSpace(model.FolderId) ? null : (Guid?)new Guid(model.FolderId);
@ -290,7 +290,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/share")] [HttpPut("{id}/share")]
[HttpPost("{id}/share")] [HttpPost("{id}/share")]
public async Task<CipherResponseModel> PutShare(string id, [FromBody]CipherShareRequestModel model) public async Task<CipherResponseModel> PutShare(string id, [FromBody] CipherShareRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var cipherId = new Guid(id); var cipherId = new Guid(id);
@ -312,7 +312,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/collections")] [HttpPut("{id}/collections")]
[HttpPost("{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 userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
@ -322,13 +322,13 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
await _cipherService.SaveCollectionsAsync(cipher, await _cipherService.SaveCollectionsAsync(cipher,
model.CollectionIds.Select(c => new Guid(c)), userId, false); model.CollectionIds.Select(c => new Guid(c)), userId, false);
} }
[HttpPut("{id}/collections-admin")] [HttpPut("{id}/collections-admin")]
[HttpPost("{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 userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id)); var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
@ -338,7 +338,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
await _cipherService.SaveCollectionsAsync(cipher, await _cipherService.SaveCollectionsAsync(cipher,
model.CollectionIds.Select(c => new Guid(c)), userId, true); model.CollectionIds.Select(c => new Guid(c)), userId, true);
} }
@ -373,7 +373,7 @@ namespace Bit.Api.Controllers
[HttpDelete("")] [HttpDelete("")]
[HttpPost("delete")] [HttpPost("delete")]
public async Task DeleteMany([FromBody]CipherBulkDeleteRequestModel model) public async Task DeleteMany([FromBody] CipherBulkDeleteRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -387,7 +387,7 @@ namespace Bit.Api.Controllers
[HttpDelete("admin")] [HttpDelete("admin")]
[HttpPost("delete-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) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -432,7 +432,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("delete")] [HttpPut("delete")]
public async Task PutDeleteMany([FromBody]CipherBulkDeleteRequestModel model) public async Task PutDeleteMany([FromBody] CipherBulkDeleteRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -444,7 +444,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("delete-admin")] [HttpPut("delete-admin")]
public async Task PutDeleteManyAdmin([FromBody]CipherBulkDeleteRequestModel model) public async Task PutDeleteManyAdmin([FromBody] CipherBulkDeleteRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -511,7 +511,7 @@ namespace Bit.Api.Controllers
[HttpPut("move")] [HttpPut("move")]
[HttpPost("move")] [HttpPost("move")]
public async Task MoveMany([FromBody]CipherBulkMoveRequestModel model) public async Task MoveMany([FromBody] CipherBulkMoveRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -525,7 +525,7 @@ namespace Bit.Api.Controllers
[HttpPut("share")] [HttpPut("share")]
[HttpPost("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); var organizationId = new Guid(model.Ciphers.First().OrganizationId);
if (!await _currentContext.OrganizationUser(organizationId)) if (!await _currentContext.OrganizationUser(organizationId))
@ -553,7 +553,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("purge")] [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); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)

View File

@ -1,16 +1,16 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; 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.Request;
using Bit.Api.Models.Response; 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 namespace Bit.Api.Controllers
{ {
@ -111,7 +111,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("")] [HttpPost("")]
public async Task<CollectionResponseModel> Post(string orgId, [FromBody]CollectionRequestModel model) public async Task<CollectionResponseModel> Post(string orgId, [FromBody] CollectionRequestModel model)
{ {
var orgIdGuid = new Guid(orgId); var orgIdGuid = new Guid(orgId);
var collection = model.ToCollection(orgIdGuid); var collection = model.ToCollection(orgIdGuid);
@ -132,7 +132,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<CollectionResponseModel> Put(string orgId, string id, [FromBody]CollectionRequestModel model) public async Task<CollectionResponseModel> Put(string orgId, string id, [FromBody] CollectionRequestModel model)
{ {
if (!await CanEditCollectionAsync(orgId, id)) if (!await CanEditCollectionAsync(orgId, id))
{ {
@ -146,7 +146,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("{id}/users")] [HttpPut("{id}/users")]
public async Task PutUsers(string orgId, string id, [FromBody]IEnumerable<SelectionReadOnlyRequestModel> model) public async Task PutUsers(string orgId, string id, [FromBody] IEnumerable<SelectionReadOnlyRequestModel> model)
{ {
var collection = await GetCollectionAsync(new Guid(id), new Guid(orgId)); var collection = await GetCollectionAsync(new Guid(id), new Guid(orgId));
await _collectionRepository.UpdateUsersAsync(collection.Id, model?.Select(g => g.ToSelectionReadOnly())); await _collectionRepository.UpdateUsersAsync(collection.Id, model?.Select(g => g.ToSelectionReadOnly()));

View File

@ -4,12 +4,12 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -66,7 +66,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("")] [HttpPost("")]
public async Task<DeviceResponseModel> Post([FromBody]DeviceRequestModel model) public async Task<DeviceResponseModel> Post([FromBody] DeviceRequestModel model)
{ {
var device = model.ToDevice(_userService.GetProperUserId(User)); var device = model.ToDevice(_userService.GetProperUserId(User));
await _deviceService.SaveAsync(device); await _deviceService.SaveAsync(device);
@ -77,7 +77,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<DeviceResponseModel> Put(string id, [FromBody]DeviceRequestModel model) public async Task<DeviceResponseModel> Put(string id, [FromBody] DeviceRequestModel model)
{ {
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
if (device == null) if (device == null)
@ -93,7 +93,7 @@ namespace Bit.Api.Controllers
[HttpPut("identifier/{identifier}/token")] [HttpPut("identifier/{identifier}/token")]
[HttpPost("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); var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
if (device == null) if (device == null)

View File

@ -77,7 +77,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{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)); var emergencyAccess = await _emergencyAccessRepository.GetByIdAsync(new Guid(id));
if (emergencyAccess == null) if (emergencyAccess == null)
@ -88,7 +88,7 @@ namespace Bit.Api.Controllers
var userId = _userService.GetProperUserId(User); var userId = _userService.GetProperUserId(User);
await _emergencyAccessService.SaveAsync(model.ToEmergencyAccess(emergencyAccess), userId.Value); await _emergencyAccessService.SaveAsync(model.ToEmergencyAccess(emergencyAccess), userId.Value);
} }
[HttpDelete("{id}")] [HttpDelete("{id}")]
[HttpPost("{id}/delete")] [HttpPost("{id}/delete")]
public async Task Delete(string id) public async Task Delete(string id)
@ -96,7 +96,7 @@ namespace Bit.Api.Controllers
var userId = _userService.GetProperUserId(User); var userId = _userService.GetProperUserId(User);
await _emergencyAccessService.DeleteAsync(new Guid(id), userId.Value); await _emergencyAccessService.DeleteAsync(new Guid(id), userId.Value);
} }
[HttpPost("invite")] [HttpPost("invite")]
public async Task Invite([FromBody] EmergencyAccessInviteRequestModel model) public async Task Invite([FromBody] EmergencyAccessInviteRequestModel model)
{ {
@ -138,7 +138,7 @@ namespace Bit.Api.Controllers
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
await _emergencyAccessService.ApproveAsync(new Guid(id), user); await _emergencyAccessService.ApproveAsync(new Guid(id), user);
} }
[HttpPost("{id}/reject")] [HttpPost("{id}/reject")]
public async Task Reject(string id) public async Task Reject(string id)
{ {
@ -153,14 +153,14 @@ namespace Bit.Api.Controllers
var (result, grantor) = await _emergencyAccessService.TakeoverAsync(new Guid(id), user); var (result, grantor) = await _emergencyAccessService.TakeoverAsync(new Guid(id), user);
return new EmergencyAccessTakeoverResponseModel(result, grantor); return new EmergencyAccessTakeoverResponseModel(result, grantor);
} }
[HttpPost("{id}/password")] [HttpPost("{id}/password")]
public async Task Password(string id, [FromBody] EmergencyAccessPasswordRequestModel model) public async Task Password(string id, [FromBody] EmergencyAccessPasswordRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
await _emergencyAccessService.PasswordAsync(new Guid(id), user, model.NewMasterPasswordHash, model.Key); await _emergencyAccessService.PasswordAsync(new Guid(id), user, model.NewMasterPasswordHash, model.Key);
} }
[HttpPost("{id}/view")] [HttpPost("{id}/view")]
public async Task<EmergencyAccessViewResponseModel> ViewCiphers(string id) public async Task<EmergencyAccessViewResponseModel> ViewCiphers(string id)
{ {

View File

@ -2,13 +2,13 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Response; 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.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Data; 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 namespace Bit.Api.Controllers
{ {
@ -41,7 +41,7 @@ namespace Bit.Api.Controllers
[HttpGet("")] [HttpGet("")]
public async Task<ListResponseModel<EventResponseModel>> GetUser( public async Task<ListResponseModel<EventResponseModel>> 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 dateRange = GetDateRange(start, end);
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
@ -53,7 +53,7 @@ namespace Bit.Api.Controllers
[HttpGet("~/ciphers/{id}/events")] [HttpGet("~/ciphers/{id}/events")]
public async Task<ListResponseModel<EventResponseModel>> GetCipher(string id, public async Task<ListResponseModel<EventResponseModel>> 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)); var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
if (cipher == null) if (cipher == null)
@ -86,7 +86,7 @@ namespace Bit.Api.Controllers
[HttpGet("~/organizations/{id}/events")] [HttpGet("~/organizations/{id}/events")]
public async Task<ListResponseModel<EventResponseModel>> GetOrganization(string id, public async Task<ListResponseModel<EventResponseModel>> 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); var orgId = new Guid(id);
if (!await _currentContext.AccessEventLogs(orgId)) if (!await _currentContext.AccessEventLogs(orgId))
@ -103,7 +103,7 @@ namespace Bit.Api.Controllers
[HttpGet("~/organizations/{orgId}/users/{id}/events")] [HttpGet("~/organizations/{orgId}/users/{id}/events")]
public async Task<ListResponseModel<EventResponseModel>> GetOrganizationUser(string orgId, string id, public async Task<ListResponseModel<EventResponseModel>> 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)); var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));
if (organizationUser == null || !organizationUser.UserId.HasValue || if (organizationUser == null || !organizationUser.UserId.HasValue ||
@ -122,7 +122,7 @@ namespace Bit.Api.Controllers
[HttpGet("~/providers/{providerId:guid}/events")] [HttpGet("~/providers/{providerId:guid}/events")]
public async Task<ListResponseModel<EventResponseModel>> GetProvider(Guid providerId, public async Task<ListResponseModel<EventResponseModel>> 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)) if (!_currentContext.ProviderAccessEventLogs(providerId))
{ {
@ -138,7 +138,7 @@ namespace Bit.Api.Controllers
[HttpGet("~/providers/{providerId:guid}/users/{id:guid}/events")] [HttpGet("~/providers/{providerId:guid}/users/{id:guid}/events")]
public async Task<ListResponseModel<EventResponseModel>> GetProviderUser(Guid providerId, Guid id, public async Task<ListResponseModel<EventResponseModel>> 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); var providerUser = await _providerUserRepository.GetByIdAsync(id);
if (providerUser == null || !providerUser.UserId.HasValue || if (providerUser == null || !providerUser.UserId.HasValue ||

View File

@ -3,11 +3,11 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -52,7 +52,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("")] [HttpPost("")]
public async Task<FolderResponseModel> Post([FromBody]FolderRequestModel model) public async Task<FolderResponseModel> Post([FromBody] FolderRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var folder = model.ToFolder(_userService.GetProperUserId(User).Value); var folder = model.ToFolder(_userService.GetProperUserId(User).Value);
@ -62,7 +62,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<FolderResponseModel> Put(string id, [FromBody]FolderRequestModel model) public async Task<FolderResponseModel> Put(string id, [FromBody] FolderRequestModel model)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId); var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId);

View File

@ -1,15 +1,15 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; 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.Request;
using Bit.Api.Models.Response; 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 namespace Bit.Api.Controllers
{ {
@ -89,7 +89,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("")] [HttpPost("")]
public async Task<GroupResponseModel> Post(string orgId, [FromBody]GroupRequestModel model) public async Task<GroupResponseModel> Post(string orgId, [FromBody] GroupRequestModel model)
{ {
var orgIdGuid = new Guid(orgId); var orgIdGuid = new Guid(orgId);
if (!await _currentContext.ManageGroups(orgIdGuid)) if (!await _currentContext.ManageGroups(orgIdGuid))
@ -104,7 +104,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<GroupResponseModel> Put(string orgId, string id, [FromBody]GroupRequestModel model) public async Task<GroupResponseModel> Put(string orgId, string id, [FromBody] GroupRequestModel model)
{ {
var group = await _groupRepository.GetByIdAsync(new Guid(id)); var group = await _groupRepository.GetByIdAsync(new Guid(id));
if (group == null || !await _currentContext.ManageGroups(group.OrganizationId)) if (group == null || !await _currentContext.ManageGroups(group.OrganizationId))
@ -117,7 +117,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("{id}/users")] [HttpPut("{id}/users")]
public async Task PutUsers(string orgId, string id, [FromBody]IEnumerable<Guid> model) public async Task PutUsers(string orgId, string id, [FromBody] IEnumerable<Guid> model)
{ {
var group = await _groupRepository.GetByIdAsync(new Guid(id)); var group = await _groupRepository.GetByIdAsync(new Guid(id));
if (group == null || !await _currentContext.ManageGroups(group.OrganizationId)) if (group == null || !await _currentContext.ManageGroups(group.OrganizationId))

View File

@ -1,16 +1,16 @@
using System; using System;
using System.Threading.Tasks; using System.Linq;
using Microsoft.AspNetCore.Mvc; using System.Net;
using Microsoft.AspNetCore.Authorization;
using System.Net.Http; using System.Net.Http;
using System.Security.Cryptography; using System.Security.Cryptography;
using Bit.Core.Services; using System.Threading.Tasks;
using Bit.Core.Context; using Bit.Core.Context;
using System.Net;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using System.Linq; using Bit.Core.Services;
using Bit.Core.Utilities;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -20,7 +20,7 @@ namespace Bit.Api.Controllers
{ {
return Json(CoreHelpers.GetVersion()); return Json(CoreHelpers.GetVersion());
} }
[HttpGet("~/ip")] [HttpGet("~/ip")]
public JsonResult Ip() public JsonResult Ip()
{ {

View File

@ -2,11 +2,11 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {

View File

@ -1,13 +1,13 @@
using Microsoft.AspNetCore.Mvc; using System;
using Bit.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Context;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Core.Models.Business; using Bit.Core.Context;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using System; using Bit.Core.Services;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -40,7 +40,7 @@ namespace Bit.Api.Controllers
} }
[HttpGet("user/{id}")] [HttpGet("user/{id}")]
public async Task<UserLicense> GetUser(string id, [FromQuery]string key) public async Task<UserLicense> GetUser(string id, [FromQuery] string key)
{ {
var user = await _userRepository.GetByIdAsync(new Guid(id)); var user = await _userRepository.GetByIdAsync(new Guid(id));
if (user == null) if (user == null)
@ -58,7 +58,7 @@ namespace Bit.Api.Controllers
} }
[HttpGet("organization/{id}")] [HttpGet("organization/{id}")]
public async Task<OrganizationLicense> GetOrganization(string id, [FromQuery]string key) public async Task<OrganizationLicense> GetOrganization(string id, [FromQuery] string key)
{ {
var org = await _organizationRepository.GetByIdAsync(new Guid(id)); var org = await _organizationRepository.GetByIdAsync(new Guid(id));
if (org == null) if (org == null)

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks;
using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Core.Settings;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Bit.Core.Settings; using Microsoft.AspNetCore.Mvc;
using Stripe; using Stripe;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
@ -24,7 +24,7 @@ namespace Bit.Api.Controllers
[Authorize("Application")] [Authorize("Application")]
[HttpPost("~/bitpay-invoice")] [HttpPost("~/bitpay-invoice")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<string> PostBitPayInvoice([FromBody]BitPayInvoiceRequestModel model) public async Task<string> PostBitPayInvoice([FromBody] BitPayInvoiceRequestModel model)
{ {
var invoice = await _bitPayClient.CreateInvoiceAsync(model.ToBitpayInvoice(_globalSettings)); var invoice = await _bitPayClient.CreateInvoiceAsync(model.ToBitpayInvoice(_globalSettings));
return invoice.Url; return invoice.Url;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Request.Organizations;
using Bit.Core.Context; using Bit.Core.Context;
@ -43,7 +43,7 @@ namespace Bit.Api.Controllers
public async Task CreateSponsorship(Guid sponsoringOrgId, [FromBody] OrganizationSponsorshipRequestModel model) public async Task CreateSponsorship(Guid sponsoringOrgId, [FromBody] OrganizationSponsorshipRequestModel model)
{ {
await _organizationsSponsorshipService.OfferSponsorshipAsync( await _organizationsSponsorshipService.OfferSponsorshipAsync(
await _organizationRepository.GetByIdAsync(sponsoringOrgId), await _organizationRepository.GetByIdAsync(sponsoringOrgId),
await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default), await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default),
model.PlanSponsorshipType, model.SponsoredEmail, model.FriendlyName, model.PlanSponsorshipType, model.SponsoredEmail, model.FriendlyName,
(await CurrentUser).Email); (await CurrentUser).Email);
@ -57,7 +57,7 @@ namespace Bit.Api.Controllers
.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default); .GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default);
await _organizationsSponsorshipService.ResendSponsorshipOfferAsync( await _organizationsSponsorshipService.ResendSponsorshipOfferAsync(
await _organizationRepository.GetByIdAsync(sponsoringOrgId), await _organizationRepository.GetByIdAsync(sponsoringOrgId),
sponsoringOrgUser, sponsoringOrgUser,
await _organizationSponsorshipRepository await _organizationSponsorshipRepository
.GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUser.Id), .GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUser.Id),

View File

@ -1,18 +1,18 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; 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.Request.Organizations;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Bit.Core.Context;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business; using Bit.Core.Models.Business;
using Bit.Core.Models.Data; 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 namespace Bit.Api.Controllers
{ {
@ -91,7 +91,7 @@ namespace Bit.Api.Controllers
var responses = groupIds.Select(g => g.ToString()); var responses = groupIds.Select(g => g.ToString());
return responses; return responses;
} }
[HttpGet("{id}/reset-password-details")] [HttpGet("{id}/reset-password-details")]
public async Task<OrganizationUserResetPasswordDetailsResponseModel> GetResetPasswordDetails(string orgId, string id) public async Task<OrganizationUserResetPasswordDetailsResponseModel> GetResetPasswordDetails(string orgId, string id)
{ {
@ -115,7 +115,7 @@ namespace Bit.Api.Controllers
{ {
throw new NotFoundException(); throw new NotFoundException();
} }
// Retrieve Encrypted Private Key from organization // Retrieve Encrypted Private Key from organization
var org = await _organizationRepository.GetByIdAsync(orgGuidId); var org = await _organizationRepository.GetByIdAsync(orgGuidId);
if (org == null) if (org == null)
@ -127,7 +127,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("invite")] [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); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -139,9 +139,9 @@ namespace Bit.Api.Controllers
var result = await _organizationService.InviteUsersAsync(orgGuidId, userId.Value, var result = await _organizationService.InviteUsersAsync(orgGuidId, userId.Value,
new (OrganizationUserInvite, string)[] { (new OrganizationUserInvite(model.ToData()), null) }); new (OrganizationUserInvite, string)[] { (new OrganizationUserInvite(model.ToData()), null) });
} }
[HttpPost("reinvite")] [HttpPost("reinvite")]
public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkReinvite(string orgId, [FromBody]OrganizationUserBulkRequestModel model) public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkReinvite(string orgId, [FromBody] OrganizationUserBulkRequestModel model)
{ {
var orgGuidId = new Guid(orgId); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -169,7 +169,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id}/accept")] [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); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -181,7 +181,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id}/confirm")] [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); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -196,7 +196,7 @@ namespace Bit.Api.Controllers
[HttpPost("confirm")] [HttpPost("confirm")]
public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkConfirm(string orgId, public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkConfirm(string orgId,
[FromBody]OrganizationUserBulkConfirmRequestModel model) [FromBody] OrganizationUserBulkConfirmRequestModel model)
{ {
var orgGuidId = new Guid(orgId); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -213,7 +213,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("public-keys")] [HttpPost("public-keys")]
public async Task<ListResponseModel<OrganizationUserPublicKeyResponseModel>> UserPublicKeys(string orgId, [FromBody]OrganizationUserBulkRequestModel model) public async Task<ListResponseModel<OrganizationUserPublicKeyResponseModel>> UserPublicKeys(string orgId, [FromBody] OrganizationUserBulkRequestModel model)
{ {
var orgGuidId = new Guid(orgId); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -228,7 +228,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{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); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -249,7 +249,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/groups")] [HttpPut("{id}/groups")]
[HttpPost("{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); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))
@ -266,26 +266,26 @@ namespace Bit.Api.Controllers
var loggedInUserId = _userService.GetProperUserId(User); var loggedInUserId = _userService.GetProperUserId(User);
await _organizationService.UpdateUserGroupsAsync(organizationUser, model.GroupIds.Select(g => new Guid(g)), loggedInUserId); await _organizationService.UpdateUserGroupsAsync(organizationUser, model.GroupIds.Select(g => new Guid(g)), loggedInUserId);
} }
[HttpPut("{userId}/reset-password-enrollment")] [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); var callingUserId = _userService.GetProperUserId(User);
await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId), new Guid(userId), model.ResetPasswordKey, callingUserId); await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId), new Guid(userId), model.ResetPasswordKey, callingUserId);
} }
[HttpPut("{id}/reset-password")] [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); var orgGuidId = new Guid(orgId);
// Calling user must have Manage Reset Password permission // Calling user must have Manage Reset Password permission
if (!await _currentContext.ManageResetPassword(orgGuidId)) if (!await _currentContext.ManageResetPassword(orgGuidId))
{ {
throw new NotFoundException(); throw new NotFoundException();
} }
// Get the users role, since provider users aren't a member of the organization we use the owner check // 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) var orgUserType = await _currentContext.OrganizationOwner(orgGuidId)
? OrganizationUserType.Owner ? OrganizationUserType.Owner
@ -326,7 +326,7 @@ namespace Bit.Api.Controllers
[HttpDelete("")] [HttpDelete("")]
[HttpPost("delete")] [HttpPost("delete")]
public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkDelete(string orgId, [FromBody]OrganizationUserBulkRequestModel model) public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkDelete(string orgId, [FromBody] OrganizationUserBulkRequestModel model)
{ {
var orgGuidId = new Guid(orgId); var orgGuidId = new Guid(orgId);
if (!await _currentContext.ManageUsers(orgGuidId)) if (!await _currentContext.ManageUsers(orgGuidId))

View File

@ -5,18 +5,18 @@ using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc; using Bit.Api.Utilities;
using Bit.Core.Repositories; using Bit.Core.Context;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Exceptions; 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.Business;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using Bit.Core.Utilities; using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
@ -130,7 +130,7 @@ namespace Bit.Api.Controllers
[HttpGet("{id}/license")] [HttpGet("{id}/license")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<OrganizationLicense> GetLicense(string id, [FromQuery]Guid installationId) public async Task<OrganizationLicense> GetLicense(string id, [FromQuery] Guid installationId)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -156,7 +156,7 @@ namespace Bit.Api.Controllers
var responses = organizations.Select(o => new ProfileOrganizationResponseModel(o)); var responses = organizations.Select(o => new ProfileOrganizationResponseModel(o));
return new ListResponseModel<ProfileOrganizationResponseModel>(responses); return new ListResponseModel<ProfileOrganizationResponseModel>(responses);
} }
[HttpGet("{identifier}/auto-enroll-status")] [HttpGet("{identifier}/auto-enroll-status")]
public async Task<OrganizationAutoEnrollStatusResponseModel> GetAutoEnrollStatus(string identifier) public async Task<OrganizationAutoEnrollStatusResponseModel> GetAutoEnrollStatus(string identifier)
{ {
@ -165,7 +165,7 @@ namespace Bit.Api.Controllers
{ {
throw new UnauthorizedAccessException(); throw new UnauthorizedAccessException();
} }
var organization = await _organizationRepository.GetByIdentifierAsync(identifier); var organization = await _organizationRepository.GetByIdentifierAsync(identifier);
if (organization == null) if (organization == null)
{ {
@ -184,14 +184,14 @@ namespace Bit.Api.Controllers
{ {
return new OrganizationAutoEnrollStatusResponseModel(organization.Id, false); return new OrganizationAutoEnrollStatusResponseModel(organization.Id, false);
} }
var data = JsonConvert.DeserializeObject<ResetPasswordDataModel>(resetPasswordPolicy.Data); var data = JsonConvert.DeserializeObject<ResetPasswordDataModel>(resetPasswordPolicy.Data);
return new OrganizationAutoEnrollStatusResponseModel(organization.Id, data?.AutoEnrollEnabled ?? false); return new OrganizationAutoEnrollStatusResponseModel(organization.Id, data?.AutoEnrollEnabled ?? false);
} }
[HttpPost("")] [HttpPost("")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<OrganizationResponseModel> Post([FromBody]OrganizationCreateRequestModel model) public async Task<OrganizationResponseModel> Post([FromBody] OrganizationCreateRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -227,7 +227,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")] [HttpPost("{id}")]
public async Task<OrganizationResponseModel> Put(string id, [FromBody]OrganizationUpdateRequestModel model) public async Task<OrganizationResponseModel> Put(string id, [FromBody] OrganizationUpdateRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -250,7 +250,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/payment")] [HttpPost("{id}/payment")]
[SelfHosted(NotSelfHostedOnly = true)] [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); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -273,7 +273,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/upgrade")] [HttpPost("{id}/upgrade")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<PaymentResponseModel> PostUpgrade(string id, [FromBody]OrganizationUpgradeRequestModel model) public async Task<PaymentResponseModel> PostUpgrade(string id, [FromBody] OrganizationUpgradeRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -304,7 +304,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/seat")] [HttpPost("{id}/seat")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<PaymentResponseModel> PostSeat(string id, [FromBody]OrganizationSeatRequestModel model) public async Task<PaymentResponseModel> PostSeat(string id, [FromBody] OrganizationSeatRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -322,7 +322,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/storage")] [HttpPost("{id}/storage")]
[SelfHosted(NotSelfHostedOnly = true)] [SelfHosted(NotSelfHostedOnly = true)]
public async Task<PaymentResponseModel> PostStorage(string id, [FromBody]StorageRequestModel model) public async Task<PaymentResponseModel> PostStorage(string id, [FromBody] StorageRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -340,7 +340,7 @@ namespace Bit.Api.Controllers
[HttpPost("{id}/verify-bank")] [HttpPost("{id}/verify-bank")]
[SelfHosted(NotSelfHostedOnly = true)] [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); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) 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."); throw new BadRequestException("Your organization's Single Sign-On settings prevent you from leaving.");
} }
await _organizationService.DeleteUserAsync(orgGuidId, user.Id); await _organizationService.DeleteUserAsync(orgGuidId, user.Id);
} }
[HttpDelete("{id}")] [HttpDelete("{id}")]
[HttpPost("{id}/delete")] [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); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -452,7 +452,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id}/import")] [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 && if (!_globalSettings.SelfHosted && !model.LargeImport &&
(model.Groups.Count() > 2000 || model.Users.Count(u => !u.Deleted) > 2000)) (model.Groups.Count() > 2000 || model.Users.Count(u => !u.Deleted) > 2000))
@ -477,7 +477,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id}/api-key")] [HttpPost("{id}/api-key")]
public async Task<ApiKeyResponseModel> ApiKey(string id, [FromBody]SecretVerificationRequestModel model) public async Task<ApiKeyResponseModel> ApiKey(string id, [FromBody] SecretVerificationRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -510,7 +510,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id}/rotate-api-key")] [HttpPost("{id}/rotate-api-key")]
public async Task<ApiKeyResponseModel> RotateApiKey(string id, [FromBody]SecretVerificationRequestModel model) public async Task<ApiKeyResponseModel> RotateApiKey(string id, [FromBody] SecretVerificationRequestModel model)
{ {
var orgIdGuid = new Guid(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -565,7 +565,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id}/tax")] [HttpPut("{id}/tax")]
[SelfHosted(NotSelfHostedOnly = true)] [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); var orgIdGuid = new Guid(id);
if (!await _currentContext.OrganizationOwner(orgIdGuid)) if (!await _currentContext.OrganizationOwner(orgIdGuid))
@ -591,7 +591,7 @@ namespace Bit.Api.Controllers
}; };
await _paymentService.SaveTaxInfoAsync(organization, taxInfo); await _paymentService.SaveTaxInfoAsync(organization, taxInfo);
} }
[HttpGet("{id}/keys")] [HttpGet("{id}/keys")]
public async Task<OrganizationKeysResponseModel> GetKeys(string id) public async Task<OrganizationKeysResponseModel> GetKeys(string id)
{ {
@ -603,9 +603,9 @@ namespace Bit.Api.Controllers
return new OrganizationKeysResponseModel(org); return new OrganizationKeysResponseModel(org);
} }
[HttpPost("{id}/keys")] [HttpPost("{id}/keys")]
public async Task<OrganizationKeysResponseModel> PostKeys(string id, [FromBody]OrganizationKeysRequestModel model) public async Task<OrganizationKeysResponseModel> PostKeys(string id, [FromBody] OrganizationKeysRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -637,7 +637,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("{id:guid}/sso")] [HttpPost("{id:guid}/sso")]
public async Task<OrganizationSsoResponseModel> PostSso(Guid id, [FromBody]OrganizationSsoRequestModel model) public async Task<OrganizationSsoResponseModel> PostSso(Guid id, [FromBody] OrganizationSsoRequestModel model)
{ {
if (!await _currentContext.ManageSso(id)) if (!await _currentContext.ManageSso(id))
{ {

View File

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Authorization; using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;
using System.Linq;
using Bit.Core.Repositories;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Response; 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 namespace Bit.Api.Controllers
{ {

View File

@ -3,16 +3,16 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; 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.Context;
using Bit.Core.Enums; 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.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -83,8 +83,8 @@ namespace Bit.Api.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpGet("token")] [HttpGet("token")]
public async Task<ListResponseModel<PolicyResponseModel>> GetByToken(string orgId, [FromQuery]string email, public async Task<ListResponseModel<PolicyResponseModel>> GetByToken(string orgId, [FromQuery] string email,
[FromQuery]string token, [FromQuery]string organizationUserId) [FromQuery] string token, [FromQuery] string organizationUserId)
{ {
var orgUserId = new Guid(organizationUserId); var orgUserId = new Guid(organizationUserId);
var tokenValid = CoreHelpers.UserInviteTokenIsValid(_organizationServiceDataProtector, token, var tokenValid = CoreHelpers.UserInviteTokenIsValid(_organizationServiceDataProtector, token,
@ -107,7 +107,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("{type}")] [HttpPut("{type}")]
public async Task<PolicyResponseModel> Put(string orgId, int type, [FromBody]PolicyRequestModel model) public async Task<PolicyResponseModel> Put(string orgId, int type, [FromBody] PolicyRequestModel model)
{ {
var orgIdGuid = new Guid(orgId); var orgIdGuid = new Guid(orgId);
if (!await _currentContext.ManagePolicies(orgIdGuid)) if (!await _currentContext.ManagePolicies(orgIdGuid))

View File

@ -18,7 +18,7 @@ namespace Bit.Api.Controllers
[Authorize("Application")] [Authorize("Application")]
public class ProviderOrganizationsController : Controller public class ProviderOrganizationsController : Controller
{ {
private readonly IProviderOrganizationRepository _providerOrganizationRepository; private readonly IProviderOrganizationRepository _providerOrganizationRepository;
private readonly IProviderService _providerService; private readonly IProviderService _providerService;
private readonly IUserService _userService; private readonly IUserService _userService;
@ -35,7 +35,7 @@ namespace Bit.Api.Controllers
_userService = userService; _userService = userService;
_currentContext = currentContext; _currentContext = currentContext;
} }
[HttpGet("")] [HttpGet("")]
public async Task<ListResponseModel<ProviderOrganizationOrganizationDetailsResponseModel>> Get(Guid providerId) public async Task<ListResponseModel<ProviderOrganizationOrganizationDetailsResponseModel>> Get(Guid providerId)
{ {
@ -50,13 +50,13 @@ namespace Bit.Api.Controllers
} }
[HttpPost("add")] [HttpPost("add")]
public async Task Add(Guid providerId, [FromBody]ProviderOrganizationAddRequestModel model) public async Task Add(Guid providerId, [FromBody] ProviderOrganizationAddRequestModel model)
{ {
if (!_currentContext.ManageProviderOrganizations(providerId)) if (!_currentContext.ManageProviderOrganizations(providerId))
{ {
throw new NotFoundException(); throw new NotFoundException();
} }
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
await _providerService.AddOrganization(providerId, model.OrganizationId, userId, model.Key); await _providerService.AddOrganization(providerId, model.OrganizationId, userId, model.Key);

View File

@ -5,13 +5,13 @@ using System.Threading.Tasks;
using Bit.Api.Models.Request.Providers; using Bit.Api.Models.Request.Providers;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Bit.Api.Models.Response.Providers; 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.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business.Provider; 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 namespace Bit.Api.Controllers
{ {
@ -62,7 +62,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("invite")] [HttpPost("invite")]
public async Task Invite(Guid providerId, [FromBody]ProviderUserInviteRequestModel model) public async Task Invite(Guid providerId, [FromBody] ProviderUserInviteRequestModel model)
{ {
if (!_currentContext.ProviderManageUsers(providerId)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -73,9 +73,9 @@ namespace Bit.Api.Controllers
_userService.GetProperUserId(User).Value, providerId); _userService.GetProperUserId(User).Value, providerId);
await _providerService.InviteUserAsync(invite); await _providerService.InviteUserAsync(invite);
} }
[HttpPost("reinvite")] [HttpPost("reinvite")]
public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkReinvite(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkReinvite(Guid providerId, [FromBody] ProviderUserBulkRequestModel model)
{ {
if (!_currentContext.ProviderManageUsers(providerId)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -87,7 +87,7 @@ namespace Bit.Api.Controllers
return new ListResponseModel<ProviderUserBulkResponseModel>( return new ListResponseModel<ProviderUserBulkResponseModel>(
result.Select(t => new ProviderUserBulkResponseModel(t.Item1.Id, t.Item2))); result.Select(t => new ProviderUserBulkResponseModel(t.Item1.Id, t.Item2)));
} }
[HttpPost("{id:guid}/reinvite")] [HttpPost("{id:guid}/reinvite")]
public async Task Reinvite(Guid providerId, Guid id) public async Task Reinvite(Guid providerId, Guid id)
{ {
@ -96,13 +96,13 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
var invite = ProviderUserInviteFactory.CreateReinvite(new [] { id }, var invite = ProviderUserInviteFactory.CreateReinvite(new[] { id },
_userService.GetProperUserId(User).Value, providerId); _userService.GetProperUserId(User).Value, providerId);
await _providerService.ResendInvitesAsync(invite); await _providerService.ResendInvitesAsync(invite);
} }
[HttpPost("{id:guid}/accept")] [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); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -112,9 +112,9 @@ namespace Bit.Api.Controllers
await _providerService.AcceptUserAsync(id, user, model.Token); await _providerService.AcceptUserAsync(id, user, model.Token);
} }
[HttpPost("{id:guid}/confirm")] [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)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -127,7 +127,7 @@ namespace Bit.Api.Controllers
[HttpPost("confirm")] [HttpPost("confirm")]
public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkConfirm(Guid providerId, public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkConfirm(Guid providerId,
[FromBody]ProviderUserBulkConfirmRequestModel model) [FromBody] ProviderUserBulkConfirmRequestModel model)
{ {
if (!_currentContext.ProviderManageUsers(providerId)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -142,7 +142,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("public-keys")] [HttpPost("public-keys")]
public async Task<ListResponseModel<ProviderUserPublicKeyResponseModel>> UserPublicKeys(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) public async Task<ListResponseModel<ProviderUserPublicKeyResponseModel>> UserPublicKeys(Guid providerId, [FromBody] ProviderUserBulkRequestModel model)
{ {
if (!_currentContext.ProviderManageUsers(providerId)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -156,7 +156,7 @@ namespace Bit.Api.Controllers
[HttpPut("{id:guid}")] [HttpPut("{id:guid}")]
[HttpPost("{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)) if (!_currentContext.ProviderManageUsers(providerId))
{ {
@ -183,12 +183,12 @@ namespace Bit.Api.Controllers
} }
var userId = _userService.GetProperUserId(User); var userId = _userService.GetProperUserId(User);
await _providerService.DeleteUsersAsync(providerId, new [] { id }, userId.Value); await _providerService.DeleteUsersAsync(providerId, new[] { id }, userId.Value);
} }
[HttpDelete("")] [HttpDelete("")]
[HttpPost("delete")] [HttpPost("delete")]
public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkDelete(Guid providerId, [FromBody]ProviderUserBulkRequestModel model) public async Task<ListResponseModel<ProviderUserBulkResponseModel>> BulkDelete(Guid providerId, [FromBody] ProviderUserBulkRequestModel model)
{ {
if (!_currentContext.ProviderManageUsers(providerId)) if (!_currentContext.ProviderManageUsers(providerId))
{ {

View File

@ -31,7 +31,7 @@ namespace Bit.Api.Controllers
_currentContext = currentContext; _currentContext = currentContext;
_globalSettings = globalSettings; _globalSettings = globalSettings;
} }
[HttpGet("{id:guid}")] [HttpGet("{id:guid}")]
public async Task<ProviderResponseModel> Get(Guid id) public async Task<ProviderResponseModel> Get(Guid id)
{ {
@ -48,10 +48,10 @@ namespace Bit.Api.Controllers
return new ProviderResponseModel(provider); return new ProviderResponseModel(provider);
} }
[HttpPut("{id:guid}")] [HttpPut("{id:guid}")]
[HttpPost("{id:guid}")] [HttpPost("{id:guid}")]
public async Task<ProviderResponseModel> Put(Guid id, [FromBody]ProviderUpdateRequestModel model) public async Task<ProviderResponseModel> Put(Guid id, [FromBody] ProviderUpdateRequestModel model)
{ {
if (!_currentContext.ProviderProviderAdmin(id)) if (!_currentContext.ProviderProviderAdmin(id))
{ {
@ -67,9 +67,9 @@ namespace Bit.Api.Controllers
await _providerService.UpdateAsync(model.ToProvider(provider, _globalSettings)); await _providerService.UpdateAsync(model.ToProvider(provider, _globalSettings));
return new ProviderResponseModel(provider); return new ProviderResponseModel(provider);
} }
[HttpPost("{id:guid}/setup")] [HttpPost("{id:guid}/setup")]
public async Task<ProviderResponseModel> Setup(Guid id, [FromBody]ProviderSetupRequestModel model) public async Task<ProviderResponseModel> Setup(Guid id, [FromBody] ProviderSetupRequestModel model)
{ {
if (!_currentContext.ProviderProviderAdmin(id)) if (!_currentContext.ProviderProviderAdmin(id))
{ {
@ -81,9 +81,9 @@ namespace Bit.Api.Controllers
{ {
throw new NotFoundException(); throw new NotFoundException();
} }
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var response = var response =
await _providerService.CompleteSetupAsync(model.ToProvider(provider), userId, model.Token, model.Key); await _providerService.CompleteSetupAsync(model.ToProvider(provider), userId, model.Token, model.Key);

View File

@ -1,14 +1,14 @@
using Microsoft.AspNetCore.Mvc; using System.Linq;
using Bit.Core.Services; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Context; using Bit.Core.Context;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
using Bit.Core.Utilities; using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
@ -39,7 +39,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("register")] [HttpPost("register")]
public async Task PostRegister([FromBody]PushRegistrationRequestModel model) public async Task PostRegister([FromBody] PushRegistrationRequestModel model)
{ {
CheckUsage(); CheckUsage();
await _pushRegistrationService.CreateOrUpdateRegistrationAsync(model.PushToken, Prefix(model.DeviceId), await _pushRegistrationService.CreateOrUpdateRegistrationAsync(model.PushToken, Prefix(model.DeviceId),
@ -54,7 +54,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("add-organization")] [HttpPut("add-organization")]
public async Task PutAddOrganization([FromBody]PushUpdateRequestModel model) public async Task PutAddOrganization([FromBody] PushUpdateRequestModel model)
{ {
CheckUsage(); CheckUsage();
await _pushRegistrationService.AddUserRegistrationOrganizationAsync( await _pushRegistrationService.AddUserRegistrationOrganizationAsync(
@ -62,7 +62,7 @@ namespace Bit.Api.Controllers
} }
[HttpPut("delete-organization")] [HttpPut("delete-organization")]
public async Task PutDeleteOrganization([FromBody]PushUpdateRequestModel model) public async Task PutDeleteOrganization([FromBody] PushUpdateRequestModel model)
{ {
CheckUsage(); CheckUsage();
await _pushRegistrationService.DeleteUserRegistrationOrganizationAsync( await _pushRegistrationService.DeleteUserRegistrationOrganizationAsync(
@ -70,7 +70,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("send")] [HttpPost("send")]
public async Task PostSend([FromBody]PushSendRequestModel model) public async Task PostSend([FromBody] PushSendRequestModel model)
{ {
CheckUsage(); CheckUsage();

View File

@ -1,25 +1,25 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; 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 Azure.Messaging.EventGrid;
using Bit.Api.Utilities;
using System.Collections.Generic;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Bit.Core.Models.Table; using Bit.Api.Utilities;
using Newtonsoft.Json;
using Bit.Core.Models.Data;
using Microsoft.Extensions.Logging;
using Bit.Core; 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 namespace Bit.Api.Controllers
{ {

View File

@ -2,9 +2,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Bit.Core.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Bit.Core.Services;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -35,7 +35,7 @@ namespace Bit.Api.Controllers
[HttpPut("domains")] [HttpPut("domains")]
[HttpPost("domains")] [HttpPost("domains")]
public async Task<DomainsResponseModel> PutDomains([FromBody]UpdateDomainsRequestModel model) public async Task<DomainsResponseModel> PutDomains([FromBody] UpdateDomainsRequestModel model)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)

View File

@ -1,18 +1,18 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; 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.Authorization;
using Microsoft.AspNetCore.Mvc; 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 namespace Bit.Api.Controllers
{ {

View File

@ -1,23 +1,23 @@
using System; 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.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts; using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Bit.Api.Models.Response.TwoFactor; using Bit.Api.Models.Response.TwoFactor;
using Bit.Core.Context; using Bit.Core.Context;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Table;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Core.Utilities.Duo; using Bit.Core.Utilities.Duo;
using Bit.Core.Settings;
using Fido2NetLib; using Fido2NetLib;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -83,7 +83,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-authenticator")] [HttpPost("get-authenticator")]
public async Task<TwoFactorAuthenticatorResponseModel> GetAuthenticator([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorAuthenticatorResponseModel> GetAuthenticator([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
var response = new TwoFactorAuthenticatorResponseModel(user); var response = new TwoFactorAuthenticatorResponseModel(user);
@ -93,7 +93,7 @@ namespace Bit.Api.Controllers
[HttpPut("authenticator")] [HttpPut("authenticator")]
[HttpPost("authenticator")] [HttpPost("authenticator")]
public async Task<TwoFactorAuthenticatorResponseModel> PutAuthenticator( public async Task<TwoFactorAuthenticatorResponseModel> PutAuthenticator(
[FromBody]UpdateTwoFactorAuthenticatorRequestModel model) [FromBody] UpdateTwoFactorAuthenticatorRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
model.ToUser(user); model.ToUser(user);
@ -111,7 +111,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-yubikey")] [HttpPost("get-yubikey")]
public async Task<TwoFactorYubiKeyResponseModel> GetYubiKey([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorYubiKeyResponseModel> GetYubiKey([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
var response = new TwoFactorYubiKeyResponseModel(user); var response = new TwoFactorYubiKeyResponseModel(user);
@ -120,7 +120,7 @@ namespace Bit.Api.Controllers
[HttpPut("yubikey")] [HttpPut("yubikey")]
[HttpPost("yubikey")] [HttpPost("yubikey")]
public async Task<TwoFactorYubiKeyResponseModel> PutYubiKey([FromBody]UpdateTwoFactorYubicoOtpRequestModel model) public async Task<TwoFactorYubiKeyResponseModel> PutYubiKey([FromBody] UpdateTwoFactorYubicoOtpRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
model.ToUser(user); model.ToUser(user);
@ -137,7 +137,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-duo")] [HttpPost("get-duo")]
public async Task<TwoFactorDuoResponseModel> GetDuo([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorDuoResponseModel> GetDuo([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
var response = new TwoFactorDuoResponseModel(user); var response = new TwoFactorDuoResponseModel(user);
@ -146,7 +146,7 @@ namespace Bit.Api.Controllers
[HttpPut("duo")] [HttpPut("duo")]
[HttpPost("duo")] [HttpPost("duo")]
public async Task<TwoFactorDuoResponseModel> PutDuo([FromBody]UpdateTwoFactorDuoRequestModel model) public async Task<TwoFactorDuoResponseModel> PutDuo([FromBody] UpdateTwoFactorDuoRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
try try
@ -167,7 +167,7 @@ namespace Bit.Api.Controllers
[HttpPost("~/organizations/{id}/two-factor/get-duo")] [HttpPost("~/organizations/{id}/two-factor/get-duo")]
public async Task<TwoFactorDuoResponseModel> GetOrganizationDuo(string id, public async Task<TwoFactorDuoResponseModel> GetOrganizationDuo(string id,
[FromBody]SecretVerificationRequestModel model) [FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
@ -190,7 +190,7 @@ namespace Bit.Api.Controllers
[HttpPut("~/organizations/{id}/two-factor/duo")] [HttpPut("~/organizations/{id}/two-factor/duo")]
[HttpPost("~/organizations/{id}/two-factor/duo")] [HttpPost("~/organizations/{id}/two-factor/duo")]
public async Task<TwoFactorDuoResponseModel> PutOrganizationDuo(string id, public async Task<TwoFactorDuoResponseModel> PutOrganizationDuo(string id,
[FromBody]UpdateTwoFactorDuoRequestModel model) [FromBody] UpdateTwoFactorDuoRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
@ -224,7 +224,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-webauthn")] [HttpPost("get-webauthn")]
public async Task<TwoFactorWebAuthnResponseModel> GetWebAuthn([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorWebAuthnResponseModel> GetWebAuthn([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
var response = new TwoFactorWebAuthnResponseModel(user); var response = new TwoFactorWebAuthnResponseModel(user);
@ -232,7 +232,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-webauthn-challenge")] [HttpPost("get-webauthn-challenge")]
public async Task<CredentialCreateOptions> GetWebAuthnChallenge([FromBody]SecretVerificationRequestModel model) public async Task<CredentialCreateOptions> GetWebAuthnChallenge([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
var reg = await _userService.StartWebAuthnRegistrationAsync(user); var reg = await _userService.StartWebAuthnRegistrationAsync(user);
@ -241,7 +241,7 @@ namespace Bit.Api.Controllers
[HttpPut("webauthn")] [HttpPut("webauthn")]
[HttpPost("webauthn")] [HttpPost("webauthn")]
public async Task<TwoFactorWebAuthnResponseModel> PutWebAuthn([FromBody]TwoFactorWebAuthnRequestModel model) public async Task<TwoFactorWebAuthnResponseModel> PutWebAuthn([FromBody] TwoFactorWebAuthnRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
@ -256,7 +256,7 @@ namespace Bit.Api.Controllers
} }
[HttpDelete("webauthn")] [HttpDelete("webauthn")]
public async Task<TwoFactorWebAuthnResponseModel> DeleteWebAuthn([FromBody]TwoFactorWebAuthnDeleteRequestModel model) public async Task<TwoFactorWebAuthnResponseModel> DeleteWebAuthn([FromBody] TwoFactorWebAuthnDeleteRequestModel model)
{ {
var user = await CheckAsync(model, true); var user = await CheckAsync(model, true);
await _userService.DeleteWebAuthnKeyAsync(user, model.Id.Value); await _userService.DeleteWebAuthnKeyAsync(user, model.Id.Value);
@ -265,7 +265,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-email")] [HttpPost("get-email")]
public async Task<TwoFactorEmailResponseModel> GetEmail([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorEmailResponseModel> GetEmail([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
var response = new TwoFactorEmailResponseModel(user); var response = new TwoFactorEmailResponseModel(user);
@ -273,7 +273,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("send-email")] [HttpPost("send-email")]
public async Task SendEmail([FromBody]TwoFactorEmailRequestModel model) public async Task SendEmail([FromBody] TwoFactorEmailRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
model.ToUser(user); model.ToUser(user);
@ -282,7 +282,7 @@ namespace Bit.Api.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost("send-email-login")] [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()); var user = await _userManager.FindByEmailAsync(model.Email.ToLowerInvariant());
if (user != null) if (user != null)
@ -300,7 +300,7 @@ namespace Bit.Api.Controllers
[HttpPut("email")] [HttpPut("email")]
[HttpPost("email")] [HttpPost("email")]
public async Task<TwoFactorEmailResponseModel> PutEmail([FromBody]UpdateTwoFactorEmailRequestModel model) public async Task<TwoFactorEmailResponseModel> PutEmail([FromBody] UpdateTwoFactorEmailRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
model.ToUser(user); model.ToUser(user);
@ -319,7 +319,7 @@ namespace Bit.Api.Controllers
[HttpPut("disable")] [HttpPut("disable")]
[HttpPost("disable")] [HttpPost("disable")]
public async Task<TwoFactorProviderResponseModel> PutDisable([FromBody]TwoFactorProviderRequestModel model) public async Task<TwoFactorProviderResponseModel> PutDisable([FromBody] TwoFactorProviderRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
await _userService.DisableTwoFactorProviderAsync(user, model.Type.Value, _organizationService); await _userService.DisableTwoFactorProviderAsync(user, model.Type.Value, _organizationService);
@ -330,7 +330,7 @@ namespace Bit.Api.Controllers
[HttpPut("~/organizations/{id}/two-factor/disable")] [HttpPut("~/organizations/{id}/two-factor/disable")]
[HttpPost("~/organizations/{id}/two-factor/disable")] [HttpPost("~/organizations/{id}/two-factor/disable")]
public async Task<TwoFactorProviderResponseModel> PutOrganizationDisable(string id, public async Task<TwoFactorProviderResponseModel> PutOrganizationDisable(string id,
[FromBody]TwoFactorProviderRequestModel model) [FromBody] TwoFactorProviderRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
@ -352,7 +352,7 @@ namespace Bit.Api.Controllers
} }
[HttpPost("get-recover")] [HttpPost("get-recover")]
public async Task<TwoFactorRecoverResponseModel> GetRecover([FromBody]SecretVerificationRequestModel model) public async Task<TwoFactorRecoverResponseModel> GetRecover([FromBody] SecretVerificationRequestModel model)
{ {
var user = await CheckAsync(model, false); var user = await CheckAsync(model, false);
var response = new TwoFactorRecoverResponseModel(user); var response = new TwoFactorRecoverResponseModel(user);
@ -361,7 +361,7 @@ namespace Bit.Api.Controllers
[HttpPost("recover")] [HttpPost("recover")]
[AllowAnonymous] [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, if (!await _userService.RecoverTwoFactorAsync(model.Email, model.MasterPasswordHash, model.RecoveryCode,
_organizationService)) _organizationService))

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Response; using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc; using Bit.Core.Exceptions;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions; using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {

View File

@ -31,7 +31,7 @@ namespace Bit.Api.Jobs
.StartNow() .StartNow()
.WithCronSchedule("0 0 * * * ?") .WithCronSchedule("0 0 * * * ?")
.Build(); .Build();
var emergencyAccessTimeoutTrigger = TriggerBuilder.Create() var emergencyAccessTimeoutTrigger = TriggerBuilder.Create()
.WithIdentity("EmergencyAccessTimeoutTrigger") .WithIdentity("EmergencyAccessTimeoutTrigger")
.StartNow() .StartNow()
.WithCronSchedule("0 0 * * * ?") .WithCronSchedule("0 0 * * * ?")

View File

@ -12,7 +12,7 @@ namespace Bit.Api.Models
FileName = data.FileName; FileName = data.FileName;
Key = data.Key; Key = data.Key;
} }
[EncryptedStringLength(1000)] [EncryptedStringLength(1000)]
public string FileName { get; set; } public string FileName { get; set; }
[EncryptedStringLength(1000)] [EncryptedStringLength(1000)]

View File

@ -16,7 +16,7 @@ namespace Bit.Api.Models.Public
{ {
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
Type = user.Type; Type = user.Type;
AccessAll = user.AccessAll; AccessAll = user.AccessAll;
ExternalId = user.ExternalId; ExternalId = user.ExternalId;
@ -29,7 +29,7 @@ namespace Bit.Api.Models.Public
{ {
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
} }
Type = user.Type; Type = user.Type;
AccessAll = user.AccessAll; AccessAll = user.AccessAll;
ExternalId = user.ExternalId; ExternalId = user.ExternalId;

View File

@ -9,7 +9,7 @@ namespace Bit.Api.Models.Request.Accounts
public string Country { get; set; } public string Country { get; set; }
public string PostalCode { get; set; } public string PostalCode { get; set; }
public virtual IEnumerable<ValidationResult> Validate (ValidationContext validationContext) public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{ {
if (Country == "US" && string.IsNullOrWhiteSpace(PostalCode)) if (Country == "US" && string.IsNullOrWhiteSpace(PostalCode))
{ {

View File

@ -1,4 +1,4 @@
namespace Bit.Api.Models.Request namespace Bit.Api.Models.Request
{ {
public class AttachmentRequestModel public class AttachmentRequestModel
{ {

View File

@ -10,7 +10,7 @@ namespace Bit.Api.Models.Request.Organizations
public string PublicKey { get; set; } public string PublicKey { get; set; }
[Required] [Required]
public string EncryptedPrivateKey { get; set; } public string EncryptedPrivateKey { get; set; }
public OrganizationSignup ToOrganizationSignup(OrganizationSignup existingSignup) public OrganizationSignup ToOrganizationSignup(OrganizationSignup existingSignup)
{ {
if (string.IsNullOrWhiteSpace(existingSignup.PublicKey)) if (string.IsNullOrWhiteSpace(existingSignup.PublicKey))
@ -25,7 +25,7 @@ namespace Bit.Api.Models.Request.Organizations
return existingSignup; return existingSignup;
} }
public OrganizationUpgrade ToOrganizationUpgrade(OrganizationUpgrade existingUpgrade) public OrganizationUpgrade ToOrganizationUpgrade(OrganizationUpgrade existingUpgrade)
{ {
if (string.IsNullOrWhiteSpace(existingUpgrade.PublicKey)) if (string.IsNullOrWhiteSpace(existingUpgrade.PublicKey))

View File

@ -1,4 +1,4 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums; using Bit.Core.Enums;

View File

@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Utilities; using Bit.Core.Utilities;

View File

@ -37,7 +37,7 @@ namespace Bit.Api.Models.Request.Organizations
public class SsoConfigurationDataRequest : IValidatableObject public class SsoConfigurationDataRequest : IValidatableObject
{ {
public SsoConfigurationDataRequest() {} public SsoConfigurationDataRequest() { }
[Required] [Required]
public SsoType ConfigType { get; set; } public SsoType ConfigType { get; set; }

View File

@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Bit.Api.Models.Request.Organizations namespace Bit.Api.Models.Request.Organizations
{ {

View File

@ -90,7 +90,7 @@ namespace Bit.Api.Models.Request.Organizations
[Required] [Required]
public IEnumerable<string> GroupIds { get; set; } public IEnumerable<string> GroupIds { get; set; }
} }
public class OrganizationUserResetPasswordEnrollmentRequestModel public class OrganizationUserResetPasswordEnrollmentRequestModel
{ {
public string ResetPasswordKey { get; set; } public string ResetPasswordKey { get; set; }

View File

@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Api.Models.Request.Organizations; using Bit.Api.Models.Request.Organizations;
using Bit.Core.Utilities; using Bit.Core.Utilities;

View File

@ -1,4 +1,4 @@
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response namespace Bit.Api.Models.Response

View File

@ -114,7 +114,7 @@ namespace Bit.Api.Models.Response
KeyEncrypted = emergencyAccess.KeyEncrypted; KeyEncrypted = emergencyAccess.KeyEncrypted;
Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings)); Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings));
} }
public string KeyEncrypted { get; set; } public string KeyEncrypted { get; set; }
public IEnumerable<CipherResponseModel> Ciphers { get; set; } public IEnumerable<CipherResponseModel> Ciphers { get; set; }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response namespace Bit.Api.Models.Response
@ -10,7 +10,7 @@ namespace Bit.Api.Models.Response
Id = orgId.ToString(); Id = orgId.ToString();
ResetPasswordEnabled = resetPasswordEnabled; ResetPasswordEnabled = resetPasswordEnabled;
} }
public string Id { get; set; } public string Id { get; set; }
public bool ResetPasswordEnabled { get; set; } public bool ResetPasswordEnabled { get; set; }
} }

View File

@ -12,11 +12,11 @@ namespace Bit.Api.Models.Response
{ {
throw new ArgumentNullException(nameof(org)); throw new ArgumentNullException(nameof(org));
} }
PublicKey = org.PublicKey; PublicKey = org.PublicKey;
PrivateKey = org.PrivateKey; PrivateKey = org.PrivateKey;
} }
public string PublicKey { get; set; } public string PublicKey { get; set; }
public string PrivateKey { get; set; } public string PrivateKey { get; set; }
} }

View File

@ -108,7 +108,7 @@ namespace Bit.Api.Models.Response
ResetPasswordKey = orgUser.ResetPasswordKey; ResetPasswordKey = orgUser.ResetPasswordKey;
EncryptedPrivateKey = orgUser.EncryptedPrivateKey; EncryptedPrivateKey = orgUser.EncryptedPrivateKey;
} }
public KdfType Kdf { get; set; } public KdfType Kdf { get; set; }
public int KdfIterations { get; set; } public int KdfIterations { get; set; }
public string ResetPasswordKey { get; set; } public string ResetPasswordKey { get; set; }

View File

@ -1,4 +1,4 @@
using System; using System;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
using Bit.Core.Models.StaticStore; using Bit.Core.Models.StaticStore;

View File

@ -7,7 +7,7 @@ namespace Bit.Api.Models.Response
{ {
public class ProfileOrganizationResponseModel : ResponseModel public class ProfileOrganizationResponseModel : ResponseModel
{ {
public ProfileOrganizationResponseModel(string str) : base(str) {} public ProfileOrganizationResponseModel(string str) : base(str) { }
public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization") public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization")
{ {
@ -45,7 +45,7 @@ namespace Bit.Api.Models.Response
StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise) StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise)
.UsersCanSponsor(organization); .UsersCanSponsor(organization);
PlanProductType = StaticStore.GetPlan(organization.PlanType).Product; PlanProductType = StaticStore.GetPlan(organization.PlanType).Product;
if (organization.SsoConfig != null) if (organization.SsoConfig != null)
{ {
var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig); var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig);

View File

@ -14,7 +14,7 @@ namespace Bit.Api.Models.Response.Providers
{ {
throw new ArgumentNullException(nameof(providerOrganization)); throw new ArgumentNullException(nameof(providerOrganization));
} }
Id = providerOrganization.Id; Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId; ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId; OrganizationId = providerOrganization.OrganizationId;
@ -31,7 +31,7 @@ namespace Bit.Api.Models.Response.Providers
{ {
throw new ArgumentNullException(nameof(providerOrganization)); throw new ArgumentNullException(nameof(providerOrganization));
} }
Id = providerOrganization.Id; Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId; ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId; OrganizationId = providerOrganization.OrganizationId;
@ -40,7 +40,7 @@ namespace Bit.Api.Models.Response.Providers
CreationDate = providerOrganization.CreationDate; CreationDate = providerOrganization.CreationDate;
RevisionDate = providerOrganization.RevisionDate; RevisionDate = providerOrganization.RevisionDate;
} }
public Guid Id { get; set; } public Guid Id { get; set; }
public Guid ProviderId { get; set; } public Guid ProviderId { get; set; }
public Guid OrganizationId { get; set; } public Guid OrganizationId { get; set; }
@ -49,7 +49,7 @@ namespace Bit.Api.Models.Response.Providers
public DateTime CreationDate { get; set; } public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; } public DateTime RevisionDate { get; set; }
} }
public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel
{ {
public ProviderOrganizationOrganizationDetailsResponseModel(ProviderOrganizationOrganizationDetails providerOrganization, public ProviderOrganizationOrganizationDetailsResponseModel(ProviderOrganizationOrganizationDetails providerOrganization,
@ -62,7 +62,7 @@ namespace Bit.Api.Models.Response.Providers
OrganizationName = providerOrganization.OrganizationName; OrganizationName = providerOrganization.OrganizationName;
} }
public string OrganizationName { get; set; } public string OrganizationName { get; set; }
} }
} }

View File

@ -23,7 +23,7 @@ namespace Bit.Api.Models.Response.Providers
BusinessTaxNumber = provider.BusinessTaxNumber; BusinessTaxNumber = provider.BusinessTaxNumber;
BillingEmail = provider.BillingEmail; BillingEmail = provider.BillingEmail;
} }
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string BusinessName { get; set; } public string BusinessName { get; set; }

View File

@ -23,7 +23,7 @@ namespace Bit.Api.Models.Response.Providers
Status = providerUser.Status; Status = providerUser.Status;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions); Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions);
} }
public ProviderUserResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUser") public ProviderUserResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUser")
: base(obj) : base(obj)
{ {
@ -48,7 +48,7 @@ namespace Bit.Api.Models.Response.Providers
public class ProviderUserUserDetailsResponseModel : ProviderUserResponseModel public class ProviderUserUserDetailsResponseModel : ProviderUserResponseModel
{ {
public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser, public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser,
string obj = "providerUserUserDetails") : base(providerUser, obj) string obj = "providerUserUserDetails") : base(providerUser, obj)
{ {
if (providerUser == null) if (providerUser == null)

View File

@ -1,4 +1,4 @@
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response namespace Bit.Api.Models.Response
{ {

View File

@ -1,4 +1,4 @@
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response namespace Bit.Api.Models.Response
@ -6,7 +6,7 @@ namespace Bit.Api.Models.Response
public class SendFileUploadDataResponseModel : ResponseModel public class SendFileUploadDataResponseModel : ResponseModel
{ {
public SendFileUploadDataResponseModel() : base("send-fileUpload") { } public SendFileUploadDataResponseModel() : base("send-fileUpload") { }
public string Url { get; set; } public string Url { get; set; }
public FileUploadType FileUploadType { get; set; } public FileUploadType FileUploadType { get; set; }
public SendResponseModel SendResponse { get; set; } public SendResponseModel SendResponse { get; set; }

View File

@ -1,4 +1,4 @@
using System; using System;
using Bit.Core.Models.Api; using Bit.Core.Models.Api;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Hosting; using AspNetCoreRateLimit;
using Microsoft.Extensions.Hosting;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Serilog.Events; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using AspNetCoreRateLimit; using Serilog.Events;
namespace Bit.Api namespace Bit.Api
{ {

View File

@ -85,7 +85,7 @@ namespace Bit.Api.Public.Controllers
[ProducesResponseType(typeof(CollectionResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(CollectionResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Put(Guid id, [FromBody]CollectionUpdateRequestModel model) public async Task<IActionResult> Put(Guid id, [FromBody] CollectionUpdateRequestModel model)
{ {
var existingCollection = await _collectionRepository.GetByIdAsync(id); var existingCollection = await _collectionRepository.GetByIdAsync(id);
if (existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId) if (existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId)

View File

@ -39,7 +39,7 @@ namespace Bit.Api.Public.Controllers
/// </remarks> /// </remarks>
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(ListResponseModel<EventResponseModel>), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ListResponseModel<EventResponseModel>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> List([FromQuery]EventFilterRequestModel request) public async Task<IActionResult> List([FromQuery] EventFilterRequestModel request)
{ {
var dateRange = request.ToDateRange(); var dateRange = request.ToDateRange();
var result = new PagedResult<IEvent>(); var result = new PagedResult<IEvent>();

View File

@ -104,7 +104,7 @@ namespace Bit.Api.Public.Controllers
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(GroupResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(GroupResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Post([FromBody]GroupCreateUpdateRequestModel model) public async Task<IActionResult> Post([FromBody] GroupCreateUpdateRequestModel model)
{ {
var group = model.ToGroup(_currentContext.OrganizationId.Value); var group = model.ToGroup(_currentContext.OrganizationId.Value);
var associations = model.Collections?.Select(c => c.ToSelectionReadOnly()); 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(GroupResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Put(Guid id, [FromBody]GroupCreateUpdateRequestModel model) public async Task<IActionResult> Put(Guid id, [FromBody] GroupCreateUpdateRequestModel model)
{ {
var existingGroup = await _groupRepository.GetByIdAsync(id); var existingGroup = await _groupRepository.GetByIdAsync(id);
if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId) if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)
@ -152,7 +152,7 @@ namespace Bit.Api.Public.Controllers
[ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> PutMemberIds(Guid id, [FromBody]UpdateMemberIdsRequestModel model) public async Task<IActionResult> PutMemberIds(Guid id, [FromBody] UpdateMemberIdsRequestModel model)
{ {
var existingGroup = await _groupRepository.GetByIdAsync(id); var existingGroup = await _groupRepository.GetByIdAsync(id);
if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId) if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)

View File

@ -115,7 +115,7 @@ namespace Bit.Api.Public.Controllers
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Post([FromBody]MemberCreateRequestModel model) public async Task<IActionResult> Post([FromBody] MemberCreateRequestModel model)
{ {
var associations = model.Collections?.Select(c => c.ToSelectionReadOnly()); var associations = model.Collections?.Select(c => c.ToSelectionReadOnly());
var invite = new OrganizationUserInvite var invite = new OrganizationUserInvite
@ -144,7 +144,7 @@ namespace Bit.Api.Public.Controllers
[ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Put(Guid id, [FromBody]MemberUpdateRequestModel model) public async Task<IActionResult> Put(Guid id, [FromBody] MemberUpdateRequestModel model)
{ {
var existingUser = await _organizationUserRepository.GetByIdAsync(id); var existingUser = await _organizationUserRepository.GetByIdAsync(id);
if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId) if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
@ -180,7 +180,7 @@ namespace Bit.Api.Public.Controllers
[ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> PutGroupIds(Guid id, [FromBody]UpdateGroupIdsRequestModel model) public async Task<IActionResult> PutGroupIds(Guid id, [FromBody] UpdateGroupIdsRequestModel model)
{ {
var existingUser = await _organizationUserRepository.GetByIdAsync(id); var existingUser = await _organizationUserRepository.GetByIdAsync(id);
if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId) if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)

View File

@ -40,7 +40,7 @@ namespace Bit.Api.Public.Controllers
[HttpPost("import")] [HttpPost("import")]
[ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(MemberResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Import([FromBody]OrganizationImportRequestModel model) public async Task<IActionResult> Import([FromBody] OrganizationImportRequestModel model)
{ {
if (!_globalSettings.SelfHosted && !model.LargeImport && if (!_globalSettings.SelfHosted && !model.LargeImport &&
(model.Groups.Count() > 2000 || model.Members.Count(u => !u.Deleted) > 2000)) (model.Groups.Count() > 2000 || model.Members.Count(u => !u.Deleted) > 2000))

View File

@ -88,7 +88,7 @@ namespace Bit.Api.Public.Controllers
[ProducesResponseType(typeof(PolicyResponseModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(PolicyResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Put(PolicyType type, [FromBody]PolicyUpdateRequestModel model) public async Task<IActionResult> Put(PolicyType type, [FromBody] PolicyUpdateRequestModel model)
{ {
var policy = await _policyRepository.GetByOrganizationIdTypeAsync( var policy = await _policyRepository.GetByOrganizationIdTypeAsync(
_currentContext.OrganizationId.Value, type); _currentContext.OrganizationId.Value, type);

View File

@ -122,11 +122,11 @@ namespace Bit.Api
services.AddDefaultServices(globalSettings); services.AddDefaultServices(globalSettings);
services.AddCoreLocalizationServices(); services.AddCoreLocalizationServices();
#if OSS #if OSS
services.AddOosServices(); services.AddOosServices();
#else #else
services.AddCommCoreServices(); services.AddCommCoreServices();
#endif #endif
// MVC // MVC
services.AddMvc(config => services.AddMvc(config =>

View File

@ -1,13 +1,13 @@
using Bit.Core.Utilities; using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Azure.Messaging.EventGrid;
using Azure.Messaging.EventGrid.SystemEvents;
using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; 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 namespace Bit.Api.Utilities
{ {

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.Filters; using System;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
namespace Bit.Api.Utilities namespace Bit.Api.Utilities
{ {

View File

@ -1,15 +1,15 @@
using System; using System;
using Bit.Api.Models.Public.Response; using Bit.Api.Models.Public.Response;
using InternalApi = Bit.Core.Models.Api;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Stripe; using Stripe;
using Microsoft.Extensions.Hosting; using InternalApi = Bit.Core.Models.Api;
namespace Bit.Api.Utilities namespace Bit.Api.Utilities
{ {

View File

@ -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 Microsoft.AspNetCore.Mvc.Filters;
using InternalApi = Bit.Core.Models.Api; using InternalApi = Bit.Core.Models.Api;
using System.Linq;
using Bit.Api.Models.Public.Response;
namespace Bit.Api.Utilities namespace Bit.Api.Utilities
{ {

View File

@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Http; using System;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Net.Http.Headers;
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Api.Models.Request; using Bit.Api.Models.Request;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Bit.Api.Utilities namespace Bit.Api.Utilities

View File

@ -53,7 +53,7 @@ namespace Bit.Api.Utilities
{ {
new OpenApiSecurityScheme new OpenApiSecurityScheme
{ {
Reference = new OpenApiReference Reference = new OpenApiReference
{ {
Type = ReferenceType.SecurityScheme, Type = ReferenceType.SecurityScheme,
Id = "OAuth2 Client Credentials" Id = "OAuth2 Client Credentials"

View File

@ -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 Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Billing.Controllers namespace Bit.Billing.Controllers
{ {

View File

@ -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.Enums;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
@ -6,11 +11,6 @@ using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
namespace Bit.Billing.Controllers namespace Bit.Billing.Controllers
{ {

View File

@ -1,20 +1,19 @@
using Bit.Core.Repositories; using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations; using Bit.Core.Repositories;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace Bit.Billing.Controllers namespace Bit.Billing.Controllers
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Billing.Controllers namespace Bit.Billing.Controllers
{ {
@ -12,7 +12,7 @@ namespace Bit.Billing.Controllers
{ {
return DateTime.UtcNow; return DateTime.UtcNow;
} }
[HttpGet("~/version")] [HttpGet("~/version")]
public JsonResult GetVersion() public JsonResult GetVersion()
{ {

View File

@ -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.Enums;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Repositories; using Bit.Core.Repositories;
@ -7,10 +11,6 @@ using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Billing.Controllers namespace Bit.Billing.Controllers
{ {
@ -183,7 +183,7 @@ namespace Bit.Billing.Controllers
} }
} }
// Catch foreign key violations because user/org could have been deleted. // 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") else if (ipnTransaction.PaymentStatus == "Refunded" || ipnTransaction.PaymentStatus == "Reversed")
{ {

Some files were not shown because too many files have changed in this diff Show More