Permission.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Jellyfin.Data.Enums;
  4. namespace Jellyfin.Data.Entities
  5. {
  6. /// <summary>
  7. /// An entity representing whether the associated user has a specific permission.
  8. /// </summary>
  9. public partial class Permission : ISavingChanges
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="Permission"/> class.
  13. /// Public constructor with required data.
  14. /// </summary>
  15. /// <param name="kind">The permission kind.</param>
  16. /// <param name="value">The value of this permission.</param>
  17. public Permission(PermissionKind kind, bool value)
  18. {
  19. Kind = kind;
  20. Value = value;
  21. Init();
  22. }
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="Permission"/> class.
  25. /// Default constructor. Protected due to required properties, but present because EF needs it.
  26. /// </summary>
  27. protected Permission()
  28. {
  29. Init();
  30. }
  31. /*************************************************************************
  32. * Properties
  33. *************************************************************************/
  34. /// <summary>
  35. /// Gets or sets the id of this permission.
  36. /// </summary>
  37. /// <remarks>
  38. /// Identity, Indexed, Required.
  39. /// </remarks>
  40. [Key]
  41. [Required]
  42. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  43. public int Id { get; protected set; }
  44. /// <summary>
  45. /// Gets or sets the type of this permission.
  46. /// </summary>
  47. /// <remarks>
  48. /// Required.
  49. /// </remarks>
  50. [Required]
  51. public PermissionKind Kind { get; protected set; }
  52. /// <summary>
  53. /// Gets or sets a value indicating whether the associated user has this permission.
  54. /// </summary>
  55. /// <remarks>
  56. /// Required.
  57. /// </remarks>
  58. [Required]
  59. public bool Value { get; set; }
  60. /// <summary>
  61. /// Gets or sets the row version.
  62. /// </summary>
  63. /// <remarks>
  64. /// Required, ConcurrencyToken.
  65. /// </remarks>
  66. [ConcurrencyCheck]
  67. [Required]
  68. public uint RowVersion { get; set; }
  69. /// <summary>
  70. /// Static create function (for use in LINQ queries, etc.)
  71. /// </summary>
  72. /// <param name="kind">The permission kind.</param>
  73. /// <param name="value">The value of this permission.</param>
  74. /// <returns>The newly created instance.</returns>
  75. public static Permission Create(PermissionKind kind, bool value)
  76. {
  77. return new Permission(kind, value);
  78. }
  79. /// <inheritdoc/>
  80. public void OnSavingChanges()
  81. {
  82. RowVersion++;
  83. }
  84. partial void Init();
  85. }
  86. }