Prevent deletion of dev slot placeholder user

This commit is contained in:
jvyden 2022-08-21 01:45:59 -04:00
commit 976d494e04
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 2 additions and 1 deletions

View file

@ -20,7 +20,7 @@ public class DeleteUserCommand : ICommand
public int RequiredArgs() => 1;
public async Task Run(string[] args, Logger logger)
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username.Length > 0 && u.Username == args[0]);
if (user == null)
try
{

View file

@ -476,6 +476,7 @@ public class Database : DbContext
public async Task RemoveUser(User? user)
{
if (user == null) return;
if (user.Username.Length == 0) return; // don't delete the placeholder user
if (user.Location != null) this.Locations.Remove(user.Location);
LastContact? lastContact = await this.LastContacts.FirstOrDefaultAsync(l => l.UserId == user.UserId);