< Summary - Jellyfin

Information
Class: Jellyfin.Data.Entities.Group
Assembly: Jellyfin.Data
File(s): /srv/git/jellyfin/Jellyfin.Data/Entities/Group.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 80
Line coverage: 0%
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%210%
HasPermission(...)100%210%
SetPermission(...)100%210%
OnSavingChanges()100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Data/Entities/Group.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel.DataAnnotations;
 4using System.Linq;
 5using Jellyfin.Data.Enums;
 6using Jellyfin.Data.Interfaces;
 7
 8namespace Jellyfin.Data.Entities
 9{
 10    /// <summary>
 11    /// An entity representing a group.
 12    /// </summary>
 13    public class Group : IHasPermissions, IHasConcurrencyToken
 14    {
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="Group"/> class.
 17        /// </summary>
 18        /// <param name="name">The name of the group.</param>
 19        public Group(string name)
 20        {
 021            ArgumentException.ThrowIfNullOrEmpty(name);
 22
 023            Name = name;
 024            Id = Guid.NewGuid();
 25
 026            Permissions = new HashSet<Permission>();
 027            Preferences = new HashSet<Preference>();
 028        }
 29
 30        /// <summary>
 31        /// Gets the id of this group.
 32        /// </summary>
 33        /// <remarks>
 34        /// Identity, Indexed, Required.
 35        /// </remarks>
 36        public Guid Id { get; private set; }
 37
 38        /// <summary>
 39        /// Gets or sets the group's name.
 40        /// </summary>
 41        /// <remarks>
 42        /// Required, Max length = 255.
 43        /// </remarks>
 44        [MaxLength(255)]
 45        [StringLength(255)]
 46        public string Name { get; set; }
 47
 48        /// <inheritdoc />
 49        [ConcurrencyCheck]
 50        public uint RowVersion { get; private set; }
 51
 52        /// <summary>
 53        /// Gets a collection containing the group's permissions.
 54        /// </summary>
 55        public virtual ICollection<Permission> Permissions { get; private set; }
 56
 57        /// <summary>
 58        /// Gets a collection containing the group's preferences.
 59        /// </summary>
 60        public virtual ICollection<Preference> Preferences { get; private set; }
 61
 62        /// <inheritdoc/>
 63        public bool HasPermission(PermissionKind kind)
 64        {
 065            return Permissions.First(p => p.Kind == kind).Value;
 66        }
 67
 68        /// <inheritdoc/>
 69        public void SetPermission(PermissionKind kind, bool value)
 70        {
 071            Permissions.First(p => p.Kind == kind).Value = value;
 072        }
 73
 74        /// <inheritdoc />
 75        public void OnSavingChanges()
 76        {
 077            RowVersion++;
 078        }
 79    }
 80}