From e451c0662cebfcc8e3f32ca0038121cbb04b3265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 13 Sep 2023 11:42:44 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Поправил инициализацию ролей и прав 2. Поправил проверки в контроллере на редактирование РТК и ГГД 3. Пересоздал миграцию --- ...913063219_Add_New_Permissions.Designer.cs} | 26 ++--------------- ... => 20230913063219_Add_New_Permissions.cs} | 28 ++----------------- .../AsbCloudDbContextModelSnapshot.cs | 20 ------------- .../EntityFillerRelationUserRolePermission.cs | 4 --- .../Controllers/ProcessMapController.cs | 7 +++-- .../Controllers/WellOperationController.cs | 5 +++- 6 files changed, 14 insertions(+), 76 deletions(-) rename AsbCloudDb/Migrations/{20230905071606_Add_New_Permissons.Designer.cs => 20230913063219_Add_New_Permissions.Designer.cs} (99%) rename AsbCloudDb/Migrations/{20230905071606_Add_New_Permissons.cs => 20230913063219_Add_New_Permissions.cs} (62%) diff --git a/AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.Designer.cs b/AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.Designer.cs similarity index 99% rename from AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.Designer.cs rename to AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.Designer.cs index a7730041..c94465b6 100644 --- a/AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.Designer.cs +++ b/AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.Designer.cs @@ -13,15 +13,15 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AsbCloudDb.Migrations { [DbContext(typeof(AsbCloudDbContext))] - [Migration("20230905071606_Add_New_Permissons")] - partial class Add_New_Permissons + [Migration("20230913063219_Add_New_Permissions")] + partial class Add_New_Permissions { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .UseCollation("Russian_Russia.1251") - .HasAnnotation("ProductVersion", "6.0.21") + .HasAnnotation("ProductVersion", "6.0.22") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack"); @@ -3066,26 +3066,6 @@ namespace AsbCloudDb.Migrations IdPermission = 204 }, new - { - IdUserRole = 2009, - IdPermission = 525 - }, - new - { - IdUserRole = 2009, - IdPermission = 526 - }, - new - { - IdUserRole = 2013, - IdPermission = 525 - }, - new - { - IdUserRole = 2013, - IdPermission = 526 - }, - new { IdUserRole = 1, IdPermission = 100 diff --git a/AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.cs b/AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.cs similarity index 62% rename from AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.cs rename to AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.cs index 9ba161cd..d6dc3d17 100644 --- a/AsbCloudDb/Migrations/20230905071606_Add_New_Permissons.cs +++ b/AsbCloudDb/Migrations/20230913063219_Add_New_Permissions.cs @@ -4,7 +4,7 @@ namespace AsbCloudDb.Migrations { - public partial class Add_New_Permissons : Migration + public partial class Add_New_Permissions : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -23,11 +23,7 @@ namespace AsbCloudDb.Migrations values: new object[,] { { 525, 1 }, - { 526, 1 }, - { 525, 2009 }, - { 526, 2009 }, - { 525, 2013 }, - { 526, 2013 } + { 526, 1 } }); } @@ -43,26 +39,6 @@ namespace AsbCloudDb.Migrations keyColumns: new[] { "id_permission", "id_user_role" }, keyValues: new object[] { 526, 1 }); - migrationBuilder.DeleteData( - table: "t_relation_user_role_permission", - keyColumns: new[] { "id_permission", "id_user_role" }, - keyValues: new object[] { 525, 2009 }); - - migrationBuilder.DeleteData( - table: "t_relation_user_role_permission", - keyColumns: new[] { "id_permission", "id_user_role" }, - keyValues: new object[] { 526, 2009 }); - - migrationBuilder.DeleteData( - table: "t_relation_user_role_permission", - keyColumns: new[] { "id_permission", "id_user_role" }, - keyValues: new object[] { 525, 2013 }); - - migrationBuilder.DeleteData( - table: "t_relation_user_role_permission", - keyColumns: new[] { "id_permission", "id_user_role" }, - keyValues: new object[] { 526, 2013 }); - migrationBuilder.DeleteData( table: "t_permission", keyColumn: "id", diff --git a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs index bc70e90f..f5269452 100644 --- a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs +++ b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs @@ -3064,26 +3064,6 @@ namespace AsbCloudDb.Migrations IdPermission = 204 }, new - { - IdUserRole = 2009, - IdPermission = 525 - }, - new - { - IdUserRole = 2009, - IdPermission = 526 - }, - new - { - IdUserRole = 2013, - IdPermission = 525 - }, - new - { - IdUserRole = 2013, - IdPermission = 526 - }, - new { IdUserRole = 1, IdPermission = 100 diff --git a/AsbCloudDb/Model/DefaultData/EntityFillerRelationUserRolePermission.cs b/AsbCloudDb/Model/DefaultData/EntityFillerRelationUserRolePermission.cs index 1e4cbbf7..72a560d3 100644 --- a/AsbCloudDb/Model/DefaultData/EntityFillerRelationUserRolePermission.cs +++ b/AsbCloudDb/Model/DefaultData/EntityFillerRelationUserRolePermission.cs @@ -58,10 +58,6 @@ namespace AsbCloudDb.Model.DefaultData new (){ IdUserRole = 2005, IdPermission = 247}, new (){ IdUserRole = 2005, IdPermission = 205}, new (){ IdUserRole = 2005, IdPermission = 204}, new (){ IdUserRole = 2006, IdPermission = 243}, new (){ IdUserRole = 2006, IdPermission = 205}, new (){ IdUserRole = 2006, IdPermission = 204}, new (){ IdUserRole = 2007, IdPermission = 241}, new (){ IdUserRole = 2007, IdPermission = 205}, new (){ IdUserRole = 2007, IdPermission = 204}, - new (){ IdUserRole = 2009, IdPermission = 525}, new (){ IdUserRole = 2009, IdPermission = 526}, - new (){ IdUserRole = 2013, IdPermission = 525}, new (){ IdUserRole = 2013, IdPermission = 526}, - - //new (){ IdUserRole = 1, IdPermission = 500}, new (){ IdUserRole = 1, IdPermission = 501}, new (){ IdUserRole = 1, IdPermission = 502}, new (){ IdUserRole = 1, IdPermission = 503}, new (){ IdUserRole = 1, IdPermission = 504}, new (){ IdUserRole = 1, IdPermission = 505}, new (){ IdUserRole = 1, IdPermission = 506}, new (){ IdUserRole = 1, IdPermission = 510}, new (){ IdUserRole = 1, IdPermission = 511}, new (){ IdUserRole = 1, IdPermission = 512}, new (){ IdUserRole = 1, IdPermission = 513}, new (){ IdUserRole = 1, IdPermission = 514}, new (){ IdUserRole = 1, IdPermission = 515}, }; var allPermissions = (new EntityFillerPermission()).GetData(); foreach ( var permission in allPermissions) diff --git a/AsbCloudWebApi/Controllers/ProcessMapController.cs b/AsbCloudWebApi/Controllers/ProcessMapController.cs index 18110908..1f5fbd6f 100644 --- a/AsbCloudWebApi/Controllers/ProcessMapController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMapController.cs @@ -254,12 +254,15 @@ namespace AsbCloudWebApi.Controllers private async Task CanUserEditProcessMapAsync(int idWell, CancellationToken token) { var idUser = User.GetUserId(); + + if (!idUser.HasValue) + return false; var well = await wellService.GetOrDefaultAsync(idWell, token); - if (!idUser.HasValue || well is null) + if (well is null) return false; - + return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "ProcessMap.editCompletedWell"); } diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index a3f6c13a..d2a619c4 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -397,10 +397,13 @@ namespace AsbCloudWebApi.Controllers private async Task CanUserEditWellOperationsAsync(int idWell, CancellationToken token) { var idUser = User.GetUserId(); + + if (!idUser.HasValue) + return false; var well = await wellService.GetOrDefaultAsync(idWell, token); - if (!idUser.HasValue || well is null) + if (well is null) return false; return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");