using System.Collections.Generic; using System.Collections.ObjectModel; namespace Jellyfin.Plugin.Keycloak { /// /// User Model for Keycloak Users. /// public class KeycloakUser { /// /// Initializes a new instance of the class. /// /// Instance of the username of the user. /// User roles. public KeycloakUser(string username, Collection roles) { Username = username; Roles = roles; IsAdmin = false; IsEditor = false; IsEnabled = false; var enabledFolders = new List(); foreach (string permission in Roles) { IsAdmin |= permission == "admin"; IsEditor |= permission == "editor"; IsEnabled |= permission == "user"; if (permission.StartsWith("lib-", System.StringComparison.Ordinal)) { enabledFolders.Add(permission[4..]); } } IsEnabled |= IsAdmin || IsEditor; EnabledFolders = enabledFolders.ToArray(); } /// /// Gets the value of the username of an user. /// public string Username { get; } /// /// Gets the value of roles of an user. /// public Collection Roles { get; } /// /// Gets a list of the enabled media libraries of an user. /// public string[] EnabledFolders { get; } /// /// Gets a value indicating whether the user is an administrator. /// public bool IsAdmin { get; } /// /// Gets a value indicating whether the user is an editor. /// public bool IsEditor { get; } /// /// Gets or sets a value indicating whether the user should be enabled. /// public bool IsEnabled { get; set; } } }