| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.ComponentModel.DataAnnotations; |
| | 4 | | using System.Linq; |
| | 5 | | using Jellyfin.Data.Enums; |
| | 6 | | using Jellyfin.Data.Interfaces; |
| | 7 | |
|
| | 8 | | namespace Jellyfin.Data.Entities |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// An entity representing a group. |
| | 12 | | /// </summary> |
| | 13 | | public class Group : IHasPermissions, IHasConcurrencyToken |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Initializes a new instance of the <see cref="Group"/> class. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="name">The name of the group.</param> |
| | 19 | | public Group(string name) |
| | 20 | | { |
| 0 | 21 | | ArgumentException.ThrowIfNullOrEmpty(name); |
| | 22 | |
|
| 0 | 23 | | Name = name; |
| 0 | 24 | | Id = Guid.NewGuid(); |
| | 25 | |
|
| 0 | 26 | | Permissions = new HashSet<Permission>(); |
| 0 | 27 | | Preferences = new HashSet<Preference>(); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets the id of this group. |
| | 32 | | /// </summary> |
| | 33 | | /// <remarks> |
| | 34 | | /// Identity, Indexed, Required. |
| | 35 | | /// </remarks> |
| | 36 | | public Guid Id { get; private set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets the group's name. |
| | 40 | | /// </summary> |
| | 41 | | /// <remarks> |
| | 42 | | /// Required, Max length = 255. |
| | 43 | | /// </remarks> |
| | 44 | | [MaxLength(255)] |
| | 45 | | [StringLength(255)] |
| | 46 | | public string Name { get; set; } |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | [ConcurrencyCheck] |
| | 50 | | public uint RowVersion { get; private set; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Gets a collection containing the group's permissions. |
| | 54 | | /// </summary> |
| | 55 | | public virtual ICollection<Permission> Permissions { get; private set; } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// Gets a collection containing the group's preferences. |
| | 59 | | /// </summary> |
| | 60 | | public virtual ICollection<Preference> Preferences { get; private set; } |
| | 61 | |
|
| | 62 | | /// <inheritdoc/> |
| | 63 | | public bool HasPermission(PermissionKind kind) |
| | 64 | | { |
| 0 | 65 | | return Permissions.First(p => p.Kind == kind).Value; |
| | 66 | | } |
| | 67 | |
|
| | 68 | | /// <inheritdoc/> |
| | 69 | | public void SetPermission(PermissionKind kind, bool value) |
| | 70 | | { |
| 0 | 71 | | Permissions.First(p => p.Kind == kind).Value = value; |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | /// <inheritdoc /> |
| | 75 | | public void OnSavingChanges() |
| | 76 | | { |
| 0 | 77 | | RowVersion++; |
| 0 | 78 | | } |
| | 79 | | } |
| | 80 | | } |