mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Berufsschule_HAM.Exceptions;
|
|
|
|
namespace Berufsschule_HAM.Models;
|
|
|
|
public class GroupModel
|
|
{
|
|
[JsonPropertyName("Cn")]
|
|
public required string Cn { get; set; }
|
|
[JsonPropertyName("DisplayName")]
|
|
public string DisplayName { get; set; }
|
|
[JsonPropertyName("GidNumber")]
|
|
public string? GidNumber { get; set; }
|
|
[JsonPropertyName("Permissions")]
|
|
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
|
|
{
|
|
GroupDescription? description = JsonSerializer.Deserialize<GroupDescription>(descriptionValue);
|
|
DisplayName = description?.DisplayName ?? Cn;
|
|
Permissions = description?.Permissions ?? [];
|
|
}
|
|
}
|
|
}
|
|
|
|
public class GroupDescription
|
|
{
|
|
[JsonPropertyName("DisplayName")]
|
|
public required string DisplayName { get; set; }
|
|
[JsonPropertyName("Permissions")]
|
|
public required List<GroupPermission> Permissions { get; set; }
|
|
}
|
|
|
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
|
public enum GroupPermission
|
|
{
|
|
None,
|
|
CanInventorize,
|
|
CanManageUsers,
|
|
CanManageLocations,
|
|
CanManageAssets,
|
|
CanManageGroups
|
|
} |