Added all fucking things except Versioning
Build Docker Linux ARM64 / build-docker-linux-arm64 (push) Failing after 3m53s

This commit is contained in:
2026-06-07 08:11:02 +02:00
parent 59442d5203
commit 0f3da6952b
14 changed files with 371 additions and 316 deletions
@@ -1,51 +1,38 @@
@page "/AdminSettings/CouchLogSettings"
@rendermode InteractiveServer
@using System.Reflection
@using CouchLog.Data
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.Forms
@inject ApplicationDbContext CouchLogDB
@inject ApplicationDbContext CouchLogDb
<h3>CouchLog Settings</h3>
<MudText Typo="Typo.h3">CouchLog Settings</MudText>
@if (accountsSettings is null)
{
<p>Lade Einstellungen…</p>
}
else
{
<EditForm Model="accountsSettings">
<div class="form-check form-switch">
<InputCheckbox class="form-check-input"
role="switch"
id="IsRegistrationallowedInput"
Value="accountsSettings.IsRegistrationAllowed"
ValueChanged="OnRegistrationChanged"
ValueExpression="() => accountsSettings.IsRegistrationAllowed" />
<EditForm Model="_accountsSettings">
<MudSwitch T="bool"
Label="Is Registration allowed"
Value="_accountsSettings.IsRegistrationAllowed"
ValueChanged="OnRegistrationChanged"
Color="Color.Primary" />
</EditForm>
<label class="form-check-label" for="IsRegistrationallowedInput">
Is Registration allowed
</label>
</div>
</EditForm>
}
<MudText>Version: @_version</MudText>
@code {
private AccountsSettings? accountsSettings;
private AccountsSettings? _accountsSettings;
private readonly string _version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion?.Split('+')[0];
protected override async Task OnInitializedAsync()
{
accountsSettings = await CouchLogDB.AccountsSettings.FirstAsync();
_accountsSettings = await CouchLogDb.AccountsSettings.FirstAsync();
}
private async Task OnRegistrationChanged(bool value)
{
accountsSettings!.IsRegistrationAllowed = value;
_accountsSettings!.IsRegistrationAllowed = value;
CouchLogDB.AccountsSettings.Update(accountsSettings);
await CouchLogDB.SaveChangesAsync();
CouchLogDb.AccountsSettings.Update(_accountsSettings);
await CouchLogDb.SaveChangesAsync();
}
}
@@ -0,0 +1,68 @@
@using CouchLog.Data
@using Microsoft.AspNetCore.Identity
@inject UserManager<ApplicationUser> UserManager
@inject ISnackbar Snackbar
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">Create New User</MudText>
</TitleContent>
<DialogContent>
<MudInput @bind-Value="@_newUsername"></MudInput>
<MudSelect @bind-Value="_newUserRole">
@foreach (var role in Roles)
{
<MudSelectItem Value="@role.Name">@role.Name</MudSelectItem>
}
</MudSelect>
</DialogContent>
<DialogActions>
<MudButton OnClick="CreateNewUser" Variant="Variant.Filled" Color="Color.Success">Create user</MudButton>
<MudButton OnClick="Cancel" Variant="Variant.Filled" Color="Color.Error">Cancel</MudButton>
</DialogActions>
</MudDialog>
@code
{
[Parameter] public required List<IdentityRole> Roles { get; set; }
[CascadingParameter]
public IMudDialogInstance MudDialog { get; set; } = null!;
private string _newUsername = string.Empty;
private string _newUserRole = string.Empty;
private async Task CreateNewUser()
{
if (string.IsNullOrWhiteSpace(_newUsername) || string.IsNullOrWhiteSpace(_newUserRole))
{
Snackbar.Add("Add Username and Role" , Severity.Warning);
return;
}
ApplicationUser newUser = new ApplicationUser
{
UserName = _newUsername,
EmailConfirmed = true
};
var result = await UserManager.CreateAsync(newUser, "NewPassword123!");
if(result.Succeeded)
{
await UserManager.AddToRoleAsync(newUser, _newUserRole);
MudDialog.Close(DialogResult.Ok(newUser));
return;
}
//Snackbar.Add("User could not be created", Severity.Error);
}
private async Task Cancel()
{
MudDialog.Cancel();
}
}
@@ -2,10 +2,15 @@
@using Microsoft.AspNetCore.Authorization
@inject NavigationManager NavigationManager
@attribute [Authorize(Roles = "Admin")]
<h3>Index</h3>
<MudLink Href="AdminSettings/CouchLogSettings">CouchLog Settings</MudLink>
<MudLink Href="AdminSettings/UserManagement">User Management</MudLink>
@code {
}
@@ -1,106 +1,84 @@
@page "/AdminSettings/UserManagement"
@rendermode InteractiveServer
@using CouchLog.Components.AdminSettings.Pages.Dialogs
@using CouchLog.Data
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.QuickGrid
@using Microsoft.AspNetCore.Authorization
@inject ApplicationDbContext CouchLogDB
@inject ApplicationDbContext CouchLogDb
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject NavigationManager NavigationManager
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@attribute [Authorize(Roles = "Admin")]
<div class="d-flex align-items-center justify-content-between">
<h3 class="mb-0">UserManagement</h3>
<MudStack Row="true">
<MudText Typo="Typo.h3">UserManagement</MudText>
<MudSpacer/>
<MudFab StartIcon="@Icons.Material.Filled.Add" Color="Color.Primary" OnClick="OpenCreateUserDialog"/>
</MudStack>
<button type="button"
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#exampleModal">
Add User
</button>
</div>
<br/>
<!-- <div>
<QuickGrid Items="@gridUsers.AsQueryable()">
<PropertyColumn Title="#" Property="@(u => u.Index)" />
<PropertyColumn Title="Username" Property="@(u => u.UserName)" />
<PropertyColumn Title="Role" Property="@(u => u.Role)" />
<TemplateColumn Title="">
@if(context.UserId != currentUserId)
{
<button class="btn btn-danger btn-sm" @onclick="() => DeleteUser(context)">Delete</button>
}
<MudDataGrid Items="_gridUsers" Filterable="false" SortMode="@SortMode.Single" Groupable="false">
<Columns>
<PropertyColumn Property="arg => arg.Index " Title="Index"/>
<PropertyColumn Property="arg => arg.UserId" Title="User Id"/>
<PropertyColumn Property="arg => arg.UserName" Title="User Name"/>
<PropertyColumn Property="arg => arg.Role" Title="Role"/>
<TemplateColumn>
<CellTemplate>
@if (context.Item.UserId != _currentUserId)
{
<MudFab Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="@(() => DeleteUser(context.Item))"/>
}
</CellTemplate>
</TemplateColumn>
</QuickGrid>
</div> -->
<!-- #region UserCreate Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" style="color: black">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" style="color: black" id="exampleModalLabel">Create User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- 1. Username Input mit Binding und Bootstrap Klasse -->
<div class="mb-3">
<label for="newUsernameInput" class="form-label">Username:</label>
<input type="text" class="form-control" id="newUsernameInput" @bind="newUsername" />
</div>
<!-- 2. Select mit Binding -->
<div class="mb-3">
<label class="form-label">Role:</label>
<select class="form-select" @bind="newUserRoleId">
<!-- WICHTIG: Eine leere Option als Standard, damit man weiß, ob etwas gewählt wurde -->
<option value="" selected disabled>Bitte Rolle wählen...</option>
@foreach (var role in roles)
{
<option value="@role.Id">@role.Name</option>
}
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" @onclick="CreateUserAsync">Create User</button>
</div>
</div>
</div>
</div>
<!-- #endregion -->
</Columns>
</MudDataGrid>
@code {
string newUsername = "";
string newUserRoleId = "";
List<UserGridItem> gridUsers = new();
List<IdentityRole> roles = new();
string? currentUserId;
private string? _currentUserId;
private List<ApplicationUser> _users = new();
private List<IdentityRole> _roles = new();
private List<UserGridItem> _gridUsers = new();
public class UserGridItem
{
public int Index { get; set; }
public string UserId { get; set; } = "";
public string UserName { get; set; } = "";
public string Role { get; set; } = "";
}
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
currentUserId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
_currentUserId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
var users = await CouchLogDB.Users.ToListAsync();
roles = await CouchLogDB.Roles.ToListAsync();
var users = await CouchLogDb.Users.ToListAsync();
_roles = await CouchLogDb.Roles.ToListAsync();
await CreateGridUserObjects();
}
private async Task CreateGridUserObjects()
{
_gridUsers.Clear();
var users = await CouchLogDb.Users.ToListAsync();
int index = 1;
gridUsers.Clear();
foreach (var user in users)
{
var role = await UserManager.GetRolesAsync(user);
gridUsers.Add(new UserGridItem
_gridUsers.Add(new UserGridItem
{
Index = index++,
UserId = user.Id,
@@ -110,17 +88,26 @@
}
}
public class UserGridItem
private async Task OpenCreateUserDialog()
{
public int Index { get; set; }
public string UserId { get; set; } = "";
public string UserName { get; set; } = "";
public string Role { get; set; } = "";
var parameters = new DialogParameters<CreateUserDialog>
{
{ x => x.Roles, _roles }
};
var dialog = await DialogService.ShowAsync<CreateUserDialog>("Create User", parameters);
var result = await dialog.Result;
if (!result!.Canceled && result.Data is ApplicationUser newUser)
{
Snackbar.Add("User created", Severity.Success);
await CreateGridUserObjects();
StateHasChanged();
}
}
async Task DeleteUser(UserGridItem user)
{
if (user.UserId == currentUserId)
if (user.UserId == _currentUserId)
return;
var identityUser = await UserManager.FindByIdAsync(user.UserId);
@@ -132,48 +119,12 @@
if (result.Succeeded)
{
gridUsers.Remove(user);
_gridUsers.Remove(user);
StateHasChanged();
}
else
{
// Optional: Fehler anzeigen
Snackbar.Add(result.Errors.ToString()!, Severity.Warning);
}
}
private async Task CreateUserAsync()
{
// Validierung
if (string.IsNullOrWhiteSpace(newUsername) || string.IsNullOrWhiteSpace(newUserRoleId))
{
// Fehlermeldung anzeigen oder abbrechen
Console.WriteLine("Bitte Benutzername und Rolle angeben.");
return;
}
// Hier deine Logik zum Erstellen des Users
var roleIdToUse = newUserRoleId;
var usernameToUse = newUsername;
ApplicationUser newUser = new ApplicationUser
{
UserName = newUsername,
EmailConfirmed = true
};
var result = await UserManager.CreateAsync(newUser, "NewPassword123!");
IdentityRole roleName = roles.FirstOrDefault(r => r.Id == newUserRoleId);
if(result.Succeeded)
{
await UserManager.AddToRoleAsync(newUser, roleName.Name);
}
// Modal schließen oder Formular zurücksetzen
newUsername = "";
newUserRoleId = "";
NavigationManager.NavigateTo(NavigationManager.Uri, true);
}
}
@@ -5,17 +5,27 @@
@attribute [Authorize(Roles = "Admin")]
<h1>Manage CouchLog</h1>
<MudText Typo="Typo.h1">Manage CouchLog</MudText>
<div>
<h2></h2>
<hr />
<div class="row">
<div class="col-lg-3">
<AdminSettingsNavMenu />
</div>
<div class="col-lg-9">
<MudContainer MaxWidth="MaxWidth.False" Class="pa-4">
<MudGrid>
<MudItem xs="12" md="3" lg="2">
<MudNavMenu>
<MudNavLink Href="/AdminSettings/CouchLogSettings"
Icon="@Icons.Material.Filled.Settings">
CouchLog Settings
</MudNavLink>
<MudNavLink Href="/AdminSettings/UserManagement"
Match="NavLinkMatch.All"
Icon="@Icons.Material.Filled.People">
User Management
</MudNavLink>
</MudNavMenu>
</MudItem>
<MudItem xs="12" md="9" lg="10">
@Body
</div>
</div>
</div>
</MudItem>
</MudGrid>
</MudContainer>
@@ -1,18 +0,0 @@
@using Microsoft.AspNetCore.Identity
@using CouchLog.Data
@inject SignInManager<ApplicationUser> SignInManager
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<NavLink class="nav-link" href="/AdminSettings/CouchLogSettings">CouchLog Settings</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="/AdminSettings/UserManagement" Match="NavLinkMatch.All">User Management</NavLink>
</li>
<!--
<li class="nav-item">
<NavLink class="nav-link" href=""></NavLink>
</li>
-->
</ul>