Запрет на редактирование завершенных скважин для инженеров

1. Добавил новые права для координаторов и тех.поддержки
2. Переименовал ProcessMapReportService.cs -> ProcessMapService.cs
3. Добавил ProcessMapService.cs метод удаления записи РТК
4. Добавил проверки на наличие прав в контроллерах
5. Накатил новые миграции
This commit is contained in:
parent 23fd77eb9d
commit b58cd2d636
11 changed files with 8657 additions and 16 deletions

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace AsbCloudApp.Services namespace AsbCloudApp.Services
{ {
/// <summary> /// <summary>
/// Сервис формирования РТК /// Сервис РТК
/// </summary> /// </summary>
public interface IProcessMapReportService public interface IProcessMapService
{ {
/// <summary> /// <summary>
/// Получение моделей РТК /// Получение моделей РТК
@ -17,5 +17,14 @@ namespace AsbCloudApp.Services
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<ProcessMapReportDto>> GetProcessMapReportAsync(int idWell, CancellationToken token); Task<IEnumerable<ProcessMapReportDto>> GetProcessMapReportAsync(int idWell, CancellationToken token);
/// <summary>
/// Удаление записи РТК
/// </summary>
/// <param name="id"></param>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(int id, int idWell, CancellationToken token);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Add_New_Permissons : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "t_permission",
columns: new[] { "id", "description", "name" },
values: new object[,]
{
{ 525, "Разрешение на редактирование РТК у завершенной скважины", "ProcessMap.editCompletedWell" },
{ 526, "Разрешение на редактирование операций у завершенной скважины", "WellOperation.editCompletedWell" }
});
migrationBuilder.InsertData(
table: "t_relation_user_role_permission",
columns: new[] { "id_permission", "id_user_role" },
values: new object[,]
{
{ 525, 1 },
{ 526, 1 },
{ 525, 2009 },
{ 526, 2009 },
{ 525, 2013 },
{ 526, 2013 }
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" },
keyValues: new object[] { 525, 1 });
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
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",
keyValue: 525);
migrationBuilder.DeleteData(
table: "t_permission",
keyColumn: "id",
keyValue: 526);
}
}
}

View File

@ -2163,6 +2163,18 @@ namespace AsbCloudDb.Migrations
Id = 522, Id = 522,
Description = "Разрешить удаление всех настроек пользователя", Description = "Разрешить удаление всех настроек пользователя",
Name = "UserSettings.delete" Name = "UserSettings.delete"
},
new
{
Id = 525,
Description = "Разрешение на редактирование РТК у завершенной скважины",
Name = "ProcessMap.editCompletedWell"
},
new
{
Id = 526,
Description = "Разрешение на редактирование операций у завершенной скважины",
Name = "WellOperation.editCompletedWell"
}); });
}); });
@ -3052,6 +3064,26 @@ namespace AsbCloudDb.Migrations
IdPermission = 204 IdPermission = 204
}, },
new new
{
IdUserRole = 2009,
IdPermission = 525
},
new
{
IdUserRole = 2009,
IdPermission = 526
},
new
{
IdUserRole = 2013,
IdPermission = 525
},
new
{
IdUserRole = 2013,
IdPermission = 526
},
new
{ {
IdUserRole = 1, IdUserRole = 1,
IdPermission = 100 IdPermission = 100
@ -3750,6 +3782,16 @@ namespace AsbCloudDb.Migrations
{ {
IdUserRole = 1, IdUserRole = 1,
IdPermission = 522 IdPermission = 522
},
new
{
IdUserRole = 1,
IdPermission = 525
},
new
{
IdUserRole = 1,
IdPermission = 526
}); });
}); });

View File

