jellyfin/Jellyfin.Data/Entities/Group.cs

81 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
2020-05-31 02:49:31 +02:00
using System.Linq;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Interfaces;
namespace Jellyfin.Data.Entities
{
2020-05-31 03:53:56 +02:00
/// <summary>
/// An entity representing a group.
/// </summary>
2020-09-01 17:16:09 +02:00
public class Group : IHasPermissions, IHasConcurrencyToken
2020-05-02 23:56:05 +02:00
{
/// <summary>
2020-05-31 03:53:56 +02:00
/// Initializes a new instance of the <see cref="Group"/> class.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-31 03:53:56 +02:00
/// <param name="name">The name of the group.</param>
public Group(string name)
2020-05-02 23:56:05 +02:00
{
ArgumentException.ThrowIfNullOrEmpty(name);
2020-05-02 23:56:05 +02:00
2020-05-31 03:53:56 +02:00
Name = name;
Id = Guid.NewGuid();
2020-05-02 23:56:05 +02:00
2020-05-31 03:53:56 +02:00
Permissions = new HashSet<Permission>();
Preferences = new HashSet<Preference>();
2020-05-02 23:56:05 +02:00
}
/// <summary>
2021-03-18 00:08:11 +01:00
/// Gets the id of this group.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-31 03:53:56 +02:00
/// <remarks>
/// Identity, Indexed, Required.
/// </remarks>
2021-03-18 00:08:11 +01:00
public Guid Id { get; private set; }
2020-05-02 23:56:05 +02:00
/// <summary>
2020-05-31 03:53:56 +02:00
/// Gets or sets the group's name.
2020-05-02 23:56:05 +02:00
/// </summary>
2020-05-31 03:53:56 +02:00
/// <remarks>
/// Required, Max length = 255.
/// </remarks>
2020-05-02 23:56:05 +02:00
[MaxLength(255)]
[StringLength(255)]
public string Name { get; set; }
2020-09-01 17:16:09 +02:00
/// <inheritdoc />
2020-05-02 23:56:05 +02:00
[ConcurrencyCheck]
2021-03-18 00:08:11 +01:00
public uint RowVersion { get; private set; }
2020-05-02 23:56:05 +02:00
2020-09-01 17:16:09 +02:00
/// <summary>
2021-03-18 00:08:11 +01:00
/// Gets a collection containing the group's permissions.
2020-09-01 17:16:09 +02:00
/// </summary>
2021-03-18 00:08:11 +01:00
public virtual ICollection<Permission> Permissions { get; private set; }
2020-05-02 23:56:05 +02:00
2020-05-31 03:53:56 +02:00
/// <summary>
2021-03-18 00:08:11 +01:00
/// Gets a collection containing the group's preferences.
2020-05-31 03:53:56 +02:00
/// </summary>
2021-03-18 00:08:11 +01:00
public virtual ICollection<Preference> Preferences { get; private set; }
2020-05-31 03:53:56 +02:00
/// <inheritdoc/>
2020-05-31 02:49:31 +02:00
public bool HasPermission(PermissionKind kind)
{
return Permissions.First(p => p.Kind == kind).Value;
}
2020-05-31 03:53:56 +02:00
/// <inheritdoc/>
2020-05-31 02:49:31 +02:00
public void SetPermission(PermissionKind kind, bool value)
{
Permissions.First(p => p.Kind == kind).Value = value;
}
2020-05-31 03:53:56 +02:00
2020-09-01 17:16:09 +02:00
/// <inheritdoc />
public void OnSavingChanges()
{
RowVersion++;
}
2020-05-02 23:56:05 +02:00
}
}