UserSettingsController Add DeleteAsync(int idUser, CancellationToken token) method

This commit is contained in:
ngfrolov 2023-07-28 11:30:17 +05:00
parent d5953917b0
commit f78a5e6e97
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
7 changed files with 8475 additions and 2 deletions

View File

@ -45,5 +45,13 @@ namespace AsbCloudApp.Services
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(int userId, string key, CancellationToken token);
/// <summary>
/// Удалить ВСЕ настройки пользователя
/// </summary>
/// <param name="userId"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(int userId, CancellationToken token);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Add_Permission_UserSettings_delete : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "t_permission",
columns: new[] { "id", "description", "name" },
values: new object[] { 522, "Разрешить удаление всех настроек пользователя", "UserSettings.delete" });
migrationBuilder.InsertData(
table: "t_relation_user_role_permission",
columns: new[] { "id_permission", "id_user_role" },
values: new object[] { 522, 1 });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" },
keyValues: new object[] { 522, 1 });
migrationBuilder.DeleteData(
table: "t_permission",
keyColumn: "id",
keyValue: 522);
}
}
}

View File

@ -19,7 +19,7 @@ namespace AsbCloudDb.Migrations
#pragma warning disable 612, 618
modelBuilder
.UseCollation("Russian_Russia.1251")
.HasAnnotation("ProductVersion", "6.0.19")
.HasAnnotation("ProductVersion", "6.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
@ -2157,6 +2157,12 @@ namespace AsbCloudDb.Migrations
Id = 521,
Description = "Разрешить создание справок по страницам",
Name = "HelpPage.edit"
},
new
{
Id = 522,
Description = "Разрешить удаление всех настроек пользователя",
Name = "UserSettings.delete"
});
});
@ -3739,6 +3745,11 @@ namespace AsbCloudDb.Migrations
{
IdUserRole = 1,
IdPermission = 521
},
new
{
IdUserRole = 1,
IdPermission = 522
});
});

View File

@ -153,7 +153,9 @@
new (){ Id = 519, Name="WellContact.get", Description="Разрешение просматривать список контактов"},
new (){ Id = 520, Name="WellContact.edit", Description="Разрешение редактировать список контактов"},
new() { Id = 521, Name = "HelpPage.edit", Description = "Разрешить создание справок по страницам" }
new() { Id = 521, Name = "HelpPage.edit", Description = "Разрешить создание справок по страницам"},
new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"},
};
}
}

View File

@ -46,6 +46,7 @@ namespace AsbCloudInfrastructure.Repository
return await context.SaveChangesAsync(token);
}
public async Task<int> DeleteAsync(int userId, string key, CancellationToken token)
{
var set = context.Set<UserSetting>();
@ -58,5 +59,15 @@ namespace AsbCloudInfrastructure.Repository
set.Remove(removingItem);
return await context.SaveChangesAsync(token);
}
public async Task<int> DeleteAsync(int userId, CancellationToken token)
{
var set = context.Set<UserSetting>();
var removingItems = set
.Where(s => s.IdUser == userId);
set.RemoveRange(removingItems);
return await context.SaveChangesAsync(token);
}
}
}

View File

@ -85,5 +85,20 @@ namespace AsbCloudWebApi.Controllers
return BadRequest(ArgumentInvalidException.MakeValidationError(nameof(key), "not found"));
return Ok(result);
}
/// <summary>
/// Удалить ВСЕ настройки пользователя. Для админки.
/// </summary>
/// <param name="idUser"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete("/api/admin/user/{idUser}/settings")]
[Permission]
public virtual async Task<ActionResult<int>> DeleteAsync(int idUser, CancellationToken token)
{
var result = await service.DeleteAsync(idUser, token).ConfigureAwait(false);
return Ok(result);
}
}
}