@ -156,6 +156,9 @@
new() { Id = 521, Name = "HelpPage.edit", Description = "Разрешить создание справок по страницам"}, new() { Id = 521, Name = "HelpPage.edit", Description = "Разрешить создание справок по страницам"},
new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"}, new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"},
new (){ Id = 525, Name = "ProcessMap.editCompletedWell", Description = "Разрешение на редактирование РТК у завершенной скважины"},
new (){ Id = 526, Name = "WellOperation.editCompletedWell", Description = "Разрешение на редактирование операций у завершенной скважины"}
}; };
} }
} }

View File

@ -58,6 +58,9 @@ namespace AsbCloudDb.Model.DefaultData
new (){ IdUserRole = 2005, IdPermission = 247}, new (){ IdUserRole = 2005, IdPermission = 205}, new (){ IdUserRole = 2005, IdPermission = 204}, 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 = 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 = 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}, //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(); var allPermissions = (new EntityFillerPermission()).GetData();

View File

@ -144,7 +144,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IFileCategoryService, FileCategoryService>(); services.AddTransient<IFileCategoryService, FileCategoryService>();
services.AddTransient<ILimitingParameterService, LimitingParameterService>(); services.AddTransient<ILimitingParameterService, LimitingParameterService>();
services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>(); services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>();
services.AddTransient<IProcessMapReportService, ProcessMapReportService>(); services.AddTransient<IProcessMapService, ProcessMapService>();
services.AddTransient<WellInfoService>(); services.AddTransient<WellInfoService>();
services.AddTransient<IHelpPageService, HelpPageService>(); services.AddTransient<IHelpPageService, HelpPageService>();

View File

@ -17,9 +17,9 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
const int headerRowsCount = 5; const int headerRowsCount = 5;
private readonly IProcessMapReportService processMapService; private readonly IProcessMapService processMapService;
public ProcessMapReportMakerService(IProcessMapReportService processMapService) public ProcessMapReportMakerService(IProcessMapService processMapService)
{ {
this.processMapService = processMapService; this.processMapService = processMapService;
} }

View File

