mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
bulk invite apis
This commit is contained in:
@ -1,18 +1,41 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class OrganizationUserInviteRequestModel
|
||||
public class OrganizationUserInviteRequestModel : IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
public IEnumerable<string> Emails { get; set; }
|
||||
[Required]
|
||||
public Enums.OrganizationUserType? Type { get; set; }
|
||||
public bool AccessAll { get; set; }
|
||||
public IEnumerable<SelectionReadOnlyRequestModel> Collections { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Emails.Any())
|
||||
{
|
||||
yield return new ValidationResult("An email is required.");
|
||||
}
|
||||
|
||||
if(Emails.Count() > 20)
|
||||
{
|
||||
yield return new ValidationResult("You can only invite up to 20 users at a time.");
|
||||
}
|
||||
|
||||
var attr = new EmailAddressAttribute();
|
||||
for(int i = 0; i < Emails.Count(); i++)
|
||||
{
|
||||
if(!attr.IsValid(Emails.ElementAt(i)))
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is not valid.", new string[] { nameof(Emails) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserAcceptRequestModel
|
||||
|
Reference in New Issue
Block a user