mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 15:01:56 +00:00
Added groups view model, implemented basic groups table view
This commit is contained in:
@@ -94,7 +94,8 @@ public class HomeController : Controller
|
|||||||
[HttpGet("Groups")]
|
[HttpGet("Groups")]
|
||||||
public async Task<ActionResult> GroupsAsync()
|
public async Task<ActionResult> GroupsAsync()
|
||||||
{
|
{
|
||||||
return View(); // TODO: Add viewmodel
|
IEnumerable<GroupModel> groups = await _ldap.ListGroupsAsync();
|
||||||
|
return View(new GroupsIndexViewModel(groups));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("Login")]
|
[HttpPost("Login")]
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ namespace Berufsschule_HAM.Models;
|
|||||||
public class GroupModel
|
public class GroupModel
|
||||||
{
|
{
|
||||||
public required string Cn { get; set; }
|
public required string Cn { get; set; }
|
||||||
|
public string DisplayName { get; set; }
|
||||||
public string? GidNumber { get; set; }
|
public string? GidNumber { get; set; }
|
||||||
public List<GroupPermission> Permissions { get; set; }
|
public List<GroupPermission> Permissions { get; set; }
|
||||||
public GroupModel(Dictionary<string, string> ldapData)
|
public GroupModel(Dictionary<string, string> ldapData)
|
||||||
{
|
{
|
||||||
Cn = ldapData.GetValueOrDefault("cn") ?? throw new GroupModelConfigurationException();
|
Cn = ldapData.GetValueOrDefault("cn") ?? throw new GroupModelConfigurationException();
|
||||||
GidNumber = ldapData.GetValueOrDefault("gidNumber");
|
GidNumber = ldapData.GetValueOrDefault("gidNumber");
|
||||||
|
DisplayName = ldapData.GetValueOrDefault("displayName") ?? Cn;
|
||||||
string? descriptionValue = ldapData.GetValueOrDefault("description");
|
string? descriptionValue = ldapData.GetValueOrDefault("description");
|
||||||
if (descriptionValue is null)
|
if (descriptionValue is null)
|
||||||
{
|
{
|
||||||
|
|||||||
38
src/Models/GroupsViewModels.cs
Normal file
38
src/Models/GroupsViewModels.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
namespace Berufsschule_HAM.Models;
|
||||||
|
|
||||||
|
public class GroupsIndexViewModel
|
||||||
|
{
|
||||||
|
public List<GroupsTableViewModel> GroupsTableViewModels { get; set; } = [];
|
||||||
|
|
||||||
|
public GroupsIndexViewModel(IEnumerable<GroupModel> groupModels)
|
||||||
|
{
|
||||||
|
foreach (GroupModel model in groupModels)
|
||||||
|
{
|
||||||
|
GroupsTableViewModels.Add(new()
|
||||||
|
{
|
||||||
|
Cn = model.Cn,
|
||||||
|
Group = model.DisplayName,
|
||||||
|
CanInventorize = model.Permissions.Any(x => x == GroupPermission.CanInventorize),
|
||||||
|
CanManageAssets = model.Permissions.Any(x => x == GroupPermission.CanManageAssets),
|
||||||
|
CanManageGroups = model.Permissions.Any(x => x == GroupPermission.CanManageGroups),
|
||||||
|
CanManageLocations = model.Permissions.Any(x => x == GroupPermission.CanManageLocations),
|
||||||
|
CanManageUsers = model.Permissions.Any(x => x == GroupPermission.CanManageUsers)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GroupsTableViewModel
|
||||||
|
{
|
||||||
|
public required string Cn { get; set; }
|
||||||
|
public required string Group { get; set; }
|
||||||
|
public required bool CanInventorize { get; set; }
|
||||||
|
public required bool CanManageUsers { get; set; }
|
||||||
|
public required bool CanManageLocations { get; set; }
|
||||||
|
public required bool CanManageAssets { get; set; }
|
||||||
|
public required bool CanManageGroups { get; set; }
|
||||||
|
}
|
||||||
@@ -134,6 +134,11 @@ public partial class LdapService : IDisposable
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<GroupModel>> ListGroupsAsync()
|
||||||
|
{
|
||||||
|
return await ListGroupsAsync(GroupsAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<GroupModel>> ListGroupsAsync(string[] attributes)
|
public async Task<IEnumerable<GroupModel>> ListGroupsAsync(string[] attributes)
|
||||||
{
|
{
|
||||||
List<GroupModel> returnValue = [];
|
List<GroupModel> returnValue = [];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@using Microsoft.AspNetCore.Mvc.Localization
|
@using Microsoft.AspNetCore.Mvc.Localization
|
||||||
@using Berufsschule_HAM.Models
|
@using Berufsschule_HAM.Models
|
||||||
@using System.Buffers.Text
|
@using System.Buffers.Text
|
||||||
@* @model UsersIndexViewModel *@
|
@model GroupsIndexViewModel
|
||||||
@inject IViewLocalizer T
|
@inject IViewLocalizer T
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = T["Groups"];
|
ViewData["Title"] = T["Groups"];
|
||||||
@@ -23,39 +23,38 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="text-align: center">Group</th>
|
<th style="text-align: center">Group</th>
|
||||||
<th style="text-align: center">@T["Can"]:<br/>@T["inventorize"]</th>
|
<th style="text-align: center">@T["Can"]:<br/>@T["inventorize"]</th>
|
||||||
<th style="text-align: center">@T["Can"]:<br/>@T["Manage users"]</th>
|
<th style="text-align: center">@T["Can"]:<br/>@T["manage users"]</th>
|
||||||
<th style="text-align: center">@T["Can"]:<br/>@T["Manage locations"]</th>
|
<th style="text-align: center">@T["Can"]:<br/>@T["manage locations"]</th>
|
||||||
<th style="text-align: center">@T["Can"]:<br/>@T["Manage assets"]</th>
|
<th style="text-align: center">@T["Can"]:<br/>@T["manage assets"]</th>
|
||||||
<th style="text-align: center">@T["Can"]:<br/>@T["manage groups"]</th>
|
<th style="text-align: center">@T["Can"]:<br/>@T["manage groups"]</th>
|
||||||
|
<th style="text-align: center">@T["Action"]</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@* @{
|
@{
|
||||||
foreach (UserTableViewModel userTableViewModel in Model.UserTableViewModels)
|
foreach (GroupsTableViewModel userTableViewModel in Model.GroupsTableViewModels)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td style="text-align: center">@userTableViewModel.Group</td>
|
||||||
<img class="rounded-circle user-icon" src="data:image/jpeg;base64,@userTableViewModel.JpegPhoto" alt="Photo" style="max-width:300px;" />
|
<td style="text-align: center">@userTableViewModel.CanInventorize</td>
|
||||||
</td>
|
<td style="text-align: center">@userTableViewModel.CanManageUsers</td>
|
||||||
<td>@userTableViewModel.Uid</td>
|
<td style="text-align: center">@userTableViewModel.CanManageLocations</td>
|
||||||
<td>@userTableViewModel.Title</td>
|
<td style="text-align: center">@userTableViewModel.CanManageAssets</td>
|
||||||
<td>@userTableViewModel.Name</td>
|
<td style="text-align: center">@userTableViewModel.CanManageGroups</td>
|
||||||
<td>@userTableViewModel.Surname</td>
|
<td style="text-align: center">
|
||||||
<td>@userTableViewModel.Workplace</td>
|
<div class="d-flex gap-2 justify-content-center">
|
||||||
<td>
|
|
||||||
<div class="d-flex gap-2">
|
|
||||||
<button class="btn btn-sm btn-primary">Update</button>
|
<button class="btn btn-sm btn-primary">Update</button>
|
||||||
<button class="btn btn-sm btn-danger btn-delete"
|
<button class="btn btn-sm btn-danger btn-delete"
|
||||||
data-user-id="@userTableViewModel.Uid"
|
data-user-id="@userTableViewModel.Cn"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#deleteModal">
|
data-bs-target="#deleteModal">
|
||||||
🗑️ Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
} *@
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user