add mare profiles
This commit is contained in:
@@ -6,11 +6,12 @@ namespace MareSynchronosShared.Utils;
|
||||
|
||||
public class MareConfigurationBase : IMareConfiguration
|
||||
{
|
||||
public Uri MainServerAddress { get; set; }
|
||||
public int DbContextPoolSize { get; set; } = 100;
|
||||
public string ShardName { get; set; } = string.Empty;
|
||||
public int MetricsPort { get; set; }
|
||||
public string Jwt { get; set; } = string.Empty;
|
||||
public Uri MainServerAddress { get; set; }
|
||||
public int MetricsPort { get; set; }
|
||||
public string RedisConnectionString { get; set; } = string.Empty;
|
||||
public string ShardName { get; set; } = string.Empty;
|
||||
|
||||
public T GetValue<T>(string key)
|
||||
{
|
||||
@@ -41,6 +42,7 @@ public class MareConfigurationBase : IMareConfiguration
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine(base.ToString());
|
||||
sb.AppendLine($"{nameof(MainServerAddress)} => {MainServerAddress}");
|
||||
sb.AppendLine($"{nameof(RedisConnectionString)} => {RedisConnectionString}");
|
||||
sb.AppendLine($"{nameof(ShardName)} => {ShardName}");
|
||||
sb.AppendLine($"{nameof(DbContextPoolSize)} => {DbContextPoolSize}");
|
||||
return sb.ToString();
|
||||
|
||||
@@ -4,23 +4,29 @@ namespace MareSynchronosShared.Utils;
|
||||
|
||||
public class ServerConfiguration : MareConfigurationAuthBase
|
||||
{
|
||||
public string RedisConnectionString { get; set; } = string.Empty;
|
||||
public int RedisPool { get; set; } = 50;
|
||||
[RemoteConfiguration]
|
||||
public Version ExpectedClientVersion { get; set; } = new Version(0, 0, 0);
|
||||
[RemoteConfiguration]
|
||||
public Uri CdnFullUrl { get; set; } = null;
|
||||
|
||||
[RemoteConfiguration]
|
||||
public Version ExpectedClientVersion { get; set; } = new Version(0, 0, 0);
|
||||
|
||||
[RemoteConfiguration]
|
||||
public int MaxExistingGroupsByUser { get; set; } = 3;
|
||||
[RemoteConfiguration]
|
||||
public int MaxJoinedGroupsByUser { get; set; } = 6;
|
||||
|
||||
[RemoteConfiguration]
|
||||
public int MaxGroupUserCount { get; set; } = 100;
|
||||
|
||||
[RemoteConfiguration]
|
||||
public int MaxJoinedGroupsByUser { get; set; } = 6;
|
||||
|
||||
[RemoteConfiguration]
|
||||
public bool PurgeUnusedAccounts { get; set; } = false;
|
||||
|
||||
[RemoteConfiguration]
|
||||
public int PurgeUnusedAccountsPeriodInDays { get; set; } = 14;
|
||||
|
||||
public int RedisPool { get; set; } = 50;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
@@ -36,4 +42,4 @@ public class ServerConfiguration : MareConfigurationAuthBase
|
||||
sb.AppendLine($"{nameof(PurgeUnusedAccountsPeriodInDays)} => {PurgeUnusedAccountsPeriodInDays}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@ namespace MareSynchronosShared.Utils;
|
||||
public class ServicesConfiguration : MareConfigurationBase
|
||||
{
|
||||
public string DiscordBotToken { get; set; } = string.Empty;
|
||||
public Uri MainServerGrpcAddress { get; set; } = null;
|
||||
public ulong? DiscordChannelForMessages { get; set; } = null;
|
||||
public ulong? DiscordChannelForReports { get; set; } = null;
|
||||
public Uri MainServerGrpcAddress { get; set; } = null;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -14,6 +15,8 @@ public class ServicesConfiguration : MareConfigurationBase
|
||||
sb.AppendLine(base.ToString());
|
||||
sb.AppendLine($"{nameof(DiscordBotToken)} => {DiscordBotToken}");
|
||||
sb.AppendLine($"{nameof(MainServerGrpcAddress)} => {MainServerGrpcAddress}");
|
||||
sb.AppendLine($"{nameof(DiscordChannelForMessages)} => {DiscordChannelForMessages}");
|
||||
sb.AppendLine($"{nameof(DiscordChannelForReports)} => {DiscordChannelForReports}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,54 @@ namespace MareSynchronosShared.Utils;
|
||||
|
||||
public static class SharedDbFunctions
|
||||
{
|
||||
public static async Task<(bool, string)> MigrateOrDeleteGroup(MareDbContext context, Group group, List<GroupPair> groupPairs, int maxGroupsByUser)
|
||||
{
|
||||
bool groupHasMigrated = false;
|
||||
string newOwner = string.Empty;
|
||||
foreach (var potentialNewOwner in groupPairs.OrderByDescending(p => p.IsModerator).ThenByDescending(p => p.IsPinned).ToList())
|
||||
{
|
||||
groupHasMigrated = await TryMigrateGroup(context, group, potentialNewOwner.GroupUserUID, maxGroupsByUser).ConfigureAwait(false);
|
||||
|
||||
if (groupHasMigrated)
|
||||
{
|
||||
newOwner = potentialNewOwner.GroupUserUID;
|
||||
potentialNewOwner.IsPinned = true;
|
||||
potentialNewOwner.IsModerator = false;
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!groupHasMigrated)
|
||||
{
|
||||
context.GroupPairs.RemoveRange(groupPairs);
|
||||
context.Groups.Remove(group);
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (groupHasMigrated, newOwner);
|
||||
}
|
||||
|
||||
public static async Task PurgeUser(ILogger _logger, User user, MareDbContext dbContext, int maxGroupsByUser)
|
||||
{
|
||||
_logger.LogInformation("Purging user: {uid}", user.UID);
|
||||
|
||||
var lodestone = dbContext.LodeStoneAuth.SingleOrDefault(a => a.User.UID == user.UID);
|
||||
|
||||
var userProfileData = await dbContext.UserProfileData.SingleOrDefaultAsync(u => u.UserUID == user.UID).ConfigureAwait(false);
|
||||
|
||||
if (lodestone != null)
|
||||
{
|
||||
dbContext.Remove(lodestone);
|
||||
}
|
||||
|
||||
if (userProfileData != null)
|
||||
{
|
||||
dbContext.Remove(userProfileData);
|
||||
}
|
||||
|
||||
var auth = dbContext.Auth.Single(a => a.UserUID == user.UID);
|
||||
|
||||
var userFiles = dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == user.UID).ToList();
|
||||
@@ -63,36 +100,6 @@ public static class SharedDbFunctions
|
||||
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<(bool, string)> MigrateOrDeleteGroup(MareDbContext context, Group group, List<GroupPair> groupPairs, int maxGroupsByUser)
|
||||
{
|
||||
bool groupHasMigrated = false;
|
||||
string newOwner = string.Empty;
|
||||
foreach (var potentialNewOwner in groupPairs.OrderByDescending(p => p.IsModerator).ThenByDescending(p => p.IsPinned).ToList())
|
||||
{
|
||||
groupHasMigrated = await TryMigrateGroup(context, group, potentialNewOwner.GroupUserUID, maxGroupsByUser).ConfigureAwait(false);
|
||||
|
||||
if (groupHasMigrated)
|
||||
{
|
||||
newOwner = potentialNewOwner.GroupUserUID;
|
||||
potentialNewOwner.IsPinned = true;
|
||||
potentialNewOwner.IsModerator = false;
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!groupHasMigrated)
|
||||
{
|
||||
context.GroupPairs.RemoveRange(groupPairs);
|
||||
context.Groups.Remove(group);
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (groupHasMigrated, newOwner);
|
||||
}
|
||||
|
||||
private static async Task<bool> TryMigrateGroup(MareDbContext context, Group group, string potentialNewOwnerUid, int maxGroupsByUser)
|
||||
{
|
||||
var newOwnerOwnedGroups = await context.Groups.CountAsync(g => g.OwnerUID == potentialNewOwnerUid).ConfigureAwait(false);
|
||||
@@ -105,4 +112,4 @@ public static class SharedDbFunctions
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user