@ -12,14 +12,14 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMap namespace AsbCloudInfrastructure.Services.ProcessMap
{ {
public partial class ProcessMapReportService : IProcessMapReportService public partial class ProcessMapService : IProcessMapService
{ {
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellOperationRepository wellOperationRepository; private readonly IWellOperationRepository wellOperationRepository;
private readonly IProcessMapPlanRepository processMapPlanRepository; private readonly IProcessMapPlanRepository processMapPlanRepository;
private readonly ITelemetryDataSaubService telemetryDataSaubService; private readonly ITelemetryDataSaubService telemetryDataSaubService;
public ProcessMapReportService( public ProcessMapService(
IWellService wellService, IWellService wellService,
IWellOperationRepository wellOperationRepository, IWellOperationRepository wellOperationRepository,
IProcessMapPlanRepository processMapPlanRepository, IProcessMapPlanRepository processMapPlanRepository,
@ -54,6 +54,16 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
return result; return result;
} }
public async Task<int> DeleteAsync(int id, int idWell, CancellationToken token)
{
var processMap = await processMapPlanRepository.GetOrDefaultAsync(id, token);
if (processMap?.IdWell != idWell)
throw new ArgumentInvalidException("Запись РТК принадлежит другой скважине", nameof(idWell));
return await processMapPlanRepository.DeleteAsync(id, token);
}
private IEnumerable<ProcessMapReportDto> CalcByIntervals(IEnumerable<ProcessMapPlanDto> processMapPlan, TelemetryDataSaubStatDto[] telemetryDataStat) private IEnumerable<ProcessMapReportDto> CalcByIntervals(IEnumerable<ProcessMapPlanDto> processMapPlan, TelemetryDataSaubStatDto[] telemetryDataStat)
{ {
var processMapIntervals = CalcDepthIntervals(processMapPlan); var processMapIntervals = CalcDepthIntervals(processMapPlan);

View File

@ -27,8 +27,9 @@ namespace AsbCloudWebApi.Controllers
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly IHubContext<TelemetryHub> telemetryHubContext; private readonly IHubContext<TelemetryHub> telemetryHubContext;
private readonly IProcessMapReportMakerService processMapReportService; private readonly IProcessMapReportMakerService processMapReportService;
private readonly IProcessMapReportService processMapService; private readonly IProcessMapService processMapService;
private readonly IProcessMapPlanImportService processMapPlanImportService; private readonly IProcessMapPlanImportService processMapPlanImportService;
private readonly IUserRepository userRepository;
private const string SirnalRMethodGetDataName = "UpdateProcessMap"; private const string SirnalRMethodGetDataName = "UpdateProcessMap";
@ -36,10 +37,11 @@ namespace AsbCloudWebApi.Controllers
IWellService wellService, IWellService wellService,
IProcessMapPlanRepository repository, IProcessMapPlanRepository repository,
IProcessMapReportMakerService processMapReportService, IProcessMapReportMakerService processMapReportService,
IProcessMapReportService processMapService, IProcessMapService processMapService,
ITelemetryService telemetryService, ITelemetryService telemetryService,
IHubContext<TelemetryHub> telemetryHubContext, IHubContext<TelemetryHub> telemetryHubContext,
IProcessMapPlanImportService processMapPlanImportService) IProcessMapPlanImportService processMapPlanImportService,
IUserRepository userRepository)
: base(wellService, repository) : base(wellService, repository)
{ {
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
@ -47,6 +49,7 @@ namespace AsbCloudWebApi.Controllers
this.processMapReportService = processMapReportService; this.processMapReportService = processMapReportService;
this.processMapService = processMapService; this.processMapService = processMapService;
this.processMapPlanImportService = processMapPlanImportService; this.processMapPlanImportService = processMapPlanImportService;
this.userRepository = userRepository;
} }
@ -139,6 +142,9 @@ namespace AsbCloudWebApi.Controllers
[HttpPost] [HttpPost]
public override async Task<ActionResult<int>> InsertAsync([FromBody] ProcessMapPlanDto value, CancellationToken token) public override async Task<ActionResult<int>> InsertAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
{ {
if (!await CanUserEditProcessMapAsync(value.IdWell, token))
return Forbid();
value.IdUser = User.GetUserId() ?? -1; value.IdUser = User.GetUserId() ?? -1;
var result = await base.InsertAsync(value, token); var result = await base.InsertAsync(value, token);
await NotifyUsersBySignalR(value.IdWell, token); await NotifyUsersBySignalR(value.IdWell, token);
@ -154,6 +160,9 @@ namespace AsbCloudWebApi.Controllers
[HttpPut] [HttpPut]
public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapPlanDto value, CancellationToken token) public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
{ {
if (!await CanUserEditProcessMapAsync(value.IdWell, token))
return Forbid();
value.IdUser = User.GetUserId() ?? -1; value.IdUser = User.GetUserId() ?? -1;
var result = await base.UpdateAsync(value, token); var result = await base.UpdateAsync(value, token);
await NotifyUsersBySignalR(value.IdWell, token); await NotifyUsersBySignalR(value.IdWell, token);
@ -188,10 +197,13 @@ namespace AsbCloudWebApi.Controllers
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
int? idUser = User.GetUserId(); int? idUser = User.GetUserId();
if (idUser is null) if (idUser is null)
return Forbid(); return Forbid();
if (!await CanUserEditProcessMapAsync(idWell, cancellationToken))
return Forbid();
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx") if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
return BadRequest("Требуется xlsx файл."); return BadRequest("Требуется xlsx файл.");
@ -239,6 +251,28 @@ namespace AsbCloudWebApi.Controllers
return File(stream, "application/octet-stream", fileName); return File(stream, "application/octet-stream", fileName);
} }
[HttpDelete("{id}/{idWell}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<ActionResult<int>> DeleteAsync(int id, int idWell, CancellationToken cancellationToken)
{
if (!await CanUserEditProcessMapAsync(idWell, cancellationToken))
return Forbid();
return await processMapService.DeleteAsync(id, idWell, cancellationToken);
}
private async Task<bool> CanUserEditProcessMapAsync(int idWell, CancellationToken token)
{
var idUser = User.GetUserId();
var well = await wellService.GetOrDefaultAsync(idWell, token);
if (!idUser.HasValue || well is null)
return false;
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "ProcessMap.editCompletedWell");
}
private async Task NotifyUsersBySignalR(int idWell, CancellationToken token) private async Task NotifyUsersBySignalR(int idWell, CancellationToken token)
{ {
var dtos = await service.GetAllAsync(idWell, null, token); var dtos = await service.GetAllAsync(idWell, null, token);

View File

@ -26,12 +26,16 @@ namespace AsbCloudWebApi.Controllers
private readonly IWellOperationRepository operationRepository; private readonly IWellOperationRepository operationRepository;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellOperationImportService wellOperationImportService; private readonly IWellOperationImportService wellOperationImportService;
private readonly IUserRepository userRepository;
public WellOperationController(IWellOperationRepository operationService, IWellService wellService, IWellOperationImportService wellOperationImportService) public WellOperationController(IWellOperationRepository operationService, IWellService wellService,
IWellOperationImportService wellOperationImportService,
IUserRepository userRepository)
{ {
this.operationRepository = operationService; this.operationRepository = operationService;
this.wellService = wellService; this.wellService = wellService;
this.wellOperationImportService = wellOperationImportService; this.wellOperationImportService = wellOperationImportService;
this.userRepository = userRepository;
} }
/// <summary> /// <summary>
@ -199,7 +203,10 @@ namespace AsbCloudWebApi.Controllers
[FromBody] IEnumerable<WellOperationDto> values, [FromBody] IEnumerable<WellOperationDto> values,
CancellationToken token) CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token))
return Forbid();
if (!await CanUserEditWellOperationsAsync(idWell, token))
return Forbid(); return Forbid();
foreach (var value in values) foreach (var value in values)
@ -229,7 +236,10 @@ namespace AsbCloudWebApi.Controllers
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation, public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
[FromBody] WellOperationDto value, CancellationToken token) [FromBody] WellOperationDto value, CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token))
return Forbid();
if (!await CanUserEditWellOperationsAsync(idWell, token))
return Forbid(); return Forbid();
value.IdWell = idWell; value.IdWell = idWell;
@ -254,8 +264,10 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token) public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, if (!await CanUserAccessToWellAsync(idWell, token))
token).ConfigureAwait(false)) return Forbid();
if (!await CanUserEditWellOperationsAsync(idWell, token))
return Forbid(); return Forbid();
var result = await operationRepository.DeleteAsync(new int[] { idOperation }, token) var result = await operationRepository.DeleteAsync(new int[] { idOperation }, token)
@ -286,6 +298,12 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null || idUser is null) if (idCompany is null || idUser is null)
return Forbid(); return Forbid();
if (!await CanUserAccessToWellAsync(idWell, token))
return Forbid();
if (!await CanUserEditWellOperationsAsync(idWell, token))
return Forbid();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false)) idWell, token).ConfigureAwait(false))
return Forbid(); return Forbid();
@ -376,6 +394,18 @@ namespace AsbCloudWebApi.Controllers
return File(stream, "application/octet-stream", fileName); return File(stream, "application/octet-stream", fileName);
} }
private async Task<bool> CanUserEditWellOperationsAsync(int idWell, CancellationToken token)
{
var idUser = User.GetUserId();
var well = await wellService.GetOrDefaultAsync(idWell, token);
if (!idUser.HasValue || well is null)
return false;
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token) private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
{ {
int? idCompany = User.GetCompanyId(); int? idCompany = User.GetCompanyId();