Added permissions to users controller and the client.
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
|
||||
<CascadingValue Name="TargetPageType" Value="routeData.PageType">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
|
||||
</CascadingValue>
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Exceptions
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.PluginFramework.Services
|
||||
@using Moonlight.Client.Interfaces
|
||||
@using Moonlight.Client.Services
|
||||
@using Moonlight.Client.UI.Partials
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject ImplementationService ImplementationService
|
||||
@inject IdentityService IdentityService
|
||||
@inject IServiceProvider ServiceProvider
|
||||
@inject ILogger<MainLayout> Logger
|
||||
|
||||
@@ -29,15 +32,21 @@ else
|
||||
<div class="lg:pl-72">
|
||||
<AppHeader Layout="this"/>
|
||||
|
||||
<ErrorHandler>
|
||||
<main class="py-10">
|
||||
<div class="px-4 sm:px-6 lg:px-8">
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@Body
|
||||
</CascadingValue>
|
||||
</div>
|
||||
</main>
|
||||
</ErrorHandler>
|
||||
<main class="py-10">
|
||||
<div class="px-4 sm:px-6 lg:px-8">
|
||||
<ErrorHandler CustomHandler="HandleException">
|
||||
|
||||
<PermissionHandler CheckFunction="CheckPermission">
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@Body
|
||||
</CascadingValue>
|
||||
</PermissionHandler>
|
||||
|
||||
</ErrorHandler>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -127,4 +136,17 @@ else
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private bool CheckPermission(string permission) => IdentityService.HasPermission(permission);
|
||||
|
||||
private Task<bool> HandleException(Exception exception, ErrorHandler handler)
|
||||
{
|
||||
if (exception is HttpApiException httpApiException && httpApiException.Status == 401)
|
||||
{
|
||||
Task.Run(Load);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
@using MoonCore.PluginFramework.Services
|
||||
@using Moonlight.Client.Interfaces
|
||||
@using Moonlight.Client.Models
|
||||
@using Moonlight.Client.Services
|
||||
@using Moonlight.Client.UI.Layouts
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@inject IdentityService IdentityService
|
||||
@inject ImplementationService ImplementationService
|
||||
|
||||
@{
|
||||
@@ -111,7 +113,7 @@
|
||||
<li>
|
||||
@if (!string.IsNullOrEmpty(group.Key))
|
||||
{
|
||||
<div class="text-xs font-semibold leading-6 text-gray-400">
|
||||
<div class="text-xs font-semibold leading-6 text-gray-400 my-2">
|
||||
@group.Key
|
||||
</div>
|
||||
}
|
||||
@@ -168,7 +170,7 @@
|
||||
{
|
||||
Items = ImplementationService.Get<ISidebarItemProvider>()
|
||||
.SelectMany(x => x.Get())
|
||||
//.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
|
||||
.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
|
||||
.GroupBy(x => x.Group ?? "")
|
||||
.OrderByDescending(x => string.IsNullOrEmpty(x.Key))
|
||||
.ToDictionary(x => x.Key, x => x.OrderBy(y => y.Priority).ToArray());
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
@page "/admin/users"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.Attributes
|
||||
@using MoonCore.Blazor.Tailwind.Forms.Components
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using Moonlight.Shared.Http.Requests.Admin.Users
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
|
||||
@attribute [RequirePermission("admin.users.read")]
|
||||
|
||||
@inject HttpApiClient HttpApiClient
|
||||
|
||||
<Crud TItem="UserDetailResponse"
|
||||
|
||||
Reference in New Issue
Block a user