mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Expand and document IHasPermissions
This commit is contained in:
parent
4cff9b8512
commit
e8b6da3cd7
@ -2,6 +2,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using Jellyfin.Data.Enums;
|
||||||
|
|
||||||
namespace Jellyfin.Data.Entities
|
namespace Jellyfin.Data.Entities
|
||||||
{
|
{
|
||||||
@ -96,6 +98,15 @@ namespace Jellyfin.Data.Entities
|
|||||||
|
|
||||||
[ForeignKey("Preference_Preferences_Id")]
|
[ForeignKey("Preference_Preferences_Id")]
|
||||||
public virtual ICollection<Preference> Preferences { get; protected set; }
|
public virtual ICollection<Preference> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,16 +389,14 @@ namespace Jellyfin.Data.Entities
|
|||||||
RowVersion++;
|
RowVersion++;
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void Init();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether the user has the specified permission.
|
/// Checks whether the user has the specified permission.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission">The permission kind.</param>
|
/// <param name="kind">The permission kind.</param>
|
||||||
/// <returns><c>True</c> if the user has the specified permission.</returns>
|
/// <returns><c>True</c> if the user has the specified permission.</returns>
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -408,8 +406,7 @@ namespace Jellyfin.Data.Entities
|
|||||||
/// <param name="value">The value to set.</param>
|
/// <param name="value">The value to set.</param>
|
||||||
public void SetPermission(PermissionKind kind, bool value)
|
public void SetPermission(PermissionKind kind, bool value)
|
||||||
{
|
{
|
||||||
var permissionObj = Permissions.First(p => p.Kind == kind);
|
Permissions.First(p => p.Kind == kind).Value = value;
|
||||||
permissionObj.Value = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -501,5 +498,7 @@ namespace Jellyfin.Data.Entities
|
|||||||
Preferences.Add(new Preference(val, string.Empty));
|
Preferences.Add(new Preference(val, string.Empty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,31 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
|
using Jellyfin.Data.Enums;
|
||||||
|
|
||||||
namespace Jellyfin.Data
|
namespace Jellyfin.Data
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An abstraction representing an entity that has permissions.
|
||||||
|
/// </summary>
|
||||||
public interface IHasPermissions
|
public interface IHasPermissions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection containing this entity's permissions.
|
||||||
|
/// </summary>
|
||||||
ICollection<Permission> Permissions { get; }
|
ICollection<Permission> Permissions { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether this entity has the specified permission kind.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="kind">The kind of permission.</param>
|
||||||
|
/// <returns><c>true</c> if this entity has the specified permission, <c>false</c> otherwise.</returns>
|
||||||
|
bool HasPermission(PermissionKind kind);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the specified permission to the provided value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="kind">The kind of permission.</param>
|
||||||
|
/// <param name="value">The value to set.</param>
|
||||||
|
void SetPermission(PermissionKind kind, bool value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user