mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Changed all C# control flow block statements to include space between keyword and open paren
This commit is contained in:
@ -53,7 +53,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PreloginResponseModel> PostPrelogin([FromBody]PreloginRequestModel model)
|
||||
{
|
||||
var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email);
|
||||
if(kdfInformation == null)
|
||||
if (kdfInformation == null)
|
||||
{
|
||||
kdfInformation = new UserKdfInformation
|
||||
{
|
||||
@ -70,12 +70,12 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var result = await _userService.RegisterUserAsync(model.ToUser(), model.MasterPasswordHash,
|
||||
model.Token, model.OrganizationUserId);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors.Where(e => e.Code != "DuplicateUserName"))
|
||||
foreach (var error in result.Errors.Where(e => e.Code != "DuplicateUserName"))
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -95,12 +95,12 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostEmailToken([FromBody]EmailTokenRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
@ -113,19 +113,19 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostEmail([FromBody]EmailRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var result = await _userService.ChangeEmailAsync(user, model.MasterPasswordHash, model.NewEmail,
|
||||
model.NewMasterPasswordHash, model.Token, model.Key);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -138,7 +138,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostVerifyEmail()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -151,17 +151,17 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostVerifyEmailToken([FromBody]VerifyEmailRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByIdAsync(new Guid(model.UserId));
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
var result = await _userService.ConfirmEmailAsync(user, model.Token);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -174,19 +174,19 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostPassword([FromBody]PasswordRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var result = await _userService.ChangePasswordAsync(user, model.MasterPasswordHash,
|
||||
model.NewMasterPasswordHash, model.Key);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -199,19 +199,19 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostKdf([FromBody]KdfRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var result = await _userService.ChangeKdfAsync(user, model.MasterPasswordHash,
|
||||
model.NewMasterPasswordHash, model.Key, model.Kdf.Value, model.KdfIterations.Value);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -224,7 +224,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostKey([FromBody]UpdateKeyRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -232,9 +232,9 @@ namespace Bit.Api.Controllers
|
||||
var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
|
||||
var ciphersDict = model.Ciphers?.ToDictionary(c => c.Id.Value);
|
||||
var ciphers = new List<Cipher>();
|
||||
if(existingCiphers.Any() && ciphersDict != null)
|
||||
if (existingCiphers.Any() && ciphersDict != null)
|
||||
{
|
||||
foreach(var cipher in existingCiphers.Where(c => ciphersDict.ContainsKey(c.Id)))
|
||||
foreach (var cipher in existingCiphers.Where(c => ciphersDict.ContainsKey(c.Id)))
|
||||
{
|
||||
ciphers.Add(ciphersDict[cipher.Id].ToCipher(cipher));
|
||||
}
|
||||
@ -243,9 +243,9 @@ namespace Bit.Api.Controllers
|
||||
var existingFolders = await _folderRepository.GetManyByUserIdAsync(user.Id);
|
||||
var foldersDict = model.Folders?.ToDictionary(f => f.Id);
|
||||
var folders = new List<Folder>();
|
||||
if(existingFolders.Any() && foldersDict != null)
|
||||
if (existingFolders.Any() && foldersDict != null)
|
||||
{
|
||||
foreach(var folder in existingFolders.Where(f => foldersDict.ContainsKey(f.Id)))
|
||||
foreach (var folder in existingFolders.Where(f => foldersDict.ContainsKey(f.Id)))
|
||||
{
|
||||
folders.Add(foldersDict[folder.Id].ToFolder(folder));
|
||||
}
|
||||
@ -259,12 +259,12 @@ namespace Bit.Api.Controllers
|
||||
ciphers,
|
||||
folders);
|
||||
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -277,18 +277,18 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostSecurityStamp([FromBody]SecurityStampRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var result = await _userService.RefreshSecurityStampAsync(user, model.MasterPasswordHash);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -301,7 +301,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ProfileResponseModel> GetProfile()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -328,7 +328,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ProfileResponseModel> PutProfile([FromBody]UpdateProfileRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -343,7 +343,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User);
|
||||
long? revisionDate = null;
|
||||
if(userId.HasValue)
|
||||
if (userId.HasValue)
|
||||
{
|
||||
var date = await _userService.GetAccountRevisionDateByIdAsync(userId.Value);
|
||||
revisionDate = CoreHelpers.ToEpocMilliseconds(date);
|
||||
@ -356,7 +356,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<KeysResponseModel> PostKeys([FromBody]KeysRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -369,7 +369,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<KeysResponseModel> GetKeys()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -382,12 +382,12 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete([FromBody]DeleteAccountRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
ModelState.AddModelError("MasterPasswordHash", "Invalid password.");
|
||||
await Task.Delay(2000);
|
||||
@ -395,12 +395,12 @@ namespace Bit.Api.Controllers
|
||||
else
|
||||
{
|
||||
var result = await _userService.DeleteAsync(user);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -421,18 +421,18 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostDeleteRecoverToken([FromBody]VerifyDeleteRecoverRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByIdAsync(new Guid(model.UserId));
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var result = await _userService.DeleteAsync(user, model.Token);
|
||||
if(result.Succeeded)
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var error in result.Errors)
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError(string.Empty, error.Description);
|
||||
}
|
||||
@ -445,7 +445,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostIapCheck([FromBody]IapCheckRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -456,19 +456,19 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PaymentResponseModel> PostPremium(PremiumRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var valid = model.Validate(_globalSettings);
|
||||
UserLicense license = null;
|
||||
if(valid && _globalSettings.SelfHosted)
|
||||
if (valid && _globalSettings.SelfHosted)
|
||||
{
|
||||
license = await ApiHelpers.ReadJsonFileFromBody<UserLicense>(HttpContext, model.License);
|
||||
}
|
||||
|
||||
if(!valid || (_globalSettings.SelfHosted && license == null))
|
||||
if (!valid || (_globalSettings.SelfHosted && license == null))
|
||||
{
|
||||
throw new BadRequestException("Invalid license.");
|
||||
}
|
||||
@ -489,7 +489,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<BillingResponseModel> GetBilling()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -502,18 +502,18 @@ namespace Bit.Api.Controllers
|
||||
public async Task<SubscriptionResponseModel> GetSubscription()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!_globalSettings.SelfHosted && user.Gateway != null)
|
||||
if (!_globalSettings.SelfHosted && user.Gateway != null)
|
||||
{
|
||||
var subscriptionInfo = await _paymentService.GetSubscriptionAsync(user);
|
||||
var license = await _userService.GenerateLicenseAsync(user, subscriptionInfo);
|
||||
return new SubscriptionResponseModel(user, subscriptionInfo, license);
|
||||
}
|
||||
else if(!_globalSettings.SelfHosted)
|
||||
else if (!_globalSettings.SelfHosted)
|
||||
{
|
||||
var license = await _userService.GenerateLicenseAsync(user);
|
||||
return new SubscriptionResponseModel(user, license);
|
||||
@ -529,7 +529,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostPayment([FromBody]PaymentRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -542,7 +542,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PaymentResponseModel> PostStorage([FromBody]StorageRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -560,13 +560,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostLicense(LicenseRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var license = await ApiHelpers.ReadJsonFileFromBody<UserLicense>(HttpContext, model.License);
|
||||
if(license == null)
|
||||
if (license == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid license");
|
||||
}
|
||||
@ -579,7 +579,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostCancel()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -592,7 +592,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostReinstate()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -59,7 +59,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<CipherMiniResponseModel> GetAdmin(string id)
|
||||
{
|
||||
var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id));
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -75,7 +75,7 @@ namespace Bit.Api.Controllers
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipherId = new Guid(id);
|
||||
var cipher = await _cipherRepository.GetByIdAsync(cipherId, userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace Bit.Api.Controllers
|
||||
// TODO: Use hasOrgs proper for cipher listing here?
|
||||
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, true || hasOrgs);
|
||||
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
|
||||
if(hasOrgs)
|
||||
if (hasOrgs)
|
||||
{
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
|
||||
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
|
||||
@ -108,7 +108,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = model.ToCipherDetails(userId);
|
||||
if(cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value))
|
||||
if (cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -123,7 +123,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = model.Cipher.ToCipherDetails(userId);
|
||||
if(cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value))
|
||||
if (cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -137,7 +137,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<CipherMiniResponseModel> PostAdmin([FromBody]CipherCreateRequestModel model)
|
||||
{
|
||||
var cipher = model.Cipher.ToOrganizationCipher();
|
||||
if(!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
if (!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -155,14 +155,14 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ?
|
||||
(Guid?)null : new Guid(model.OrganizationId);
|
||||
if(cipher.OrganizationId != modelOrgId)
|
||||
if (cipher.OrganizationId != modelOrgId)
|
||||
{
|
||||
throw new BadRequestException("Organization mismatch. Re-sync if you recently shared this item, " +
|
||||
"then try again.");
|
||||
@ -180,7 +180,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id));
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -200,7 +200,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var orgIdGuid = new Guid(organizationId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -218,7 +218,7 @@ namespace Bit.Api.Controllers
|
||||
[HttpPost("import")]
|
||||
public async Task PostImport([FromBody]ImportCiphersRequestModel model)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted &&
|
||||
if (!_globalSettings.SelfHosted &&
|
||||
(model.Ciphers.Count() > 6000 || model.FolderRelationships.Count() > 6000 ||
|
||||
model.Folders.Count() > 1000))
|
||||
{
|
||||
@ -235,7 +235,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostImport([FromQuery]string organizationId,
|
||||
[FromBody]ImportOrganizationCiphersRequestModel model)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted &&
|
||||
if (!_globalSettings.SelfHosted &&
|
||||
(model.Ciphers.Count() > 6000 || model.CollectionRelationships.Count() > 12000 ||
|
||||
model.Collections.Count() > 1000))
|
||||
{
|
||||
@ -243,7 +243,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
var orgId = new Guid(organizationId);
|
||||
if(!_currentContext.OrganizationAdmin(orgId))
|
||||
if (!_currentContext.OrganizationAdmin(orgId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -270,7 +270,7 @@ namespace Bit.Api.Controllers
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipherId = new Guid(id);
|
||||
var cipher = await _cipherRepository.GetByIdAsync(cipherId);
|
||||
if(cipher == null || cipher.UserId != userId ||
|
||||
if (cipher == null || cipher.UserId != userId ||
|
||||
!_currentContext.OrganizationUser(new Guid(model.Cipher.OrganizationId)))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -291,7 +291,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationUser(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -307,7 +307,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -323,7 +323,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -337,7 +337,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -350,7 +350,7 @@ namespace Bit.Api.Controllers
|
||||
[HttpPost("delete")]
|
||||
public async Task DeleteMany([FromBody]CipherBulkDeleteRequestModel model)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
{
|
||||
throw new BadRequestException("You can only delete up to 500 items at a time. " +
|
||||
"Consider using the \"Purge Vault\" option instead.");
|
||||
@ -364,7 +364,7 @@ namespace Bit.Api.Controllers
|
||||
[HttpPost("move")]
|
||||
public async Task MoveMany([FromBody]CipherBulkMoveRequestModel model)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
{
|
||||
throw new BadRequestException("You can only move up to 500 items at a time.");
|
||||
}
|
||||
@ -379,7 +379,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PutShareMany([FromBody]CipherBulkShareRequestModel model)
|
||||
{
|
||||
var organizationId = new Guid(model.Ciphers.First().OrganizationId);
|
||||
if(!_currentContext.OrganizationUser(organizationId))
|
||||
if (!_currentContext.OrganizationUser(organizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -389,9 +389,9 @@ namespace Bit.Api.Controllers
|
||||
var ciphersDict = ciphers.ToDictionary(c => c.Id);
|
||||
|
||||
var shareCiphers = new List<Cipher>();
|
||||
foreach(var cipher in model.Ciphers)
|
||||
foreach (var cipher in model.Ciphers)
|
||||
{
|
||||
if(!ciphersDict.ContainsKey(cipher.Id.Value))
|
||||
if (!ciphersDict.ContainsKey(cipher.Id.Value))
|
||||
{
|
||||
throw new BadRequestException("Trying to share ciphers that you do not own.");
|
||||
}
|
||||
@ -407,26 +407,26 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostPurge([FromBody]CipherPurgeRequestModel model, string organizationId = null)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
ModelState.AddModelError("MasterPasswordHash", "Invalid password.");
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException(ModelState);
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(organizationId))
|
||||
if (string.IsNullOrWhiteSpace(organizationId))
|
||||
{
|
||||
await _cipherRepository.DeleteByUserIdAsync(user.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
var orgId = new Guid(organizationId);
|
||||
if(!_currentContext.OrganizationAdmin(orgId))
|
||||
if (!_currentContext.OrganizationAdmin(orgId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -444,7 +444,7 @@ namespace Bit.Api.Controllers
|
||||
var idGuid = new Guid(id);
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(idGuid, userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -468,7 +468,7 @@ namespace Bit.Api.Controllers
|
||||
var idGuid = new Guid(id);
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(idGuid);
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -492,7 +492,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
|
||||
if(cipher == null || cipher.UserId != userId || !_currentContext.OrganizationUser(organizationId))
|
||||
if (cipher == null || cipher.UserId != userId || !_currentContext.OrganizationUser(organizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -511,7 +511,7 @@ namespace Bit.Api.Controllers
|
||||
var idGuid = new Guid(id);
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(idGuid, userId);
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -526,7 +526,7 @@ namespace Bit.Api.Controllers
|
||||
var idGuid = new Guid(id);
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(idGuid);
|
||||
if(cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
if (cipher == null || !cipher.OrganizationId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -537,12 +537,12 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private void ValidateAttachment()
|
||||
{
|
||||
if(!Request?.ContentType.Contains("multipart/") ?? true)
|
||||
if (!Request?.ContentType.Contains("multipart/") ?? true)
|
||||
{
|
||||
throw new BadRequestException("Invalid content.");
|
||||
}
|
||||
|
||||
if(Request.ContentLength > 105906176) // 101 MB, give em' 1 extra MB for cushion
|
||||
if (Request.ContentLength > 105906176) // 101 MB, give em' 1 extra MB for cushion
|
||||
{
|
||||
throw new BadRequestException("Max file size is 100 MB.");
|
||||
}
|
||||
|
@ -45,16 +45,16 @@ namespace Bit.Api.Controllers
|
||||
public async Task<CollectionGroupDetailsResponseModel> GetDetails(string orgId, string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationManager(orgIdGuid))
|
||||
if (!_currentContext.OrganizationManager(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var idGuid = new Guid(id);
|
||||
if(_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
var collectionDetails = await _collectionRepository.GetByIdWithGroupsAsync(idGuid);
|
||||
if(collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
|
||||
if (collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var collectionDetails = await _collectionRepository.GetByIdWithGroupsAsync(idGuid,
|
||||
_currentContext.UserId.Value);
|
||||
if(collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
|
||||
if (collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -76,7 +76,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<CollectionResponseModel>> Get(string orgId)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -108,7 +108,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<CollectionResponseModel> Post(string orgId, [FromBody]CollectionRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationManager(orgIdGuid))
|
||||
if (!_currentContext.OrganizationManager(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -154,7 +154,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private async Task<Collection> GetCollectionAsync(Guid id, Guid orgId)
|
||||
{
|
||||
if(!_currentContext.OrganizationManager(orgId))
|
||||
if (!_currentContext.OrganizationManager(orgId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -162,7 +162,7 @@ namespace Bit.Api.Controllers
|
||||
var collection = _currentContext.OrganizationAdmin(orgId) ?
|
||||
await _collectionRepository.GetByIdAsync(id) :
|
||||
await _collectionRepository.GetByIdAsync(id, _currentContext.UserId.Value);
|
||||
if(collection == null || collection.OrganizationId != orgId)
|
||||
if (collection == null || collection.OrganizationId != orgId)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<DeviceResponseModel> Get(string id)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -47,7 +47,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<DeviceResponseModel> GetByIdentifier(string identifier)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -79,7 +79,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<DeviceResponseModel> Put(string id, [FromBody]DeviceRequestModel model)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -95,7 +95,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PutToken(string identifier, [FromBody]DeviceTokenRequestModel model)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -109,7 +109,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PutClearToken(string identifier)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdentifierAsync(identifier);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -122,7 +122,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete(string id)
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
|
||||
if(device == null)
|
||||
if (device == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -53,23 +53,23 @@ namespace Bit.Api.Controllers
|
||||
[FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null)
|
||||
{
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
|
||||
if(cipher == null)
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var canView = false;
|
||||
if(cipher.OrganizationId.HasValue)
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
{
|
||||
canView = _currentContext.OrganizationAdmin(cipher.OrganizationId.Value);
|
||||
}
|
||||
else if(cipher.UserId.HasValue)
|
||||
else if (cipher.UserId.HasValue)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
canView = userId == cipher.UserId.Value;
|
||||
}
|
||||
|
||||
if(!canView)
|
||||
if (!canView)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -86,7 +86,7 @@ namespace Bit.Api.Controllers
|
||||
[FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null)
|
||||
{
|
||||
var orgId = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgId))
|
||||
if (!_currentContext.OrganizationAdmin(orgId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace Bit.Api.Controllers
|
||||
[FromQuery]DateTime? start = null, [FromQuery]DateTime? end = null, [FromQuery]string continuationToken = null)
|
||||
{
|
||||
var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));
|
||||
if(organizationUser == null || !organizationUser.UserId.HasValue ||
|
||||
if (organizationUser == null || !organizationUser.UserId.HasValue ||
|
||||
!_currentContext.OrganizationAdmin(organizationUser.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
@ -119,19 +119,19 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private Tuple<DateTime, DateTime> GetDateRange(DateTime? start, DateTime? end)
|
||||
{
|
||||
if(!end.HasValue || !start.HasValue)
|
||||
if (!end.HasValue || !start.HasValue)
|
||||
{
|
||||
end = DateTime.UtcNow.Date.AddDays(1).AddMilliseconds(-1);
|
||||
start = DateTime.UtcNow.Date.AddDays(-30);
|
||||
}
|
||||
else if(start.Value > end.Value)
|
||||
else if (start.Value > end.Value)
|
||||
{
|
||||
var newEnd = start;
|
||||
start = end;
|
||||
end = newEnd;
|
||||
}
|
||||
|
||||
if((end.Value - start.Value) > TimeSpan.FromDays(367))
|
||||
if ((end.Value - start.Value) > TimeSpan.FromDays(367))
|
||||
{
|
||||
throw new BadRequestException("Range too large.");
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(folder == null)
|
||||
if (folder == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -65,7 +65,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(folder == null)
|
||||
if (folder == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -80,7 +80,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(folder == null)
|
||||
if (folder == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<GroupResponseModel> Get(string orgId, string id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(new Guid(id));
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<GroupDetailsResponseModel> GetDetails(string orgId, string id)
|
||||
{
|
||||
var groupDetails = await _groupRepository.GetByIdWithCollectionsAsync(new Guid(id));
|
||||
if(groupDetails?.Item1 == null || !_currentContext.OrganizationAdmin(groupDetails.Item1.OrganizationId))
|
||||
if (groupDetails?.Item1 == null || !_currentContext.OrganizationAdmin(groupDetails.Item1.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<GroupResponseModel>> Get(string orgId)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationManager(orgIdGuid))
|
||||
if (!_currentContext.OrganizationManager(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -73,7 +73,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var idGuid = new Guid(id);
|
||||
var group = await _groupRepository.GetByIdAsync(idGuid);
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -86,7 +86,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<GroupResponseModel> Post(string orgId, [FromBody]GroupRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -101,7 +101,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<GroupResponseModel> Put(string orgId, string id, [FromBody]GroupRequestModel model)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(new Guid(id));
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -114,7 +114,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PutUsers(string orgId, string id, [FromBody]IEnumerable<Guid> model)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(new Guid(id));
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -126,7 +126,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete(string orgId, string id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(new Guid(id));
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -139,7 +139,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete(string orgId, string id, string orgUserId)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(new Guid(id));
|
||||
if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
if (group == null || !_currentContext.OrganizationAdmin(group.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private async Task<IActionResult> SendAsync(string username, bool retry)
|
||||
{
|
||||
if(!CoreHelpers.SettingHasValue(_globalSettings.HibpApiKey))
|
||||
if (!CoreHelpers.SettingHasValue(_globalSettings.HibpApiKey))
|
||||
{
|
||||
throw new BadRequestException("HaveIBeenPwned API key not set.");
|
||||
}
|
||||
@ -59,22 +59,22 @@ namespace Bit.Api.Controllers
|
||||
request.Headers.Add("hibp-client-id", GetClientId());
|
||||
request.Headers.Add("User-Agent", _userAgent);
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
if(response.IsSuccessStatusCode)
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await response.Content.ReadAsStringAsync();
|
||||
return Content(data, "application/json");
|
||||
}
|
||||
else if(response.StatusCode == HttpStatusCode.NotFound)
|
||||
else if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
else if(response.StatusCode == HttpStatusCode.TooManyRequests && retry)
|
||||
else if (response.StatusCode == HttpStatusCode.TooManyRequests && retry)
|
||||
{
|
||||
var delay = 2000;
|
||||
if(response.Headers.Contains("retry-after"))
|
||||
if (response.Headers.Contains("retry-after"))
|
||||
{
|
||||
var vals = response.Headers.GetValues("retry-after");
|
||||
if(vals.Any() && int.TryParse(vals.FirstOrDefault(), out var secDelay))
|
||||
if (vals.Any() && int.TryParse(vals.FirstOrDefault(), out var secDelay))
|
||||
{
|
||||
delay = (secDelay * 1000) + 200;
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace Bit.Api.Controllers
|
||||
private string GetClientId()
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
using(var sha256 = SHA256.Create())
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
var hash = sha256.ComputeHash(userId.ToByteArray());
|
||||
return Convert.ToBase64String(hash);
|
||||
|
@ -26,7 +26,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<InstallationResponseModel> Get(Guid id)
|
||||
{
|
||||
var installation = await _installationRepository.GetByIdAsync(id);
|
||||
if(installation == null)
|
||||
if (installation == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ namespace Bit.Api.Controllers
|
||||
public async Task<UserLicense> GetUser(string id, [FromQuery]string key)
|
||||
{
|
||||
var user = await _userRepository.GetByIdAsync(new Guid(id));
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if(!user.LicenseKey.Equals(key))
|
||||
else if (!user.LicenseKey.Equals(key))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("Invalid license key.");
|
||||
@ -61,11 +61,11 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationLicense> GetOrganization(string id, [FromQuery]string key)
|
||||
{
|
||||
var org = await _organizationRepository.GetByIdAsync(new Guid(id));
|
||||
if(org == null)
|
||||
if (org == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if(!org.LicenseKey.Equals(key))
|
||||
else if (!org.LicenseKey.Equals(key))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("Invalid license key.");
|
||||
|
@ -46,7 +46,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationUserDetailsResponseModel> Get(string orgId, string id)
|
||||
{
|
||||
var organizationUser = await _organizationUserRepository.GetByIdWithCollectionsAsync(new Guid(id));
|
||||
if(organizationUser == null || !_currentContext.OrganizationAdmin(organizationUser.Item1.OrganizationId))
|
||||
if (organizationUser == null || !_currentContext.OrganizationAdmin(organizationUser.Item1.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<OrganizationUserUserDetailsResponseModel>> Get(string orgId)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationManager(orgGuidId))
|
||||
if (!_currentContext.OrganizationManager(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -74,7 +74,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<IEnumerable<string>> GetGroups(string orgId, string id)
|
||||
{
|
||||
var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));
|
||||
if(organizationUser == null || !_currentContext.OrganizationAdmin(organizationUser.OrganizationId))
|
||||
if (organizationUser == null || !_currentContext.OrganizationAdmin(organizationUser.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -88,7 +88,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Invite(string orgId, [FromBody]OrganizationUserInviteRequestModel model)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -102,7 +102,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Reinvite(string orgId, string id)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -115,7 +115,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Accept(string orgId, string id, [FromBody]OrganizationUserAcceptRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -127,7 +127,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Confirm(string orgId, string id, [FromBody]OrganizationUserConfirmRequestModel model)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -142,13 +142,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task Put(string orgId, string id, [FromBody]OrganizationUserUpdateRequestModel model)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));
|
||||
if(organizationUser == null || organizationUser.OrganizationId != orgGuidId)
|
||||
if (organizationUser == null || organizationUser.OrganizationId != orgGuidId)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -163,13 +163,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task PutGroups(string orgId, string id, [FromBody]OrganizationUserUpdateGroupsRequestModel model)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organizationUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));
|
||||
if(organizationUser == null || organizationUser.OrganizationId != orgGuidId)
|
||||
if (organizationUser == null || organizationUser.OrganizationId != orgGuidId)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -182,7 +182,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete(string orgId, string id)
|
||||
{
|
||||
var orgGuidId = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
if (!_currentContext.OrganizationAdmin(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -48,13 +48,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationResponseModel> Get(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -67,13 +67,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<BillingResponseModel> GetBilling(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -86,21 +86,21 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationSubscriptionResponseModel> GetSubscription(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if(!_globalSettings.SelfHosted && organization.Gateway != null)
|
||||
if (!_globalSettings.SelfHosted && organization.Gateway != null)
|
||||
{
|
||||
var subscriptionInfo = await _paymentService.GetSubscriptionAsync(organization);
|
||||
if(subscriptionInfo == null)
|
||||
if (subscriptionInfo == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -117,13 +117,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationLicense> GetLicense(string id, [FromQuery]Guid installationId)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var license = await _organizationService.GenerateLicenseAsync(orgIdGuid, installationId);
|
||||
if(license == null)
|
||||
if (license == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -145,7 +145,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationResponseModel> Post([FromBody]OrganizationCreateRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -160,13 +160,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationResponseModel> PostLicense(OrganizationCreateLicenseRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var license = await ApiHelpers.ReadJsonFileFromBody<OrganizationLicense>(HttpContext, model.License);
|
||||
if(license == null)
|
||||
if (license == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid license");
|
||||
}
|
||||
@ -181,13 +181,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<OrganizationResponseModel> Put(string id, [FromBody]OrganizationUpdateRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -204,7 +204,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostPayment(string id, [FromBody]PaymentRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -218,7 +218,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PaymentResponseModel> PostUpgrade(string id, [FromBody]OrganizationUpgradeRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -236,7 +236,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PaymentResponseModel> PostSeat(string id, [FromBody]OrganizationSeatRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -254,7 +254,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PaymentResponseModel> PostStorage(string id, [FromBody]StorageRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -272,7 +272,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostVerifyBank(string id, [FromBody]OrganizationVerifyBankRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -285,7 +285,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostCancel(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -298,7 +298,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostReinstate(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -310,7 +310,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task Leave(string id)
|
||||
{
|
||||
var orgGuidId = new Guid(id);
|
||||
if(!_currentContext.OrganizationUser(orgGuidId))
|
||||
if (!_currentContext.OrganizationUser(orgGuidId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -324,24 +324,24 @@ namespace Bit.Api.Controllers
|
||||
public async Task Delete(string id, [FromBody]OrganizationDeleteRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
@ -357,13 +357,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task PostLicense(string id, LicenseRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var license = await ApiHelpers.ReadJsonFileFromBody<OrganizationLicense>(HttpContext, model.License);
|
||||
if(license == null)
|
||||
if (license == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid license");
|
||||
}
|
||||
@ -374,13 +374,13 @@ namespace Bit.Api.Controllers
|
||||
[HttpPost("{id}/import")]
|
||||
public async Task Import(string id, [FromBody]ImportOrganizationUsersRequestModel model)
|
||||
{
|
||||
if(!_globalSettings.SelfHosted && (model.Groups.Count() > 200 || model.Users.Count() > 1000))
|
||||
if (!_globalSettings.SelfHosted && (model.Groups.Count() > 200 || model.Users.Count() > 1000))
|
||||
{
|
||||
throw new BadRequestException("You cannot import this much data at once.");
|
||||
}
|
||||
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -399,24 +399,24 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ApiKeyResponseModel> ApiKey(string id, [FromBody]ApiKeyRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
@ -432,24 +432,24 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ApiKeyResponseModel> RotateApiKey(string id, [FromBody]ApiKeyRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
if (!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
|
@ -52,12 +52,12 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PolicyResponseModel> Get(string orgId, int type)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
var policy = await _policyRepository.GetByOrganizationIdTypeAsync(orgIdGuid, (PolicyType)type);
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -69,7 +69,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<PolicyResponseModel>> Get(string orgId)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationManager(orgIdGuid))
|
||||
if (!_currentContext.OrganizationManager(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -87,14 +87,14 @@ namespace Bit.Api.Controllers
|
||||
var orgUserId = new Guid(organizationUserId);
|
||||
var tokenValid = CoreHelpers.UserInviteTokenIsValid(_organizationServiceDataProtector, token,
|
||||
email, orgUserId, _globalSettings);
|
||||
if(!tokenValid)
|
||||
if (!tokenValid)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
var orgUser = await _organizationUserRepository.GetByIdAsync(orgUserId);
|
||||
if(orgUser == null || orgUser.OrganizationId != orgIdGuid)
|
||||
if (orgUser == null || orgUser.OrganizationId != orgIdGuid)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -108,12 +108,12 @@ namespace Bit.Api.Controllers
|
||||
public async Task<PolicyResponseModel> Put(string orgId, int type, [FromBody]PolicyRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
var policy = await _policyRepository.GetByOrganizationIdTypeAsync(new Guid(orgId), (PolicyType)type);
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
policy = model.ToPolicy(orgIdGuid);
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
CheckUsage();
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(model.UserId))
|
||||
if (!string.IsNullOrWhiteSpace(model.UserId))
|
||||
{
|
||||
await _pushNotificationService.SendPayloadToUserAsync(Prefix(model.UserId),
|
||||
model.Type.Value, model.Payload, Prefix(model.Identifier), Prefix(model.DeviceId));
|
||||
}
|
||||
else if(!string.IsNullOrWhiteSpace(model.OrganizationId))
|
||||
else if (!string.IsNullOrWhiteSpace(model.OrganizationId))
|
||||
{
|
||||
await _pushNotificationService.SendPayloadToOrganizationAsync(Prefix(model.OrganizationId),
|
||||
model.Type.Value, model.Payload, Prefix(model.Identifier), Prefix(model.DeviceId));
|
||||
@ -88,7 +88,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private string Prefix(string value)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(value))
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -98,7 +98,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private void CheckUsage()
|
||||
{
|
||||
if(CanUse())
|
||||
if (CanUse())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -108,7 +108,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private bool CanUse()
|
||||
{
|
||||
if(_environment.IsDevelopment())
|
||||
if (_environment.IsDevelopment())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<DomainsResponseModel> GetDomains(bool excluded = true)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -37,7 +37,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<DomainsResponseModel> PutDomains([FromBody]UpdateDomainsRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<SyncResponseModel> Get([FromQuery]bool excludeDomains = false)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new BadRequestException("User not found.");
|
||||
}
|
||||
@ -66,7 +66,7 @@ namespace Bit.Api.Controllers
|
||||
IEnumerable<CollectionDetails> collections = null;
|
||||
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
|
||||
IEnumerable<Policy> policies = null;
|
||||
if(hasEnabledOrgs)
|
||||
if (hasEnabledOrgs)
|
||||
{
|
||||
collections = await _collectionRepository.GetManyByUserIdAsync(user.Id);
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id);
|
||||
|
@ -47,7 +47,7 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<TwoFactorProviderResponseModel>> Get()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
@ -61,13 +61,13 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ListResponseModel<TwoFactorProviderResponseModel>> GetOrganization(string id)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -93,7 +93,7 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, false);
|
||||
model.ToUser(user);
|
||||
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
if (!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(TwoFactorProviderType.Authenticator), model.Token))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
@ -149,7 +149,7 @@ namespace Bit.Api.Controllers
|
||||
var duoApi = new DuoApi(model.IntegrationKey, model.SecretKey, model.Host);
|
||||
duoApi.JSONApiCall<object>("GET", "/auth/v2/check");
|
||||
}
|
||||
catch(DuoException)
|
||||
catch (DuoException)
|
||||
{
|
||||
throw new BadRequestException("Duo configuration settings are not valid. Please re-check the Duo Admin panel.");
|
||||
}
|
||||
@ -167,13 +167,13 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, false);
|
||||
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -190,13 +190,13 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, false);
|
||||
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -206,7 +206,7 @@ namespace Bit.Api.Controllers
|
||||
var duoApi = new DuoApi(model.IntegrationKey, model.SecretKey, model.Host);
|
||||
duoApi.JSONApiCall<object>("GET", "/auth/v2/check");
|
||||
}
|
||||
catch(DuoException)
|
||||
catch (DuoException)
|
||||
{
|
||||
throw new BadRequestException("Duo configuration settings are not valid. Please re-check the Duo Admin panel.");
|
||||
}
|
||||
@ -243,7 +243,7 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, true);
|
||||
var success = await _userService.CompleteU2fRegistrationAsync(
|
||||
user, model.Id.Value, model.Name, model.DeviceResponse);
|
||||
if(!success)
|
||||
if (!success)
|
||||
{
|
||||
throw new BadRequestException("Unable to complete U2F key registration.");
|
||||
}
|
||||
@ -281,9 +281,9 @@ namespace Bit.Api.Controllers
|
||||
public async Task SendEmailLogin([FromBody]TwoFactorEmailRequestModel model)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(model.Email.ToLowerInvariant());
|
||||
if(user != null)
|
||||
if (user != null)
|
||||
{
|
||||
if(await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
if (await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||
{
|
||||
await _userService.SendTwoFactorEmailAsync(user);
|
||||
return;
|
||||
@ -301,7 +301,7 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, false);
|
||||
model.ToUser(user);
|
||||
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
if (!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(TwoFactorProviderType.Email), model.Token))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
@ -331,13 +331,13 @@ namespace Bit.Api.Controllers
|
||||
var user = await CheckAsync(model.MasterPasswordHash, false);
|
||||
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
if (!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@ -359,7 +359,7 @@ namespace Bit.Api.Controllers
|
||||
[AllowAnonymous]
|
||||
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))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
@ -370,18 +370,18 @@ namespace Bit.Api.Controllers
|
||||
private async Task<User> CheckAsync(string masterPasswordHash, bool premium)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if(!await _userService.CheckPasswordAsync(user, masterPasswordHash))
|
||||
if (!await _userService.CheckPasswordAsync(user, masterPasswordHash))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
}
|
||||
|
||||
if(premium && !(await _userService.CanAccessPremium(user)))
|
||||
if (premium && !(await _userService.CanAccessPremium(user)))
|
||||
{
|
||||
throw new BadRequestException("Premium status is required.");
|
||||
}
|
||||
@ -391,12 +391,12 @@ namespace Bit.Api.Controllers
|
||||
|
||||
private async Task ValidateYubiKeyAsync(User user, string name, string value)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(value) || value.Length == 12)
|
||||
if (string.IsNullOrWhiteSpace(value) || value.Length == 12)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
if (!await _userManager.VerifyTwoFactorTokenAsync(user,
|
||||
CoreHelpers.CustomProviderName(TwoFactorProviderType.YubiKey), value))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
|
@ -25,7 +25,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
var guidId = new Guid(id);
|
||||
var key = await _userRepository.GetPublicKeyAsync(guidId);
|
||||
if(key == null)
|
||||
if (key == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
@ -20,20 +20,20 @@ namespace Bit.Api
|
||||
logging.AddSerilog(hostingContext, e =>
|
||||
{
|
||||
var context = e.Properties["SourceContext"].ToString();
|
||||
if(e.Exception != null &&
|
||||
if (e.Exception != null &&
|
||||
(e.Exception.GetType() == typeof(SecurityTokenValidationException) ||
|
||||
e.Exception.Message == "Bad security stamp."))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(e.Level == LogEventLevel.Information &&
|
||||
if (e.Level == LogEventLevel.Information &&
|
||||
context.Contains(typeof(IpRateLimitMiddleware).FullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||
|
||||
if (context.Contains("IdentityServer4.Validation.TokenValidator") ||
|
||||
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
|
||||
{
|
||||
return e.Level > LogEventLevel.Error;
|
||||
|
@ -44,7 +44,7 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var collectionWithGroups = await _collectionRepository.GetByIdWithGroupsAsync(id);
|
||||
var collection = collectionWithGroups?.Item1;
|
||||
if(collection == null || collection.OrganizationId != _currentContext.OrganizationId)
|
||||
if (collection == null || collection.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -87,7 +87,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Put(Guid id, [FromBody]CollectionUpdateRequestModel model)
|
||||
{
|
||||
var existingCollection = await _collectionRepository.GetByIdAsync(id);
|
||||
if(existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
var collection = await _collectionRepository.GetByIdAsync(id);
|
||||
if(collection == null || collection.OrganizationId != _currentContext.OrganizationId)
|
||||
if (collection == null || collection.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
@ -42,16 +42,16 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var dateRange = request.ToDateRange();
|
||||
var result = new PagedResult<IEvent>();
|
||||
if(request.ActingUserId.HasValue)
|
||||
if (request.ActingUserId.HasValue)
|
||||
{
|
||||
result = await _eventRepository.GetManyByOrganizationActingUserAsync(
|
||||
_currentContext.OrganizationId.Value, request.ActingUserId.Value, dateRange.Item1, dateRange.Item2,
|
||||
new PageOptions { ContinuationToken = request.ContinuationToken });
|
||||
}
|
||||
else if(request.ItemId.HasValue)
|
||||
else if (request.ItemId.HasValue)
|
||||
{
|
||||
var cipher = await _cipherRepository.GetByIdAsync(request.ItemId.Value);
|
||||
if(cipher != null && cipher.OrganizationId == _currentContext.OrganizationId.Value)
|
||||
if (cipher != null && cipher.OrganizationId == _currentContext.OrganizationId.Value)
|
||||
{
|
||||
result = await _eventRepository.GetManyByCipherAsync(
|
||||
cipher, dateRange.Item1, dateRange.Item2,
|
||||
|
@ -45,7 +45,7 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var groupDetails = await _groupRepository.GetByIdWithCollectionsAsync(id);
|
||||
var group = groupDetails?.Item1;
|
||||
if(group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
if (group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -67,7 +67,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> GetMemberIds(Guid id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(id);
|
||||
if(group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
if (group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -128,7 +128,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Put(Guid id, [FromBody]GroupCreateUpdateRequestModel model)
|
||||
{
|
||||
var existingGroup = await _groupRepository.GetByIdAsync(id);
|
||||
if(existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -154,7 +154,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> PutMemberIds(Guid id, [FromBody]UpdateMemberIdsRequestModel model)
|
||||
{
|
||||
var existingGroup = await _groupRepository.GetByIdAsync(id);
|
||||
if(existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingGroup == null || existingGroup.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -175,7 +175,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(id);
|
||||
if(group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
if (group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var userDetails = await _organizationUserRepository.GetDetailsByIdWithCollectionsAsync(id);
|
||||
var orgUser = userDetails?.Item1;
|
||||
if(orgUser == null || orgUser.OrganizationId != _currentContext.OrganizationId)
|
||||
if (orgUser == null || orgUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -74,7 +74,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> GetGroupIds(Guid id)
|
||||
{
|
||||
var orgUser = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(orgUser == null || orgUser.OrganizationId != _currentContext.OrganizationId)
|
||||
if (orgUser == null || orgUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -138,7 +138,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Put(Guid id, [FromBody]MemberUpdateRequestModel model)
|
||||
{
|
||||
var existingUser = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -146,7 +146,7 @@ namespace Bit.Api.Public.Controllers
|
||||
var associations = model.Collections?.Select(c => c.ToSelectionReadOnly());
|
||||
await _organizationService.SaveUserAsync(updatedUser, null, associations);
|
||||
MemberResponseModel response = null;
|
||||
if(existingUser.UserId.HasValue)
|
||||
if (existingUser.UserId.HasValue)
|
||||
{
|
||||
var existingUserDetails = await _organizationUserRepository.GetDetailsByIdAsync(id);
|
||||
response = new MemberResponseModel(existingUserDetails,
|
||||
@ -174,7 +174,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> PutGroupIds(Guid id, [FromBody]UpdateGroupIdsRequestModel model)
|
||||
{
|
||||
var existingUser = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -196,7 +196,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
var user = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(user == null || user.OrganizationId != _currentContext.OrganizationId)
|
||||
if (user == null || user.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -218,7 +218,7 @@ namespace Bit.Api.Public.Controllers
|
||||
public async Task<IActionResult> PostReinvite(Guid id)
|
||||
{
|
||||
var existingUser = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
if (existingUser == null || existingUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var policy = await _policyRepository.GetByOrganizationIdTypeAsync(
|
||||
_currentContext.OrganizationId.Value, type);
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace Bit.Api.Public.Controllers
|
||||
{
|
||||
var policy = await _policyRepository.GetByOrganizationIdTypeAsync(
|
||||
_currentContext.OrganizationId.Value, type);
|
||||
if(policy == null)
|
||||
if (policy == null)
|
||||
{
|
||||
policy = model.ToPolicy(_currentContext.OrganizationId.Value);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace Bit.Api
|
||||
|
||||
// Settings
|
||||
var globalSettings = services.AddGlobalSettingsServices(Configuration);
|
||||
if(!globalSettings.SelfHosted)
|
||||
if (!globalSettings.SelfHosted)
|
||||
{
|
||||
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
|
||||
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
|
||||
@ -64,7 +64,7 @@ namespace Bit.Api
|
||||
// BitPay
|
||||
services.AddSingleton<BitPayClient>();
|
||||
|
||||
if(!globalSettings.SelfHosted)
|
||||
if (!globalSettings.SelfHosted)
|
||||
{
|
||||
// Rate limiting
|
||||
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
|
||||
@ -118,7 +118,7 @@ namespace Bit.Api
|
||||
config.Conventions.Add(new PublicApiControllersModelConvention());
|
||||
}).AddNewtonsoftJson(options =>
|
||||
{
|
||||
if(Environment.IsProduction() && Configuration["swaggerGen"] != "true")
|
||||
if (Environment.IsProduction() && Configuration["swaggerGen"] != "true")
|
||||
{
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
}
|
||||
@ -126,13 +126,13 @@ namespace Bit.Api
|
||||
|
||||
services.AddSwagger(globalSettings);
|
||||
|
||||
if(globalSettings.SelfHosted)
|
||||
if (globalSettings.SelfHosted)
|
||||
{
|
||||
// Jobs service
|
||||
Jobs.JobsHostedService.AddJobsServices(services);
|
||||
services.AddHostedService<Jobs.JobsHostedService>();
|
||||
}
|
||||
if(CoreHelpers.SettingHasValue(globalSettings.ServiceBus.ConnectionString) &&
|
||||
if (CoreHelpers.SettingHasValue(globalSettings.ServiceBus.ConnectionString) &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.ServiceBus.ApplicationCacheTopicName))
|
||||
{
|
||||
services.AddHostedService<Core.HostedServices.ApplicationCacheHostedService>();
|
||||
@ -152,7 +152,7 @@ namespace Bit.Api
|
||||
// Default Middleware
|
||||
app.UseDefaultMiddleware(env, globalSettings);
|
||||
|
||||
if(!globalSettings.SelfHosted)
|
||||
if (!globalSettings.SelfHosted)
|
||||
{
|
||||
// Rate limiting
|
||||
app.UseMiddleware<CustomIpRateLimitMiddleware>();
|
||||
@ -183,7 +183,7 @@ namespace Bit.Api
|
||||
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||
|
||||
// Add Swagger
|
||||
if(Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
if (Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
{
|
||||
app.UseSwagger(config =>
|
||||
{
|
||||
|
@ -10,15 +10,15 @@ namespace Bit.Api.Utilities
|
||||
public async static Task<T> ReadJsonFileFromBody<T>(HttpContext httpContext, IFormFile file, long maxSize = 51200)
|
||||
{
|
||||
T obj = default(T);
|
||||
if(file != null && httpContext.Request.ContentLength.HasValue && httpContext.Request.ContentLength.Value <= maxSize)
|
||||
if (file != null && httpContext.Request.ContentLength.HasValue && httpContext.Request.ContentLength.Value <= maxSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
using(var stream = file.OpenReadStream())
|
||||
using(var reader = new StreamReader(stream))
|
||||
using (var stream = file.OpenReadStream())
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
var s = await reader.ReadToEndAsync();
|
||||
if(!string.IsNullOrWhiteSpace(s))
|
||||
if (!string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
obj = JsonConvert.DeserializeObject<T>(s);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace Bit.Api.Utilities
|
||||
|
||||
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
|
||||
{
|
||||
if(context.Result is JsonResult jsonResult)
|
||||
if (context.Result is JsonResult jsonResult)
|
||||
{
|
||||
context.Result = new JsonResult(jsonResult.Value, _jsonSerializerSettings);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Bit.Api.Utilities
|
||||
var errorMessage = "An error has occurred.";
|
||||
|
||||
var exception = context.Exception;
|
||||
if(exception == null)
|
||||
if (exception == null)
|
||||
{
|
||||
// Should never happen.
|
||||
return;
|
||||
@ -35,12 +35,12 @@ namespace Bit.Api.Utilities
|
||||
|
||||
PublicApi.ErrorResponseModel publicErrorModel = null;
|
||||
InternalApi.ErrorResponseModel internalErrorModel = null;
|
||||
if(exception is BadRequestException badRequestException)
|
||||
if (exception is BadRequestException badRequestException)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = 400;
|
||||
if(badRequestException.ModelState != null)
|
||||
if (badRequestException.ModelState != null)
|
||||
{
|
||||
if(_publicApi)
|
||||
if (_publicApi)
|
||||
{
|
||||
publicErrorModel = new PublicApi.ErrorResponseModel(badRequestException.ModelState);
|
||||
}
|
||||
@ -54,11 +54,11 @@ namespace Bit.Api.Utilities
|
||||
errorMessage = badRequestException.Message;
|
||||
}
|
||||
}
|
||||
else if(exception is StripeException stripeException &&
|
||||
else if (exception is StripeException stripeException &&
|
||||
stripeException?.StripeError?.ErrorType == "card_error")
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = 400;
|
||||
if(_publicApi)
|
||||
if (_publicApi)
|
||||
{
|
||||
publicErrorModel = new PublicApi.ErrorResponseModel(stripeException.StripeError.Parameter,
|
||||
stripeException.Message);
|
||||
@ -69,31 +69,31 @@ namespace Bit.Api.Utilities
|
||||
stripeException.Message);
|
||||
}
|
||||
}
|
||||
else if(exception is GatewayException)
|
||||
else if (exception is GatewayException)
|
||||
{
|
||||
errorMessage = exception.Message;
|
||||
context.HttpContext.Response.StatusCode = 400;
|
||||
}
|
||||
else if(exception is NotSupportedException && !string.IsNullOrWhiteSpace(exception.Message))
|
||||
else if (exception is NotSupportedException && !string.IsNullOrWhiteSpace(exception.Message))
|
||||
{
|
||||
errorMessage = exception.Message;
|
||||
context.HttpContext.Response.StatusCode = 400;
|
||||
}
|
||||
else if(exception is ApplicationException)
|
||||
else if (exception is ApplicationException)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = 402;
|
||||
}
|
||||
else if(exception is NotFoundException)
|
||||
else if (exception is NotFoundException)
|
||||
{
|
||||
errorMessage = "Resource not found.";
|
||||
context.HttpContext.Response.StatusCode = 404;
|
||||
}
|
||||
else if(exception is SecurityTokenValidationException)
|
||||
else if (exception is SecurityTokenValidationException)
|
||||
{
|
||||
errorMessage = "Invalid token.";
|
||||
context.HttpContext.Response.StatusCode = 403;
|
||||
}
|
||||
else if(exception is UnauthorizedAccessException)
|
||||
else if (exception is UnauthorizedAccessException)
|
||||
{
|
||||
errorMessage = "Unauthorized.";
|
||||
context.HttpContext.Response.StatusCode = 401;
|
||||
@ -106,7 +106,7 @@ namespace Bit.Api.Utilities
|
||||
context.HttpContext.Response.StatusCode = 500;
|
||||
}
|
||||
|
||||
if(_publicApi)
|
||||
if (_publicApi)
|
||||
{
|
||||
var errorModel = publicErrorModel ?? new PublicApi.ErrorResponseModel(errorMessage);
|
||||
context.Result = new ObjectResult(errorModel);
|
||||
@ -115,7 +115,7 @@ namespace Bit.Api.Utilities
|
||||
{
|
||||
var errorModel = internalErrorModel ?? new InternalApi.ErrorResponseModel(errorMessage);
|
||||
var env = context.HttpContext.RequestServices.GetRequiredService<IWebHostEnvironment>();
|
||||
if(env.IsDevelopment())
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
errorModel.ExceptionMessage = exception.Message;
|
||||
errorModel.ExceptionStackTrace = exception.StackTrace;
|
||||
|
@ -18,14 +18,14 @@ namespace Bit.Api.Utilities
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var model = context.ActionArguments.FirstOrDefault(a => a.Key == "model");
|
||||
if(model.Key == "model" && model.Value == null)
|
||||
if (model.Key == "model" && model.Value == null)
|
||||
{
|
||||
context.ModelState.AddModelError(string.Empty, "Body is empty.");
|
||||
}
|
||||
|
||||
if(!context.ModelState.IsValid)
|
||||
if (!context.ModelState.IsValid)
|
||||
{
|
||||
if(_publicApi)
|
||||
if (_publicApi)
|
||||
{
|
||||
context.Result = new BadRequestObjectResult(new PublicApi.ErrorResponseModel(context.ModelState));
|
||||
}
|
||||
|
@ -20,36 +20,36 @@ namespace Bit.Api.Utilities
|
||||
var reader = new MultipartReader(boundary, request.Body);
|
||||
|
||||
var firstSection = await reader.ReadNextSectionAsync();
|
||||
if(firstSection != null)
|
||||
if (firstSection != null)
|
||||
{
|
||||
if(ContentDispositionHeaderValue.TryParse(firstSection.ContentDisposition, out var firstContent))
|
||||
if (ContentDispositionHeaderValue.TryParse(firstSection.ContentDisposition, out var firstContent))
|
||||
{
|
||||
if(HasFileContentDisposition(firstContent))
|
||||
if (HasFileContentDisposition(firstContent))
|
||||
{
|
||||
// Old style with just data
|
||||
var fileName = HeaderUtilities.RemoveQuotes(firstContent.FileName).ToString();
|
||||
using(firstSection.Body)
|
||||
using (firstSection.Body)
|
||||
{
|
||||
await callback(firstSection.Body, fileName, null);
|
||||
}
|
||||
}
|
||||
else if(HasKeyDisposition(firstContent))
|
||||
else if (HasKeyDisposition(firstContent))
|
||||
{
|
||||
// New style with key, then data
|
||||
string key = null;
|
||||
using(var sr = new StreamReader(firstSection.Body))
|
||||
using (var sr = new StreamReader(firstSection.Body))
|
||||
{
|
||||
key = await sr.ReadToEndAsync();
|
||||
}
|
||||
|
||||
var secondSection = await reader.ReadNextSectionAsync();
|
||||
if(secondSection != null)
|
||||
if (secondSection != null)
|
||||
{
|
||||
if(ContentDispositionHeaderValue.TryParse(secondSection.ContentDisposition,
|
||||
if (ContentDispositionHeaderValue.TryParse(secondSection.ContentDisposition,
|
||||
out var secondContent) && HasFileContentDisposition(secondContent))
|
||||
{
|
||||
var fileName = HeaderUtilities.RemoveQuotes(secondContent.FileName).ToString();
|
||||
using(secondSection.Body)
|
||||
using (secondSection.Body)
|
||||
{
|
||||
await callback(secondSection.Body, fileName, key);
|
||||
}
|
||||
@ -67,12 +67,12 @@ namespace Bit.Api.Utilities
|
||||
private static string GetBoundary(MediaTypeHeaderValue contentType, int lengthLimit)
|
||||
{
|
||||
var boundary = HeaderUtilities.RemoveQuotes(contentType.Boundary);
|
||||
if(StringSegment.IsNullOrEmpty(boundary))
|
||||
if (StringSegment.IsNullOrEmpty(boundary))
|
||||
{
|
||||
throw new InvalidDataException("Missing content-type boundary.");
|
||||
}
|
||||
|
||||
if(boundary.Length > lengthLimit)
|
||||
if (boundary.Length > lengthLimit)
|
||||
{
|
||||
throw new InvalidDataException($"Multipart boundary length limit {lengthLimit} exceeded.");
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Bit.Api.Utilities
|
||||
{
|
||||
var controllerNamespace = controller.ControllerType.Namespace;
|
||||
var publicApi = controllerNamespace.Contains(".Public.");
|
||||
if(publicApi)
|
||||
if (publicApi)
|
||||
{
|
||||
controller.Filters.Add(new CamelCaseJsonResultFilterAttribute());
|
||||
}
|
||||
|
Reference in New Issue
Block a user