forked from ddrilling/AsbCloudServer
Add RelationUserRoleUserRole for multiple parents. INCOMPLETE
This commit is contained in:
parent
2c51c352b1
commit
e09e358cd0
10
AsbCloud.sln
10
AsbCloud.sln
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32014.148
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi", "AsbCloudWebApi\AsbCloudWebApi.csproj", "{A2768702-47CB-4127-941C-E339D5EFCFFE}"
|
||||
EndProject
|
||||
@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudDb", "AsbCloudDb\As
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi.Tests", "AsbCloudWebApi.Tests\AsbCloudWebApi.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppDbExperiments", "ConsoleAppDbExperiments\ConsoleAppDbExperiments.csproj", "{9F689214-B4EA-4614-8345-97C53C678F00}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -45,6 +47,10 @@ Global
|
||||
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9F689214-B4EA-4614-8345-97C53C678F00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9F689214-B4EA-4614-8345-97C53C678F00}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9F689214-B4EA-4614-8345-97C53C678F00}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9F689214-B4EA-4614-8345-97C53C678F00}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -7,10 +7,14 @@ namespace AsbCloudApp.Data
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public int? IdParent { get; set; }
|
||||
public int IdType { get; set; }
|
||||
public IEnumerable<PermissionDto> Permissions { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<UserRoleDto> Roles { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<UserDto> Users { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
3131
AsbCloudDb/Migrations/20220112104809_Refactor_UserRole.Designer.cs
generated
Normal file
3131
AsbCloudDb/Migrations/20220112104809_Refactor_UserRole.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
59
AsbCloudDb/Migrations/20220112104809_Refactor_UserRole.cs
Normal file
59
AsbCloudDb/Migrations/20220112104809_Refactor_UserRole.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Refactor_UserRole : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "id_parent",
|
||||
table: "t_user_role");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "t_relation_user_role_user_role",
|
||||
columns: table => new
|
||||
{
|
||||
id_user_role = table.Column<int>(type: "integer", nullable: false),
|
||||
id_include_user_role = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("t_relation_user_role_user_role_pk", x => new { x.id_user_role, x.id_include_user_role });
|
||||
table.ForeignKey(
|
||||
name: "FK_t_relation_user_role_user_role_t_user_role_id_include_user_~",
|
||||
column: x => x.id_include_user_role,
|
||||
principalTable: "t_user_role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_t_relation_user_role_user_role_t_user_role_id_user_role",
|
||||
column: x => x.id_user_role,
|
||||
principalTable: "t_user_role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
},
|
||||
comment: "Отношение ролей к ролям");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_t_relation_user_role_user_role_id_include_user_role",
|
||||
table: "t_relation_user_role_user_role",
|
||||
column: "id_include_user_role");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "t_relation_user_role_user_role");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "id_parent",
|
||||
table: "t_user_role",
|
||||
type: "integer",
|
||||
nullable: true,
|
||||
comment: "От какой роли унаследована данная роль");
|
||||
}
|
||||
}
|
||||
}
|
@ -756,6 +756,26 @@ namespace AsbCloudDb.Migrations
|
||||
b.HasComment("Отношение ролей пользователей и разрешений доступа");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRoleUserRole", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_user_role");
|
||||
|
||||
b.Property<int>("IdInclude")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_include_user_role");
|
||||
|
||||
b.HasKey("Id", "IdInclude")
|
||||
.HasName("t_relation_user_role_user_role_pk");
|
||||
|
||||
b.HasIndex("IdInclude");
|
||||
|
||||
b.ToTable("t_relation_user_role_user_role");
|
||||
|
||||
b.HasComment("Отношение ролей к ролям");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||
{
|
||||
b.Property<int>("IdUser")
|
||||
@ -1764,11 +1784,6 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("caption")
|
||||
.HasComment("Название");
|
||||
|
||||
b.Property<int?>("IdParent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_parent")
|
||||
.HasComment("От какой роли унаследована данная роль");
|
||||
|
||||
b.Property<int>("IdType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_type")
|
||||
@ -2758,6 +2773,25 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("UserRole");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRoleUserRole", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.UserRole", "Role")
|
||||
.WithMany("RelationUserRoleUserRoles")
|
||||
.HasForeignKey("Id")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AsbCloudDb.Model.UserRole", "IncludeRole")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdInclude")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("IncludeRole");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.User", "User")
|
||||
@ -3055,6 +3089,8 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
b.Navigation("RelationUserRolePermissions");
|
||||
|
||||
b.Navigation("RelationUserRoleUserRoles");
|
||||
|
||||
b.Navigation("RelationUsersUserRoles");
|
||||
});
|
||||
|
||||
|
@ -38,6 +38,7 @@ namespace AsbCloudDb.Model
|
||||
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
public virtual DbSet<Permission> Permissions { get; set; }
|
||||
public virtual DbSet<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||
public virtual DbSet<RelationUserRoleUserRole> RelationUserRoleUserRoles { get; set; }
|
||||
|
||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
@ -205,6 +206,11 @@ namespace AsbCloudDb.Model
|
||||
.HasConstraintName("t_relation_company_well_t_company_id_fk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RelationUserRoleUserRole>(entity => {
|
||||
entity.HasKey(x => new { x.Id, x.IdInclude })
|
||||
.HasName("t_relation_user_role_user_role_pk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<WellOperation>(entity =>
|
||||
{
|
||||
entity.HasIndex(d => d.DepthEnd);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
|
23
AsbCloudDb/Model/RelationUserRoleUserRole.cs
Normal file
23
AsbCloudDb/Model/RelationUserRoleUserRole.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_relation_user_role_user_role"), Comment("Отношение ролей к ролям")]
|
||||
public class RelationUserRoleUserRole
|
||||
{
|
||||
[Column("id_user_role")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_include_user_role")]
|
||||
public int IdInclude { get; set; }
|
||||
|
||||
[ForeignKey(nameof(Id))]
|
||||
[InverseProperty(nameof(UserRole.RelationUserRoleUserRoles))]
|
||||
public virtual UserRole Role { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdInclude))]
|
||||
public virtual UserRole IncludeRole { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -20,9 +20,8 @@ namespace AsbCloudDb.Model
|
||||
[Column("id_type"), Comment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя")]
|
||||
public int IdType { get; set; }
|
||||
|
||||
[Column("id_parent"), Comment("От какой роли унаследована данная роль")]
|
||||
public int? IdParent { get; set; }
|
||||
|
||||
[InverseProperty(nameof(RelationUserRoleUserRole.Role))]
|
||||
public virtual ICollection<RelationUserRoleUserRole> RelationUserRoleUserRoles { get; set; }
|
||||
|
||||
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
||||
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
||||
|
15
ConsoleAppDbExperiments/ConsoleAppDbExperiments.csproj
Normal file
15
ConsoleAppDbExperiments/ConsoleAppDbExperiments.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AsbCloudApp\AsbCloudApp.csproj" />
|
||||
<ProjectReference Include="..\AsbCloudDb\AsbCloudDb.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
47
ConsoleAppDbExperiments/Program.cs
Normal file
47
ConsoleAppDbExperiments/Program.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
.UseNpgsql("Host=localhost;Database=experiments;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True")
|
||||
.Options;
|
||||
var context = new AsbCloudDbContext(options);
|
||||
|
||||
var rels = context.RelationUserRoleUserRoles.Include(r=>r.Role).Include(r => r.IncludeRole);
|
||||
|
||||
IEnumerable<UserRoleDto> GetIncludedRole(int id)
|
||||
{
|
||||
var res = context.UserRoles
|
||||
.Include(r=>r.RelationUserRoleUserRoles)
|
||||
.Where(r=>r.Id == id)
|
||||
.SelectMany(r=>r.);
|
||||
return rels.Where(r => r.Id == id).;
|
||||
}
|
||||
|
||||
UserRoleDto Convert(UserRole role)
|
||||
{
|
||||
if (role is null)
|
||||
return null;
|
||||
|
||||
var res = new UserRoleDto
|
||||
{
|
||||
Id = role.Id,
|
||||
Caption = role.Caption,
|
||||
IdType = role.IdType,
|
||||
Permissions = role.RelationUserRolePermissions?.Select(r => r.Permission).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
PermissionDto Convert(Permission permission)
|
||||
{
|
||||
if (permission is null)
|
||||
return null;
|
||||
return new PermissionDto
|
||||
{
|
||||
Name = permission.Name,
|
||||
Id = permission.Id,
|
||||
Description = permission.Description
|
||||
};
|
||||
}
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
Loading…
Reference in New Issue
Block a user