1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-02 23:41:21 +01:00

Move request/response models (#1754)

This commit is contained in:
Oscar Hinton 2021-12-14 15:05:07 +00:00 committed by GitHub
parent 3ae573bd8d
commit 63f6dd9a24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
206 changed files with 641 additions and 516 deletions

View File

@ -23,7 +23,6 @@ using System.Threading.Tasks;
using Bit.Core.Models;
using Bit.Core.Models.Api;
using Bit.Core.Utilities;
using System.Text.Json;
using Bit.Core.Models.Data;
using Bit.Core.Settings;

View File

@ -2,8 +2,6 @@
using Bit.Core;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Models.Api.Request.Accounts;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
@ -17,6 +15,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Response;
using Bit.Core.Enums.Provider;
namespace Bit.Api.Controllers

View File

@ -4,7 +4,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;
@ -15,6 +14,10 @@ using Bit.Core.Models.Table;
using Bit.Core.Settings;
using Core.Models.Data;
using Azure.Messaging.EventGrid;
using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response;
using Bit.Core.Models.Data;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
@ -600,8 +603,8 @@ namespace Bit.Api.Controllers
throw new BadRequestException($"Max file size is {CipherService.MAX_FILE_SIZE_READABLE}.");
}
var (attachmentId, uploadUrl) = await _cipherService.CreateAttachmentForDelayedUploadAsync(cipher, request, userId);
var (attachmentId, uploadUrl) = await _cipherService.CreateAttachmentForDelayedUploadAsync(cipher,
request.Key, request.FileName, request.FileSize, request.AdminRequest, userId);
return new AttachmentUploadDataResponseModel
{
AttachmentId = attachmentId,
@ -713,7 +716,8 @@ namespace Bit.Api.Controllers
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
return await _cipherService.GetAttachmentDownloadDataAsync(cipher, attachmentId);
var result = await _cipherService.GetAttachmentDownloadDataAsync(cipher, attachmentId);
return new AttachmentResponseModel(result.Id, result.Data, result.Cipher, _globalSettings);
}
[HttpPost("{id}/attachment/{attachmentId}/share")]

View File

@ -4,12 +4,13 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;
using Bit.Core.Models.Table;
using System.Collections.Generic;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
namespace Bit.Api.Controllers
{

View File

@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Models.Table;
using Bit.Core.Services;

View File

@ -1,13 +1,14 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Models.Api.Request;
using Bit.Core.Models.Api.Response;
using Bit.Core.Models.Table;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@ -20,15 +21,18 @@ namespace Bit.Api.Controllers
private readonly IUserService _userService;
private readonly IEmergencyAccessRepository _emergencyAccessRepository;
private readonly IEmergencyAccessService _emergencyAccessService;
private readonly IGlobalSettings _globalSettings;
public EmergencyAccessController(
IUserService userService,
IEmergencyAccessRepository emergencyAccessRepository,
IEmergencyAccessService emergencyAccessService)
IEmergencyAccessService emergencyAccessService,
IGlobalSettings globalSettings)
{
_userService = userService;
_emergencyAccessRepository = emergencyAccessRepository;
_emergencyAccessService = emergencyAccessService;
_globalSettings = globalSettings;
}
[HttpGet("trusted")]
@ -161,14 +165,17 @@ namespace Bit.Api.Controllers
public async Task<EmergencyAccessViewResponseModel> ViewCiphers(string id)
{
var user = await _userService.GetUserByPrincipalAsync(User);
return await _emergencyAccessService.ViewAsync(new Guid(id), user);
var viewResult = await _emergencyAccessService.ViewAsync(new Guid(id), user);
return new EmergencyAccessViewResponseModel(_globalSettings, viewResult.EmergencyAccess, viewResult.Ciphers);
}
[HttpGet("{id}/{cipherId}/attachment/{attachmentId}")]
public async Task<AttachmentResponseModel> GetAttachmentData(string id, string cipherId, string attachmentId)
{
var user = await _userService.GetUserByPrincipalAsync(User);
return await _emergencyAccessService.GetAttachmentDownloadAsync(new Guid(id), cipherId, attachmentId, user);
var result =
await _emergencyAccessService.GetAttachmentDownloadAsync(new Guid(id), cipherId, attachmentId, user);
return new AttachmentResponseModel(result.Id, result.Data, result.Cipher, _globalSettings);
}
}
}

