diff --git a/extra/admin-api/Spacebar.AdminAPI/Controllers/Media/UserMediaController.cs b/extra/admin-api/Spacebar.AdminAPI/Controllers/Media/UserMediaController.cs
new file mode 100644
index 000000000..a06d110bb
--- /dev/null
+++ b/extra/admin-api/Spacebar.AdminAPI/Controllers/Media/UserMediaController.cs
@@ -0,0 +1,27 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Spacebar.AdminApi.Models;
+using Spacebar.Db.Contexts;
+using Spacebar.Db.Models;
+using Spacebar.RabbitMqUtilities;
+
+namespace Spacebar.AdminAPI.Controllers.Media;
+
+[ApiController]
+[Route("/media/user")]
+public class UserMediaController(ILogger<UserMediaController> logger, SpacebarDbContext db, RabbitMQService mq, IServiceProvider sp) : ControllerBase {
+
+ [HttpGet("{userId}/attachments")]
+ public async IAsyncEnumerable<Attachment> GetAttachmentsByUser(string userId) {
+ var db2 = sp.CreateScope().ServiceProvider.GetService<SpacebarDbContext>();
+ var attachments = db.Attachments
+ // .IgnoreAutoIncludes()
+ .Where(x => x.Message!.AuthorId == userId)
+ .AsAsyncEnumerable();
+ await foreach (var attachment in attachments) {
+ attachment.Message = await db2.Messages.FindAsync(attachment.MessageId);
+ // attachment.Message.Author = await db2.Users.FindAsync(attachment.Message.AuthorId);
+ yield return attachment;
+ }
+ }
+}
\ No newline at end of file
diff --git a/extra/admin-api/Spacebar.AdminAPI/Controllers/UserController.cs b/extra/admin-api/Spacebar.AdminAPI/Controllers/UserController.cs
index 3b753ebde..620382e1f 100644
--- a/extra/admin-api/Spacebar.AdminAPI/Controllers/UserController.cs
+++ b/extra/admin-api/Spacebar.AdminAPI/Controllers/UserController.cs
@@ -146,6 +146,13 @@ public class UserController(ILogger<UserController> logger, SpacebarDbContext db
yield break;
}
+ user.Data = "{}";
+ user.Deleted = true;
+ user.Disabled = true;
+ user.Rights = 0;
+ db.Users.Update(user);
+ await db.SaveChangesAsync();
+
var factory = new ConnectionFactory {
Uri = new Uri("amqp://guest:guest@127.0.0.1/")
};
diff --git a/extra/admin-api/Spacebar.AdminAPI/Middleware/AuthenticationMiddleware.cs b/extra/admin-api/Spacebar.AdminAPI/Middleware/AuthenticationMiddleware.cs
index c87d568fe..2dc4c9774 100644
--- a/extra/admin-api/Spacebar.AdminAPI/Middleware/AuthenticationMiddleware.cs
+++ b/extra/admin-api/Spacebar.AdminAPI/Middleware/AuthenticationMiddleware.cs
@@ -2,6 +2,7 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography;
using ArcaneLibs.Extensions;
using Microsoft.IdentityModel.Tokens;
+using Spacebar.AdminAPI.Services;
using Spacebar.Db.Contexts;
using Spacebar.Db.Models;
@@ -54,7 +55,8 @@ public class AuthenticationMiddleware(RequestDelegate next) {
if (!_userCache.ContainsKey(token)) {
var db = sp.GetRequiredService<SpacebarDbContext>();
- user = await db.Users.FindAsync(res.ClaimsIdentity.Claims.First(x => x.Type == "id").Value)
+ var config = sp.GetRequiredService<Configuration>();
+ user = await db.Users.FindAsync(config.OverrideUid ?? res.ClaimsIdentity.Claims.First(x => x.Type == "id").Value)
?? throw new InvalidOperationException();
_userCache[token] = user;
_userCacheExpiry[token] = DateTime.Now.AddMinutes(5);
diff --git a/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs b/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs
index 2ec7fab15..53d2cf217 100644
--- a/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs
+++ b/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs
@@ -7,7 +7,7 @@ using Spacebar.Db.Models;
namespace Spacebar.AdminAPI.Services;
-public class AuthenticationService(SpacebarDbContext db) {
+public class AuthenticationService(SpacebarDbContext db, Configuration config) {
private static Dictionary<string, User> _userCache = new();
private static Dictionary<string, DateTime> _userCacheExpiry = new();
@@ -37,6 +37,6 @@ public class AuthenticationService(SpacebarDbContext db) {
throw new UnauthorizedAccessException();
}
- return await db.Users.FindAsync(res.ClaimsIdentity.Claims.First(x => x.Type == "id").Value) ?? throw new InvalidOperationException();
+ return await db.Users.FindAsync(config.OverrideUid ?? res.ClaimsIdentity.Claims.First(x => x.Type == "id").Value) ?? throw new InvalidOperationException();
}
}
\ No newline at end of file
diff --git a/extra/admin-api/Spacebar.AdminAPI/Services/Configuration.cs b/extra/admin-api/Spacebar.AdminAPI/Services/Configuration.cs
index a580e6c64..a988a316e 100644
--- a/extra/admin-api/Spacebar.AdminAPI/Services/Configuration.cs
+++ b/extra/admin-api/Spacebar.AdminAPI/Services/Configuration.cs
@@ -4,4 +4,6 @@ public class Configuration {
public Configuration(IConfiguration configuration) {
configuration.GetRequiredSection("SpacebarAdminApi").Bind(this);
}
+
+ public string? OverrideUid { get; set; }
}
\ No newline at end of file
|