-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into auth/pm-2996/add-auth-requ…
…est-data-to-devices-response-model
- Loading branch information
Showing
62 changed files
with
2,467 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Api/Auth/Models/Request/Accounts/UnauthenticatedSecretVerificatioRequestModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Bit.Core.Utilities; | ||
|
||
namespace Bit.Api.Auth.Models.Request.Accounts; | ||
|
||
public class UnauthenticatedSecretVerificatioRequestModel : SecretVerificationRequestModel | ||
{ | ||
[Required] | ||
[StrictEmailAddress] | ||
[StringLength(256)] | ||
public string Email { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Bit.Api.Billing.Public.Models; | ||
|
||
public class OrganizationSubscriptionDetailsResponseModel : IValidatableObject | ||
{ | ||
public PasswordManagerSubscriptionDetails PasswordManager { get; set; } | ||
public SecretsManagerSubscriptionDetails SecretsManager { get; set; } | ||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
if (PasswordManager == null && SecretsManager == null) | ||
{ | ||
yield return new ValidationResult("At least one of PasswordManager or SecretsManager must be provided."); | ||
} | ||
|
||
yield return ValidationResult.Success; | ||
} | ||
} | ||
public class PasswordManagerSubscriptionDetails | ||
{ | ||
public int? Seats { get; set; } | ||
public int? MaxAutoScaleSeats { get; set; } | ||
public short? Storage { get; set; } | ||
} | ||
|
||
public class SecretsManagerSubscriptionDetails | ||
{ | ||
public int? Seats { get; set; } | ||
public int? MaxAutoScaleSeats { get; set; } | ||
public int? ServiceAccounts { get; set; } | ||
public int? MaxAutoScaleServiceAccounts { get; set; } | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Api/KeyManagement/Controllers/AccountsKeyManagementController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#nullable enable | ||
using Bit.Api.KeyManagement.Models.Requests; | ||
using Bit.Core; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.KeyManagement.Commands.Interfaces; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Bit.Api.KeyManagement.Controllers; | ||
|
||
[Route("accounts/key-management")] | ||
[Authorize("Application")] | ||
public class AccountsKeyManagementController : Controller | ||
{ | ||
private readonly IEmergencyAccessRepository _emergencyAccessRepository; | ||
private readonly IFeatureService _featureService; | ||
private readonly IOrganizationUserRepository _organizationUserRepository; | ||
private readonly IRegenerateUserAsymmetricKeysCommand _regenerateUserAsymmetricKeysCommand; | ||
private readonly IUserService _userService; | ||
|
||
public AccountsKeyManagementController(IUserService userService, | ||
IFeatureService featureService, | ||
IOrganizationUserRepository organizationUserRepository, | ||
IEmergencyAccessRepository emergencyAccessRepository, | ||
IRegenerateUserAsymmetricKeysCommand regenerateUserAsymmetricKeysCommand) | ||
{ | ||
_userService = userService; | ||
_featureService = featureService; | ||
_regenerateUserAsymmetricKeysCommand = regenerateUserAsymmetricKeysCommand; | ||
_organizationUserRepository = organizationUserRepository; | ||
_emergencyAccessRepository = emergencyAccessRepository; | ||
} | ||
|
||
[HttpPost("regenerate-keys")] | ||
public async Task RegenerateKeysAsync([FromBody] KeyRegenerationRequestModel request) | ||
{ | ||
if (!_featureService.IsEnabled(FeatureFlagKeys.PrivateKeyRegeneration)) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
var user = await _userService.GetUserByPrincipalAsync(User) ?? throw new UnauthorizedAccessException(); | ||
var usersOrganizationAccounts = await _organizationUserRepository.GetManyByUserAsync(user.Id); | ||
var designatedEmergencyAccess = await _emergencyAccessRepository.GetManyDetailsByGranteeIdAsync(user.Id); | ||
await _regenerateUserAsymmetricKeysCommand.RegenerateKeysAsync(request.ToUserAsymmetricKeys(user.Id), | ||
usersOrganizationAccounts, designatedEmergencyAccess); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Api/KeyManagement/Models/Requests/KeyRegenerationRequestModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#nullable enable | ||
using Bit.Core.KeyManagement.Models.Data; | ||
using Bit.Core.Utilities; | ||
|
||
namespace Bit.Api.KeyManagement.Models.Requests; | ||
|
||
public class KeyRegenerationRequestModel | ||
{ | ||
public required string UserPublicKey { get; set; } | ||
|
||
[EncryptedString] | ||
public required string UserKeyEncryptedUserPrivateKey { get; set; } | ||
|
||
public UserAsymmetricKeys ToUserAsymmetricKeys(Guid userId) | ||
{ | ||
return new UserAsymmetricKeys | ||
{ | ||
UserId = userId, | ||
PublicKey = UserPublicKey, | ||
UserKeyEncryptedPrivateKey = UserKeyEncryptedUserPrivateKey, | ||
}; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/Api/NotificationCenter/Controllers/NotificationsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#nullable enable | ||
using Bit.Api.Models.Response; | ||
using Bit.Api.NotificationCenter.Models.Request; | ||
using Bit.Api.NotificationCenter.Models.Response; | ||
using Bit.Core.Models.Data; | ||
using Bit.Core.NotificationCenter.Commands.Interfaces; | ||
using Bit.Core.NotificationCenter.Models.Filter; | ||
using Bit.Core.NotificationCenter.Queries.Interfaces; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Bit.Api.NotificationCenter.Controllers; | ||
|
||
[Route("notifications")] | ||
[Authorize("Application")] | ||
public class NotificationsController : Controller | ||
{ | ||
private readonly IGetNotificationStatusDetailsForUserQuery _getNotificationStatusDetailsForUserQuery; | ||
private readonly IMarkNotificationDeletedCommand _markNotificationDeletedCommand; | ||
private readonly IMarkNotificationReadCommand _markNotificationReadCommand; | ||
|
||
public NotificationsController( | ||
IGetNotificationStatusDetailsForUserQuery getNotificationStatusDetailsForUserQuery, | ||
IMarkNotificationDeletedCommand markNotificationDeletedCommand, | ||
IMarkNotificationReadCommand markNotificationReadCommand) | ||
{ | ||
_getNotificationStatusDetailsForUserQuery = getNotificationStatusDetailsForUserQuery; | ||
_markNotificationDeletedCommand = markNotificationDeletedCommand; | ||
_markNotificationReadCommand = markNotificationReadCommand; | ||
} | ||
|
||
[HttpGet("")] | ||
public async Task<ListResponseModel<NotificationResponseModel>> ListAsync( | ||
[FromQuery] NotificationFilterRequestModel filter) | ||
{ | ||
var pageOptions = new PageOptions | ||
{ | ||
ContinuationToken = filter.ContinuationToken, | ||
PageSize = filter.PageSize | ||
}; | ||
|
||
var notificationStatusFilter = new NotificationStatusFilter | ||
{ | ||
Read = filter.ReadStatusFilter, | ||
Deleted = filter.DeletedStatusFilter | ||
}; | ||
|
||
var notificationStatusDetailsPagedResult = | ||
await _getNotificationStatusDetailsForUserQuery.GetByUserIdStatusFilterAsync(notificationStatusFilter, | ||
pageOptions); | ||
|
||
var responses = notificationStatusDetailsPagedResult.Data | ||
.Select(n => new NotificationResponseModel(n)) | ||
.ToList(); | ||
|
||
return new ListResponseModel<NotificationResponseModel>(responses, | ||
notificationStatusDetailsPagedResult.ContinuationToken); | ||
} | ||
|
||
[HttpPatch("{id}/delete")] | ||
public async Task MarkAsDeletedAsync([FromRoute] Guid id) | ||
{ | ||
await _markNotificationDeletedCommand.MarkDeletedAsync(id); | ||
} | ||
|
||
[HttpPatch("{id}/read")] | ||
public async Task MarkAsReadAsync([FromRoute] Guid id) | ||
{ | ||
await _markNotificationReadCommand.MarkReadAsync(id); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Api/NotificationCenter/Models/Request/NotificationFilterRequestModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#nullable enable | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Bit.Api.NotificationCenter.Models.Request; | ||
|
||
public class NotificationFilterRequestModel : IValidatableObject | ||
{ | ||
/// <summary> | ||
/// Filters notifications by read status. When not set, includes notifications without a status. | ||
/// </summary> | ||
public bool? ReadStatusFilter { get; set; } | ||
|
||
/// <summary> | ||
/// Filters notifications by deleted status. When not set, includes notifications without a status. | ||
/// </summary> | ||
public bool? DeletedStatusFilter { get; set; } | ||
|
||
/// <summary> | ||
/// A cursor for use in pagination. | ||
/// </summary> | ||
[StringLength(9)] | ||
public string? ContinuationToken { get; set; } | ||
|
||
/// <summary> | ||
/// The number of items to return in a single page. | ||
/// Default 10. Minimum 10, maximum 1000. | ||
/// </summary> | ||
[Range(10, 1000)] | ||
public int PageSize { get; set; } = 10; | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(ContinuationToken) && | ||
(!int.TryParse(ContinuationToken, out var pageNumber) || pageNumber <= 0)) | ||
{ | ||
yield return new ValidationResult( | ||
"Continuation token must be a positive, non zero integer.", | ||
[nameof(ContinuationToken)]); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Api/NotificationCenter/Models/Response/NotificationResponseModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#nullable enable | ||
using Bit.Core.Models.Api; | ||
using Bit.Core.NotificationCenter.Enums; | ||
using Bit.Core.NotificationCenter.Models.Data; | ||
|
||
namespace Bit.Api.NotificationCenter.Models.Response; | ||
|
||
public class NotificationResponseModel : ResponseModel | ||
{ | ||
private const string _objectName = "notification"; | ||
|
||
public NotificationResponseModel(NotificationStatusDetails notificationStatusDetails, string obj = _objectName) | ||
: base(obj) | ||
{ | ||
if (notificationStatusDetails == null) | ||
{ | ||
throw new ArgumentNullException(nameof(notificationStatusDetails)); | ||
} | ||
|
||
Id = notificationStatusDetails.Id; | ||
Priority = notificationStatusDetails.Priority; | ||
Title = notificationStatusDetails.Title; | ||
Body = notificationStatusDetails.Body; | ||
Date = notificationStatusDetails.RevisionDate; | ||
ReadDate = notificationStatusDetails.ReadDate; | ||
DeletedDate = notificationStatusDetails.DeletedDate; | ||
} | ||
|
||
public NotificationResponseModel() : base(_objectName) | ||
{ | ||
} | ||
|
||
public Guid Id { get; set; } | ||
|
||
public Priority Priority { get; set; } | ||
|
||
public string? Title { get; set; } | ||
|
||
public string? Body { get; set; } | ||
|
||
public DateTime Date { get; set; } | ||
|
||
public DateTime? ReadDate { get; set; } | ||
|
||
public DateTime? DeletedDate { get; set; } | ||
} |
Oops, something went wrong.