86 lines
3.1 KiB
Text
86 lines
3.1 KiB
Text
@page "/Settings/Roles/{id:guid}"
|
|
@using Microsoft.EntityFrameworkCore
|
|
@inject RoleService RoleService
|
|
@inject CollectionService CollectionService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Edit> Logger
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Edit Role">
|
|
<PageHeaderExtra>
|
|
<Space Direction="SpaceDirection.Horizontal">
|
|
<SpaceItem>
|
|
<Button Type="ButtonType.Primary" OnClick="Save">Save</Button>
|
|
</SpaceItem>
|
|
</Space>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="@Role" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="Role.Name" />
|
|
</FormItem>
|
|
<FormItem Label="Collections">
|
|
<TransferInput LeftTitle="Available" RightTitle="Allowed" DataSource="Collections" TitleSelector="c => c.Name" @bind-Values="SelectedCollections" />
|
|
</FormItem>
|
|
<FormItem Label="Storage Quota (MB)" Help="0 or blank = unlimited">
|
|
<AntDesign.InputNumber TValue="int?" @bind-Value="Role.StorageQuotaMB" Min="0" />
|
|
</FormItem>
|
|
<FormItem Label="Download Speed (KB/s)" Help="0 or blank = unlimited">
|
|
<AntDesign.InputNumber TValue="int?" @bind-Value="Role.DownloadSpeedKBps" Min="0" />
|
|
</FormItem>
|
|
<FormItem Label="Cloud Saves" Help="Disable cloud saves for users in this role">
|
|
<Select TItemValue="bool?" TItem="bool?" @bind-Value="Role.EnableSaves">
|
|
<SelectOptions>
|
|
<SelectOption TItemValue="bool?" TItem="bool?" Value="(bool?)null" Label="Not set" />
|
|
<SelectOption TItemValue="bool?" TItem="bool?" Value="(bool?)true" Label="Enabled" />
|
|
<SelectOption TItemValue="bool?" TItem="bool?" Value="(bool?)false" Label="Disabled" />
|
|
</SelectOptions>
|
|
</Select>
|
|
</FormItem>
|
|
</Form>
|
|
</PageContent>
|
|
|
|
@code {
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
Role Role = new Role();
|
|
IEnumerable<Collection> Collections = new List<Collection>();
|
|
|
|
ICollection<Collection> SelectedCollections = new List<Collection>();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Role = await RoleService
|
|
.AsNoTracking()
|
|
.Query(q =>
|
|
{
|
|
return q
|
|
.Include(r => r.UserRoles)
|
|
.ThenInclude(ur => ur.User);
|
|
})
|
|
.Include(r => r.Collections)
|
|
.GetAsync(Id);
|
|
|
|
SelectedCollections = Role.Collections;
|
|
|
|
Collections = await CollectionService.GetAsync();
|
|
}
|
|
|
|
async Task Save()
|
|
{
|
|
try
|
|
{
|
|
await RoleService.UpdateAsync(Role);
|
|
await RoleService.AssignCollections(Id, SelectedCollections.Select(c => c.Id));
|
|
|
|
MessageService.Success("Role updated!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("Role could not be updated!");
|
|
Logger.LogError(ex, "Role could not be updated!");
|
|
}
|
|
}
|
|
}
|