47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System.Text.RegularExpressions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Authinator.Backend.Database.Tables;
|
|
|
|
public class ACL {
|
|
public int Id { get; }
|
|
public string Name { get; set; } = null!;
|
|
public bool Enabled { get; set; } = true;
|
|
public string Target { get; set; } = null!;
|
|
public bool TargetIsRegex { get; set; }
|
|
public List<User> Users { get; set; } = new();
|
|
public List<Group> Groups { get; set; } = new();
|
|
public List<Network> Networks { get; set; } = new();
|
|
|
|
public class Configuration : IEntityTypeConfiguration<ACL> {
|
|
public void Configure(EntityTypeBuilder<ACL> acl) {
|
|
acl.ToTable("ACLs");
|
|
acl.HasKey(p => p.Id);
|
|
acl.Property(b => b.Name).HasColumnName("Name").IsRequired();
|
|
acl.Property(p => p.Target).HasColumnName("Target").IsRequired();
|
|
acl.Property(p => p.Enabled).HasColumnName("Enabled").IsRequired();
|
|
acl.Property(p => p.TargetIsRegex).HasColumnName("TargetIsRegex").HasDefaultValue(false);
|
|
acl.HasMany(p => p.Networks).WithMany();
|
|
acl.HasMany(p => p.Groups).WithMany();
|
|
acl.HasMany(p => p.Users).WithMany();
|
|
}
|
|
}
|
|
|
|
private bool Equals(ACL other) => Id == other.Id;
|
|
|
|
public override bool Equals(object? obj) {
|
|
if (ReferenceEquals(null, obj))
|
|
return false;
|
|
if (ReferenceEquals(this, obj))
|
|
return true;
|
|
return obj.GetType() == GetType() && Equals((ACL)obj);
|
|
}
|
|
|
|
public override int GetHashCode() => Id;
|
|
|
|
public static bool operator ==(ACL? left, ACL? right) => Equals(left, right);
|
|
|
|
public static bool operator !=(ACL? left, ACL? right) => !Equals(left, right);
|
|
}
|