2020-09-01 08:36:45 -07:00
|
|
|
#pragma warning disable CA2227
|
|
|
|
|
2019-06-01 13:40:01 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-05-30 17:49:31 -07:00
|
|
|
using System.Linq;
|
|
|
|
using Jellyfin.Data.Enums;
|
2020-08-30 15:50:54 -07:00
|
|
|
using Jellyfin.Data.Interfaces;
|
2019-06-01 13:40:01 -07:00
|
|
|
|
|
|
|
namespace Jellyfin.Data.Entities
|
|
|
|
{
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <summary>
|
|
|
|
/// An entity representing a group.
|
|
|
|
/// </summary>
|
2020-09-01 08:16:09 -07:00
|
|
|
public class Group : IHasPermissions, IHasConcurrencyToken
|
2020-05-02 14:56:05 -07:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// Initializes a new instance of the <see cref="Group"/> class.
|
2020-05-02 14:56:05 -07:00
|
|
|
/// </summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <param name="name">The name of the group.</param>
|
|
|
|
public Group(string name)
|
2020-05-02 14:56:05 -07:00
|
|
|
{
|
2020-05-15 14:24:01 -07:00
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(name));
|
|
|
|
}
|
2020-05-02 14:56:05 -07:00
|
|
|
|
2020-05-30 18:53:56 -07:00
|
|
|
Name = name;
|
|
|
|
Id = Guid.NewGuid();
|
2020-05-02 14:56:05 -07:00
|
|
|
|
2020-05-30 18:53:56 -07:00
|
|
|
Permissions = new HashSet<Permission>();
|
|
|
|
Preferences = new HashSet<Preference>();
|
2020-05-02 14:56:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// Initializes a new instance of the <see cref="Group"/> class.
|
2020-05-02 14:56:05 -07:00
|
|
|
/// </summary>
|
2020-09-01 08:16:09 -07:00
|
|
|
/// <remarks>
|
|
|
|
/// Default constructor. Protected due to required properties, but present because EF needs it.
|
|
|
|
/// </remarks>
|
2020-05-30 18:53:56 -07:00
|
|
|
protected Group()
|
2020-05-02 14:56:05 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// Gets or sets the id of this group.
|
2020-05-02 14:56:05 -07:00
|
|
|
/// </summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <remarks>
|
|
|
|
/// Identity, Indexed, Required.
|
|
|
|
/// </remarks>
|
2020-05-15 14:24:01 -07:00
|
|
|
public Guid Id { get; protected set; }
|
2020-05-02 14:56:05 -07:00
|
|
|
|
|
|
|
/// <summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// Gets or sets the group's name.
|
2020-05-02 14:56:05 -07:00
|
|
|
/// </summary>
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <remarks>
|
|
|
|
/// Required, Max length = 255.
|
|
|
|
/// </remarks>
|
2020-05-02 14:56:05 -07:00
|
|
|
[Required]
|
|
|
|
[MaxLength(255)]
|
|
|
|
[StringLength(255)]
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
2020-09-01 08:16:09 -07:00
|
|
|
/// <inheritdoc />
|
2020-05-02 14:56:05 -07:00
|
|
|
[ConcurrencyCheck]
|
|
|
|
public uint RowVersion { get; set; }
|
|
|
|
|
2020-09-01 08:16:09 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a collection containing the group's permissions.
|
|
|
|
/// </summary>
|
2020-05-19 16:05:17 -07:00
|
|
|
public virtual ICollection<Permission> Permissions { get; protected set; }
|
2020-05-02 14:56:05 -07:00
|
|
|
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <summary>
|
2020-09-01 08:16:09 -07:00
|
|
|
/// Gets or sets a collection containing the group's preferences.
|
2020-05-30 18:53:56 -07:00
|
|
|
/// </summary>
|
2020-09-01 08:16:09 -07:00
|
|
|
public virtual ICollection<Preference> Preferences { get; protected set; }
|
2020-05-30 18:53:56 -07:00
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2020-05-30 17:49:31 -07:00
|
|
|
public bool HasPermission(PermissionKind kind)
|
|
|
|
{
|
|
|
|
return Permissions.First(p => p.Kind == kind).Value;
|
|
|
|
}
|
|
|
|
|
2020-05-30 18:53:56 -07:00
|
|
|
/// <inheritdoc/>
|
2020-05-30 17:49:31 -07:00
|
|
|
public void SetPermission(PermissionKind kind, bool value)
|
|
|
|
{
|
|
|
|
Permissions.First(p => p.Kind == kind).Value = value;
|
|
|
|
}
|
2020-05-30 18:53:56 -07:00
|
|
|
|
2020-09-01 08:16:09 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
public void OnSavingChanges()
|
|
|
|
{
|
|
|
|
RowVersion++;
|
|
|
|
}
|
2020-05-02 14:56:05 -07:00
|
|
|
}
|
2019-06-01 13:40:01 -07:00
|
|
|
}
|