From bcc2a2a1ce02811f1137916a5ab8c9fbc17994bc Mon Sep 17 00:00:00 2001 From: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Date: Thu, 16 Feb 2023 10:05:19 -0600 Subject: [PATCH] [SM-502] Fix Users with no name (#2698) * Return email if username is empty --- .../Models/Response/AccessPolicyResponseModel.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Api/SecretsManager/Models/Response/AccessPolicyResponseModel.cs b/src/Api/SecretsManager/Models/Response/AccessPolicyResponseModel.cs index f273e6d57c..a298e15b3a 100644 --- a/src/Api/SecretsManager/Models/Response/AccessPolicyResponseModel.cs +++ b/src/Api/SecretsManager/Models/Response/AccessPolicyResponseModel.cs @@ -1,4 +1,5 @@ #nullable enable +using Bit.Core.Entities; using Bit.Core.Models.Api; using Bit.Core.SecretsManager.Entities; @@ -20,6 +21,11 @@ public abstract class BaseAccessPolicyResponseModel : ResponseModel public bool Write { get; set; } public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } + + public string? GetUserDisplayName(User? user) + { + return string.IsNullOrWhiteSpace(user?.Name) ? user?.Email : user?.Name; + } } public class UserProjectAccessPolicyResponseModel : BaseAccessPolicyResponseModel @@ -30,7 +36,7 @@ public class UserProjectAccessPolicyResponseModel : BaseAccessPolicyResponseMode { OrganizationUserId = accessPolicy.OrganizationUserId; GrantedProjectId = accessPolicy.GrantedProjectId; - OrganizationUserName = accessPolicy.User?.Name; + OrganizationUserName = GetUserDisplayName(accessPolicy.User); } public UserProjectAccessPolicyResponseModel() : base(new UserProjectAccessPolicy(), _objectName) @@ -51,7 +57,7 @@ public class UserServiceAccountAccessPolicyResponseModel : BaseAccessPolicyRespo { OrganizationUserId = accessPolicy.OrganizationUserId; GrantedServiceAccountId = accessPolicy.GrantedServiceAccountId; - OrganizationUserName = accessPolicy.User?.Name; + OrganizationUserName = GetUserDisplayName(accessPolicy.User); } public UserServiceAccountAccessPolicyResponseModel() : base(new UserServiceAccountAccessPolicy(), _objectName)