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 int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public int Type { get; set; }
|
||||
public string Name { 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 string Caption { get; set; }
|
||||
public int IdParent { get; set; }
|
||||
public int RoleType { get; set; }
|
||||
public int? IdParent { get; set; }
|
||||
public int IdType { get; set; }
|
||||
public virtual ICollection<UserDto> Users { get; set; }
|
||||
public IEnumerable<int> PermissionIds { get; set; }
|
||||
public IEnumerable<PermissionDto> Permissions { get; set; }
|
||||
|
@ -6,8 +6,8 @@ namespace AsbCloudApp.Data
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string CompanyName { get; set; }
|
||||
public IDictionary<string, int> Permissions { get; set; }
|
||||
public IEnumerable<string> RoleNames { get; set; }
|
||||
public IDictionary<string, int> Permissions { 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")
|
||||
.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)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("caption")
|
||||
.HasComment("Название");
|
||||
.HasColumnName("description")
|
||||
.HasComment("Краткое описание");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type")
|
||||
.HasComment("1-чтение, 2-запись, 3-чтение и запись");
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("name")
|
||||
.HasComment("Название");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -728,28 +734,24 @@ namespace AsbCloudDb.Migrations
|
||||
.HasComment("отношение скважин и компаний");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationRolePermission", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
b.Property<int>("IdRole")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
.HasColumnName("id_user_role");
|
||||
|
||||
b.Property<int>("IdPermission")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_permission");
|
||||
|
||||
b.Property<int>("IdUserRole")
|
||||
b.Property<int>("PermissionValue")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_user_role");
|
||||
.HasColumnName("permission_value");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("IdRole", "IdPermission");
|
||||
|
||||
b.HasIndex("IdPermission");
|
||||
|
||||
b.HasIndex("IdUserRole");
|
||||
|
||||
b.ToTable("t_relation_user_role_permission");
|
||||
|
||||
b
|
||||
@ -758,12 +760,6 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserUserRole", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
b.Property<int>("IdUser")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_user");
|
||||
@ -772,9 +768,7 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_user_role");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IdUser");
|
||||
b.HasKey("IdUser", "IdUserRole");
|
||||
|
||||
b.HasIndex("IdUserRole");
|
||||
|
||||
@ -782,6 +776,13 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
b
|
||||
.HasComment("Отношение пользователей и ролей");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
IdUser = 1,
|
||||
IdUserRole = 2
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.ReportProperty", b =>
|
||||
@ -1715,14 +1716,14 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("caption")
|
||||
.HasComment("Название");
|
||||
|
||||
b.Property<int>("IdParent")
|
||||
b.Property<int?>("IdParent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_parent")
|
||||
.HasComment("От какой роли унаследована данная роль");
|
||||
|
||||
b.Property<int>("RoleType")
|
||||
b.Property<int>("IdType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("role_type")
|
||||
.HasColumnName("id_type")
|
||||
.HasComment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя");
|
||||
|
||||
b.HasKey("Id");
|
||||
@ -1737,15 +1738,13 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
Id = 1,
|
||||
Caption = "Администратор",
|
||||
IdParent = 0,
|
||||
RoleType = 0
|
||||
IdType = 0
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Caption = "Пользователь",
|
||||
IdParent = 0,
|
||||
RoleType = 0
|
||||
IdType = 0
|
||||
});
|
||||
});
|
||||
|
||||
@ -2557,7 +2556,7 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("Well");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationUserRolePermission", b =>
|
||||
modelBuilder.Entity("AsbCloudDb.Model.RelationRolePermission", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.Permission", "Permission")
|
||||
.WithMany("RelationUserRolesPermissions")
|
||||
@ -2567,7 +2566,7 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
b.HasOne("AsbCloudDb.Model.UserRole", "UserRole")
|
||||
.WithMany("RelationUserRolesPermissions")
|
||||
.HasForeignKey("IdUserRole")
|
||||
.HasForeignKey("IdRole")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
|
@ -39,7 +39,7 @@ namespace AsbCloudDb.Model
|
||||
public virtual DbSet<DrillParams> DrillParams { get; set; }
|
||||
public virtual DbSet<DrillFlowChart> DrillFlowChart { 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; }
|
||||
|
||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
@ -247,6 +247,16 @@ namespace AsbCloudDb.Model
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.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);
|
||||
}
|
||||
@ -273,6 +283,13 @@ namespace AsbCloudDb.Model
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RelationUserUserRole>(entity =>
|
||||
{
|
||||
entity.HasData(new List<RelationUserUserRole>{
|
||||
new RelationUserUserRole{ IdUser = 1, IdUserRole = 2, },
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Company>(entity =>
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ namespace AsbCloudDb.Model
|
||||
DbSet<DrillParams> DrillParams { get; set; }
|
||||
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
DbSet<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
||||
DbSet<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||
DbSet<Permission> Permissions { get; set; }
|
||||
|
||||
DatabaseFacade Database { get; }
|
||||
|
@ -12,14 +12,18 @@ namespace AsbCloudDb.Model
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("caption"), Comment("Название")]
|
||||
[Column("name"), Comment("Название")]
|
||||
[StringLength(255)]
|
||||
public string Caption { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("type"), Comment("1-чтение, 2-запись, 3-чтение и запись")]
|
||||
public int Type { get; set; }
|
||||
[Column("description"), Comment("Краткое описание")]
|
||||
[StringLength(255)]
|
||||
public string Description { get; set; }
|
||||
|
||||
[InverseProperty(nameof(RelationUserRolePermission.Permission))]
|
||||
public virtual ICollection<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
||||
[Column("bit_description", TypeName = "jsonb"), Comment("Описание каждого бита разрешений")]
|
||||
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
|
||||
{
|
||||
[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")]
|
||||
public int IdUserRole { get; set; }
|
||||
public int IdRole { get; set; }
|
||||
|
||||
[Column("id_permission")]
|
||||
public int IdPermission { get; set; }
|
||||
|
||||
[Column("permission_value")]
|
||||
public int PermissionValue { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdUserRole))]
|
||||
[ForeignKey(nameof(IdRole))]
|
||||
[InverseProperty(nameof(Model.UserRole.RelationUserRolesPermissions))]
|
||||
public virtual UserRole UserRole { get; set; }
|
||||
|
@ -7,10 +7,6 @@ namespace AsbCloudDb.Model
|
||||
[Table("t_relation_user_user_role"), Comment("Отношение пользователей и ролей")]
|
||||
public class RelationUserUserRole
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_user")]
|
||||
public int IdUser { get; set; }
|
||||
|
||||
|
@ -17,17 +17,17 @@ namespace AsbCloudDb.Model
|
||||
[StringLength(255)]
|
||||
public string Caption { get; set; }
|
||||
|
||||
[Column("role_type"), Comment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя")]
|
||||
public int RoleType { get; set; }
|
||||
[Column("id_type"), Comment("0-роль из стандартной матрицы, \n1-специальная роль для какого-либо пользователя")]
|
||||
public int IdType { get; set; }
|
||||
|
||||
[Column("id_parent"), Comment("От какой роли унаследована данная роль")]
|
||||
public int IdParent { get; set; }
|
||||
public int? IdParent { get; set; }
|
||||
|
||||
|
||||
[InverseProperty(nameof(RelationUserUserRole.UserRole))]
|
||||
public virtual ICollection<RelationUserUserRole> RelationUsersUserRoles { get; set; }
|
||||
|
||||
[InverseProperty(nameof(RelationUserRolePermission.UserRole))]
|
||||
public virtual ICollection<RelationUserRolePermission> RelationUserRolesPermissions { get; set; }
|
||||
[InverseProperty(nameof(RelationRolePermission.UserRole))]
|
||||
public virtual ICollection<RelationRolePermission> RelationUserRolesPermissions { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,38 @@ namespace AsbCloudDevOperations
|
||||
new WellOperation { Id = 51329, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, DepthEnd = 1400, DateStart = DateTime.Parse("2021-08-27 08: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();
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||
private readonly CacheTable<RelationUserUserRole> cacheUsersUserRoles;
|
||||
private readonly CacheTable<Permission> cachePermissions;
|
||||
private readonly CacheTable<RelationUserRolePermission> cacheUserRolesPermissions;
|
||||
private readonly CacheTable<RelationRolePermission> cacheUserRolesPermissions;
|
||||
|
||||
public const string issuer = "a";
|
||||
public const string audience = "a";
|
||||
@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)db);
|
||||
cacheUsersUserRoles = cacheDb.GetCachedTable<RelationUserUserRole>((AsbCloudDbContext)db);
|
||||
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)db);
|
||||
cacheUserRolesPermissions = cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)db);
|
||||
cacheUserRolesPermissions = cacheDb.GetCachedTable<RelationRolePermission>((AsbCloudDbContext)db);
|
||||
hashAlgoritm = SHA384.Create();
|
||||
rnd = new Random((int)(DateTime.Now.Ticks % 2147480161));
|
||||
}
|
||||
@ -57,10 +57,10 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (identity == default || user.State == 0)
|
||||
return null;
|
||||
|
||||
var idCaptionRoles = GetUserRolesIdsNames(user.Id);
|
||||
|
||||
var userPermissions = GetUserPermissions(idCaptionRoles.Select(r => r.Id));
|
||||
var userRoles = GetUserRoles(user.Id);
|
||||
|
||||
var roleNames = userRoles.Select(r => r.Caption);
|
||||
|
||||
return new UserTokenDto
|
||||
{
|
||||
Id = user.Id,
|
||||
@ -68,8 +68,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
CompanyName = user.Company.Caption,
|
||||
Login = user.Login,
|
||||
Patronymic = user.Patronymic,
|
||||
RoleNames = idCaptionRoles.Select(r => r.Caption),
|
||||
Permissions = userPermissions,
|
||||
RoleNames = roleNames,
|
||||
Permissions = GetUserPermissions(userRoles),
|
||||
Surname = user.Surname,
|
||||
Token = MakeToken(identity.Claims),
|
||||
};
|
||||
@ -177,22 +177,26 @@ namespace AsbCloudInfrastructure.Services
|
||||
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 =>
|
||||
r.IdUser == idUser).Select(r => r.IdUserRole);
|
||||
|
||||
return cacheUserRoles.Where(r => userRolesIds.Contains(r.Id))
|
||||
.Select(r => (r.Id, r.Caption));
|
||||
return cacheUserRoles.Where(r => userRolesIds.Contains(r.Id));
|
||||
}
|
||||
|
||||
private IDictionary<string, int> GetUserPermissions(IEnumerable<int> idRoles)
|
||||
|
||||
private IDictionary<string, int> GetUserPermissions(IEnumerable<UserRole> userRoles)
|
||||
{
|
||||
var userPermissionIds = cacheUserRolesPermissions.Where(p =>
|
||||
idRoles.Contains(p.IdUserRole)).Select(r => r.IdPermission);
|
||||
|
||||
return cachePermissions.Where(r => userPermissionIds.Contains(r.Id))
|
||||
.ToDictionary(k => k.Caption, v => v.Type);
|
||||
var rolesIds = userRoles.Select(r => r.Id);
|
||||
var userPermissionsInfo = cacheUserRolesPermissions.Where(p =>
|
||||
rolesIds.Contains(p.IdRole))
|
||||
.Select(perm => new { perm.IdPermission, perm.PermissionValue });
|
||||
|
||||
return userPermissionsInfo.Select(p => new
|
||||
{
|
||||
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,
|
||||
@ -210,7 +214,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (!CheckPassword(user.PasswordHash, password))
|
||||
return default;
|
||||
|
||||
var userRolesNames = GetUserRolesIdsNames(user.Id)
|
||||
var userRolesNames = GetUserRoles(user.Id)
|
||||
.Select(r => r.Caption);
|
||||
|
||||
var claims = new List<Claim>
|
||||
|
@ -14,7 +14,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
private readonly CacheTable<UserRole> cacheUserRoles;
|
||||
private readonly CacheTable<Permission> cachePermissions;
|
||||
private readonly CacheTable<RelationUserRolePermission> cacheUserRolesPermissions;
|
||||
private readonly CacheTable<RelationRolePermission> cacheUserRolesPermissions;
|
||||
private int counter = 0;
|
||||
|
||||
public UserRoleService(IAsbCloudDbContext context, CacheDb cacheDb) : base(context)
|
||||
@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
cacheUserRoles = cacheDb.GetCachedTable<UserRole>((AsbCloudDbContext)context);
|
||||
cachePermissions = cacheDb.GetCachedTable<Permission>((AsbCloudDbContext)context);
|
||||
cacheUserRolesPermissions =
|
||||
cacheDb.GetCachedTable<RelationUserRolePermission>((AsbCloudDbContext)context);
|
||||
cacheDb.GetCachedTable<RelationRolePermission>((AsbCloudDbContext)context);
|
||||
}
|
||||
|
||||
public override async Task<PaginationContainer<UserRoleDto>> GetPageAsync(int skip = 0,
|
||||
@ -56,9 +56,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
foreach (var pId in dto.PermissionIds)
|
||||
{
|
||||
var relation = new RelationUserRolePermission()
|
||||
var relation = new RelationRolePermission()
|
||||
{
|
||||
IdUserRole = newRoleId,
|
||||
IdRole = newRoleId,
|
||||
IdPermission = pId
|
||||
};
|
||||
|
||||
@ -75,12 +75,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (item.PermissionIds == default)
|
||||
return result;
|
||||
|
||||
await cacheUserRolesPermissions.RemoveAsync(r => r.IdUserRole == item.Id, token)
|
||||
await cacheUserRolesPermissions.RemoveAsync(r => r.IdRole == item.Id, token)
|
||||
.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
|
||||
});
|
||||
await cacheUserRolesPermissions.InsertAsync(newRelations, token);
|
||||
@ -91,7 +91,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
private UserRoleDto FillUserRoleWithPermissions(UserRoleDto roleDto)
|
||||
{
|
||||
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))
|
||||
.Adapt<PermissionDto>();
|
||||
|
||||
@ -115,7 +115,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var parentRole = cacheUserRoles.FirstOrDefault(r => r.Id == idParent)
|
||||
.Adapt<UserRoleDto>();
|
||||
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);
|
||||
|
||||
counter++;
|
||||
|
Loading…
Reference in New Issue
Block a user