mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
[SM-1197] - Duplicate GUIDS Show a more detailed error message if duplicate GUIDS are passed ot g… (#4161)
* Show a more detailed error message if duplicate GUIDS are passed ot get by Ids * Update test/Api.IntegrationTest/SecretsManager/Controllers/SecretsControllerTests.cs Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Update src/Api/SecretsManager/Models/Request/GetSecretsRequestModel.cs Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Update src/Api/SecretsManager/Models/Request/GetSecretsRequestModel.cs Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Making requested changes to tests * lint fix * fixing whitespace --------- Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>
This commit is contained in:
@ -1,9 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.SecretsManager.Models.Request;
|
||||
|
||||
public class GetSecretsRequestModel
|
||||
public class GetSecretsRequestModel : IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
public IEnumerable<Guid> Ids { get; set; }
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
var isDistinct = Ids.Distinct().Count() == Ids.Count();
|
||||
if (!isDistinct)
|
||||
{
|
||||
var duplicateGuids = Ids.GroupBy(x => x)
|
||||
.Where(g => g.Count() > 1)
|
||||
.Select(g => g.Key);
|
||||
|
||||
yield return new ValidationResult(
|
||||
$"The following GUIDs were duplicated {string.Join(", ", duplicateGuids)} ",
|
||||
new[] { nameof(GetSecretsRequestModel) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user