forked from ddrilling/AsbCloudServer
CS2-133: Removed Value property from roles to permissions models and services
This commit is contained in:
parent
dc636a1d8c
commit
888c28cdf8
@ -7,6 +7,5 @@ namespace AsbCloudApp.Data
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public IDictionary<int, string> BitDescription { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,8 +2,7 @@
|
|||||||
{
|
{
|
||||||
public class PermissionBaseDto
|
public class PermissionBaseDto
|
||||||
{
|
{
|
||||||
public int IdPermissionInfo { get; set; }
|
public int Id { get; set; }
|
||||||
public string PermissionName { get; set; }
|
public string PermissionName { get; set; }
|
||||||
public int Value { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
2978
AsbCloudDb/Migrations/20211215111416_RemovedPermissionValues.Designer.cs
generated
Normal file
2978
AsbCloudDb/Migrations/20211215111416_RemovedPermissionValues.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
214
AsbCloudDb/Migrations/20211215111416_RemovedPermissionValues.cs
Normal file
214
AsbCloudDb/Migrations/20211215111416_RemovedPermissionValues.cs
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class RemovedPermissionValues : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_t_permission_t_permission_info_id_permission_info",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_t_permission_t_user_role_id_user_role",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "t_permission_info");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_permission",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_t_permission_id_permission_info",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "id_user_role",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "id_permission_info",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "value",
|
||||||
|
table: "t_permission",
|
||||||
|
newName: "id");
|
||||||
|
|
||||||
|
migrationBuilder.AlterTable(
|
||||||
|
name: "t_permission",
|
||||||
|
comment: "Разрешения на доступ к данным",
|
||||||
|
oldComment: "Отношение ролей пользователей и разрешений доступа");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer")
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "description",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "character varying(255)",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: true,
|
||||||
|
comment: "Краткое описание");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "name",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "character varying(255)",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: true,
|
||||||
|
comment: "Название");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_permission",
|
||||||
|
table: "t_permission",
|
||||||
|
column: "id");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "t_relation_user_role_permission",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id_user_role = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
id_permission = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_t_relation_user_role_permission", x => new { x.id_user_role, x.id_permission });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_t_relation_user_role_permission_t_permission_id_permission",
|
||||||
|
column: x => x.id_permission,
|
||||||
|
principalTable: "t_permission",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_t_relation_user_role_permission_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_permission_id_permission",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
column: "id_permission");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "t_relation_user_role_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_permission",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_user_role");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "description",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "name",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "id",
|
||||||
|
table: "t_permission",
|
||||||
|
newName: "value");
|
||||||
|
|
||||||
|
migrationBuilder.AlterTable(
|
||||||
|
name: "t_permission",
|
||||||
|
comment: "Отношение ролей пользователей и разрешений доступа",
|
||||||
|
oldComment: "Разрешения на доступ к данным");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "value",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer")
|
||||||
|
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "id_user_role",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "id_permission_info",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_permission",
|
||||||
|
table: "t_permission",
|
||||||
|
columns: new[] { "id_user_role", "id_permission_info" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "t_permission_info",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
bit_description = table.Column<IDictionary<int, string>>(type: "jsonb", nullable: true, comment: "Описание каждого бита разрешений"),
|
||||||
|
description = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Краткое описание"),
|
||||||
|
name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Название")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_t_permission_info", x => x.id);
|
||||||
|
},
|
||||||
|
comment: "Разрешения на доступ к данным");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_t_permission_id_permission_info",
|
||||||
|
table: "t_permission",
|
||||||
|
column: "id_permission_info");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_t_permission_t_permission_info_id_permission_info",
|
||||||
|
table: "t_permission",
|
||||||
|
column: "id_permission_info",
|
||||||
|
principalTable: "t_permission_info",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_t_permission_t_user_role_id_user_role",
|
||||||
|
table: "t_permission",
|
||||||
|
column: "id_user_role",
|
||||||
|
principalTable: "t_user_role",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -682,30 +682,6 @@ namespace AsbCloudDb.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.Permission", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.Permission", b =>
|
||||||
{
|
|
||||||
b.Property<int>("IdUserRole")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("id_user_role");
|
|
||||||
|
|
||||||
b.Property<int>("IdPermissionInfo")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("id_permission_info");
|
|
||||||
|
|
||||||
b.Property<int>("Value")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("value");
|
|
||||||
|
|
||||||
b.HasKey("IdUserRole", "IdPermissionInfo");
|
|
||||||
|
|
||||||
b.HasIndex("IdPermissionInfo");
|
|
||||||
|
|
||||||
b.ToTable("t_permission");
|
|
||||||
|
|
||||||
b
|
|
||||||
.HasComment("Отношение ролей пользователей и разрешений доступа");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.PermissionInfo", b =>
|
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -713,11 +689,6 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnName("id")
|
.HasColumnName("id")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
b.Property<IDictionary<int, string>>("BitDescription")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("bit_description")
|
|
||||||
.HasComment("Описание каждого бита разрешений");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.HasMaxLength(255)
|
.HasMaxLength(255)
|
||||||
.HasColumnType("character varying(255)")
|
.HasColumnType("character varying(255)")
|
||||||
@ -732,7 +703,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("t_permission_info");
|
b.ToTable("t_permission");
|
||||||
|
|
||||||
b
|
b
|
||||||
.HasComment("Разрешения на доступ к данным");
|
.HasComment("Разрешения на доступ к данным");
|
||||||
@ -758,6 +729,30 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasComment("отношение скважин и компаний");
|
.HasComment("отношение скважин и компаний");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("IdUserRole")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id_user_role");
|
||||||
|
|
||||||
|
b.Property<int>("IdPermission")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id_permission");
|
||||||
|
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
b.HasKey("IdUserRole", "IdPermission");
|
||||||
|
|
||||||
|
b.HasIndex("IdPermission");
|
||||||
|
|
||||||
|
b.ToTable("t_relation_user_role_permission");
|
||||||
|
|
||||||
|
b
|
||||||
|
.HasComment("Отношение ролей пользователей и разрешений доступа");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("IdUser")
|
b.Property<int>("IdUser")
|
||||||
@ -768,6 +763,10 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_user_role");
|
.HasColumnName("id_user_role");
|
||||||
|
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
b.HasKey("IdUser", "IdUserRole");
|
b.HasKey("IdUser", "IdUserRole");
|
||||||
|
|
||||||
b.HasIndex("IdUserRole");
|
b.HasIndex("IdUserRole");
|
||||||
@ -781,7 +780,8 @@ namespace AsbCloudDb.Migrations
|
|||||||
new
|
new
|
||||||
{
|
{
|
||||||
IdUser = 1,
|
IdUser = 1,
|
||||||
IdUserRole = 2
|
IdUserRole = 2,
|
||||||
|
Id = 0
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2601,25 +2601,6 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Well");
|
b.Navigation("Well");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.Permission", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("AsbCloudDb.Model.PermissionInfo", "PermissionInfo")
|
|
||||||
.WithMany("Permissions")
|
|
||||||
.HasForeignKey("IdPermissionInfo")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("AsbCloudDb.Model.UserRole", "UserRole")
|
|
||||||
.WithMany("Permissions")
|
|
||||||
.HasForeignKey("IdUserRole")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("PermissionInfo");
|
|
||||||
|
|
||||||
b.Navigation("UserRole");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationCompanyWell", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationCompanyWell", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("AsbCloudDb.Model.Company", "Company")
|
b.HasOne("AsbCloudDb.Model.Company", "Company")
|
||||||
@ -2641,6 +2622,25 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Well");
|
b.Navigation("Well");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("AsbCloudDb.Model.Permission", "Permission")
|
||||||
|
.WithMany("RelationUserRolePermissions")
|
||||||
|
.HasForeignKey("IdPermission")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("AsbCloudDb.Model.UserRole", "UserRole")
|
||||||
|
.WithMany("RelationUserRolePermissions")
|
||||||
|
.HasForeignKey("IdUserRole")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Permission");
|
||||||
|
|
||||||
|
b.Navigation("UserRole");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("AsbCloudDb.Model.User", "User")
|
b.HasOne("AsbCloudDb.Model.User", "User")
|
||||||
@ -2903,9 +2903,9 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Measures");
|
b.Navigation("Measures");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.PermissionInfo", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.Permission", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Permissions");
|
b.Navigation("RelationUserRolePermissions");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.Telemetry", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.Telemetry", b =>
|
||||||
@ -2936,7 +2936,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.UserRole", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.UserRole", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Permissions");
|
b.Navigation("RelationUserRolePermissions");
|
||||||
|
|
||||||
b.Navigation("RelationUsersUserRoles");
|
b.Navigation("RelationUsersUserRoles");
|
||||||
});
|
});
|
||||||
|
@ -41,7 +41,7 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
public virtual DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||||
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||||
public virtual DbSet<Permission> Permissions { get; set; }
|
public virtual DbSet<Permission> Permissions { get; set; }
|
||||||
public virtual DbSet<PermissionInfo> PermissionInfos { get; set; }
|
public virtual DbSet<Permission> PermissionInfos { get; set; }
|
||||||
|
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
@ -254,9 +254,9 @@ namespace AsbCloudDb.Model
|
|||||||
entity.HasKey(e => new { e.IdUser, e.IdUserRole });
|
entity.HasKey(e => new { e.IdUser, e.IdUserRole });
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Permission>(entity =>
|
modelBuilder.Entity<RelationUserRolePermission>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(e => new { e.IdUserRole, e.IdPermissionInfo });
|
entity.HasKey(e => new { e.IdUserRole, e.IdPermission });
|
||||||
});
|
});
|
||||||
|
|
||||||
FillData(modelBuilder);
|
FillData(modelBuilder);
|
||||||
|
@ -38,7 +38,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||||
DbSet<Permission> Permissions { get; set; }
|
DbSet<Permission> Permissions { get; set; }
|
||||||
DbSet<PermissionInfo> PermissionInfos { get; set; }
|
DbSet<Permission> PermissionInfos { get; set; }
|
||||||
|
|
||||||
DatabaseFacade Database { get; }
|
DatabaseFacade Database { get; }
|
||||||
|
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_permission"), Comment("Отношение ролей пользователей и разрешений доступа")]
|
[Table("t_permission"), Comment("Разрешения на доступ к данным")]
|
||||||
public class Permission
|
public class Permission : IId
|
||||||
{
|
{
|
||||||
[Column("id_user_role")]
|
[Key]
|
||||||
public int IdUserRole { get; set; }
|
[Column("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("id_permission_info")]
|
[Column("name"), Comment("Название")]
|
||||||
public int IdPermissionInfo { get; set; }
|
[StringLength(255)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
[Column("value")]
|
[Column("description"), Comment("Краткое описание")]
|
||||||
public int Value { get; set; }
|
[StringLength(255)]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
[ForeignKey(nameof(IdUserRole))]
|
[InverseProperty(nameof(RelationUserRolePermission.Permission))]
|
||||||
[InverseProperty(nameof(Model.UserRole.Permissions))]
|
public virtual ICollection<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||||
public virtual UserRole UserRole { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey(nameof(IdPermissionInfo))]
|
|
||||||
[InverseProperty(nameof(Model.PermissionInfo.Permissions))]
|
|
||||||
public virtual PermissionInfo PermissionInfo { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
|
||||||
{
|
|
||||||
[Table("t_permission_info"), Comment("Разрешения на доступ к данным")]
|
|
||||||
public class PermissionInfo : IId
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
[Column("id")]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Column("name"), Comment("Название")]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
[Column("description"), Comment("Краткое описание")]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
[Column("bit_description", TypeName = "jsonb"), Comment("Описание каждого бита разрешений")]
|
|
||||||
public IDictionary<int, string> BitDescription { get; set; }
|
|
||||||
|
|
||||||
[InverseProperty(nameof(Permission.PermissionInfo))]
|
|
||||||
public virtual ICollection<Permission> Permissions { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
28
AsbCloudDb/Model/RelationUserRolePermission.cs
Normal file
28
AsbCloudDb/Model/RelationUserRolePermission.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Model
|
||||||
|
{
|
||||||
|
[Table("t_relation_user_role_permission"), Comment("Отношение ролей пользователей и разрешений доступа")]
|
||||||
|
public class RelationUserRolePermission
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[Column("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Column("id_user_role")]
|
||||||
|
public int IdUserRole { get; set; }
|
||||||
|
|
||||||
|
[Column("id_permission")]
|
||||||
|
public int IdPermission { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(IdUserRole))]
|
||||||
|
[InverseProperty(nameof(Model.UserRole.RelationUserRolePermissions))]
|
||||||
|
public virtual UserRole UserRole { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(IdPermission))]
|
||||||
|
[InverseProperty(nameof(Model.Permission.RelationUserRolePermissions))]
|
||||||
|
public virtual Permission Permission { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,10 @@ namespace AsbCloudDb.Model
|
|||||||
[Table("t_relation_user_user_role"), Comment("Отношение пользователей и ролей")]
|
[Table("t_relation_user_user_role"), Comment("Отношение пользователей и ролей")]
|
||||||
public class RelationUserUserRole
|
public class RelationUserUserRole
|
||||||
{
|
{
|
||||||
|
[Key]
|
||||||
|
[Column("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("id_user")]
|
[Column("id_user")]
|
||||||
public int IdUser { get; set; }
|
public int IdUser { get; set; }
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace AsbCloudDb.Model
|
|||||||
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
||||||
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(Permission.UserRole))]
|
[InverseProperty(nameof(RelationUserRolePermission.UserRole))]
|
||||||
public virtual ICollection<Permission> Permissions { get; set; }
|
public virtual ICollection<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ namespace AsbCloudInfrastructure
|
|||||||
// admin crud services:
|
// admin crud services:
|
||||||
services.AddTransient<ICrudService<WellDto>, CrudServiceBase<WellDto, Well>>();
|
services.AddTransient<ICrudService<WellDto>, CrudServiceBase<WellDto, Well>>();
|
||||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
||||||
services.AddTransient<ICrudService<PermissionInfoDto>, CrudServiceBase<PermissionInfoDto, PermissionInfo>>();
|
services.AddTransient<ICrudService<PermissionInfoDto>, CrudServiceBase<PermissionInfoDto, Permission>>();
|
||||||
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
||||||
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
||||||
services.AddTransient<ICrudService<CompanyDto>, CrudServiceBase<CompanyDto, Company>>();
|
services.AddTransient<ICrudService<CompanyDto>, CrudServiceBase<CompanyDto, Company>>();
|
||||||
|
@ -11,23 +11,26 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public class PermissionService : IPermissionService, IConverter<PermissionDto, Permission>
|
public class PermissionService : IPermissionService
|
||||||
{
|
{
|
||||||
|
private readonly CacheTable<RelationUserRolePermission> cacheUserRolePermission;
|
||||||
private readonly CacheTable<Permission> cachePermission;
|
private readonly CacheTable<Permission> cachePermission;
|
||||||
|
|
||||||
public PermissionService(IAsbCloudDbContext db, CacheDb cacheDb)
|
public PermissionService(IAsbCloudDbContext db, CacheDb cacheDb)
|
||||||
{
|
{
|
||||||
cachePermission = cacheDb.GetCachedTable<Permission>(
|
cacheUserRolePermission = cacheDb.GetCachedTable<RelationUserRolePermission>(
|
||||||
(AsbCloudDbContext)db,
|
(AsbCloudDbContext)db,
|
||||||
new string[] { nameof(Permission.PermissionInfo) });
|
new string[] { nameof(RelationUserRolePermission.Permission) });
|
||||||
|
cachePermission = cacheDb.GetCachedTable<Permission>(
|
||||||
|
(AsbCloudDbContext)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<PermissionDto>> GetByIdRoleAsync(int idRole, CancellationToken token)
|
public async Task<IEnumerable<PermissionDto>> GetByIdRoleAsync(int idRole, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entities = await cachePermission
|
var entities = await cacheUserRolePermission
|
||||||
.WhereAsync(p => p.IdUserRole == idRole, token)
|
.WhereAsync(p => p.IdUserRole == idRole, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
var dto = entities.Select(Convert);
|
var dto = entities.Select(e => e.Permission).Adapt<PermissionDto>();
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,21 +50,21 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public Task<int> DeleteAsync(int idUserRole, int idPermission, CancellationToken token)
|
public Task<int> DeleteAsync(int idUserRole, int idPermission, CancellationToken token)
|
||||||
{
|
{
|
||||||
bool predicate(Permission p) => p.IdUserRole == idUserRole && p.IdPermissionInfo == idPermission;
|
bool predicate(RelationUserRolePermission p) => p.IdUserRole == idUserRole && p.IdPermission == idPermission;
|
||||||
return DeleteAsync(predicate, token);
|
return DeleteAsync(predicate, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> DeleteAllByRoleAsync(int idUserRole, CancellationToken token)
|
public Task<int> DeleteAllByRoleAsync(int idUserRole, CancellationToken token)
|
||||||
{
|
{
|
||||||
bool predicate(Permission p) => p.IdUserRole == idUserRole;
|
bool predicate(RelationUserRolePermission p) => p.IdUserRole == idUserRole;
|
||||||
return DeleteAsync(predicate, token);
|
return DeleteAsync(predicate, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<int> DeleteAsync(Func<Permission, bool> predicate, CancellationToken token)
|
private async Task<int> DeleteAsync(Func<RelationUserRolePermission, bool> predicate, CancellationToken token)
|
||||||
{
|
{
|
||||||
var count = (await cachePermission.WhereAsync(predicate, token).ConfigureAwait(false)).Count();
|
var count = (await cacheUserRolePermission.WhereAsync(predicate, token).ConfigureAwait(false)).Count();
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
await cachePermission.RemoveAsync(predicate, token)
|
await cacheUserRolePermission.RemoveAsync(predicate, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -71,13 +74,5 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var entity = src.Adapt<Permission>();
|
var entity = src.Adapt<Permission>();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionDto Convert(Permission src)
|
|
||||||
{
|
|
||||||
var dto = src.Adapt<PermissionDto>();
|
|
||||||
dto.PermissionName = src.PermissionInfo?.Name;
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,14 +15,14 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public class UserRoleService : IUserRoleService
|
public class UserRoleService : IUserRoleService
|
||||||
{
|
{
|
||||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||||
private readonly CacheTable<PermissionInfo> cachePermissionInfo;
|
private readonly CacheTable<Permission> cachePermission;
|
||||||
private readonly IPermissionService permissionService;
|
private readonly IPermissionService permissionService;
|
||||||
public List<string> Includes { get; } = new();
|
public List<string> Includes { get; } = new();
|
||||||
|
|
||||||
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb, IPermissionService permissionService)
|
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb, IPermissionService permissionService)
|
||||||
{
|
{
|
||||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, new [] { nameof(UserRole.Permissions) });
|
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context, new [] { nameof(UserRole.RelationUserRolePermissions) });
|
||||||
cachePermissionInfo = cacheDb.GetCachedTable<PermissionInfo>((AsbCloudDbContext)context);
|
cachePermission = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)context);
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,19 +106,18 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
foreach (var newPermission in rolePermissions)
|
foreach (var newPermission in rolePermissions)
|
||||||
{
|
{
|
||||||
if (permissions.ContainsKey(newPermission.IdPermissionInfo))
|
if (permissions.ContainsKey(newPermission.Id))
|
||||||
{
|
{
|
||||||
permissions[newPermission.IdPermissionInfo].Value |= newPermission.Value;
|
permissions[newPermission.Id] = newPermission.Adapt<PermissionBaseDto>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
permissions.Add(newPermission.IdPermissionInfo,
|
permissions.Add(newPermission.Id,
|
||||||
new PermissionBaseDto
|
new PermissionBaseDto
|
||||||
{
|
{
|
||||||
IdPermissionInfo = newPermission.IdPermissionInfo,
|
Id = newPermission.Id,
|
||||||
PermissionName = newPermission.PermissionInfo?.Name ??
|
PermissionName = newPermission.Name ??
|
||||||
cachePermissionInfo.FirstOrDefault(p => p.Id == newPermission.IdPermissionInfo).Name,
|
cachePermission.FirstOrDefault(p => p.Id == newPermission.Id).Name
|
||||||
Value = newPermission.Value,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,10 +135,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var newPermissions = roleDto.Permissions.Select(p => new PermissionDto
|
var newPermissions = roleDto.Permissions.Select(p => new PermissionDto
|
||||||
{
|
{
|
||||||
IdPermissionInfo = p.IdPermissionInfo,
|
Id = p.Id,
|
||||||
IdUserRole = roleDto.Id,
|
IdUserRole = roleDto.Id,
|
||||||
PermissionName = p.PermissionName,
|
PermissionName = p.PermissionName
|
||||||
Value = p.Value,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await permissionService.InsertRangeAsync(newPermissions, token)
|
await permissionService.InsertRangeAsync(newPermissions, token)
|
||||||
@ -148,22 +146,23 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
private IEnumerable<Permission> GetNestedPermissions(UserRole role, int recursionLevel = 7)
|
private IEnumerable<Permission> GetNestedPermissions(UserRole role, int recursionLevel = 7)
|
||||||
{
|
{
|
||||||
var permissions = role.Permissions.ToList();
|
var permissionRelations = role.RelationUserRolePermissions.ToList();
|
||||||
|
var permissionIds = permissionRelations.Select(p => p.IdPermission);
|
||||||
if (role.IdParent is null)
|
if (role.IdParent is null)
|
||||||
return permissions;
|
return cachePermission.Where(c => permissionIds.Contains(c.Id));
|
||||||
if (recursionLevel == 0)
|
if (recursionLevel == 0)
|
||||||
{
|
{
|
||||||
Trace.WriteLine($"User role with id: {role.Id} has more than 10 nested childs");
|
Trace.WriteLine($"User role with id: {role.Id} has more than 10 nested children");
|
||||||
return permissions;
|
cachePermission.Where(c => permissionIds.Contains(c.Id));
|
||||||
}
|
}
|
||||||
var parentRole = cacheUserRoles.FirstOrDefault(r => r.Id == role.IdParent);
|
var parentRole = cacheUserRoles.FirstOrDefault(r => r.Id == role.IdParent);
|
||||||
|
|
||||||
if (parentRole is null)
|
if (parentRole is null)
|
||||||
return permissions;
|
return cachePermission.Where(c => permissionIds.Contains(c.Id));
|
||||||
|
|
||||||
var parentPermissions = GetNestedPermissions(parentRole, --recursionLevel);
|
var parentPermissions = GetNestedPermissions(parentRole, --recursionLevel);
|
||||||
|
|
||||||
return permissions.Union(parentPermissions);
|
return cachePermission.Where(c => permissionIds.Contains(c.Id)).Union(parentPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> DeleteAsync(int id, CancellationToken token = default)
|
public Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||||
@ -174,7 +173,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public bool HasPermission(IEnumerable<int> rolesIds, string permissionName, int permissionMask = 0)
|
public bool HasPermission(IEnumerable<int> rolesIds, string permissionName, int permissionMask = 0)
|
||||||
{
|
{
|
||||||
var permissionInfo = cachePermissionInfo.FirstOrDefault(p => p.Name.ToLower() == permissionName.ToLower());
|
var permissionInfo = cachePermission.FirstOrDefault(p => p.Name.ToLower() == permissionName.ToLower());
|
||||||
|
|
||||||
if (permissionInfo is null)
|
if (permissionInfo is null)
|
||||||
return false;
|
return false;
|
||||||
@ -190,14 +189,14 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HasPermission(UserRole userRole, int idPermissionInfo, int permissionMask, int recursionLevel = 7)
|
private bool HasPermission(UserRole userRole, int idPermission, int recursionLevel = 7)
|
||||||
{
|
{
|
||||||
if (userRole.Permissions.Any(p => p.IdPermissionInfo == idPermissionInfo && (p.Value & permissionMask) > 0))
|
if (userRole.RelationUserRolePermissions.Any(p => p.IdPermission == idPermission))
|
||||||
return true;
|
return true;
|
||||||
if (userRole.IdParent is not null && recursionLevel > 0)
|
if (userRole.IdParent is not null && recursionLevel > 0)
|
||||||
{
|
{
|
||||||
var parentRole = cacheUserRoles.FirstOrDefault(p => p.Id == userRole.IdParent);
|
var parentRole = cacheUserRoles.FirstOrDefault(p => p.Id == userRole.IdParent);
|
||||||
return HasPermission(parentRole, idPermissionInfo, permissionMask, --recursionLevel);
|
return HasPermission(parentRole, idPermission, --recursionLevel);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user