forked from ddrilling/AsbCloudServer
CS2-123: Returned table for roles permissions.
This commit is contained in:
parent
2d9388cb2a
commit
9280b28e10
@ -3,7 +3,8 @@ namespace AsbCloudApp.Data
|
|||||||
public class PermissionDto
|
public class PermissionDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Caption { get; set; }
|
public string Name { get; set; }
|
||||||
public int Type { get; set; }
|
public string Description { get; set; }
|
||||||
|
public string BitDescription { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,8 @@ namespace AsbCloudApp.Data
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Caption { get; set; }
|
public string Caption { get; set; }
|
||||||
public int IdParent { get; set; }
|
public int? IdParent { get; set; }
|
||||||
public int RoleType { get; set; }
|
public int IdType { get; set; }
|
||||||
public virtual ICollection<UserDto> Users { get; set; }
|
public virtual ICollection<UserDto> Users { get; set; }
|
||||||
public IEnumerable<int> PermissionIds { get; set; }
|
public IEnumerable<int> PermissionIds { get; set; }
|
||||||
public IEnumerable<PermissionDto> Permissions { get; set; }
|
public IEnumerable<PermissionDto> Permissions { get; set; }
|
||||||
|
@ -6,8 +6,8 @@ namespace AsbCloudApp.Data
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string CompanyName { get; set; }
|
public string CompanyName { get; set; }
|
||||||
public IDictionary<string, int> Permissions { get; set; }
|
|
||||||
public IEnumerable<string> RoleNames { get; set; }
|
public IEnumerable<string> RoleNames { get; set; }
|
||||||
|
public IDictionary<string, int> Permissions { get; set; }
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2893
AsbCloudDb/Migrations/20211129122956_Fixed_Role_Permissions_Value.Designer.cs
generated
Normal file
2893
AsbCloudDb/Migrations/20211129122956_Fixed_Role_Permissions_Value.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,223 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Fixed_Role_Permissions_Value : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_user_role",
|
||||||
|
table: "t_relation_user_user_role");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_t_relation_user_user_role_id_user",
|
||||||
|
table: "t_relation_user_user_role");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_role_permission",
|
||||||
|
table: "t_relation_user_role_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_t_relation_user_role_permission_id_user_role",
|
||||||
|
table: "t_relation_user_role_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_user_role");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "type",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "role_type",
|
||||||
|
table: "t_user_role",
|
||||||
|
newName: "id_type");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
newName: "permission_value");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "caption",
|
||||||
|
table: "t_permission",
|
||||||
|
newName: "name");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_parent",
|
||||||
|
table: "t_user_role",
|
||||||
|
type: "integer",
|
||||||
|
nullable: true,
|
||||||
|
comment: "От какой роли унаследована данная роль",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldComment: "От какой роли унаследована данная роль");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "permission_value",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer")
|
||||||
|
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "bit_description",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "jsonb",
|
||||||
|
nullable: true,
|
||||||
|
comment: "Описание каждого бита разрешений");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "description",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "character varying(255)",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: true,
|
||||||
|
comment: "Краткое описание");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_user_role",
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
columns: new[] { "id_user", "id_user_role" });
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_role_permission",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
columns: new[] { "id_user_role", "id_permission" });
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
columns: new[] { "id_user", "id_user_role" },
|
||||||
|
values: new object[] { 1, 2 });
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user_role",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 1,
|
||||||
|
column: "id_parent",
|
||||||
|
value: null);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user_role",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 2,
|
||||||
|
column: "id_parent",
|
||||||
|
value: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_user_role",
|
||||||
|
table: "t_relation_user_user_role");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_role_permission",
|
||||||
|
table: "t_relation_user_role_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
keyColumns: new[] { "id_user", "id_user_role" },
|
||||||
|
keyValues: new object[] { 1, 2 });
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "bit_description",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "description",
|
||||||
|
table: "t_permission");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "id_type",
|
||||||
|
table: "t_user_role",
|
||||||
|
newName: "role_type");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "permission_value",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
newName: "id");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "name",
|
||||||
|
table: "t_permission",
|
||||||
|
newName: "caption");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_parent",
|
||||||
|
table: "t_user_role",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: "От какой роли унаследована данная роль",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldNullable: true,
|
||||||
|
oldComment: "От какой роли унаследована данная роль");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer")
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "type",
|
||||||
|
table: "t_permission",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: "1-чтение, 2-запись, 3-чтение и запись");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_user_role",
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
column: "id");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_t_relation_user_role_permission",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
column: "id");
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user_role",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 1,
|
||||||
|
column: "id_parent",
|
||||||
|
value: 0);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user_role",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 2,
|
||||||
|
column: "id_parent",
|
||||||
|
value: 0);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_t_relation_user_user_role_id_user",
|
||||||
|
table: "t_relation_user_user_role",
|
||||||
|
column: "id_user");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_t_relation_user_role_permission_id_user_role",
|
||||||
|
table: "t_relation_user_role_permission",
|
||||||
|
column: "id_user_role");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -689,16 +689,22 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnName("id")
|
.HasColumnName("id")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
b.Property<string>("Caption")
|
b.Property<string>("BitDescription")
|
||||||
|
.HasColumnType("jsonb")
|
||||||
|
.HasColumnName("bit_description")
|
||||||
|
.HasComment("Описание каждого бита разрешений");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
.HasMaxLength(255)
|
.HasMaxLength(255)
|
||||||
.HasColumnType("character varying(255)")
|
.HasColumnType("character varying(255)")
|
||||||
.HasColumnName("caption")
|
.HasColumnName("description")
|
||||||
.HasComment("Название");
|
.HasComment("Краткое описание");
|
||||||
|
|
||||||
b.Property<int>("Type")
|
b.Property<string>("Name")
|
||||||
.HasColumnType("integer")
|
.HasMaxLength(255)
|
||||||
.HasColumnName("type")
|
.HasColumnType("character varying(255)")
|
||||||
.HasComment("1-чтение, 2-запись, 3-чтение и запись");
|
.HasColumnName("name")
|
||||||
|
.HasComment("Название");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -728,28 +734,24 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasComment("отношение скважин и компаний");
|
.HasComment("отношение скважин и компаний");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationRolePermission", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("IdRole")
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id")
|
.HasColumnName("id_user_role");
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
|
||||||
|
|
||||||
b.Property<int>("IdPermission")
|
b.Property<int>("IdPermission")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_permission");
|
.HasColumnName("id_permission");
|
||||||
|
|
||||||
b.Property<int>("IdUserRole")
|
b.Property<int>("PermissionValue")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_user_role");
|
.HasColumnName("permission_value");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("IdRole", "IdPermission");
|
||||||
|
|
||||||
b.HasIndex("IdPermission");
|
b.HasIndex("IdPermission");
|
||||||
|
|
||||||
b.HasIndex("IdUserRole");
|
|
||||||
|
|
||||||
b.ToTable("t_relation_user_role_permission");
|
b.ToTable("t_relation_user_role_permission");
|
||||||
|
|
||||||
b
|
b
|
||||||
@ -758,12 +760,6 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("id")
|
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
|
||||||
|
|
||||||
b.Property<int>("IdUser")
|
b.Property<int>("IdUser")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_user");
|
.HasColumnName("id_user");
|
||||||
@ -772,9 +768,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_user_role");
|
.HasColumnName("id_user_role");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("IdUser", "IdUserRole");
|
||||||
|
|
||||||
b.HasIndex("IdUser");
|
|
||||||
|
|
||||||
b.HasIndex("IdUserRole");
|
b.HasIndex("IdUserRole");
|
||||||
|
|
||||||
@ -782,6 +776,13 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
b
|
b
|
||||||
.HasComment("Отношение пользователей и ролей");
|
.HasComment("Отношение пользователей и ролей");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
IdUser = 1,
|
||||||
|
IdUserRole = 2
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.ReportProperty", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.ReportProperty", b =>
|
||||||
@ -1715,14 +1716,14 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnName("caption")
|
.HasColumnName("caption")
|
||||||
.HasComment("Название");
|
.HasComment("Название");
|
||||||
|
|
||||||
b.Property<int>("IdParent")
|
b.Property<int?>("IdParent")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_parent")
|
.HasColumnName("id_parent")
|
||||||
.HasComment("От какой роли унаследована данная роль");
|
.HasComment("От какой роли унаследована данная роль");
|
||||||
|
|
||||||
b.Property<int>("RoleType")
|
b.Property<int>("IdType")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("role_type")
|
.HasColumnName("id_type")
|
||||||
.HasComment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя");
|
.HasComment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@ -1737,15 +1738,13 @@ namespace AsbCloudDb.Migrations
|
|||||||
{
|
{
|
||||||
Id = 1,
|
Id = 1,
|
||||||
Caption = "Администратор",
|
Caption = "Администратор",
|
||||||
IdParent = 0,
|
IdType = 0
|
||||||
RoleType = 0
|
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Caption = "Пользователь",
|
Caption = "Пользователь",
|
||||||
IdParent = 0,
|
IdType = 0
|
||||||
RoleType = 0
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2557,7 +2556,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Well");
|
b.Navigation("Well");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.RelationRolePermission", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("AsbCloudDb.Model.Permission", "Permission")
|
b.HasOne("AsbCloudDb.Model.Permission", "Permission")
|
||||||
.WithMany("RelationUserRolesPermissions")
|
.WithMany("RelationUserRolesPermissions")
|
||||||
@ -2567,7 +2566,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
b.HasOne("AsbCloudDb.Model.UserRole", "UserRole")
|
b.HasOne("AsbCloudDb.Model.UserRole", "UserRole")
|
||||||
.WithMany("RelationUserRolesPermissions")
|
.WithMany("RelationUserRolesPermissions")
|
||||||
.HasForeignKey("IdUserRole")
|
.HasForeignKey("IdRole")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<DrillParams> DrillParams { get; set; }
|
public virtual DbSet<DrillParams> DrillParams { get; set; }
|
||||||
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<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
public virtual DbSet<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||||
public virtual DbSet<Permission> Permissions { get; set; }
|
public virtual DbSet<Permission> Permissions { get; set; }
|
||||||
|
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
@ -248,6 +248,16 @@ namespace AsbCloudDb.Model
|
|||||||
.HasConstraintName("t_file_mark_t_file_info_fk");
|
.HasConstraintName("t_file_mark_t_file_info_fk");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<RelationUserUserRole>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => new { e.IdUser, e.IdUserRole });
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<RelationRolePermission>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => new { e.IdRole, e.IdPermission });
|
||||||
|
});
|
||||||
|
|
||||||
FillData(modelBuilder);
|
FillData(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +284,13 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<RelationUserUserRole>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasData(new List<RelationUserUserRole>{
|
||||||
|
new RelationUserUserRole{ IdUser = 1, IdUserRole = 2, },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Company>(entity =>
|
modelBuilder.Entity<Company>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasData(new List<Company>{
|
entity.HasData(new List<Company>{
|
||||||
|
@ -37,7 +37,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<DrillParams> DrillParams { get; set; }
|
DbSet<DrillParams> DrillParams { get; set; }
|
||||||
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||||
DbSet<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
DbSet<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||||
DbSet<Permission> Permissions { get; set; }
|
DbSet<Permission> Permissions { get; set; }
|
||||||
|
|
||||||
DatabaseFacade Database { get; }
|
DatabaseFacade Database { get; }
|
||||||
|
@ -12,14 +12,18 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("caption"), Comment("Название")]
|
[Column("name"), Comment("Название")]
|
||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
public string Caption { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[Column("type"), Comment("1-чтение, 2-запись, 3-чтение и запись")]
|
[Column("description"), Comment("Краткое описание")]
|
||||||
public int Type { get; set; }
|
[StringLength(255)]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(RelationUserRolePermission.Permission))]
|
[Column("bit_description", TypeName = "jsonb"), Comment("Описание каждого бита разрешений")]
|
||||||
public virtual ICollection<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
public string BitDescription { get; set; }
|
||||||
|
|
||||||
|
[InverseProperty(nameof(RelationRolePermission.Permission))]
|
||||||
|
public virtual ICollection<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,19 +5,18 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_relation_user_role_permission"), Comment("Отношение ролей пользователей и разрешений доступа")]
|
[Table("t_relation_user_role_permission"), Comment("Отношение ролей пользователей и разрешений доступа")]
|
||||||
public class RelationUserRolePermission
|
public class RelationRolePermission
|
||||||
{
|
{
|
||||||
[Key]
|
|
||||||
[Column("id")]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Column("id_user_role")]
|
[Column("id_user_role")]
|
||||||
public int IdUserRole { get; set; }
|
public int IdRole { get; set; }
|
||||||
|
|
||||||
[Column("id_permission")]
|
[Column("id_permission")]
|
||||||
public int IdPermission { get; set; }
|
public int IdPermission { get; set; }
|
||||||
|
|
||||||
[ForeignKey(nameof(IdUserRole))]
|
[Column("permission_value")]
|
||||||
|
public int PermissionValue { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(IdRole))]
|
||||||
[InverseProperty(nameof(Model.UserRole.RelationUserRolesPermissions))]
|
[InverseProperty(nameof(Model.UserRole.RelationUserRolesPermissions))]
|
||||||
public virtual UserRole UserRole { get; set; }
|
public virtual UserRole UserRole { get; set; }
|
||||||
|
|
@ -7,10 +7,6 @@ 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; }
|
||||||
|
|
||||||
|
@ -17,17 +17,17 @@ namespace AsbCloudDb.Model
|
|||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
public string Caption { get; set; }
|
public string Caption { get; set; }
|
||||||
|
|
||||||
[Column("role_type"), Comment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя")]
|
[Column("id_type"), Comment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя")]
|
||||||
public int RoleType { get; set; }
|
public int IdType { get; set; }
|
||||||
|
|
||||||
[Column("id_parent"), Comment("От какой роли унаследована данная роль")]
|
[Column("id_parent"), Comment("От какой роли унаследована данная роль")]
|
||||||
public int IdParent { get; set; }
|
public int? IdParent { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
||||||
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(RelationUserRolePermission.UserRole))]
|
[InverseProperty(nameof(RelationRolePermission.UserRole))]
|
||||||
public virtual ICollection<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
public virtual ICollection<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,38 @@ namespace AsbCloudDevOperations
|
|||||||
new WellOperation { Id = 76341, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, DepthEnd = 1250, DateStart = DateTime.Parse("2021-08-26 11:30"), DurationHours = 3.5 }
|
new WellOperation { Id = 76341, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, DepthEnd = 1250, DateStart = DateTime.Parse("2021-08-26 11:30"), DurationHours = 3.5 }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
demoContext.Permissions.AddRange(
|
||||||
|
new Permission()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Name = "test permission",
|
||||||
|
Description = "some description",
|
||||||
|
BitDescription = "{\"0\": \"some zero bit description\"}"
|
||||||
|
},
|
||||||
|
new Permission()
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
Name = "second test permission",
|
||||||
|
Description = "some second description",
|
||||||
|
BitDescription = "{\"1\": \"some first bit description\"}"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
demoContext.RelationUserRolesPermissions.AddRange(
|
||||||
|
new RelationRolePermission()
|
||||||
|
{
|
||||||
|
IdRole = 2,
|
||||||
|
IdPermission = 1,
|
||||||
|
PermissionValue = 143
|
||||||
|
},
|
||||||
|
new RelationRolePermission()
|
||||||
|
{
|
||||||
|
IdRole = 2,
|
||||||
|
IdPermission = 2,
|
||||||
|
PermissionValue = 12
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
int res = demoContext.SaveChanges();
|
int res = demoContext.SaveChanges();
|
||||||
|
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
|
@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||||
private readonly CacheTable<RelationUserUserRole> cacheUsersUserRoles;
|
private readonly CacheTable<RelationUserUserRole> cacheUsersUserRoles;
|
||||||
private readonly CacheTable<Permission> cachePermissions;
|
private readonly CacheTable<Permission> cachePermissions;
|
||||||
private readonly CacheTable<RelationUserRolePermission> cacheUserRolesPermissions;
|
private readonly CacheTable<RelationRolePermission> cacheUserRolesPermissions;
|
||||||
|
|
||||||
public const string issuer = "a";
|
public const string issuer = "a";
|
||||||
public const string audience = "a";
|
public const string audience = "a";
|
||||||
@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)db);
|
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)db);
|
||||||
cacheUsersUserRoles = cacheDb.GetCachedTable<RelationUserUserRole>((AsbCloudDbContext)db);
|
cacheUsersUserRoles = cacheDb.GetCachedTable<RelationUserUserRole>((AsbCloudDbContext)db);
|
||||||
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)db);
|
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)db);
|
||||||
cacheUserRolesPermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)db);
|
cacheUserRolesPermissions = cacheDb.GetCachedTable<RelationRolePermission>((AsbCloudDbContext)db);
|
||||||
hashAlgoritm = SHA384.Create();
|
hashAlgoritm = SHA384.Create();
|
||||||
rnd = new Random((int)(DateTime.Now.Ticks % 2147480161));
|
rnd = new Random((int)(DateTime.Now.Ticks % 2147480161));
|
||||||
}
|
}
|
||||||
@ -57,9 +57,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (identity == default || user.State == 0)
|
if (identity == default || user.State == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var idCaptionRoles = GetUserRolesIdsNames(user.Id);
|
var userRoles = GetUserRoles(user.Id);
|
||||||
|
|
||||||
var userPermissions = GetUserPermissions(idCaptionRoles.Select(r => r.Id));
|
var roleNames = userRoles.Select(r => r.Caption);
|
||||||
|
|
||||||
return new UserTokenDto
|
return new UserTokenDto
|
||||||
{
|
{
|
||||||
@ -68,8 +68,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
CompanyName = user.Company.Caption,
|
CompanyName = user.Company.Caption,
|
||||||
Login = user.Login,
|
Login = user.Login,
|
||||||
Patronymic = user.Patronymic,
|
Patronymic = user.Patronymic,
|
||||||
RoleNames = idCaptionRoles.Select(r => r.Caption),
|
RoleNames = roleNames,
|
||||||
Permissions = userPermissions,
|
Permissions = GetUserPermissions(userRoles),
|
||||||
Surname = user.Surname,
|
Surname = user.Surname,
|
||||||
Token = MakeToken(identity.Claims),
|
Token = MakeToken(identity.Claims),
|
||||||
};
|
};
|
||||||
@ -177,22 +177,26 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return new JwtSecurityTokenHandler().WriteToken(jwt);
|
return new JwtSecurityTokenHandler().WriteToken(jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<(int Id, string Caption)> GetUserRolesIdsNames(int idUser)
|
private IEnumerable<UserRole> GetUserRoles(int idUser)
|
||||||
{
|
{
|
||||||
var userRolesIds = cacheUsersUserRoles.Where(r =>
|
var userRolesIds = cacheUsersUserRoles.Where(r =>
|
||||||
r.IdUser == idUser).Select(r => r.IdUserRole);
|
r.IdUser == idUser).Select(r => r.IdUserRole);
|
||||||
|
|
||||||
return cacheUserRoles.Where(r => userRolesIds.Contains(r.Id))
|
return cacheUserRoles.Where(r => userRolesIds.Contains(r.Id));
|
||||||
.Select(r => (r.Id, r.Caption));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IDictionary<string, int> GetUserPermissions(IEnumerable<int> idRoles)
|
private IDictionary<string, int> GetUserPermissions(IEnumerable<UserRole> userRoles)
|
||||||
{
|
{
|
||||||
var userPermissionIds = cacheUserRolesPermissions.Where(p =>
|
var rolesIds = userRoles.Select(r => r.Id);
|
||||||
idRoles.Contains(p.IdUserRole)).Select(r => r.IdPermission);
|
var userPermissionsInfo = cacheUserRolesPermissions.Where(p =>
|
||||||
|
rolesIds.Contains(p.IdRole))
|
||||||
|
.Select(perm => new { perm.IdPermission, perm.PermissionValue });
|
||||||
|
|
||||||
return cachePermissions.Where(r => userPermissionIds.Contains(r.Id))
|
return userPermissionsInfo.Select(p => new
|
||||||
.ToDictionary(k => k.Caption, v => v.Type);
|
{
|
||||||
|
PermissionName = cachePermissions.FirstOrDefault(c => c.Id == p.IdPermission)?.Name,
|
||||||
|
PermissionValue = p.PermissionValue
|
||||||
|
}).ToDictionary(k => k.PermissionName, v => v.PermissionValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login,
|
private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login,
|
||||||
@ -210,7 +214,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (!CheckPassword(user.PasswordHash, password))
|
if (!CheckPassword(user.PasswordHash, password))
|
||||||
return default;
|
return default;
|
||||||
|
|
||||||
var userRolesNames = GetUserRolesIdsNames(user.Id)
|
var userRolesNames = GetUserRoles(user.Id)
|
||||||
.Select(r => r.Caption);
|
.Select(r => r.Caption);
|
||||||
|
|
||||||
var claims = new List<Claim>
|
var claims = new List<Claim>
|
||||||
|
@ -14,7 +14,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||||
private readonly CacheTable<Permission> cachePermissions;
|
private readonly CacheTable<Permission> cachePermissions;
|
||||||
private readonly CacheTable<RelationUserRolePermission> cacheUserRolesPermissions;
|
private readonly CacheTable<RelationRolePermission> cacheUserRolesPermissions;
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
|
|
||||||
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb) : base(context)
|
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb) : base(context)
|
||||||
@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context);
|
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context);
|
||||||
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)context);
|
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)context);
|
||||||
cacheUserRolesPermissions =
|
cacheUserRolesPermissions =
|
||||||
cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context);
|
cacheDb.GetCachedTable<RelationRolePermission>((AsbCloudDbContext)context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<PaginationContainer<UserRoleDto>> GetPageAsync(int skip = 0,
|
public override async Task<PaginationContainer<UserRoleDto>> GetPageAsync(int skip = 0,
|
||||||
@ -56,9 +56,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
foreach (var pId in dto.PermissionIds)
|
foreach (var pId in dto.PermissionIds)
|
||||||
{
|
{
|
||||||
var relation = new RelationUserRolePermission()
|
var relation = new RelationRolePermission()
|
||||||
{
|
{
|
||||||
IdUserRole = newRoleId,
|
IdRole = newRoleId,
|
||||||
IdPermission = pId
|
IdPermission = pId
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (item.PermissionIds == default)
|
if (item.PermissionIds == default)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
await cacheUserRolesPermissions.RemoveAsync(r => r.IdUserRole == item.Id, token)
|
await cacheUserRolesPermissions.RemoveAsync(r => r.IdRole == item.Id, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var newRelations = item.PermissionIds.Select(p => new RelationUserRolePermission()
|
var newRelations = item.PermissionIds.Select(p => new RelationRolePermission()
|
||||||
{
|
{
|
||||||
IdUserRole = item.Id,
|
IdRole = item.Id,
|
||||||
IdPermission = p
|
IdPermission = p
|
||||||
});
|
});
|
||||||
await cacheUserRolesPermissions.InsertAsync(newRelations, token);
|
await cacheUserRolesPermissions.InsertAsync(newRelations, token);
|
||||||
@ -91,7 +91,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
private UserRoleDto FillUserRoleWithPermissions(UserRoleDto roleDto)
|
private UserRoleDto FillUserRoleWithPermissions(UserRoleDto roleDto)
|
||||||
{
|
{
|
||||||
var rolePermissionIds = cacheUserRolesPermissions.Where(c =>
|
var rolePermissionIds = cacheUserRolesPermissions.Where(c =>
|
||||||
c.IdUserRole == roleDto.Id).Select(p => p.IdPermission);
|
c.IdRole == roleDto.Id).Select(p => p.IdPermission);
|
||||||
roleDto.Permissions = cachePermissions.Where(permission => rolePermissionIds.Contains(permission.Id))
|
roleDto.Permissions = cachePermissions.Where(permission => rolePermissionIds.Contains(permission.Id))
|
||||||
.Adapt<PermissionDto>();
|
.Adapt<PermissionDto>();
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var parentRole = cacheUserRoles.FirstOrDefault(r => r.Id == idParent)
|
var parentRole = cacheUserRoles.FirstOrDefault(r => r.Id == idParent)
|
||||||
.Adapt<UserRoleDto>();
|
.Adapt<UserRoleDto>();
|
||||||
var parentRolePermissionsIds = cacheUserRolesPermissions.Where(p =>
|
var parentRolePermissionsIds = cacheUserRolesPermissions.Where(p =>
|
||||||
p.IdUserRole == parentRole.Id).Select(perm => perm.IdPermission);
|
p.IdRole == parentRole.Id).Select(perm => perm.IdPermission);
|
||||||
parentRole.PermissionIds = resultPermissionsIds.Union(parentRolePermissionsIds);
|
parentRole.PermissionIds = resultPermissionsIds.Union(parentRolePermissionsIds);
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
Loading…
Reference in New Issue
Block a user