mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 15:01:56 +00:00
Added Group backend CRUD
This commit is contained in:
42
src/Models/GroupModel.cs
Normal file
42
src/Models/GroupModel.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Berufsschule_HAM.Exceptions;
|
||||
|
||||
namespace Berufsschule_HAM.Models;
|
||||
|
||||
public class GroupModel
|
||||
{
|
||||
public required string Cn { get; set; }
|
||||
public string? GidNumber { get; set; }
|
||||
public List<GroupPermission> Permissions { get; set; }
|
||||
public GroupModel(Dictionary<string, string> ldapData)
|
||||
{
|
||||
Cn = ldapData.GetValueOrDefault("cn") ?? throw new GroupModelConfigurationException();
|
||||
GidNumber = ldapData.GetValueOrDefault("gidNumber");
|
||||
string? descriptionValue = ldapData.GetValueOrDefault("description");
|
||||
if (descriptionValue is null)
|
||||
{
|
||||
Permissions = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
Permissions = JsonSerializer.Deserialize<GroupPermissions>(descriptionValue)?.Permissions ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupPermissions
|
||||
{
|
||||
public required List<GroupPermission> Permissions { get; set; }
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum GroupPermission
|
||||
{
|
||||
None,
|
||||
CanInventorize,
|
||||
CanManageUsers,
|
||||
CanManageLocations,
|
||||
CanManageAssets,
|
||||
CanManageGroups
|
||||
}
|
||||
16
src/Models/GroupsRequestModels.cs
Normal file
16
src/Models/GroupsRequestModels.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Berufsschule_HAM.Models;
|
||||
|
||||
public class GroupsIndexRequestModel
|
||||
{
|
||||
public string? Cn { get; set; }
|
||||
public bool GidNumber { get; set; } = true;
|
||||
public bool Permissions { get; set; } = true;
|
||||
}
|
||||
|
||||
public class GroupsModifyRequestModel
|
||||
{
|
||||
public required string Cn { get; set; }
|
||||
public string? NewCn { get; set; } = null;
|
||||
public string? GidNumber { get; set; } = null;
|
||||
public GroupPermissions? Permissions { get; set; } = null;
|
||||
}
|
||||
Reference in New Issue
Block a user