mirror of
https://github.com/bitwarden/server
synced 2025-12-16 16:23:31 +00:00
[SM-706] Extract Authorization From Create/Update Secret Commands (#2896)
* Extract authorization from commands * Swap to request model validation. * Swap to pattern detection
This commit is contained in:
@@ -4,7 +4,7 @@ using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Api.SecretsManager.Models.Request;
|
||||
|
||||
public class SecretCreateRequestModel
|
||||
public class SecretCreateRequestModel : IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
@@ -32,4 +32,14 @@ public class SecretCreateRequestModel
|
||||
Projects = ProjectIds != null && ProjectIds.Any() ? ProjectIds.Select(x => new Project() { Id = x }).ToList() : null,
|
||||
};
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (ProjectIds is { Length: > 1 })
|
||||
{
|
||||
yield return new ValidationResult(
|
||||
$"Only one project assignment is supported.",
|
||||
new[] { nameof(ProjectIds) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Api.SecretsManager.Models.Request;
|
||||
|
||||
public class SecretUpdateRequestModel
|
||||
public class SecretUpdateRequestModel : IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
@@ -20,11 +20,12 @@ public class SecretUpdateRequestModel
|
||||
|
||||
public Guid[] ProjectIds { get; set; }
|
||||
|
||||
public Secret ToSecret(Guid id)
|
||||
public Secret ToSecret(Guid id, Guid organizationId)
|
||||
{
|
||||
return new Secret()
|
||||
{
|
||||
Id = id,
|
||||
OrganizationId = organizationId,
|
||||
Key = Key,
|
||||
Value = Value,
|
||||
Note = Note,
|
||||
@@ -32,4 +33,14 @@ public class SecretUpdateRequestModel
|
||||
Projects = ProjectIds != null && ProjectIds.Any() ? ProjectIds.Select(x => new Project() { Id = x }).ToList() : null,
|
||||
};
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (ProjectIds is { Length: > 1 })
|
||||
{
|
||||
yield return new ValidationResult(
|
||||
$"Only one project assignment is supported.",
|
||||
new[] { nameof(ProjectIds) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user