forked from ddrilling/AsbCloudServer
UserSettingsController Add DeleteAsync(int idUser, CancellationToken token) method
This commit is contained in:
parent
d5953917b0
commit
f78a5e6e97
@ -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);
|
||||
}
|
||||
}
|
8391
AsbCloudDb/Migrations/20230728062743_Add_Permission_UserSettings_delete.Designer.cs
generated
Normal file
8391
AsbCloudDb/Migrations/20230728062743_Add_Permission_UserSettings_delete.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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 = "Разрешить удаление всех настроек пользователя"},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user