From e8b6da3cd71ebb9dd01f3aff4a1c8805be6ba91b Mon Sep 17 00:00:00 2001 From: Patrick Barron Date: Sat, 30 May 2020 20:49:31 -0400 Subject: [PATCH] Expand and document IHasPermissions --- Jellyfin.Data/Entities/Group.cs | 13 ++++++++++++- Jellyfin.Data/Entities/User.cs | 13 ++++++------- Jellyfin.Data/IHasPermissions.cs | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Jellyfin.Data/Entities/Group.cs b/Jellyfin.Data/Entities/Group.cs index ecef4102c..b71a1bd78 100644 --- a/Jellyfin.Data/Entities/Group.cs +++ b/Jellyfin.Data/Entities/Group.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using Jellyfin.Data.Enums; namespace Jellyfin.Data.Entities { @@ -96,6 +98,15 @@ namespace Jellyfin.Data.Entities [ForeignKey("Preference_Preferences_Id")] public virtual ICollection Preferences { get; protected set; } + + public bool HasPermission(PermissionKind kind) + { + return Permissions.First(p => p.Kind == kind).Value; + } + + public void SetPermission(PermissionKind kind, bool value) + { + Permissions.First(p => p.Kind == kind).Value = value; + } } } - diff --git a/Jellyfin.Data/Entities/User.cs b/Jellyfin.Data/Entities/User.cs index ac87c7ec2..a6221a249 100644 --- a/Jellyfin.Data/Entities/User.cs +++ b/Jellyfin.Data/Entities/User.cs @@ -389,16 +389,14 @@ namespace Jellyfin.Data.Entities RowVersion++; } - partial void Init(); - /// /// Checks whether the user has the specified permission. /// - /// The permission kind. + /// The permission kind. /// True if the user has the specified permission. - public bool HasPermission(PermissionKind permission) + public bool HasPermission(PermissionKind kind) { - return Permissions.First(p => p.Kind == permission).Value; + return Permissions.First(p => p.Kind == kind).Value; } /// @@ -408,8 +406,7 @@ namespace Jellyfin.Data.Entities /// The value to set. public void SetPermission(PermissionKind kind, bool value) { - var permissionObj = Permissions.First(p => p.Kind == kind); - permissionObj.Value = value; + Permissions.First(p => p.Kind == kind).Value = value; } /// @@ -501,5 +498,7 @@ namespace Jellyfin.Data.Entities Preferences.Add(new Preference(val, string.Empty)); } } + + partial void Init(); } } diff --git a/Jellyfin.Data/IHasPermissions.cs b/Jellyfin.Data/IHasPermissions.cs index a77e51e1e..3be72259a 100644 --- a/Jellyfin.Data/IHasPermissions.cs +++ b/Jellyfin.Data/IHasPermissions.cs @@ -1,10 +1,31 @@ using System.Collections.Generic; using Jellyfin.Data.Entities; +using Jellyfin.Data.Enums; namespace Jellyfin.Data { + /// + /// An abstraction representing an entity that has permissions. + /// public interface IHasPermissions { + /// + /// Gets a collection containing this entity's permissions. + /// ICollection Permissions { get; } + + /// + /// Checks whether this entity has the specified permission kind. + /// + /// The kind of permission. + /// true if this entity has the specified permission, false otherwise. + bool HasPermission(PermissionKind kind); + + /// + /// Sets the specified permission to the provided value. + /// + /// The kind of permission. + /// The value to set. + void SetPermission(PermissionKind kind, bool value); } }