View File

@ -1,11 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Services;
using Bit.Core.Context;
using Bit.Core.Models.Data;

View File

@ -1,10 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;

View File

@ -4,11 +4,12 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;
using System.Collections.Generic;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
namespace Bit.Api.Controllers
{

View File

@ -1,8 +1,9 @@
using System;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Bit.Core.Models.Api;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;

View File

@ -1,12 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Models.Api;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Settings;
using Stripe;
using System.Linq;
using System.Collections.Generic;
namespace Bit.Api.Controllers
{

View File

@ -1,9 +1,8 @@
using System;
using System.Threading.Tasks;
using Bit.Api.Models.Request.Organizations;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Models.Api.Request;
using Bit.Core.Models.Table;
using Bit.Core.Repositories;
using Bit.Core.Services;

View File

@ -4,11 +4,12 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;
using System.Collections.Generic;
using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
@ -136,7 +137,7 @@ namespace Bit.Api.Controllers
var userId = _userService.GetProperUserId(User);
var result = await _organizationService.InviteUsersAsync(orgGuidId, userId.Value,
new (OrganizationUserInvite, string)[] { (new OrganizationUserInvite(model), null) });
new (OrganizationUserInvite, string)[] { (new OrganizationUserInvite(model.ToData()), null) });
}
[HttpPost("reinvite")]

View File

@ -1,16 +1,18 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Request.Organizations;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Enums;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;
using Bit.Api.Utilities;
using Bit.Core.Models.Api.Response;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;

View File

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

View File

@ -1,10 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;

View File

@ -1,10 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request.Providers;
using Bit.Api.Models.Response;
using Bit.Api.Models.Response.Providers;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Models.Api.Request;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Utilities;

View File

@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bit.Api.Models.Request.Providers;
using Bit.Api.Models.Response;
using Bit.Api.Models.Response.Providers;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Context;

View File

@ -1,8 +1,9 @@
using System;
using System.Threading.Tasks;
using Bit.Api.Models.Request.Providers;
using Bit.Api.Models.Response.Providers;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings;

View File

@ -1,14 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Models.Api;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Bit.Api.Utilities;
using Bit.Core.Models.Api;
using Bit.Core.Utilities;
using Bit.Core.Settings;
using Microsoft.Extensions.Hosting;

View File

@ -4,17 +4,17 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Bit.Core.Settings;
using Bit.Core.Models.Api.Response;
using Bit.Core.Enums;
using Bit.Core.Context;
using Azure.Messaging.EventGrid;
using Bit.Api.Utilities;
using System.Collections.Generic;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
using Bit.Core.Models.Data;

View File

@ -1,8 +1,9 @@
using System;
using System.Threading.Tasks;
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Models.Api;
using Bit.Core.Services;
namespace Bit.Api.Controllers

View File

@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Models.Api;
using Bit.Core.Services;
using Bit.Core.Repositories;
using Bit.Core.Enums;
@ -10,6 +9,7 @@ using Bit.Core.Exceptions;
using System.Linq;
using Bit.Core.Models.Table;
using System.Collections.Generic;
using Bit.Api.Models.Response;
using Bit.Core.Enums.Provider;
using Bit.Core.Models.Data;
using Bit.Core.Settings;

View File

@ -2,13 +2,16 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using System.Linq;
using Bit.Api.Models.Request;
using Bit.Api.Models.Request.Accounts;
using Bit.Api.Models.Response;
using Bit.Api.Models.Response.TwoFactor;
using Bit.Core.Context;
using Bit.Core.Repositories;
using Bit.Core.Utilities;

View File

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

View File

@ -1,7 +1,7 @@
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherAttachmentModel
{

View File

@ -2,7 +2,7 @@
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherCardModel
{

View File

@ -1,9 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherFieldModel
{
@ -23,5 +22,16 @@ namespace Bit.Core.Models.Api
[EncryptedStringLength(5000)]
public string Value { get; set; }
public int? LinkedId { get; set; }
public CipherFieldData ToCipherFieldData()
{
return new CipherFieldData
{
Type = Type,
Name = Name,
Value = Value,
LinkedId = LinkedId ?? null,
};
}
}
}

View File

@ -2,7 +2,7 @@
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherIdentityModel
{

View File

@ -1,12 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Enums;
using System.Collections.Generic;
using System.Linq;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherLoginModel
{
@ -79,6 +78,11 @@ namespace Bit.Core.Models.Api
[EncryptedStringLength(10000)]
public string Uri { get; set; }
public UriMatchType? Match { get; set; } = null;
public CipherLoginData.CipherLoginUriData ToCipherLoginUriData()
{
return new CipherLoginData.CipherLoginUriData { Uri = Uri, Match = Match, };
}
}
}
}

