2024-06-04 08:17:01 +10:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-11-22 16:05:15 -05:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2019-03-05 23:24:14 -05:00
|
|
|
|
using Bit.Core.Enums;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
2019-03-05 23:24:14 -05:00
|
|
|
|
|
2024-11-22 16:05:15 -05:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
2023-10-19 01:27:56 +10:00
|
|
|
|
namespace Bit.Api.AdminConsole.Public.Models;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2021-12-14 15:05:07 +00:00
|
|
|
|
public abstract class MemberBaseModel
|
2019-03-05 23:24:14 -05:00
|
|
|
|
{
|
|
|
|
|
|
public MemberBaseModel() { }
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2024-06-04 08:58:44 +10:00
|
|
|
|
public MemberBaseModel(OrganizationUser user)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2021-05-06 14:53:12 -05:00
|
|
|
|
if (user == null)
|
2019-03-05 23:24:14 -05:00
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
|
|
|
|
|
}
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2024-09-10 15:06:13 +01:00
|
|
|
|
Type = user.Type;
|
2021-05-06 14:53:12 -05:00
|
|
|
|
ExternalId = user.ExternalId;
|
2024-05-31 09:23:31 +10:00
|
|
|
|
|
|
|
|
|
|
if (Type == OrganizationUserType.Custom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Permissions = new PermissionsModel(user.GetPermissions());
|
|
|
|
|
|
}
|
2022-08-29 15:53:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-22 16:05:15 -05:00
|
|
|
|
[SetsRequiredMembers]
|
2024-06-04 08:58:44 +10:00
|
|
|
|
public MemberBaseModel(OrganizationUserUserDetails user)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2021-05-06 14:53:12 -05:00
|
|
|
|
if (user == null)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2021-05-06 14:53:12 -05:00
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
2019-03-05 23:24:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-10 15:06:13 +01:00
|
|
|
|
Type = user.Type;
|
2019-03-07 15:18:27 -05:00
|
|
|
|
ExternalId = user.ExternalId;
|
2024-05-31 09:23:31 +10:00
|
|
|
|
|
|
|
|
|
|
if (Type == OrganizationUserType.Custom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Permissions = new PermissionsModel(user.GetPermissions());
|
|
|
|
|
|
}
|
2019-03-05 23:24:14 -05:00
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-03-05 23:24:14 -05:00
|
|
|
|
/// <summary>
|
2024-07-12 06:13:10 +10:00
|
|
|
|
/// The member's type (or role) within the organization.
|
2019-03-05 23:24:14 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Required]
|
2024-07-12 06:13:10 +10:00
|
|
|
|
[EnumDataType(typeof(OrganizationUserType))]
|
2024-11-22 16:05:15 -05:00
|
|
|
|
public required OrganizationUserType? Type { get; set; }
|
2019-03-05 23:24:14 -05:00
|
|
|
|
/// <summary>
|
2019-03-07 15:18:27 -05:00
|
|
|
|
/// External identifier for reference or linking this member to another system, such as a user directory.
|
2019-03-05 23:24:14 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <example>external_id_123456</example>
|
|
|
|
|
|
[StringLength(300)]
|
2024-11-22 16:05:15 -05:00
|
|
|
|
public string? ExternalId { get; set; }
|
2024-05-31 09:23:31 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The member's custom permissions if the member has a Custom role. If not supplied, all custom permissions will
|
|
|
|
|
|
/// default to false.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public PermissionsModel? Permissions { get; set; }
|
2019-03-05 23:24:14 -05:00
|
|
|
|
}
|