< Summary - Jellyfin

Information
Class: Jellyfin.Database.Implementations.Entities.User
Assembly: Jellyfin.Database.Implementations
File(s): /srv/git/jellyfin/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/User.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 351
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/5/2026 - 12:13:57 AM Line coverage: 100% (28/28) Total lines: 3405/27/2026 - 12:15:38 AM Line coverage: 100% (29/29) Total lines: 351

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
OnSavingChanges()100%11100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/User.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel.DataAnnotations;
 4using System.ComponentModel.DataAnnotations.Schema;
 5using System.Text.Json.Serialization;
 6using Jellyfin.Database.Implementations.Enums;
 7using Jellyfin.Database.Implementations.Interfaces;
 8
 9namespace Jellyfin.Database.Implementations.Entities
 10{
 11    /// <summary>
 12    /// An entity representing a user.
 13    /// </summary>
 14    public class User : IHasPermissions, IHasConcurrencyToken
 15    {
 16        /// <summary>
 17        /// Initializes a new instance of the <see cref="User"/> class.
 18        /// Public constructor with required data.
 19        /// </summary>
 20        /// <param name="username">The username for the new user.</param>
 21        /// <param name="authenticationProviderId">The Id of the user's authentication provider.</param>
 22        /// <param name="passwordResetProviderId">The Id of the user's password reset provider.</param>
 23        public User(string username, string authenticationProviderId, string passwordResetProviderId)
 24        {
 47025            ArgumentException.ThrowIfNullOrEmpty(username);
 47026            ArgumentException.ThrowIfNullOrEmpty(authenticationProviderId);
 47027            ArgumentException.ThrowIfNullOrEmpty(passwordResetProviderId);
 28
 47029            Username = username;
 47030            NormalizedUsername = username.ToUpperInvariant();
 47031            AuthenticationProviderId = authenticationProviderId;
 47032            PasswordResetProviderId = passwordResetProviderId;
 33
 47034            AccessSchedules = new HashSet<AccessSchedule>();
 47035            DisplayPreferences = new HashSet<DisplayPreferences>();
 47036            ItemDisplayPreferences = new HashSet<ItemDisplayPreferences>();
 37            // Groups = new HashSet<Group>();
 47038            Permissions = new HashSet<Permission>();
 47039            Preferences = new HashSet<Preference>();
 40            // ProviderMappings = new HashSet<ProviderMapping>();
 41
 42            // Set default values
 47043            Id = Guid.NewGuid();
 47044            InvalidLoginAttemptCount = 0;
 47045            EnableUserPreferenceAccess = true;
 47046            MustUpdatePassword = false;
 47047            DisplayMissingEpisodes = false;
 47048            DisplayCollectionsView = false;
 47049            HidePlayedInLatest = true;
 47050            RememberAudioSelections = true;
 47051            RememberSubtitleSelections = true;
 47052            EnableNextEpisodeAutoPlay = true;
 47053            EnableAutoLogin = false;
 47054            PlayDefaultAudioTrack = true;
 47055            SubtitleMode = SubtitlePlaybackMode.Default;
 47056            SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups;
 47057        }
 58
 59        /// <summary>
 60        /// Gets or sets the Id of the user.
 61        /// </summary>
 62        /// <remarks>
 63        /// Identity, Indexed, Required.
 64        /// </remarks>
 65        public Guid Id { get; set; }
 66
 67        /// <summary>
 68        /// Gets or sets the user's name.
 69        /// </summary>
 70        /// <remarks>
 71        /// Required, Max length = 255.
 72        /// </remarks>
 73        [MaxLength(255)]
 74        [StringLength(255)]
 75        public string Username { get; set; }
 76
 77        /// <summary>
 78        /// Gets or sets the user's normalized name.
 79        /// </summary>
 80        /// <remarks>
 81        /// Required, Max length = 255.
 82        /// </remarks>
 83        [MaxLength(255)]
 84        [StringLength(255)]
 85        public string NormalizedUsername { get; set; }
 86
 87        /// <summary>
 88        /// Gets or sets the user's password, or <c>null</c> if none is set.
 89        /// </summary>
 90        /// <remarks>
 91        /// Max length = 65535.
 92        /// </remarks>
 93        [MaxLength(65535)]
 94        [StringLength(65535)]
 95        public string? Password { get; set; }
 96
 97        /// <summary>
 98        /// Gets or sets a value indicating whether the user must update their password.
 99        /// </summary>
 100        /// <remarks>
 101        /// Required.
 102        /// </remarks>
 103        public bool MustUpdatePassword { get; set; }
 104
 105        /// <summary>
 106        /// Gets or sets the audio language preference.
 107        /// </summary>
 108        /// <remarks>
 109        /// Max length = 255.
 110        /// </remarks>
 111        [MaxLength(255)]
 112        [StringLength(255)]
 113        public string? AudioLanguagePreference { get; set; }
 114
 115        /// <summary>
 116        /// Gets or sets the authentication provider id.
 117        /// </summary>
 118        /// <remarks>
 119        /// Required, Max length = 255.
 120        /// </remarks>
 121        [MaxLength(255)]
 122        [StringLength(255)]
 123        public string AuthenticationProviderId { get; set; }
 124
 125        /// <summary>
 126        /// Gets or sets the password reset provider id.
 127        /// </summary>
 128        /// <remarks>
 129        /// Required, Max length = 255.
 130        /// </remarks>
 131        [MaxLength(255)]
 132        [StringLength(255)]
 133        public string PasswordResetProviderId { get; set; }
 134
 135        /// <summary>
 136        /// Gets or sets the invalid login attempt count.
 137        /// </summary>
 138        /// <remarks>
 139        /// Required.
 140        /// </remarks>
 141        public int InvalidLoginAttemptCount { get; set; }
 142
 143        /// <summary>
 144        /// Gets or sets the last activity date.
 145        /// </summary>
 146        public DateTime? LastActivityDate { get; set; }
 147
 148        /// <summary>
 149        /// Gets or sets the last login date.
 150        /// </summary>
 151        public DateTime? LastLoginDate { get; set; }
 152
 153        /// <summary>
 154        /// Gets or sets the number of login attempts the user can make before they are locked out.
 155        /// </summary>
 156        public int? LoginAttemptsBeforeLockout { get; set; }
 157
 158        /// <summary>
 159        /// Gets or sets the maximum number of active sessions the user can have at once.
 160        /// </summary>
 161        public int MaxActiveSessions { get; set; }
 162
 163        /// <summary>
 164        /// Gets or sets the subtitle mode.
 165        /// </summary>
 166        /// <remarks>
 167        /// Required.
 168        /// </remarks>
 169        public SubtitlePlaybackMode SubtitleMode { get; set; }
 170
 171        /// <summary>
 172        /// Gets or sets a value indicating whether the default audio track should be played.
 173        /// </summary>
 174        /// <remarks>
 175        /// Required.
 176        /// </remarks>
 177        public bool PlayDefaultAudioTrack { get; set; }
 178
 179        /// <summary>
 180        /// Gets or sets the subtitle language preference.
 181        /// </summary>
 182        /// <remarks>
 183        /// Max length = 255.
 184        /// </remarks>
 185        [MaxLength(255)]
 186        [StringLength(255)]
 187        public string? SubtitleLanguagePreference { get; set; }
 188
 189        /// <summary>
 190        /// Gets or sets a value indicating whether missing episodes should be displayed.
 191        /// </summary>
 192        /// <remarks>
 193        /// Required.
 194        /// </remarks>
 195        public bool DisplayMissingEpisodes { get; set; }
 196
 197        /// <summary>
 198        /// Gets or sets a value indicating whether to display the collections view.
 199        /// </summary>
 200        /// <remarks>
 201        /// Required.
 202        /// </remarks>
 203        public bool DisplayCollectionsView { get; set; }
 204
 205        /// <summary>
 206        /// Gets or sets a value indicating whether the user has a local password.
 207        /// </summary>
 208        /// <remarks>
 209        /// Required.
 210        /// </remarks>
 211        public bool EnableLocalPassword { get; set; }
 212
 213        /// <summary>
 214        /// Gets or sets a value indicating whether the server should hide played content in "Latest".
 215        /// </summary>
 216        /// <remarks>
 217        /// Required.
 218        /// </remarks>
 219        public bool HidePlayedInLatest { get; set; }
 220
 221        /// <summary>
 222        /// Gets or sets a value indicating whether to remember audio selections on played content.
 223        /// </summary>
 224        /// <remarks>
 225        /// Required.
 226        /// </remarks>
 227        public bool RememberAudioSelections { get; set; }
 228
 229        /// <summary>
 230        /// Gets or sets a value indicating whether to remember subtitle selections on played content.
 231        /// </summary>
 232        /// <remarks>
 233        /// Required.
 234        /// </remarks>
 235        public bool RememberSubtitleSelections { get; set; }
 236
 237        /// <summary>
 238        /// Gets or sets a value indicating whether to enable auto-play for the next episode.
 239        /// </summary>
 240        /// <remarks>
 241        /// Required.
 242        /// </remarks>
 243        public bool EnableNextEpisodeAutoPlay { get; set; }
 244
 245        /// <summary>
 246        /// Gets or sets a value indicating whether the user should auto-login.
 247        /// </summary>
 248        /// <remarks>
 249        /// Required.
 250        /// </remarks>
 251        public bool EnableAutoLogin { get; set; }
 252
 253        /// <summary>
 254        /// Gets or sets a value indicating whether the user can change their preferences.
 255        /// </summary>
 256        /// <remarks>
 257        /// Required.
 258        /// </remarks>
 259        public bool EnableUserPreferenceAccess { get; set; }
 260
 261        /// <summary>
 262        /// Gets or sets the maximum parental rating score.
 263        /// </summary>
 264        public int? MaxParentalRatingScore { get; set; }
 265
 266        /// <summary>
 267        /// Gets or sets the maximum parental rating sub score.
 268        /// </summary>
 269        public int? MaxParentalRatingSubScore { get; set; }
 270
 271        /// <summary>
 272        /// Gets or sets the remote client bitrate limit.
 273        /// </summary>
 274        public int? RemoteClientBitrateLimit { get; set; }
 275
 276        /// <summary>
 277        /// Gets or sets the internal id.
 278        /// This is a temporary stopgap for until the library db is migrated.
 279        /// This corresponds to the value of the index of this user in the library db.
 280        /// </summary>
 281        public long InternalId { get; set; }
 282
 283        /// <summary>
 284        /// Gets or sets the user's profile image. Can be <c>null</c>.
 285        /// </summary>
 286        // [ForeignKey("UserId")]
 287        public virtual ImageInfo? ProfileImage { get; set; }
 288
 289        /// <summary>
 290        /// Gets the user's display preferences.
 291        /// </summary>
 292        public virtual ICollection<DisplayPreferences> DisplayPreferences { get; private set; }
 293
 294        /// <summary>
 295        /// Gets or sets the level of sync play permissions this user has.
 296        /// </summary>
 297        public SyncPlayUserAccessType SyncPlayAccess { get; set; }
 298
 299        /// <summary>
 300        /// Gets or sets the cast receiver id.
 301        /// </summary>
 302        [StringLength(32)]
 303        public string? CastReceiverId { get; set; }
 304
 305        /// <inheritdoc />
 306        [ConcurrencyCheck]
 307        public uint RowVersion { get; private set; }
 308
 309        /// <summary>
 310        /// Gets the list of access schedules this user has.
 311        /// </summary>
 312        public virtual ICollection<AccessSchedule> AccessSchedules { get; private set; }
 313
 314        /// <summary>
 315        /// Gets the list of item display preferences.
 316        /// </summary>
 317        public virtual ICollection<ItemDisplayPreferences> ItemDisplayPreferences { get; private set; }
 318
 319        /*
 320        /// <summary>
 321        /// Gets the list of groups this user is a member of.
 322        /// </summary>
 323        public virtual ICollection<Group> Groups { get; private set; }
 324        */
 325
 326        /// <summary>
 327        /// Gets the list of permissions this user has.
 328        /// </summary>
 329        [ForeignKey("Permission_Permissions_Guid")]
 330        public virtual ICollection<Permission> Permissions { get; private set; }
 331
 332        /*
 333        /// <summary>
 334        /// Gets the list of provider mappings this user has.
 335        /// </summary>
 336        public virtual ICollection<ProviderMapping> ProviderMappings { get; private set; }
 337        */
 338
 339        /// <summary>
 340        /// Gets the list of preferences this user has.
 341        /// </summary>
 342        [ForeignKey("Preference_Preferences_Guid")]
 343        public virtual ICollection<Preference> Preferences { get; private set; }
 344
 345        /// <inheritdoc/>
 346        public void OnSavingChanges()
 347        {
 23348            RowVersion++;
 23349        }
 350    }
 351}