72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Jellyfin.Plugin.Keycloak
|
|
{
|
|
/// <summary>
|
|
/// User Model for Keycloak Users.
|
|
/// </summary>
|
|
public class KeycloakUser
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="KeycloakUser"/> class.
|
|
/// </summary>
|
|
/// <param name="username">Instance of the username of the user.</param>
|
|
/// <param name="roles">User roles.</param>
|
|
public KeycloakUser(string username, Collection<string> roles)
|
|
{
|
|
Username = username;
|
|
Roles = roles;
|
|
|
|
IsAdmin = false;
|
|
IsEditor = false;
|
|
IsEnabled = false;
|
|
var enabledFolders = new List<string>();
|
|
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the value of the username of an user.
|
|
/// </summary>
|
|
public string Username { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the value of roles of an user.
|
|
/// </summary>
|
|
public Collection<string> Roles { get; }
|
|
|
|
/// <summary>
|
|
/// Gets a list of the enabled media libraries of an user.
|
|
/// </summary>
|
|
public string[] EnabledFolders { get; }
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the user is an administrator.
|
|
/// </summary>
|
|
public bool IsAdmin { get; }
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the user is an editor.
|
|
/// </summary>
|
|
public bool IsEditor { get; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether the user should be enabled.
|
|
/// </summary>
|
|
public bool IsEnabled { get; set; }
|
|
}
|
|
}
|