feat(dal): таблицы Users, Roles

This commit is contained in:
Mikhail Trubnikov
2023-12-01 10:05:54 +10:00
parent e00826c398
commit 78f2310199
12 changed files with 6111 additions and 5 deletions

View File

@@ -0,0 +1,44 @@
namespace PARR.Constants
{
/// <summary>
/// Роли ПАРР
/// </summary>
public static class ParrRoles
{
// Подробнее о авторизации в документации в разделе Авторизация
private const string Base = Administrator.Role + ",";
/// <summary>
/// Роль: Администратор
/// </summary>
public static class Administrator
{
public const string Role = "administrator";
public const string Description = "Администратор";
}
/// <summary>
/// Роль: agent Агент
/// </summary>
public static class Agent
{
public const string Role = "agent";
public const string RoleOrAdmin = Base + Role;
public const string Description = "Агент";
}
/// <summary>
/// Роль: espp-robot Робот ЕСПП
/// </summary>
public static class EsppRobot
{
public const string Role = "espp-robot";
public const string RoleOrAdmin = Base + Role;
public const string Description = "Робот ЕСПП";
}
}
}

View File

@@ -47,15 +47,21 @@ namespace PARR.DAL.Context
public DbSet<AgentHistory> AgentHistories { get; set; }
public DbSet<AgentHistoryLevel> AgentHistoryLevels { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Models.Order> Orders { get; set; }
public DbSet<OrderStatus> OrderStatuses { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Models.Role> Roles { get; set; }
public DbSet<UsersInRole> UsersInRoles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var dateCreated = new DateTimeOffset(2023, 05, 01, 0, 0, 0, new TimeSpan(0));
#region ApplicationType
modelBuilder.Entity<ApplicationType>(f =>
{
f.HasData(
@@ -64,7 +70,9 @@ namespace PARR.DAL.Context
new() { Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.DB.ToString(), Description = "Поле СУБД xml АИХ ИТ" }
);
});
#endregion
#region AIHIT_Setting
modelBuilder.Entity<Models.AIHIT.Setting>(f =>
{
f.HasData(
@@ -89,8 +97,9 @@ namespace PARR.DAL.Context
new() { Id = new Guid("77C73C0A-8E4D-4676-B6E2-6A112F20E346"), DateCreated = dateCreated, DateModified = null, Group = AIHTITSettings.StatusGroupName, Name = "Exploitation", Value = "3-В эксплуатации", Description = "Статус актуальных ЭК" }
);
});
#endregion
#region TaskStatus
modelBuilder.Entity<Models.TaskStatus>(f =>
{
f.HasData(
@@ -100,7 +109,9 @@ namespace PARR.DAL.Context
new() { Code = (int)TaskStatusEnum.Ok, Name = TaskStatusEnum.Ok.ToString(), Description = "Нормальное состояние объекта в ЕСПП и ПАРР. ОБъект в ПАРР соответствует объекту в ЕСПП" }
);
});
#endregion
#region Settings
modelBuilder.Entity<Models.Setting>(f =>
{
// При добавлении записей, добавлять тоже в PARR.DAL.Contracts.SettingsFromDb
@@ -117,7 +128,9 @@ namespace PARR.DAL.Context
new { Name = nameof(SettingsFromDb.OrderSearchDeltaDate), Description = "Промежуток времени для поиска нарядов в ЕСПП", Value = new TimeSpan(1, 30, 0).ToString() }
);
});
#endregion
#region EK
modelBuilder.Entity<EkStatus>(f =>
{
f.HasData(
@@ -131,7 +144,9 @@ namespace PARR.DAL.Context
new { Code = (int)EkStatusEnum.Development, Name = "9-В разработке" }
);
});
#endregion
#region ResponseArea
modelBuilder.Entity<ResponseArea>(f =>
{
f.HasData(
@@ -154,6 +169,7 @@ namespace PARR.DAL.Context
new { Code = (int)ResponseAreaEnum.gvc, Name = "00-ГВЦ" }
);
});
#endregion
#region Robots
@@ -326,6 +342,7 @@ namespace PARR.DAL.Context
#endregion
#region AgentHistoryLevel
modelBuilder.Entity<AgentHistoryLevel>(f =>
{
f.HasData(
@@ -333,7 +350,9 @@ namespace PARR.DAL.Context
new { Id = (int)AgentHistoryLevelEnum.End, Name = AgentHistoryLevelEnum.End.ToString(), Description = "Агент завершил выполнение задания" }
);
});
#endregion
#region OrderStatus
modelBuilder.Entity<OrderStatus>(f =>
{
f.HasData(
@@ -344,6 +363,17 @@ namespace PARR.DAL.Context
new { Code = (int)OrderStatusEnum.Closed, Name = OrderStatusEnum.Closed.ToString(), Description = "5-Закрыт" }
);
});
#endregion
#region Roles
modelBuilder.Entity<Models.Role>(f =>
{
f.HasData(
new() { Id = new Guid("C8F2F144-E6C2-45D7-BA66-5E9BBD376376"), DateCreated = dateCreated, Name = ParrRoles.Administrator.Role, Description = ParrRoles.Administrator.Description },
new() { Id = new Guid("13BCA225-7FA4-42FA-9D80-D2D46DE261FE"), DateCreated = dateCreated, Name = ParrRoles.EsppRobot.Role, Description = ParrRoles.EsppRobot.Description }
);
});
#endregion
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class TblUsersRoles : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Ip = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UsersInRoles",
columns: table => new
{
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UsersInRoles", x => new { x.RoleId, x.UserId });
table.ForeignKey(
name: "FK_UsersInRoles_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UsersInRoles_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Users_Ip",
table: "Users",
column: "Ip",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UsersInRoles_UserId",
table: "UsersInRoles",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UsersInRoles");
migrationBuilder.DropTable(
name: "Roles");
migrationBuilder.DropTable(
name: "Users");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class TblRolesInitData : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Roles",
columns: new[] { "Id", "DateCreated", "Description", "Name" },
values: new object[,]
{
{ new Guid("13bca225-7fa4-42fa-9d80-d2d46de261fe"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "Робот ЕСПП", "espp-robot" },
{ new Guid("c8f2f144-e6c2-45d7-ba66-5e9bbd376376"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "Администратор", "administrator" }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: new Guid("13bca225-7fa4-42fa-9d80-d2d46de261fe"));
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: new Guid("c8f2f144-e6c2-45d7-ba66-5e9bbd376376"));
}
}
}

View File

@@ -2079,6 +2079,44 @@ namespace PARR.DAL.Migrations
});
});
modelBuilder.Entity("PARR.DAL.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
b.HasData(
new
{
Id = new Guid("c8f2f144-e6c2-45d7-ba66-5e9bbd376376"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Администратор",
Name = "administrator"
},
new
{
Id = new Guid("13bca225-7fa4-42fa-9d80-d2d46de261fe"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Робот ЕСПП",
Name = "espp-robot"
});
});
modelBuilder.Entity("PARR.DAL.Models.Setting", b =>
{
b.Property<string>("Name")
@@ -2301,6 +2339,49 @@ namespace PARR.DAL.Migrations
b.ToTable("Tnks");
});
modelBuilder.Entity("PARR.DAL.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Ip")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Ip")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("PARR.DAL.Models.UsersInRole", b =>
{
b.Property<Guid>("RoleId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("RoleId", "UserId");
b.HasIndex("UserId");
b.ToTable("UsersInRoles");
});
modelBuilder.Entity("PARR.DAL.Models.Work", b =>
{
b.Property<Guid>("Id")
@@ -2606,6 +2687,25 @@ namespace PARR.DAL.Migrations
b.Navigation("Subprocess");
});
modelBuilder.Entity("PARR.DAL.Models.UsersInRole", b =>
{
b.HasOne("PARR.DAL.Models.Role", "Role")
.WithMany("Users")
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.User", "User")
.WithMany("Roles")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
});
modelBuilder.Entity("PARR.DAL.Models.Work", b =>
{
b.HasOne("PARR.DAL.Models.Tnk", "Tnk")
@@ -2717,6 +2817,11 @@ namespace PARR.DAL.Migrations
b.Navigation("RobotConfigurations");
});
modelBuilder.Entity("PARR.DAL.Models.Role", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("PARR.DAL.Models.Subprocess", b =>
{
b.Navigation("Tnks");
@@ -2743,6 +2848,11 @@ namespace PARR.DAL.Migrations
b.Navigation("Works");
});
modelBuilder.Entity("PARR.DAL.Models.User", b =>
{
b.Navigation("Roles");
});
modelBuilder.Entity("PARR.DAL.Models.Work", b =>
{
b.Navigation("ApplicationsInWorks");

25
PARR.DAL/Models/Role.cs Normal file
View File

@@ -0,0 +1,25 @@
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("Roles")]
public class Role : IBase
{
[Key]
public Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; }
[NotMapped]
public DateTimeOffset? DateModified { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public ICollection<UsersInRole> Users { get; set; } = new HashSet<UsersInRole>();
}
}

29
PARR.DAL/Models/User.cs Normal file
View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("Users")]
[Index(nameof(Ip), IsUnique = true)]
public class User : IBase
{
[Key]
public Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; }
[NotMapped]
public DateTimeOffset? DateModified { get; set; }
public required string Ip { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public ICollection<UsersInRole> Roles { get; set; } = new HashSet<UsersInRole>();
}
}

View File

@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("UsersInRoles")]
[PrimaryKey(nameof(RoleId), nameof(UserId))]
public class UsersInRole
{
public Guid RoleId { get; set; }
public Guid UserId { get; set; }
[ForeignKey(nameof(RoleId))]
public Role? Role { get; set; }
[ForeignKey(nameof(UserId))]
public User? User { get; set; }
}
}

View File

@@ -11,7 +11,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />

View File

@@ -9,7 +9,7 @@ services:
#restart: always
environment:
- ASPNETCORE_ENVIRONMENT=Production
- TZ=Europe/Moscow
- TZ=Europe/Moscow
ports:
- 8082:80
#volumes:
@@ -35,7 +35,7 @@ services:
- parr_redis_data:/data
#- parr_redis_config/redis.conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_ARGS="--requirepass ParrP@ssPtk202MMdevDvs"
- REDIS_ARGS=--requirepass ParrP@ssPtk202MMdevDvs
deploy:
replicas: 1
networks: