jellyfin-server/Jellyfin.Data/Entities/Group.cs

86 lines
2.3 KiB
C#
Raw Normal View History

2020-09-01 15:36:45 +00:00
#pragma warning disable CA2227
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
2020-05-31 00:49:31 +00:00
using System.Linq;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Interfaces;
namespace Jellyfin.Data.Entities
{
2020-05-31 01:53:56 +00:00
/// <summary>
/// An entity representing a group.
/// </summary>
2020-09-01 15:16:09 +00:00
public class Group : IHasPermissions, IHasConcurrencyToken
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.
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>();
Preferences = new HashSet<Preference>();
2020-05-02 21:56:05 +00:00
}
/// <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-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
[MaxLength(255)]
[StringLength(255)]
public string Name { get; set; }
2020-09-01 15:16:09 +00:00
/// <inheritdoc />
2020-05-02 21:56:05 +00:00
[ConcurrencyCheck]
public uint RowVersion { get; set; }
2020-09-01 15:16:09 +00:00
/// <summary>
/// Gets or sets a collection containing the group's permissions.
/// </summary>
2020-05-19 23:05:17 +00:00
public virtual ICollection<Permission> Permissions { get; protected set; }
2020-05-02 21:56:05 +00:00
2020-05-31 01:53:56 +00:00
/// <summary>
2020-09-01 15:16:09 +00:00
/// Gets or sets a collection containing the group's preferences.
2020-05-31 01:53:56 +00:00
/// </summary>
2020-09-01 15:16:09 +00:00
public virtual ICollection<Preference> Preferences { get; protected set; }
2020-05-31 01:53:56 +00:00
/// <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
2020-09-01 15:16:09 +00:00
/// <inheritdoc />
public void OnSavingChanges()
{
RowVersion++;
}
2020-05-02 21:56:05 +00:00
}
}