Add whitelisting and admin

This commit is contained in:
2025-11-07 23:46:48 +07:00
parent 21110cd771
commit e0795677e4
17 changed files with 2280 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Managing.Infrastructure.Databases.Migrations
{
/// <inheritdoc />
public partial class AddIsAdminToUsers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsAdmin",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsAdmin",
table: "Users");
}
}
}

View File

@@ -1306,6 +1306,9 @@ namespace Managing.Infrastructure.Databases.Migrations
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)

View File

@@ -13,6 +13,7 @@ public class UserEntity
[MaxLength(255)] public string? AgentName { get; set; }
public string? AvatarUrl { get; set; }
public string? TelegramChannel { get; set; }
public bool IsAdmin { get; set; } = false;
// Navigation properties
public virtual ICollection<AccountEntity> Accounts { get; set; } = new List<AccountEntity>();

View File

@@ -131,6 +131,7 @@ public static class PostgreSqlMappers
AvatarUrl = entity.AvatarUrl,
TelegramChannel = entity.TelegramChannel,
Id = entity.Id, // Assuming Id is the primary key for UserEntity
IsAdmin = entity.IsAdmin,
Accounts = entity.Accounts?.Select(MapAccountWithoutUser).ToList() ?? new List<Account>()
};
}
@@ -163,7 +164,8 @@ public static class PostgreSqlMappers
Name = user.Name,
AgentName = user.AgentName,
AvatarUrl = user.AvatarUrl,
TelegramChannel = user.TelegramChannel
TelegramChannel = user.TelegramChannel,
IsAdmin = user.IsAdmin
};
}

View File

@@ -201,6 +201,7 @@ public class PostgreSqlUserRepository : BaseRepositoryWithLogging, IUserReposito
existingUser.AgentName = user.AgentName;
existingUser.AvatarUrl = user.AvatarUrl;
existingUser.TelegramChannel = user.TelegramChannel;
existingUser.IsAdmin = user.IsAdmin;
_context.Users.Update(existingUser);