Permission.cs 2.9 KB

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