jellyfin/Jellyfin.Data/Entities/Permission.cs

100 lines
2.9 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2020-05-15 23:24:01 +02:00
using Jellyfin.Data.Enums;
namespace Jellyfin.Data.Entities
{
2020-05-23 02:20:18 +02:00
/// <summary>
/// An entity representing whether the associated user has a specific permission.
/// </summary>
2020-05-15 23:24:01 +02:00
public partial class Permission : ISavingChanges
2020-05-02 23:56:05 +02:00
{
/// <summary>
/// Initializes a new instance of the <see cref="Permission"/> class.
2020-05-23 02:20:18 +02:00
/// Public constructor with required data.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
/// <param name="kind">The permission kind.</param>
/// <param name="value">The value of this permission.</param>
2020-05-15 23:24:01 +02:00
public Permission(PermissionKind kind, bool value)
2020-05-02 23:56:05 +02:00
{
2020-05-15 23:24:01 +02:00
Kind = kind;
Value = value;
2020-05-02 23:56:05 +02:00
Init();
}
/// <summary>
/// Initializes a new instance of the <see cref="Permission"/> class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
/// </summary>
protected Permission()
{
Init();
}
2020-05-02 23:56:05 +02:00
/*************************************************************************
* Properties
*************************************************************************/
/// <summary>
2020-05-23 02:20:18 +02:00
/// Gets or sets the id of this permission.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
/// <remarks>
/// Identity, Indexed, Required.
/// </remarks>
2020-05-02 23:56:05 +02:00
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
/// <summary>
2020-05-23 02:20:18 +02:00
/// Gets or sets the type of this permission.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-02 23:56:05 +02:00
[Required]
2020-05-23 02:20:18 +02:00
public PermissionKind Kind { get; protected set; }
2020-05-02 23:56:05 +02:00
/// <summary>
2020-05-23 02:20:18 +02:00
/// Gets or sets a value indicating whether the associated user has this permission.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-02 23:56:05 +02:00
[Required]
public bool Value { get; set; }
/// <summary>
2020-05-23 02:20:18 +02:00
/// Gets or sets the row version.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
/// <remarks>
/// Required, ConcurrencyToken.
/// </remarks>
2020-05-02 23:56:05 +02:00
[ConcurrencyCheck]
[Required]
public uint RowVersion { get; set; }
2020-05-23 02:20:18 +02:00
/// <summary>
/// Static create function (for use in LINQ queries, etc.)
/// </summary>
/// <param name="kind">The permission kind.</param>
/// <param name="value">The value of this permission.</param>
/// <returns>The newly created instance.</returns>
public static Permission Create(PermissionKind kind, bool value)
2020-05-02 23:56:05 +02:00
{
2020-05-23 02:20:18 +02:00
return new Permission(kind, value);
2020-05-02 23:56:05 +02:00
}
2020-05-23 02:20:18 +02:00
/// <inheritdoc/>
public void OnSavingChanges()
2020-05-02 23:56:05 +02:00
{
2020-05-23 02:20:18 +02:00
RowVersion++;
2020-05-02 23:56:05 +02:00
}
2020-05-23 02:20:18 +02:00
partial void Init();
2020-05-02 23:56:05 +02:00
}
}