View File

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherPasswordHistoryModel
{
@ -21,5 +21,10 @@ namespace Bit.Core.Models.Api
public string Password { get; set; }
[Required]
public DateTime? LastUsedDate { get; set; }
public CipherPasswordHistoryData ToCipherPasswordHistoryData()
{
return new CipherPasswordHistoryData { Password = Password, LastUsedDate = LastUsedDate.Value, };
}
}
}

View File

@ -1,7 +1,7 @@
using Bit.Core.Enums;
using Bit.Core.Models.Data;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models
{
public class CipherSecureNoteModel
{

View File

@ -1,8 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public
{
public abstract class AssociationWithPermissionsBaseModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public
{
public abstract class CollectionBaseModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public
{
public abstract class GroupBaseModel
{

View File

@ -4,7 +4,7 @@ using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public
{
public abstract class MemberBaseModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public
{
public abstract class PolicyBaseModel
{

View File

@ -1,6 +1,6 @@
using Bit.Core.Models.Data;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class AssociationWithPermissionsRequestModel : AssociationWithPermissionsBaseModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class CollectionUpdateRequestModel : CollectionBaseModel
{

View File

@ -1,7 +1,7 @@
using System;
using Bit.Core.Exceptions;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class EventFilterRequestModel
{

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class GroupCreateUpdateRequestModel : GroupBaseModel
{

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class MemberCreateRequestModel : MemberUpdateRequestModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class MemberUpdateRequestModel : MemberBaseModel
{

View File

@ -1,9 +1,10 @@
using Bit.Core.Models.Business;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Business;
using Table = Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class OrganizationImportRequestModel
{

View File

@ -2,7 +2,7 @@
using Bit.Core.Models.Table;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class PolicyUpdateRequestModel : PolicyBaseModel
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class UpdateGroupIdsRequestModel
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Request
{
public class UpdateMemberIdsRequestModel
{

View File

@ -1,7 +1,7 @@
using System;
using Bit.Core.Models.Data;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
public class AssociationWithPermissionsResponseModel : AssociationWithPermissionsBaseModel
{

View File

@ -5,7 +5,7 @@ using System.Linq;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
/// <summary>
/// A collection.

View File

@ -1,9 +1,9 @@
using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
public class ErrorResponseModel : IResponseModel
{

View File

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
/// <summary>
/// An event log.

View File

@ -5,7 +5,7 @@ using System.Linq;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
/// <summary>
/// A user group.

View File

@ -1,4 +1,4 @@
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
public interface IResponseModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
public class ListResponseModel<T> : IResponseModel where T : IResponseModel
{

View File

@ -6,7 +6,7 @@ using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
/// <summary>
/// An organization member.

View File

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api.Public
namespace Bit.Api.Models.Public.Response
{
/// <summary>
/// A policy.
@ -43,6 +44,6 @@ namespace Bit.Core.Models.Api.Public
/// The type of policy.
/// </summary>
[Required]
public Enums.PolicyType? Type { get; set; }
public PolicyType? Type { get; set; }
}
}

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class DeleteRecoverRequestModel
{

View File

@ -1,8 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Models.Api;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class EmailRequestModel : SecretVerificationRequestModel
{

View File

@ -1,8 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Models.Api;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class EmailTokenRequestModel : SecretVerificationRequestModel
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class ImportCiphersRequestModel
{

View File

@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class KdfRequestModel : PasswordRequestModel, IValidatableObject
{

View File

@ -1,7 +1,7 @@
using Bit.Core.Models.Table;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class KeysRequestModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class PasswordHintRequestModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class PasswordRequestModel : SecretVerificationRequestModel
{

View File

@ -1,7 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class PreloginRequestModel
{

View File

@ -1,16 +1,15 @@
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using Bit.Core.Enums;
using Bit.Core.Settings;
using Microsoft.AspNetCore.Http;
using Enums = Bit.Core.Enums;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class PremiumRequestModel : IValidatableObject
{
[Required]
public PaymentMethodType? PaymentMethodType { get; set; }
public Enums.PaymentMethodType? PaymentMethodType { get; set; }
public string PaymentToken { get; set; }
[Range(0, 99)]
public short? AdditionalStorageGb { get; set; }

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class RegenerateTwoFactorRequestModel
{

View File

@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using Bit.Core.Models.Api;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class RegisterRequestModel : IValidatableObject, ICaptchaProtectedModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class SecretVerificationRequestModel : IValidatableObject
{

View File

@ -2,7 +2,7 @@
using Bit.Core.Enums;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Request.Accounts
namespace Bit.Api.Models.Request.Accounts
{
public class SetKeyConnectorKeyRequestModel
{

View File

@ -2,7 +2,7 @@
using Bit.Core.Enums;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Request.Accounts
namespace Bit.Api.Models.Request.Accounts
{
public class SetPasswordRequestModel
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class StorageRequestModel : IValidatableObject
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class TaxInfoUpdateRequestModel : IValidatableObject
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class UpdateKeyRequestModel
{

View File

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class UpdateProfileRequestModel
{

View File

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Bit.Api.Models.Request.Organizations;
namespace Bit.Core.Models.Api.Request.Accounts
namespace Bit.Api.Models.Request.Accounts
{
public class UpdateTempPasswordRequestModel : OrganizationUserResetPasswordRequestModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class VerifyDeleteRecoverRequestModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class VerifyEmailRequestModel
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Accounts
{
public class VerifyOTPRequestModel
{

View File

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

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Settings;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class BitPayInvoiceRequestModel : IValidatableObject
{

View File

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class CipherPartialRequestModel
{

View File

@ -1,16 +1,16 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Core.Models.Data;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Core.Models.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class CipherRequestModel
{
@ -69,21 +69,21 @@ namespace Bit.Core.Models.Api
switch (existingCipher.Type)
{
case CipherType.Login:
var loginObj = JObject.FromObject(new CipherLoginData(this),
var loginObj = JObject.FromObject(ToCipherLoginData(),
new JsonSerializer { NullValueHandling = NullValueHandling.Ignore });
loginObj[nameof(CipherLoginData.Uri)]?.Parent?.Remove();
existingCipher.Data = loginObj.ToString(Formatting.None);
break;
case CipherType.Card:
existingCipher.Data = JsonConvert.SerializeObject(new CipherCardData(this),
existingCipher.Data = JsonConvert.SerializeObject(ToCipherCardData(),
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
case CipherType.Identity:
existingCipher.Data = JsonConvert.SerializeObject(new CipherIdentityData(this),
existingCipher.Data = JsonConvert.SerializeObject(ToCipherIdentityData(),
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
case CipherType.SecureNote:
existingCipher.Data = JsonConvert.SerializeObject(new CipherSecureNoteData(this),
existingCipher.Data = JsonConvert.SerializeObject(ToCipherSecureNoteData(),
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
default:
@ -151,6 +151,87 @@ namespace Bit.Core.Models.Api
Edit = true
});
}
private CipherLoginData ToCipherLoginData()
{
return new CipherLoginData
{
Name = Name,
Notes = Notes,
Fields = Fields?.Select(f => f.ToCipherFieldData()),
PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()),
Uris =
Login.Uris?.Where(u => u != null)
.Select(u => u.ToCipherLoginUriData()),
Username = Login.Username,
Password = Login.Password,
PasswordRevisionDate = Login.PasswordRevisionDate,
Totp = Login.Totp,
AutofillOnPageLoad = Login.AutofillOnPageLoad,
};
}
private CipherIdentityData ToCipherIdentityData()
{
return new CipherIdentityData
{
Name = Name,
Notes = Notes,
Fields = Fields?.Select(f => f.ToCipherFieldData()),
PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()),
Title = Identity.Title,
FirstName = Identity.FirstName,
MiddleName = Identity.MiddleName,
LastName = Identity.LastName,
Address1 = Identity.Address1,
Address2 = Identity.Address2,
Address3 = Identity.Address3,
City = Identity.City,
State = Identity.State,
PostalCode = Identity.PostalCode,
Country = Identity.Country,
Company = Identity.Company,
Email = Identity.Email,
Phone = Identity.Phone,
SSN = Identity.SSN,
Username = Identity.Username,
PassportNumber = Identity.PassportNumber,
LicenseNumber = Identity.LicenseNumber,
};
}
private CipherCardData ToCipherCardData()
{
return new CipherCardData
{
Name = Name,
Notes = Notes,
Fields = Fields?.Select(f => f.ToCipherFieldData()),
PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()),
CardholderName = Card.CardholderName,
Brand = Card.Brand,
Number = Card.Number,
ExpMonth = Card.ExpMonth,
ExpYear = Card.ExpYear,
Code = Card.Code,
};
}
private CipherSecureNoteData ToCipherSecureNoteData()
{
return new CipherSecureNoteData
{
Name = Name,
Notes = Notes,
Fields = Fields?.Select(f => f.ToCipherFieldData()),
PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()),
Type = SecureNote.Type,
};
}
}
public class CipherWithIdRequestModel : CipherRequestModel

View File

@ -1,11 +1,10 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class CollectionRequestModel
{

View File

@ -1,10 +1,9 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using Newtonsoft.Json;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class DeviceRequestModel
{

View File

@ -1,8 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api.Request
namespace Bit.Api.Models.Request
{
public class EmergencyAccessInviteRequestModel
{
@ -11,7 +12,7 @@ namespace Bit.Core.Models.Api.Request
[StringLength(256)]
public string Email { get; set; }
[Required]
public Enums.EmergencyAccessType? Type { get; set; }
public EmergencyAccessType? Type { get; set; }
[Required]
public int WaitTimeDays { get; set; }
}
@ -19,7 +20,7 @@ namespace Bit.Core.Models.Api.Request
public class EmergencyAccessUpdateRequestModel
{
[Required]
public Enums.EmergencyAccessType Type { get; set; }
public EmergencyAccessType Type { get; set; }
[Required]
public int WaitTimeDays { get; set; }
public string KeyEncrypted { get; set; }

View File

@ -1,10 +1,9 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class FolderRequestModel
{

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class GroupRequestModel
{

View File

@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Enums = Bit.Core.Enums;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class IapCheckRequestModel : IValidatableObject
{
[Required]
public PaymentMethodType? PaymentMethodType { get; set; }
public Enums.PaymentMethodType? PaymentMethodType { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{

View File

@ -1,7 +1,8 @@
using Bit.Core.Models.Table;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class InstallationRequestModel
{
@ -14,7 +15,7 @@ namespace Bit.Core.Models.Api
{
return new Installation
{
Key = Utilities.CoreHelpers.SecureRandomString(20),
Key = CoreHelpers.SecureRandomString(20),
Email = Email,
Enabled = true
};

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Http;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request
{
public class LicenseRequestModel
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class ImportOrganizationCiphersRequestModel
{

View File

@ -1,10 +1,10 @@
using Bit.Core.Models.Business;
using Bit.Core.Models.Table;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Business;
using Table = Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class ImportOrganizationUsersRequestModel
{

View File

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationCreateLicenseRequestModel : LicenseRequestModel
{

View File

@ -1,11 +1,11 @@
using Bit.Core.Models.Table;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationCreateRequestModel : IValidatableObject
{

View File

@ -1,8 +1,8 @@
using Bit.Core.Models.Table;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Business;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationKeysRequestModel
{

View File

@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationSeatRequestModel : IValidatableObject
{

View File

@ -2,7 +2,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationSponsorshipRedeemRequestModel
{

View File

@ -1,9 +1,8 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api.Request
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationSponsorshipRequestModel
{

View File

@ -1,18 +1,18 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using Bit.Core.Services;
using Bit.Core.Models.Data;
using Bit.Core.Enums;
using Bit.Core.Sso;
using U2F.Core.Utils;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
using Bit.Core.Services;
using Bit.Core.Sso;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using U2F.Core.Utils;
namespace Bit.Core.Models.Api
namespace Bit.Api.Models.Request.Organizations
{
public class OrganizationSsoRequestModel
{

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