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 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
{
ArgumentException.ThrowIfNullOrEmpty(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>
2021-03-17 23:08:11 +00:00
/// Gets 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>
2021-03-17 23:08:11 +00:00
public Guid Id { get; private 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]
2021-03-17 23:08:11 +00:00
public uint RowVersion { get; private set; }
2020-05-02 21:56:05 +00:00
2020-09-01 15:16:09 +00:00
/// <summary>
2021-03-17 23:08:11 +00:00
/// Gets a collection containing the group's permissions.
2020-09-01 15:16:09 +00:00
/// </summary>
2021-03-17 23:08:11 +00:00
public virtual ICollection<Permission> Permissions { get; private set; }
2020-05-02 21:56:05 +00:00
2020-05-31 01:53:56 +00:00
/// <summary>
2021-03-17 23:08:11 +00:00
/// Gets a collection containing the group's preferences.
2020-05-31 01:53:56 +00:00
/// </summary>
2021-03-17 23:08:11 +00:00
public virtual ICollection<Preference> Preferences { get; private 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
}
}