diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 7f9a0ab1..f56a700a 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -235,7 +235,7 @@ namespace AsbCloudDb.Model entity.HasOne(d => d.User) .WithMany(p => p.FileMarks) .HasForeignKey(d => d.IdUser) - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.Cascade) .HasConstraintName("t_user_t_file_mark_fk"); entity.HasOne(d => d.FileInfo) diff --git a/AsbCloudWebApi/Controllers/AuthController.cs b/AsbCloudWebApi/Controllers/AuthController.cs index 7b9e828e..549fed3c 100644 --- a/AsbCloudWebApi/Controllers/AuthController.cs +++ b/AsbCloudWebApi/Controllers/AuthController.cs @@ -13,10 +13,12 @@ namespace AsbCloudWebApi.Controllers public class AuthController : ControllerBase { private readonly IAuthService authService; + private readonly IUserService userService; - public AuthController(IAuthService authService) + public AuthController(IAuthService authService, IUserService userService) { this.authService = authService; + this.userService = userService; } /// @@ -81,14 +83,15 @@ namespace AsbCloudWebApi.Controllers /// Ок [Authorize] [HttpPut("{idUser}/ChangePassword")] - [Permission] public IActionResult ChangePassword([FromRoute]int idUser, [FromBody]string newPassword) { - const string roleName = "Администратор"; - var allow = (User.GetUserId() == idUser) || User.IsInRole(roleName); + var editorUserId = User.GetUserId(); - if (!allow) - return Forbid($"You must be an {roleName} or user with id:{idUser}."); + if (editorUserId is null) + return Forbid(); + + if (!((editorUserId == idUser) || userService.HasPermission((int)editorUserId, "Auth.edit"))) + return Forbid(); var code = authService.ChangePassword(idUser, newPassword); return code switch diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index 7a11b397..f4ce6b09 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -31,13 +31,14 @@ namespace AsbCloudWebApi.Controllers /// id скважины /// id категории файла /// Коллекция файлов + /// dependency /// Токен отмены задачи /// [HttpPost] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task SaveFilesAsync(int idWell, int idCategory, - [FromForm] IFormFileCollection files, CancellationToken token = default) + [FromForm] IFormFileCollection files, [FromServices] IUserService userService, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); int? idUser = User.GetUserId(); @@ -49,6 +50,9 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); + if(!userService.HasPermission((int)idUser, $"File.edit{idCategory}")) + return Forbid(); + var fileInfoCollection = files.Select(f => new FileInfoDto { Name = f.FileName, @@ -149,20 +153,29 @@ namespace AsbCloudWebApi.Controllers /// /// id скважины /// id запрашиваемого файла + /// dependency /// Токен отмены задачи /// [HttpDelete("{idFile}")] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task DeleteAsync(int idWell, int idFile, + [FromServices] IUserService userService, CancellationToken token = default) { + int? idUser = User.GetUserId(); + int? idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) return Forbid(); + var file = await fileService.GetInfoAsync((int)idFile,token); + + if (!userService.HasPermission((int)idUser, $"File.edit{file.IdCategory}")) + return Forbid(); + var result = await fileService.MarkAsDeletedAsync(idFile, token); return Ok(result); diff --git a/AsbCloudWebApi/Docs/Create permissions.ods b/AsbCloudWebApi/Docs/Create permissions.ods index ec824b8e..9bf04a91 100644 Binary files a/AsbCloudWebApi/Docs/Create permissions.ods and b/AsbCloudWebApi/Docs/Create permissions.ods differ diff --git a/AsbCloudWebApi/wwwroot/asset-manifest.json b/AsbCloudWebApi/wwwroot/asset-manifest.json index 3adca2c8..ab5044e8 100644 --- a/AsbCloudWebApi/wwwroot/asset-manifest.json +++ b/AsbCloudWebApi/wwwroot/asset-manifest.json @@ -1,40 +1,46 @@ { "files": { - "main.css": "/static/css/main.dd1fcee2.chunk.css", - "main.js": "/static/js/main.b2e71633.chunk.js", - "main.js.map": "/static/js/main.b2e71633.chunk.js.map", - "runtime-main.js": "/static/js/runtime-main.33aef657.js", - "runtime-main.js.map": "/static/js/runtime-main.33aef657.js.map", - "static/js/2.968888d9.chunk.js": "/static/js/2.968888d9.chunk.js", - "static/js/2.968888d9.chunk.js.map": "/static/js/2.968888d9.chunk.js.map", - "static/js/3.d96a3708.chunk.js": "/static/js/3.d96a3708.chunk.js", - "static/js/3.d96a3708.chunk.js.map": "/static/js/3.d96a3708.chunk.js.map", - "static/js/4.a0d32a2c.chunk.js": "/static/js/4.a0d32a2c.chunk.js", - "static/js/4.a0d32a2c.chunk.js.map": "/static/js/4.a0d32a2c.chunk.js.map", - "static/js/5.8306e86d.chunk.js": "/static/js/5.8306e86d.chunk.js", - "static/js/5.8306e86d.chunk.js.map": "/static/js/5.8306e86d.chunk.js.map", - "static/js/6.642e7ca1.chunk.js": "/static/js/6.642e7ca1.chunk.js", - "static/js/6.642e7ca1.chunk.js.map": "/static/js/6.642e7ca1.chunk.js.map", - "static/js/7.d412fe5e.chunk.js": "/static/js/7.d412fe5e.chunk.js", - "static/js/7.d412fe5e.chunk.js.map": "/static/js/7.d412fe5e.chunk.js.map", - "static/js/8.0292b3ca.chunk.js": "/static/js/8.0292b3ca.chunk.js", - "static/js/8.0292b3ca.chunk.js.map": "/static/js/8.0292b3ca.chunk.js.map", - "static/js/9.35059bd2.chunk.js": "/static/js/9.35059bd2.chunk.js", - "static/js/9.35059bd2.chunk.js.map": "/static/js/9.35059bd2.chunk.js.map", - "static/js/10.de99360f.chunk.js": "/static/js/10.de99360f.chunk.js", - "static/js/10.de99360f.chunk.js.map": "/static/js/10.de99360f.chunk.js.map", - "static/js/11.8f392911.chunk.js": "/static/js/11.8f392911.chunk.js", - "static/js/11.8f392911.chunk.js.map": "/static/js/11.8f392911.chunk.js.map", + "main.css": "/static/css/main.6f0755b9.chunk.css", + "main.js": "/static/js/main.7c7cb383.chunk.js", + "main.js.map": "/static/js/main.7c7cb383.chunk.js.map", + "runtime-main.js": "/static/js/runtime-main.b3b46d3d.js", + "runtime-main.js.map": "/static/js/runtime-main.b3b46d3d.js.map", + "static/js/2.bf9b3ba2.chunk.js": "/static/js/2.bf9b3ba2.chunk.js", + "static/js/2.bf9b3ba2.chunk.js.map": "/static/js/2.bf9b3ba2.chunk.js.map", + "static/css/3.03947450.chunk.css": "/static/css/3.03947450.chunk.css", + "static/js/3.d34c16b8.chunk.js": "/static/js/3.d34c16b8.chunk.js", + "static/js/3.d34c16b8.chunk.js.map": "/static/js/3.d34c16b8.chunk.js.map", + "static/js/4.2ad36218.chunk.js": "/static/js/4.2ad36218.chunk.js", + "static/js/4.2ad36218.chunk.js.map": "/static/js/4.2ad36218.chunk.js.map", + "static/js/5.acfe9843.chunk.js": "/static/js/5.acfe9843.chunk.js", + "static/js/5.acfe9843.chunk.js.map": "/static/js/5.acfe9843.chunk.js.map", + "static/js/6.dc92bc85.chunk.js": "/static/js/6.dc92bc85.chunk.js", + "static/js/6.dc92bc85.chunk.js.map": "/static/js/6.dc92bc85.chunk.js.map", + "static/js/7.04ca453e.chunk.js": "/static/js/7.04ca453e.chunk.js", + "static/js/7.04ca453e.chunk.js.map": "/static/js/7.04ca453e.chunk.js.map", + "static/js/8.22b44d11.chunk.js": "/static/js/8.22b44d11.chunk.js", + "static/js/8.22b44d11.chunk.js.map": "/static/js/8.22b44d11.chunk.js.map", + "static/js/9.ce938494.chunk.js": "/static/js/9.ce938494.chunk.js", + "static/js/9.ce938494.chunk.js.map": "/static/js/9.ce938494.chunk.js.map", + "static/js/10.85013738.chunk.js": "/static/js/10.85013738.chunk.js", + "static/js/10.85013738.chunk.js.map": "/static/js/10.85013738.chunk.js.map", + "static/js/11.f78b37df.chunk.js": "/static/js/11.f78b37df.chunk.js", + "static/js/11.f78b37df.chunk.js.map": "/static/js/11.f78b37df.chunk.js.map", + "static/js/12.cb29526d.chunk.js": "/static/js/12.cb29526d.chunk.js", + "static/js/12.cb29526d.chunk.js.map": "/static/js/12.cb29526d.chunk.js.map", + "static/js/13.438f2178.chunk.js": "/static/js/13.438f2178.chunk.js", + "static/js/13.438f2178.chunk.js.map": "/static/js/13.438f2178.chunk.js.map", "index.html": "/index.html", - "static/css/main.dd1fcee2.chunk.css.map": "/static/css/main.dd1fcee2.chunk.css.map", - "static/js/2.968888d9.chunk.js.LICENSE.txt": "/static/js/2.968888d9.chunk.js.LICENSE.txt", + "static/css/3.03947450.chunk.css.map": "/static/css/3.03947450.chunk.css.map", + "static/css/main.6f0755b9.chunk.css.map": "/static/css/main.6f0755b9.chunk.css.map", + "static/js/2.bf9b3ba2.chunk.js.LICENSE.txt": "/static/js/2.bf9b3ba2.chunk.js.LICENSE.txt", "static/media/ClusterIcon.a395f860.svg": "/static/media/ClusterIcon.a395f860.svg", "static/media/DepositIcon.6de7c7ae.svg": "/static/media/DepositIcon.6de7c7ae.svg" }, "entrypoints": [ - "static/js/runtime-main.33aef657.js", - "static/js/2.968888d9.chunk.js", - "static/css/main.dd1fcee2.chunk.css", - "static/js/main.b2e71633.chunk.js" + "static/js/runtime-main.b3b46d3d.js", + "static/js/2.bf9b3ba2.chunk.js", + "static/css/main.6f0755b9.chunk.css", + "static/js/main.7c7cb383.chunk.js" ] } \ No newline at end of file diff --git a/AsbCloudWebApi/wwwroot/index.html b/AsbCloudWebApi/wwwroot/index.html index 25fbd8ab..1161009d 100644 --- a/AsbCloudWebApi/wwwroot/index.html +++ b/AsbCloudWebApi/wwwroot/index.html @@ -1 +1 @@ -АСБ Vision
ц \ No newline at end of file +АСБ Vision
\ No newline at end of file