Added security entities

master
Tudor Stanciu 2023-04-13 01:51:53 +03:00
parent cbaf4154bd
commit 8e54fdc184
7 changed files with 82 additions and 0 deletions

View File

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Power;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security;
using NetworkResurrector.Api.Domain.Entities;
namespace NetworkResurrector.Api.Domain.Data.DbContexts
@ -26,6 +27,9 @@ namespace NetworkResurrector.Api.Domain.Data.DbContexts
modelBuilder.ApplyConfiguration(new PowerActionPerformerConfiguration());
modelBuilder.ApplyConfiguration(new PowerActionConfigurationEf());
modelBuilder.ApplyConfiguration(new MachineAgentConfiguration());
modelBuilder.ApplyConfiguration(new PermissionConfiguration());
modelBuilder.ApplyConfiguration(new PermissionHierarchyConfiguration());
modelBuilder.ApplyConfiguration(new UserRoleAuthorizationConfiguration());
}
}
}

View File

@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using NetworkResurrector.Api.Domain.Entities.Security;
namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security
{
class PermissionConfiguration : IEntityTypeConfiguration<Permission>
{
public void Configure(EntityTypeBuilder<Permission> builder)
{
builder.ToTable("Permission").HasKey(key => key.PermissionId);
builder.Property(z => z.PermissionId).ValueGeneratedOnAdd();
builder.HasMany(z => z.Children).WithOne().HasForeignKey(z => z.ParentPermissionId);
}
}
}

View File

@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using NetworkResurrector.Api.Domain.Entities.Security;
namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security
{
class PermissionHierarchyConfiguration : IEntityTypeConfiguration<PermissionHierarchy>
{
public void Configure(EntityTypeBuilder<PermissionHierarchy> builder)
{
builder.ToTable("PermissionHierarchy").HasKey(p => new { p.ParentPermissionId, p.ChildPermissionId });
builder.HasOne(z => z.Child).WithMany().HasForeignKey(p => p.ChildPermissionId);
}
}
}

View File

@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using NetworkResurrector.Api.Domain.Entities.Security;
namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security
{
class UserRoleAuthorizationConfiguration : IEntityTypeConfiguration<UserRoleAuthorization>
{
public void Configure(EntityTypeBuilder<UserRoleAuthorization> builder)
{
builder.ToTable("UserRoleAuthorization").HasKey(z => new { z.UserRoleId, z.PermissionId });
builder.HasOne(z => z.Permission).WithMany().HasForeignKey(z => z.PermissionId);
}
}
}

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace NetworkResurrector.Api.Domain.Entities.Security
{
public class Permission
{
public int PermissionId { get; set; }
public string PermissionCode { get; set; }
public string PermissionName { get; set; }
public string PermissionDescription { get; set; }
public ICollection<PermissionHierarchy> Children { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace NetworkResurrector.Api.Domain.Entities.Security
{
public class PermissionHierarchy
{
public int ParentPermissionId { get; set; }
public int ChildPermissionId { get; set; }
public Permission Child { get; set; }
}
}

View File

@ -0,0 +1,10 @@
namespace NetworkResurrector.Api.Domain.Entities.Security
{
public class UserRoleAuthorization
{
public int UserRoleId { get; set; }
public int PermissionId { get; set; }
public bool Active { get; set; }
public Permission Permission { get; set; }
}
}