forked from ddrilling/AsbCloudServer
#5998816 WellFinalDocument edit publisher
This commit is contained in:
parent
7918bfc678
commit
44be18f5ed
6648
AsbCloudDb/Migrations/20220913040912_Update_t_permission.Designer.cs
generated
Normal file
6648
AsbCloudDb/Migrations/20220913040912_Update_t_permission.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
AsbCloudDb/Migrations/20220913040912_Update_t_permission.cs
Normal file
25
AsbCloudDb/Migrations/20220913040912_Update_t_permission.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Update_t_permission : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_permission",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[] { 506, "Разрешение редактировать ответственных за загрузку файла Дело скважины", "WellFinalDocument.editPublisher" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 506);
|
||||
}
|
||||
}
|
||||
}
|
@ -1903,6 +1903,12 @@ namespace AsbCloudDb.Migrations
|
||||
Id = 505,
|
||||
Description = "Разрешение просматривать Дело скважины",
|
||||
Name = "WellFinalDocument.get"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 506,
|
||||
Description = "Разрешение редактировать ответственных за загрузку файла Дело скважины",
|
||||
Name = "WellFinalDocument.editPublisher"
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -129,6 +129,7 @@
|
||||
new (){ Id = 503, Name="WellFinalDocument.delete", Description="Разрешение удалять Дело скважины"},
|
||||
new (){ Id = 504, Name="WellFinalDocument.edit", Description="Разрешение редактировать Дело скважины"},
|
||||
new (){ Id = 505, Name="WellFinalDocument.get", Description="Разрешение просматривать Дело скважины"},
|
||||
new (){ Id = 506, Name="WellFinalDocument.editPublisher", Description="Разрешение редактировать ответственных за загрузку файла Дело скважины"},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetWellFinalDocument_return_collection_rows()
|
||||
{
|
||||
var data = await service.GetByWellId(90, CancellationToken.None);
|
||||
Assert.NotEmpty(data);
|
||||
var data = await service.GetByWellId(90, 1,CancellationToken.None);
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -38,8 +38,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(WellCaseDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var idUser = User?.GetUserId();
|
||||
@ -59,8 +58,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<UserDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetAvailableUsersAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var data = await this.wellFinalDocumentsService.GetAvailableUsersAsync(idWell, token);
|
||||
@ -75,10 +73,13 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Permission]
|
||||
[Permission("WellFinalDocument.editPublisher")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var data = await this.wellFinalDocumentsService.UpdateRangeAsync(idWell, dtos, token);
|
||||
return Ok(data);
|
||||
}
|
||||
@ -98,8 +99,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
int idCategory,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var data = await this.wellFinalDocumentsService.GetFilesHistoryByIdCategory(idWell, idCategory, token);
|
||||
@ -119,11 +119,21 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> SaveCategoryFile(int idWell, int idCategory, IFormFile file, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var idUser = User.GetUserId() ?? -1;
|
||||
var fileStream = file.OpenReadStream();
|
||||
var data = await this.wellFinalDocumentsService.SaveCategoryFile(idWell, idCategory, idUser, fileStream, file.FileName, token);
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user