From 6fa91d8890135996bf29dc379a8e2b8eb19b2040 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 16:27:46 +0200 Subject: [PATCH] Added a Minimum Required Permission Level For the component Masu you said it would be possible to handle this in the Components Razor file, but if nothing is shown there will still be an empty space (empty cols are still showing in boostrap, margin on the userdashboard and admindashboard components). I think this would be the best solution --- .../Core/Models/Abstractions/UiComponent.cs | 2 ++ Moonlight/Core/UI/Views/Admin/Index.razor | 25 +++++++++++-------- Moonlight/Core/UI/Views/Index.razor | 10 +++++--- Moonlight/Moonlight.csproj | 1 - 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Moonlight/Core/Models/Abstractions/UiComponent.cs b/Moonlight/Core/Models/Abstractions/UiComponent.cs index 60329f63..f994bad4 100644 --- a/Moonlight/Core/Models/Abstractions/UiComponent.cs +++ b/Moonlight/Core/Models/Abstractions/UiComponent.cs @@ -7,4 +7,6 @@ public class UiComponent public required RenderFragment Component { get; set; } public int Index { get; set; } = 0; + + public int RequiredPermissionLevel { get; set; } = 0; } \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor index a7c6747a..ab479889 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -1,30 +1,33 @@ @page "/admin" -@using MoonCore.Abstractions -@using Moonlight.Core.Database.Entities -@using Moonlight.Core.Interfaces @using Moonlight.Core.Interfaces.Ui.Admin @using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Services -@using Moonlight.Features.Servers.Entities @inject PluginService PluginService +@inject IdentityService IdentityService @attribute [RequirePermission(999)]
- @foreach(var column in Columns.OrderBy(x => x.Index)) + @foreach (var column in Columns.OrderBy(x => x.Index)) { -
- @column.Component -
+ if (column.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @column.Component +
+ } }
@foreach (var component in Components.OrderBy(x => x.Index)) { -
- @component.Component -
+ if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @component.Component +
+ } }
diff --git a/Moonlight/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index e36cf092..acef82a3 100644 --- a/Moonlight/Core/UI/Views/Index.razor +++ b/Moonlight/Core/UI/Views/Index.razor @@ -4,13 +4,17 @@ @using Moonlight.Core.Services @inject PluginService PluginService +@inject IdentityService IdentityService @foreach (var component in Components.OrderBy(x => x.Index)) { -
- @component.Component -
+ if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @component.Component +
+ } }
diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 6f369f1d..baf8e518 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,7 +53,6 @@ -