2019-06-01 20:40:01 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2020-05-31 00:49:31 +00:00
|
|
|
using System.Linq;
|
|
|
|
using Jellyfin.Data.Enums;
|
2019-06-01 20:40:01 +00:00
|
|
|
|
|
|
|
namespace Jellyfin.Data.Entities
|
|
|
|
{
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <summary>
|
|
|
|
/// An entity representing a group.
|
|
|
|
/// </summary>
|
2020-05-15 21:24:01 +00:00
|
|
|
public partial class Group : IHasPermissions, ISavingChanges
|
2020-05-02 21:56:05 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// Initializes a new instance of the <see cref="Group"/> class.
|
|
|
|
/// Public constructor with required data.
|
2020-05-02 21:56:05 +00:00
|
|
|
/// </summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <param name="name">The name of the group.</param>
|
|
|
|
public Group(string name)
|
2020-05-02 21:56:05 +00:00
|
|
|
{
|
2020-05-15 21:24:01 +00:00
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(name));
|
|
|
|
}
|
2020-05-02 21:56:05 +00:00
|
|
|
|
2020-05-31 01:53:56 +00:00
|
|
|
Name = name;
|
|
|
|
Id = Guid.NewGuid();
|
2020-05-02 21:56:05 +00:00
|
|
|
|
2020-05-31 01:53:56 +00:00
|
|
|
Permissions = new HashSet<Permission>();
|
|
|
|
ProviderMappings = new HashSet<ProviderMapping>();
|
|
|
|
Preferences = new HashSet<Preference>();
|
2020-05-02 21:56:05 +00:00
|
|
|
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// Initializes a new instance of the <see cref="Group"/> class.
|
|
|
|
/// Default constructor. Protected due to required properties, but present because EF needs it.
|
2020-05-02 21:56:05 +00:00
|
|
|
/// </summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
protected Group()
|
2020-05-02 21:56:05 +00:00
|
|
|
{
|
2020-05-31 01:53:56 +00:00
|
|
|
Init();
|
2020-05-02 21:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Properties
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// Gets or sets the id of this group.
|
2020-05-02 21:56:05 +00:00
|
|
|
/// </summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// Identity, Indexed, Required.
|
|
|
|
/// </remarks>
|
2020-05-02 21:56:05 +00:00
|
|
|
[Key]
|
|
|
|
[Required]
|
2020-05-15 21:24:01 +00:00
|
|
|
public Guid Id { get; protected set; }
|
2020-05-02 21:56:05 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// Gets or sets the group's name.
|
2020-05-02 21:56:05 +00:00
|
|
|
/// </summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// Required, Max length = 255.
|
|
|
|
/// </remarks>
|
2020-05-02 21:56:05 +00:00
|
|
|
[Required]
|
|
|
|
[MaxLength(255)]
|
|
|
|
[StringLength(255)]
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// Gets or sets the row version.
|
2020-05-02 21:56:05 +00:00
|
|
|
/// </summary>
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// Required, Concurrency Token.
|
|
|
|
/// </remarks>
|
2020-05-02 21:56:05 +00:00
|
|
|
[ConcurrencyCheck]
|
|
|
|
[Required]
|
|
|
|
public uint RowVersion { get; set; }
|
|
|
|
|
|
|
|
public void OnSavingChanges()
|
|
|
|
{
|
|
|
|
RowVersion++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Navigation properties
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
[ForeignKey("Permission_GroupPermissions_Id")]
|
2020-05-19 23:05:17 +00:00
|
|
|
public virtual ICollection<Permission> Permissions { get; protected set; }
|
2020-05-02 21:56:05 +00:00
|
|
|
|
|
|
|
[ForeignKey("ProviderMapping_ProviderMappings_Id")]
|
2020-05-19 23:05:17 +00:00
|
|
|
public virtual ICollection<ProviderMapping> ProviderMappings { get; protected set; }
|
2020-05-02 21:56:05 +00:00
|
|
|
|
|
|
|
[ForeignKey("Preference_Preferences_Id")]
|
2020-05-19 23:05:17 +00:00
|
|
|
public virtual ICollection<Preference> Preferences { get; protected set; }
|
2020-05-31 00:49:31 +00:00
|
|
|
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Static create function (for use in LINQ queries, etc.)
|
|
|
|
/// </summary>
|
2020-06-19 10:21:49 +00:00
|
|
|
/// <param name="name">The name of this group.</param>
|
2020-05-31 01:53:56 +00:00
|
|
|
public static Group Create(string name)
|
|
|
|
{
|
|
|
|
return new Group(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2020-05-31 00:49:31 +00:00
|
|
|
public bool HasPermission(PermissionKind kind)
|
|
|
|
{
|
|
|
|
return Permissions.First(p => p.Kind == kind).Value;
|
|
|
|
}
|
|
|
|
|
2020-05-31 01:53:56 +00:00
|
|
|
/// <inheritdoc/>
|
2020-05-31 00:49:31 +00:00
|
|
|
public void SetPermission(PermissionKind kind, bool value)
|
|
|
|
{
|
|
|
|
Permissions.First(p => p.Kind == kind).Value = value;
|
|
|
|
}
|
2020-05-31 01:53:56 +00:00
|
|
|
|
|
|
|
partial void Init();
|
2020-05-02 21:56:05 +00:00
|
|
|
}
|
2019-06-01 20:40:01 +00:00
|
|
|
}
|