< 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: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 340
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

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        {
 5325            ArgumentException.ThrowIfNullOrEmpty(username);
 5326            ArgumentException.ThrowIfNullOrEmpty(authenticationProviderId);
 5327            ArgumentException.ThrowIfNullOrEmpty(passwordResetProviderId);
 28
 5329            Username = username;
 5330            AuthenticationProviderId = authenticationProviderId;
 5331            PasswordResetProviderId = passwordResetProviderId;
 32
 5333            AccessSchedules = new HashSet<AccessSchedule>();
 5334            DisplayPreferences = new HashSet<DisplayPreferences>();
 5335            ItemDisplayPreferences = new HashSet<ItemDisplayPreferences>();
 36            // Groups = new HashSet<Group>();
 5337            Permissions = new HashSet<Permission>();
 5338            Preferences = new HashSet<Preference>();
 39            // ProviderMappings = new HashSet<ProviderMapping>();
 40
 41            // Set default values
 5342            Id = Guid.NewGuid();
 5343            InvalidLoginAttemptCount = 0;
 5344            EnableUserPreferenceAccess = true;
 5345            MustUpdatePassword = false;
 5346            DisplayMissingEpisodes = false;
 5347            DisplayCollectionsView = false;
 5348            HidePlayedInLatest = true;
 5349            RememberAudioSelections = true;
 5350            RememberSubtitleSelections = true;
 5351            EnableNextEpisodeAutoPlay = true;
 5352            EnableAutoLogin = false;
 5353            PlayDefaultAudioTrack = true;
 5354            SubtitleMode = SubtitlePlaybackMode.Default;
 5355            SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups;
 5356        }
 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 password, or <c>null</c> if none is set.
 78        /// </summary>
 79        /// <remarks>
 80        /// Max length = 65535.
 81        /// </remarks>
 82        [MaxLength(65535)]
 83        [StringLength(65535)]
 84        public string? Password { get; set; }
 85
 86        /// <summary>
 87        /// Gets or sets a value indicating whether the user must update their password.
 88        /// </summary>
 89        /// <remarks>
 90        /// Required.
 91        /// </remarks>
 92        public bool MustUpdatePassword { get; set; }
 93
 94        /// <summary>
 95        /// Gets or sets the audio language preference.
 96        /// </summary>
 97        /// <remarks>
 98        /// Max length = 255.
 99        /// </remarks>
 100        [MaxLength(255)]
 101        [StringLength(255)]
 102        public string? AudioLanguagePreference { get; set; }
 103
 104        /// <summary>
 105        /// Gets or sets the authentication provider id.
 106        /// </summary>
 107        /// <remarks>
 108        /// Required, Max length = 255.
 109        /// </remarks>
 110        [MaxLength(255)]
 111        [StringLength(255)]
 112        public string AuthenticationProviderId { get; set; }
 113
 114        /// <summary>
 115        /// Gets or sets the password reset provider id.
 116        /// </summary>
 117        /// <remarks>
 118        /// Required, Max length = 255.
 119        /// </remarks>
 120        [MaxLength(255)]
 121        [StringLength(255)]
 122        public string PasswordResetProviderId { get; set; }
 123
 124        /// <summary>
 125        /// Gets or sets the invalid login attempt count.
 126        /// </summary>
 127        /// <remarks>
 128        /// Required.
 129        /// </remarks>
 130        public int InvalidLoginAttemptCount { get; set; }
 131
 132        /// <summary>
 133        /// Gets or sets the last activity date.
 134        /// </summary>
 135        public DateTime? LastActivityDate { get; set; }
 136
 137        /// <summary>
 138        /// Gets or sets the last login date.
 139        /// </summary>
 140        public DateTime? LastLoginDate { get; set; }
 141
 142        /// <summary>
 143        /// Gets or sets the number of login attempts the user can make before they are locked out.
 144        /// </summary>
 145        public int? LoginAttemptsBeforeLockout { get; set; }
 146
 147        /// <summary>
 148        /// Gets or sets the maximum number of active sessions the user can have at once.
 149        /// </summary>
 150        public int MaxActiveSessions { get; set; }
 151
 152        /// <summary>
 153        /// Gets or sets the subtitle mode.
 154        /// </summary>
 155        /// <remarks>
 156        /// Required.
 157        /// </remarks>
 158        public SubtitlePlaybackMode SubtitleMode { get; set; }
 159
 160        /// <summary>
 161        /// Gets or sets a value indicating whether the default audio track should be played.
 162        /// </summary>
 163        /// <remarks>
 164        /// Required.
 165        /// </remarks>
 166        public bool PlayDefaultAudioTrack { get; set; }
 167
 168        /// <summary>
 169        /// Gets or sets the subtitle language preference.
 170        /// </summary>
 171        /// <remarks>
 172        /// Max length = 255.
 173        /// </remarks>
 174        [MaxLength(255)]
 175        [StringLength(255)]
 176        public string? SubtitleLanguagePreference { get; set; }
 177
 178        /// <summary>
 179        /// Gets or sets a value indicating whether missing episodes should be displayed.
 180        /// </summary>
 181        /// <remarks>
 182        /// Required.
 183        /// </remarks>
 184        public bool DisplayMissingEpisodes { get; set; }
 185
 186        /// <summary>
 187        /// Gets or sets a value indicating whether to display the collections view.
 188        /// </summary>
 189        /// <remarks>
 190        /// Required.
 191        /// </remarks>
 192        public bool DisplayCollectionsView { get; set; }
 193
 194        /// <summary>
 195        /// Gets or sets a value indicating whether the user has a local password.
 196        /// </summary>
 197        /// <remarks>
 198        /// Required.
 199        /// </remarks>
 200        public bool EnableLocalPassword { get; set; }
 201
 202        /// <summary>
 203        /// Gets or sets a value indicating whether the server should hide played content in "Latest".
 204        /// </summary>
 205        /// <remarks>
 206        /// Required.
 207        /// </remarks>
 208        public bool HidePlayedInLatest { get; set; }
 209
 210        /// <summary>
 211        /// Gets or sets a value indicating whether to remember audio selections on played content.
 212        /// </summary>
 213        /// <remarks>
 214        /// Required.
 215        /// </remarks>
 216        public bool RememberAudioSelections { get; set; }
 217
 218        /// <summary>
 219        /// Gets or sets a value indicating whether to remember subtitle selections on played content.
 220        /// </summary>
 221        /// <remarks>
 222        /// Required.
 223        /// </remarks>
 224        public bool RememberSubtitleSelections { get; set; }
 225
 226        /// <summary>
 227        /// Gets or sets a value indicating whether to enable auto-play for the next episode.
 228        /// </summary>
 229        /// <remarks>
 230        /// Required.
 231        /// </remarks>
 232        public bool EnableNextEpisodeAutoPlay { get; set; }
 233
 234        /// <summary>
 235        /// Gets or sets a value indicating whether the user should auto-login.
 236        /// </summary>
 237        /// <remarks>
 238        /// Required.
 239        /// </remarks>
 240        public bool EnableAutoLogin { get; set; }
 241
 242        /// <summary>
 243        /// Gets or sets a value indicating whether the user can change their preferences.
 244        /// </summary>
 245        /// <remarks>
 246        /// Required.
 247        /// </remarks>
 248        public bool EnableUserPreferenceAccess { get; set; }
 249
 250        /// <summary>
 251        /// Gets or sets the maximum parental rating score.
 252        /// </summary>
 253        public int? MaxParentalRatingScore { get; set; }
 254
 255        /// <summary>
 256        /// Gets or sets the maximum parental rating sub score.
 257        /// </summary>
 258        public int? MaxParentalRatingSubScore { get; set; }
 259
 260        /// <summary>
 261        /// Gets or sets the remote client bitrate limit.
 262        /// </summary>
 263        public int? RemoteClientBitrateLimit { get; set; }
 264
 265        /// <summary>
 266        /// Gets or sets the internal id.
 267        /// This is a temporary stopgap for until the library db is migrated.
 268        /// This corresponds to the value of the index of this user in the library db.
 269        /// </summary>
 270        public long InternalId { get; set; }
 271
 272        /// <summary>
 273        /// Gets or sets the user's profile image. Can be <c>null</c>.
 274        /// </summary>
 275        // [ForeignKey("UserId")]
 276        public virtual ImageInfo? ProfileImage { get; set; }
 277
 278        /// <summary>
 279        /// Gets the user's display preferences.
 280        /// </summary>
 281        public virtual ICollection<DisplayPreferences> DisplayPreferences { get; private set; }
 282
 283        /// <summary>
 284        /// Gets or sets the level of sync play permissions this user has.
 285        /// </summary>
 286        public SyncPlayUserAccessType SyncPlayAccess { get; set; }
 287
 288        /// <summary>
 289        /// Gets or sets the cast receiver id.
 290        /// </summary>
 291        [StringLength(32)]
 292        public string? CastReceiverId { get; set; }
 293
 294        /// <inheritdoc />
 295        [ConcurrencyCheck]
 296        public uint RowVersion { get; private set; }
 297
 298        /// <summary>
 299        /// Gets the list of access schedules this user has.
 300        /// </summary>
 301        public virtual ICollection<AccessSchedule> AccessSchedules { get; private set; }
 302
 303        /// <summary>
 304        /// Gets the list of item display preferences.
 305        /// </summary>
 306        public virtual ICollection<ItemDisplayPreferences> ItemDisplayPreferences { get; private set; }
 307
 308        /*
 309        /// <summary>
 310        /// Gets the list of groups this user is a member of.
 311        /// </summary>
 312        public virtual ICollection<Group> Groups { get; private set; }
 313        */
 314
 315        /// <summary>
 316        /// Gets the list of permissions this user has.
 317        /// </summary>
 318        [ForeignKey("Permission_Permissions_Guid")]
 319        public virtual ICollection<Permission> Permissions { get; private set; }
 320
 321        /*
 322        /// <summary>
 323        /// Gets the list of provider mappings this user has.
 324        /// </summary>
 325        public virtual ICollection<ProviderMapping> ProviderMappings { get; private set; }
 326        */
 327
 328        /// <summary>
 329        /// Gets the list of preferences this user has.
 330        /// </summary>
 331        [ForeignKey("Preference_Preferences_Guid")]
 332        public virtual ICollection<Preference> Preferences { get; private set; }
 333
 334        /// <inheritdoc/>
 335        public void OnSavingChanges()
 336        {
 19337            RowVersion++;
 19338        }
 339    }
 340}