From b8add59a1a0204c0b003ff77830d6618d0c7accd Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Tue, 10 Sep 2024 18:17:38 +0200 Subject: [PATCH] feat: expose plex usernames in APIv3 User DTO --- Shoko.Server/API/v3/Models/Shoko/User.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Shoko.Server/API/v3/Models/Shoko/User.cs b/Shoko.Server/API/v3/Models/Shoko/User.cs index 0808bc856..7bf2f5783 100644 --- a/Shoko.Server/API/v3/Models/Shoko/User.cs +++ b/Shoko.Server/API/v3/Models/Shoko/User.cs @@ -50,6 +50,11 @@ public class User /// public string Avatar { get; set; } + /// + /// The user's Plex usernames. + /// + public List PlexUsernames { get; set; } + public User(SVR_JMMUser user) { ID = user.JMMUserID; @@ -78,6 +83,8 @@ public User(SVR_JMMUser user) .ToList(); Avatar = user.HasAvatarImage ? ModelHelper.ToDataURL(user.AvatarImageBlob, user.AvatarImageMetadata.ContentType) ?? string.Empty : string.Empty; + + PlexUsernames = user.PlexUsers.Split(',', System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries).ToList(); } public class Input @@ -139,6 +146,11 @@ public class CreateOrUpdateUserBody /// public string? Avatar { get; set; } = null; + /// + /// The new user's Plex usernames. + /// + public List? PlexUsernames { get; set; } + public CreateOrUpdateUserBody() { } private const long MaxFileSize = 8 * 1024 * 1024; // 8MiB in bytes @@ -230,6 +242,11 @@ public CreateOrUpdateUserBody() { } user.IsAniDBUser = CommunitySites.Contains(global::Shoko.Models.Enums.CommunitySites.AniDB) ? 1 : 0; } + if (PlexUsernames != null) + { + user.PlexUsers = string.Join(',', PlexUsernames.Select(username => username.Trim()).Where(username => !string.IsNullOrEmpty(username))); + } + // Save the model now. RepoFactory.JMMUser.Save(user);