< 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: 348
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 5/16/2026 - 12:15:55 AM Line coverage: 100% (28/28) Total lines: 3405/27/2026 - 12:15:38 AM Line coverage: 100% (29/29) Total lines: 35110/29/2026 - 12:17:11 AM Line coverage: 100% (29/29) Total lines: 348

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