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
This commit is contained in:
Moritz Deiaco
2024-05-29 16:27:46 +02:00
parent a4080cc1b1
commit 6fa91d8890
4 changed files with 23 additions and 15 deletions

View File

@@ -7,4 +7,6 @@ public class UiComponent
public required RenderFragment Component { get; set; } public required RenderFragment Component { get; set; }
public int Index { get; set; } = 0; public int Index { get; set; } = 0;
public int RequiredPermissionLevel { get; set; } = 0;
} }

View File

@@ -1,30 +1,33 @@
@page "/admin" @page "/admin"
@using MoonCore.Abstractions
@using Moonlight.Core.Database.Entities
@using Moonlight.Core.Interfaces
@using Moonlight.Core.Interfaces.Ui.Admin @using Moonlight.Core.Interfaces.Ui.Admin
@using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Models.Abstractions
@using Moonlight.Core.Services @using Moonlight.Core.Services
@using Moonlight.Features.Servers.Entities
@inject PluginService PluginService @inject PluginService PluginService
@inject IdentityService IdentityService
@attribute [RequirePermission(999)] @attribute [RequirePermission(999)]
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<div class="row mb-8"> <div class="row mb-8">
@foreach(var column in Columns.OrderBy(x => x.Index)) @foreach (var column in Columns.OrderBy(x => x.Index))
{ {
<div class="col-12 col-lg-6 col-xl"> if (column.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions)
@column.Component {
</div> <div class="col-12 col-lg-6 col-xl">
@column.Component
</div>
}
} }
</div> </div>
@foreach (var component in Components.OrderBy(x => x.Index)) @foreach (var component in Components.OrderBy(x => x.Index))
{ {
<div class="mb-4"> if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions)
@component.Component {
</div> <div class="mb-4">
@component.Component
</div>
}
} }
</LazyLoader> </LazyLoader>

View File

@@ -4,13 +4,17 @@
@using Moonlight.Core.Services @using Moonlight.Core.Services
@inject PluginService PluginService @inject PluginService PluginService
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@foreach (var component in Components.OrderBy(x => x.Index)) @foreach (var component in Components.OrderBy(x => x.Index))
{ {
<div class="mb-4"> if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions)
@component.Component {
</div> <div class="mb-4">
@component.Component
</div>
}
} }
</LazyLoader> </LazyLoader>

View File

@@ -53,7 +53,6 @@
<Folder Include="Core\Database\Migrations\" /> <Folder Include="Core\Database\Migrations\" />
<Folder Include="Core\Http\Requests\" /> <Folder Include="Core\Http\Requests\" />
<Folder Include="Core\Http\Resources\" /> <Folder Include="Core\Http\Resources\" />
<Folder Include="Core\Implementations\UI\Admin\AdminComponents\" />
<Folder Include="Core\UI\Components\Forms\" /> <Folder Include="Core\UI\Components\Forms\" />
<Folder Include="Features\Dummy\Configuration\" /> <Folder Include="Features\Dummy\Configuration\" />
<Folder Include="Features\Dummy\Entities\" /> <Folder Include="Features\Dummy\Entities\" />