initial permissions based webfront access implementation
This commit is contained in:
@ -30,6 +30,7 @@ namespace SharedLibraryCore
|
||||
private static string SocialTitle;
|
||||
protected readonly DatabaseContext Context;
|
||||
protected List<Page> Pages;
|
||||
protected List<string> PermissionsSet;
|
||||
|
||||
public BaseController(IManager manager)
|
||||
{
|
||||
@ -43,7 +44,6 @@ namespace SharedLibraryCore
|
||||
SocialTitle = AppConfig.SocialLinkTitle;
|
||||
}
|
||||
|
||||
|
||||
Pages = Manager.GetPageList().Pages
|
||||
.Select(page => new Page
|
||||
{
|
||||
@ -135,6 +135,11 @@ namespace SharedLibraryCore
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "login");
|
||||
SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait();
|
||||
}
|
||||
|
||||
if (AppConfig.PermissionSets.ContainsKey(Client.Level.ToString()))
|
||||
{
|
||||
PermissionsSet = AppConfig.PermissionSets[Client.Level.ToString()];
|
||||
}
|
||||
|
||||
var communityName = AppConfig.CommunityInformation?.Name;
|
||||
var shouldUseCommunityName = !string.IsNullOrWhiteSpace(communityName)
|
||||
@ -160,4 +165,4 @@ namespace SharedLibraryCore
|
||||
base.OnActionExecuting(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ namespace SharedLibraryCore.Configuration
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")]
|
||||
public bool EnableColorCodes { get; set; }
|
||||
|
||||
|
||||
[ConfigurationIgnore] public string IngameAccentColorKey { get; set; } = "Cyan";
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
|
||||
@ -144,6 +144,16 @@ namespace SharedLibraryCore.Configuration
|
||||
TimeSpan.FromDays(30)
|
||||
};
|
||||
|
||||
public Dictionary<string, List<string>> PermissionSets { get; set; } = new()
|
||||
{
|
||||
{ Permission.Trusted.ToString(), new List<string> { "*" } },
|
||||
{ Permission.Moderator.ToString(), new List<string> { "*" } },
|
||||
{ Permission.Administrator.ToString(), new List<string> { "*" } },
|
||||
{ Permission.SeniorAdmin.ToString(), new List<string> { "*" } },
|
||||
{ Permission.Owner.ToString(), new List<string> { "*" } },
|
||||
{ Permission.Console.ToString(), new List<string> { "*" } }
|
||||
};
|
||||
|
||||
[ConfigurationIgnore]
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRESET_BAN_REASONS")]
|
||||
public Dictionary<string, string> PresetPenaltyReasons { get; set; } = new Dictionary<string, string>
|
||||
|
@ -525,6 +525,45 @@ namespace SharedLibraryCore
|
||||
return new TimeSpan(1, 0, 0);
|
||||
}
|
||||
|
||||
public static bool HasPermission<TEntity, TPermission>(this IEnumerable<string> permissionsSet, TEntity entity,
|
||||
TPermission permission) where TEntity : Enum where TPermission : Enum
|
||||
{
|
||||
return permissionsSet?.Any(raw =>
|
||||
{
|
||||
if (raw == "*")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var split = raw.Split(".");
|
||||
|
||||
if (split.Length != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(typeof(TEntity), split[0], out var e))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(typeof(TPermission), split[1], out var p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (e?.Equals(entity) ?? false) && (p?.Equals(permission) ?? false);
|
||||
}) ?? false;
|
||||
}
|
||||
|
||||
public static bool HasPermission<TEntity, TPermission>(this ApplicationConfiguration appConfig,
|
||||
Permission permissionLevel, TEntity entity,
|
||||
TPermission permission) where TEntity : Enum where TPermission : Enum
|
||||
{
|
||||
return appConfig.PermissionSets.ContainsKey(permissionLevel.ToString()) &&
|
||||
HasPermission(appConfig.PermissionSets[permissionLevel.ToString()], entity, permission);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns a list of penalty types that should be shown across all profiles
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user