2022-06-29 19:46:41 -04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using Bit.Core.Models.Business;
|
2017-05-13 12:00:40 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
namespace Bit.Api.Models.Request.Organizations
|
2017-05-13 12:00:40 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class ImportOrganizationUsersRequestModel
|
2017-05-13 12:00:40 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public Group[] Groups { get; set; }
|
|
|
|
|
|
public User[] Users { get; set; }
|
|
|
|
|
|
public bool OverwriteExisting { get; set; }
|
|
|
|
|
|
public bool LargeImport { get; set; }
|
2017-05-13 12:00:40 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class Group
|
2017-05-13 12:00:40 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
[Required]
|
|
|
|
|
|
[StringLength(100)]
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[StringLength(300)]
|
|
|
|
|
|
public string ExternalId { get; set; }
|
|
|
|
|
|
public IEnumerable<string> Users { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ImportedGroup ToImportedGroup(Guid organizationId)
|
2017-05-13 12:00:40 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
var importedGroup = new ImportedGroup
|
2017-05-13 12:00:40 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
Group = new Core.Entities.Group
|
|
|
|
|
|
{
|
|
|
|
|
|
OrganizationId = organizationId,
|
|
|
|
|
|
Name = Name,
|
|
|
|
|
|
ExternalId = ExternalId
|
|
|
|
|
|
},
|
|
|
|
|
|
ExternalUserIds = new HashSet<string>(Users)
|
|
|
|
|
|
};
|
2017-05-15 14:41:20 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
return importedGroup;
|
|
|
|
|
|
}
|
2017-05-13 12:00:40 -04:00
|
|
|
|
}
|
2017-05-16 00:11:21 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class User : IValidatableObject
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
[EmailAddress]
|
|
|
|
|
|
[StringLength(256)]
|
|
|
|
|
|
public string Email { get; set; }
|
|
|
|
|
|
public bool Deleted { get; set; }
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[StringLength(300)]
|
|
|
|
|
|
public string ExternalId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ImportedOrganizationUser ToImportedOrganizationUser()
|
2017-05-16 00:11:21 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
var importedUser = new ImportedOrganizationUser
|
|
|
|
|
|
{
|
|
|
|
|
|
Email = Email.ToLowerInvariant(),
|
|
|
|
|
|
ExternalId = ExternalId
|
|
|
|
|
|
};
|
2017-05-16 00:11:21 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
return importedUser;
|
|
|
|
|
|
}
|
2017-05-16 00:11:21 -04:00
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
2017-05-16 00:11:21 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(Email) && !Deleted)
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return new ValidationResult("Email is required for enabled users.", new string[] { nameof(Email) });
|
|
|
|
|
|
}
|
2017-05-16 00:11:21 -04:00
|
|
|
|
}
|
2017-05-13 12:00:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|