diff --git a/DysonNetwork.Develop/Program.cs b/DysonNetwork.Develop/Program.cs index c9af0c2..f735267 100644 --- a/DysonNetwork.Develop/Program.cs +++ b/DysonNetwork.Develop/Program.cs @@ -35,6 +35,6 @@ using (var scope = app.Services.CreateScope()) app.ConfigureAppMiddleware(builder.Configuration); -app.UseSwaggerManifest(); +app.UseSwaggerManifest("DysonNetwork.Develop"); app.Run(); \ No newline at end of file diff --git a/DysonNetwork.Drive/Program.cs b/DysonNetwork.Drive/Program.cs index e175ce3..3cc28fa 100644 --- a/DysonNetwork.Drive/Program.cs +++ b/DysonNetwork.Drive/Program.cs @@ -48,6 +48,6 @@ app.ConfigureAppMiddleware(tusDiskStore); // Configure gRPC app.ConfigureGrpcServices(); -app.UseSwaggerManifest(); +app.UseSwaggerManifest("DysonNetwork.Drive"); app.Run(); diff --git a/DysonNetwork.Gateway/Program.cs b/DysonNetwork.Gateway/Program.cs index e888b64..6891e46 100644 --- a/DysonNetwork.Gateway/Program.cs +++ b/DysonNetwork.Gateway/Program.cs @@ -90,7 +90,6 @@ var apiRoutes = serviceNames.Select(serviceName => { var apiPath = serviceName switch { - "pass" => "/id", _ => $"/{serviceName}" }; return new RouteConfig @@ -162,8 +161,6 @@ app.UseForwardedHeaders(forwardedHeadersOptions); app.UseCors(); -app.UseRateLimiter(); - app.MapReverseProxy().RequireRateLimiting("fixed"); app.MapControllers(); diff --git a/DysonNetwork.Pass/Account/AccountServiceGrpc.cs b/DysonNetwork.Pass/Account/AccountServiceGrpc.cs index 107d051..2636d49 100644 --- a/DysonNetwork.Pass/Account/AccountServiceGrpc.cs +++ b/DysonNetwork.Pass/Account/AccountServiceGrpc.cs @@ -12,13 +12,11 @@ public class AccountServiceGrpc( AccountEventService accountEvents, RelationshipService relationships, SubscriptionService subscriptions, - IClock clock, ILogger logger ) : Shared.Proto.AccountService.AccountServiceBase { private readonly AppDatabase _db = db ?? throw new ArgumentNullException(nameof(db)); - private readonly IClock _clock = clock ?? throw new ArgumentNullException(nameof(clock)); private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -266,7 +264,7 @@ public class AccountServiceGrpc( public override async Task HasRelationship(GetRelationshipRequest request, ServerCallContext context) { - var hasRelationship = false; + bool hasRelationship; if (!request.HasStatus) hasRelationship = await relationships.HasExistingRelationship( Guid.Parse(request.AccountId), diff --git a/DysonNetwork.Pass/Auth/OidcProvider/Controllers/OidcProviderController.cs b/DysonNetwork.Pass/Auth/OidcProvider/Controllers/OidcProviderController.cs index 1f8f933..f356dd6 100644 --- a/DysonNetwork.Pass/Auth/OidcProvider/Controllers/OidcProviderController.cs +++ b/DysonNetwork.Pass/Auth/OidcProvider/Controllers/OidcProviderController.cs @@ -343,8 +343,8 @@ public class OidcProviderController( { issuer, authorization_endpoint = $"{siteUrl}/auth/authorize", - token_endpoint = $"{baseUrl}/id/auth/open/token", - userinfo_endpoint = $"{baseUrl}/id/auth/open/userinfo", + token_endpoint = $"{baseUrl}/pass/auth/open/token", + userinfo_endpoint = $"{baseUrl}/pass/auth/open/userinfo", jwks_uri = $"{baseUrl}/.well-known/jwks", scopes_supported = new[] { "openid", "profile", "email" }, response_types_supported = new[] diff --git a/DysonNetwork.Pass/Program.cs b/DysonNetwork.Pass/Program.cs index 7f1ce7d..d59150e 100644 --- a/DysonNetwork.Pass/Program.cs +++ b/DysonNetwork.Pass/Program.cs @@ -51,6 +51,6 @@ app.ConfigureAppMiddleware(builder.Configuration); // Configure gRPC app.ConfigureGrpcServices(); -app.UseSwaggerManifest(); +app.UseSwaggerManifest("DysonNetwork.Pass"); app.Run(); diff --git a/DysonNetwork.Pass/Realm/RealmController.cs b/DysonNetwork.Pass/Realm/RealmController.cs index b1df29a..40c8ae3 100644 --- a/DysonNetwork.Pass/Realm/RealmController.cs +++ b/DysonNetwork.Pass/Realm/RealmController.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using DysonNetwork.Pass.Account; using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Registry; @@ -7,6 +8,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using NodaTime; +using AccountService = DysonNetwork.Pass.Account.AccountService; +using ActionLogService = DysonNetwork.Pass.Account.ActionLogService; namespace DysonNetwork.Pass.Realm; @@ -17,9 +20,9 @@ public class RealmController( RealmService rs, FileService.FileServiceClient files, FileReferenceService.FileReferenceServiceClient fileRefs, - ActionLogService.ActionLogServiceClient als, - AccountService.AccountServiceClient accounts, - RemoteAccountService remoteAccountsHelper + ActionLogService als, + RelationshipService rels, + AccountEventService accountEvents ) : Controller { [HttpGet("{slug}")] @@ -37,8 +40,8 @@ public class RealmController( [Authorize] public async Task>> ListJoinedRealms() { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var members = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -54,8 +57,8 @@ public class RealmController( [Authorize] public async Task>> ListInvites() { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var members = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -77,20 +80,18 @@ public class RealmController( public async Task> InviteMember(string slug, [FromBody] RealmMemberRequest request) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; - var relatedUser = - await accounts.GetAccountAsync(new GetAccountRequest { Id = request.RelatedUserId.ToString() }); + var relatedUser = await db.Accounts.Where(a => a.Id == request.RelatedUserId).FirstOrDefaultAsync(); if (relatedUser == null) return BadRequest("Related user was not found"); - var hasBlocked = await accounts.HasRelationshipAsync(new GetRelationshipRequest() - { - AccountId = currentUser.Id, - RelatedId = request.RelatedUserId.ToString(), - Status = -100 - }); - if (hasBlocked?.Value ?? false) + var hasBlocked = await rels.HasRelationshipWithStatus( + currentUser.Id, + request.RelatedUserId, + RelationshipStatus.Blocked + ); + if (hasBlocked) return StatusCode(403, "You cannot invite a user that blocked you."); var realm = await db.Realms @@ -102,7 +103,7 @@ public class RealmController( return StatusCode(403, "You cannot invite member has higher permission than yours."); var existingMember = await db.RealmMembers - .Where(m => m.AccountId == Guid.Parse(relatedUser.Id)) + .Where(m => m.AccountId == relatedUser.Id) .Where(m => m.RealmId == realm.Id) .FirstOrDefaultAsync(); if (existingMember != null) @@ -116,48 +117,42 @@ public class RealmController( await db.SaveChangesAsync(); await rs.SendInviteNotify(existingMember); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.invite", - Meta = - { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "account_id", Value.ForString(existingMember.AccountId.ToString()) }, - { "role", Value.ForNumber(request.Role) } - }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + als.CreateActionLogFromRequest( + "realms.members.invite", + new Dictionary() + { + { "realm_id", Value.ForString(realm.Id.ToString()) }, + { "account_id", Value.ForString(existingMember.AccountId.ToString()) }, + { "role", Value.ForNumber(request.Role) } + }, + Request + ); return Ok(existingMember); } var member = new SnRealmMember { - AccountId = Guid.Parse(relatedUser.Id), + AccountId = relatedUser.Id, RealmId = realm.Id, Role = request.Role, }; db.RealmMembers.Add(member); await db.SaveChangesAsync(); - - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.invite", - Meta = + + als.CreateActionLogFromRequest( + "realms.members.invite", + new Dictionary() { { "realm_id", Value.ForString(realm.Id.ToString()) }, { "account_id", Value.ForString(member.AccountId.ToString()) }, { "role", Value.ForNumber(request.Role) } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); - member.AccountId = Guid.Parse(relatedUser.Id); + member.AccountId = relatedUser.Id; member.Realm = realm; await rs.SendInviteNotify(member); @@ -168,8 +163,8 @@ public class RealmController( [Authorize] public async Task> AcceptMemberInvite(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var member = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -182,18 +177,15 @@ public class RealmController( db.Update(member); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.join", - Meta = + als.CreateActionLogFromRequest( + "realms.members.join", + new Dictionary() { - { "realm_id", Value.ForString(member.RealmId.ToString()) }, - { "account_id", Value.ForString(member.AccountId.ToString()) } + { "realm_id", member.RealmId.ToString() }, + { "account_id", member.AccountId.ToString() } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return Ok(member); } @@ -202,8 +194,8 @@ public class RealmController( [Authorize] public async Task DeclineMemberInvite(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var member = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -215,19 +207,16 @@ public class RealmController( member.LeaveAt = SystemClock.Instance.GetCurrentInstant(); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.decline_invite", - Meta = + als.CreateActionLogFromRequest( + "realms.members.decline_invite", + new Dictionary() { { "realm_id", Value.ForString(member.RealmId.ToString()) }, { "account_id", Value.ForString(member.AccountId.ToString()) }, - { "decliner_id", Value.ForString(currentUser.Id) } + { "decliner_id", Value.ForString(currentUser.Id.ToString()) } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return NoContent(); } @@ -248,8 +237,8 @@ public class RealmController( if (!realm.IsPublic) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - if (!await rs.IsMemberWithRole(realm.Id, Guid.Parse(currentUser.Id), RealmMemberRole.Normal)) + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + if (!await rs.IsMemberWithRole(realm.Id, currentUser.Id, RealmMemberRole.Normal)) return StatusCode(403, "You must be a member to view this realm's members."); } @@ -263,7 +252,7 @@ public class RealmController( .OrderBy(m => m.JoinedAt) .ToListAsync(); - var memberStatuses = await remoteAccountsHelper.GetAccountStatusBatch( + var memberStatuses = await accountEvents.GetStatuses( members.Select(m => m.AccountId).ToList() ); @@ -306,8 +295,8 @@ public class RealmController( [Authorize] public async Task> GetCurrentIdentity(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var member = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -323,8 +312,8 @@ public class RealmController( [Authorize] public async Task LeaveRealm(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + var accountId = currentUser.Id; var member = await db.RealmMembers .Where(m => m.AccountId == accountId) @@ -339,19 +328,16 @@ public class RealmController( member.LeaveAt = SystemClock.Instance.GetCurrentInstant(); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.leave", - Meta = + als.CreateActionLogFromRequest( + "realms.members.leave", + new Dictionary() { - { "realm_id", Value.ForString(member.RealmId.ToString()) }, - { "account_id", Value.ForString(member.AccountId.ToString()) }, - { "leaver_id", Value.ForString(currentUser.Id) } + { "realm_id", member.RealmId.ToString() }, + { "account_id", member.AccountId.ToString() }, + { "leaver_id", currentUser.Id } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return NoContent(); } @@ -371,7 +357,7 @@ public class RealmController( [Authorize] public async Task> CreateRealm(RealmRequest request) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); if (string.IsNullOrWhiteSpace(request.Name)) return BadRequest("You cannot create a realm without a name."); if (string.IsNullOrWhiteSpace(request.Slug)) return BadRequest("You cannot create a realm without a slug."); @@ -383,7 +369,7 @@ public class RealmController( Name = request.Name!, Slug = request.Slug!, Description = request.Description!, - AccountId = Guid.Parse(currentUser.Id), + AccountId = currentUser.Id, IsCommunity = request.IsCommunity ?? false, IsPublic = request.IsPublic ?? false, Members = new List @@ -391,7 +377,7 @@ public class RealmController( new() { Role = RealmMemberRole.Owner, - AccountId = Guid.Parse(currentUser.Id), + AccountId = currentUser.Id, JoinedAt = NodaTime.Instant.FromDateTimeUtc(DateTime.UtcNow) } } @@ -414,21 +400,18 @@ public class RealmController( db.Realms.Add(realm); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.create", - Meta = + als.CreateActionLogFromRequest( + "realms.create", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "name", Value.ForString(realm.Name) }, - { "slug", Value.ForString(realm.Slug) }, - { "is_community", Value.ForBool(realm.IsCommunity) }, - { "is_public", Value.ForBool(realm.IsPublic) } + { "realm_id", realm.Id.ToString() }, + { "name", realm.Name }, + { "slug", realm.Slug }, + { "is_community", realm.IsCommunity }, + { "is_public", realm.IsPublic } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); var realmResourceId = $"realm:{realm.Id}"; @@ -459,14 +442,14 @@ public class RealmController( [Authorize] public async Task> Update(string slug, [FromBody] RealmRequest request) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); var realm = await db.Realms .Where(r => r.Slug == slug) .FirstOrDefaultAsync(); if (realm is null) return NotFound(); - var accountId = Guid.Parse(currentUser.Id); + var accountId = currentUser.Id; var member = await db.RealmMembers .Where(m => m.AccountId == accountId && m.RealmId == realm.Id && m.JoinedAt != null && m.LeaveAt == null) .FirstOrDefaultAsync(); @@ -542,24 +525,21 @@ public class RealmController( db.Realms.Update(realm); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.update", - Meta = + als.CreateActionLogFromRequest( + "realms.update", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "name_updated", Value.ForBool(request.Name != null) }, - { "slug_updated", Value.ForBool(request.Slug != null) }, - { "description_updated", Value.ForBool(request.Description != null) }, - { "picture_updated", Value.ForBool(request.PictureId != null) }, - { "background_updated", Value.ForBool(request.BackgroundId != null) }, - { "is_community_updated", Value.ForBool(request.IsCommunity != null) }, - { "is_public_updated", Value.ForBool(request.IsPublic != null) } + { "realm_id", realm.Id.ToString() }, + { "name_updated", request.Name != null }, + { "slug_updated", request.Slug != null }, + { "description_updated", request.Description != null }, + { "picture_updated", request.PictureId != null }, + { "background_updated", request.BackgroundId != null }, + { "is_community_updated", request.IsCommunity != null }, + { "is_public_updated", request.IsPublic != null } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return Ok(realm); } @@ -568,7 +548,7 @@ public class RealmController( [Authorize] public async Task> JoinRealm(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); var realm = await db.Realms .Where(r => r.Slug == slug) @@ -579,7 +559,7 @@ public class RealmController( return StatusCode(403, "Only community realms can be joined without invitation."); var existingMember = await db.RealmMembers - .Where(m => m.AccountId == Guid.Parse(currentUser.Id) && m.RealmId == realm.Id) + .Where(m => m.AccountId == currentUser.Id && m.RealmId == realm.Id) .FirstOrDefaultAsync(); if (existingMember is not null) { @@ -592,26 +572,23 @@ public class RealmController( db.Update(existingMember); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.join", - Meta = - { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "account_id", Value.ForString(currentUser.Id) }, - { "is_community", Value.ForBool(realm.IsCommunity) } - }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + als.CreateActionLogFromRequest( + "realms.members.join", + new Dictionary() + { + { "realm_id", existingMember.RealmId.ToString() }, + { "account_id", currentUser.Id }, + { "is_community", realm.IsCommunity } + }, + Request + ); return Ok(existingMember); } var member = new SnRealmMember { - AccountId = Guid.Parse(currentUser.Id), + AccountId = currentUser.Id, RealmId = realm.Id, Role = RealmMemberRole.Normal, JoinedAt = NodaTime.Instant.FromDateTimeUtc(DateTime.UtcNow) @@ -620,19 +597,16 @@ public class RealmController( db.RealmMembers.Add(member); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.join", - Meta = + als.CreateActionLogFromRequest( + "realms.members.join", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "account_id", Value.ForString(currentUser.Id) }, - { "is_community", Value.ForBool(realm.IsCommunity) } + { "realm_id", realm.Id.ToString() }, + { "account_id", currentUser.Id }, + { "is_community", realm.IsCommunity } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return Ok(member); } @@ -641,7 +615,7 @@ public class RealmController( [Authorize] public async Task RemoveMember(string slug, Guid memberId) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); var realm = await db.Realms .Where(r => r.Slug == slug) @@ -653,25 +627,22 @@ public class RealmController( .FirstOrDefaultAsync(); if (member is null) return NotFound(); - if (!await rs.IsMemberWithRole(realm.Id, Guid.Parse(currentUser.Id), RealmMemberRole.Moderator, member.Role)) + if (!await rs.IsMemberWithRole(realm.Id, currentUser.Id, RealmMemberRole.Moderator, member.Role)) return StatusCode(403, "You do not have permission to remove members from this realm."); member.LeaveAt = SystemClock.Instance.GetCurrentInstant(); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.kick", - Meta = + als.CreateActionLogFromRequest( + "realms.members.kick", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "account_id", Value.ForString(memberId.ToString()) }, - { "kicker_id", Value.ForString(currentUser.Id) } + { "realm_id", realm.Id.ToString() }, + { "account_id", memberId.ToString() }, + { "kicker_id", currentUser.Id } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return NoContent(); } @@ -681,7 +652,7 @@ public class RealmController( public async Task> UpdateMemberRole(string slug, Guid memberId, [FromBody] int newRole) { if (newRole >= RealmMemberRole.Owner) return BadRequest("Unable to set realm member to owner or greater role."); - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); var realm = await db.Realms .Where(r => r.Slug == slug) @@ -693,7 +664,7 @@ public class RealmController( .FirstOrDefaultAsync(); if (member is null) return NotFound(); - if (!await rs.IsMemberWithRole(realm.Id, Guid.Parse(currentUser.Id), RealmMemberRole.Moderator, member.Role, + if (!await rs.IsMemberWithRole(realm.Id, currentUser.Id, RealmMemberRole.Moderator, member.Role, newRole)) return StatusCode(403, "You do not have permission to update member roles in this realm."); @@ -701,20 +672,17 @@ public class RealmController( db.RealmMembers.Update(member); await db.SaveChangesAsync(); - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.members.role_update", - Meta = + als.CreateActionLogFromRequest( + "realms.members.role_update", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "account_id", Value.ForString(memberId.ToString()) }, - { "new_role", Value.ForNumber(newRole) }, - { "updater_id", Value.ForString(currentUser.Id) } + { "realm_id", realm.Id.ToString() }, + { "account_id", memberId.ToString() }, + { "new_role", newRole }, + { "updater_id", currentUser.Id } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); return Ok(member); } @@ -723,7 +691,7 @@ public class RealmController( [Authorize] public async Task Delete(string slug) { - if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser) return Unauthorized(); + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); var transaction = await db.Database.BeginTransactionAsync(); @@ -732,7 +700,7 @@ public class RealmController( .FirstOrDefaultAsync(); if (realm is null) return NotFound(); - if (!await rs.IsMemberWithRole(realm.Id, Guid.Parse(currentUser.Id), RealmMemberRole.Owner)) + if (!await rs.IsMemberWithRole(realm.Id, currentUser.Id, RealmMemberRole.Owner)) return StatusCode(403, "Only the owner can delete this realm."); try @@ -753,19 +721,16 @@ public class RealmController( throw; } - _ = als.CreateActionLogAsync(new CreateActionLogRequest - { - Action = "realms.delete", - Meta = + als.CreateActionLogFromRequest( + "realms.delete", + new Dictionary() { - { "realm_id", Value.ForString(realm.Id.ToString()) }, - { "realm_name", Value.ForString(realm.Name) }, - { "realm_slug", Value.ForString(realm.Slug) } + { "realm_id", realm.Id.ToString() }, + { "realm_name", realm.Name }, + { "realm_slug", realm.Slug } }, - AccountId = currentUser.Id, - UserAgent = Request.Headers.UserAgent.ToString(), - IpAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "" - }); + Request + ); // Delete all file references for this realm var realmResourceId = $"realm:{realm.Id}"; diff --git a/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs b/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs index b29cac0..d0ee30e 100644 --- a/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs +++ b/DysonNetwork.Pass/Startup/ApplicationConfiguration.cs @@ -22,7 +22,6 @@ public static class ApplicationConfiguration app.ConfigureForwardedHeaders(configuration); app.UseWebSockets(); - app.UseRateLimiter(); app.UseAuthentication(); app.UseAuthorization(); app.UseMiddleware(); diff --git a/DysonNetwork.Ring/Program.cs b/DysonNetwork.Ring/Program.cs index 4fd888f..72258c3 100644 --- a/DysonNetwork.Ring/Program.cs +++ b/DysonNetwork.Ring/Program.cs @@ -44,6 +44,6 @@ app.ConfigureAppMiddleware(builder.Configuration); // Configure gRPC app.ConfigureGrpcServices(); -app.UseSwaggerManifest(); +app.UseSwaggerManifest("DysonNetwork.Ring"); app.Run(); diff --git a/DysonNetwork.Ring/Startup/ApplicationConfiguration.cs b/DysonNetwork.Ring/Startup/ApplicationConfiguration.cs index d6ecd6e..8600eaa 100644 --- a/DysonNetwork.Ring/Startup/ApplicationConfiguration.cs +++ b/DysonNetwork.Ring/Startup/ApplicationConfiguration.cs @@ -12,7 +12,6 @@ public static class ApplicationConfiguration app.ConfigureForwardedHeaders(configuration); app.UseWebSockets(); - app.UseRateLimiter(); app.UseAuthentication(); app.UseAuthorization(); diff --git a/DysonNetwork.Shared/Http/SwaggerGen.cs b/DysonNetwork.Shared/Http/SwaggerGen.cs index 05efff7..a726e81 100644 --- a/DysonNetwork.Shared/Http/SwaggerGen.cs +++ b/DysonNetwork.Shared/Http/SwaggerGen.cs @@ -56,7 +56,7 @@ public static class SwaggerGen return builder; } - public static WebApplication UseSwaggerManifest(this WebApplication app) + public static WebApplication UseSwaggerManifest(this WebApplication app, string serviceName) { app.MapOpenApi(); @@ -103,7 +103,7 @@ public static class SwaggerGen var publicBasePath = configuration["Swagger:PublicBasePath"]?.TrimEnd('/') ?? ""; options.SwaggerEndpoint( $"{publicBasePath}/swagger/v1/swagger.json", - "Develop API v1"); + $"{serviceName} API v1"); }); return app; diff --git a/DysonNetwork.Sphere/Program.cs b/DysonNetwork.Sphere/Program.cs index 4d1427a..f820430 100644 --- a/DysonNetwork.Sphere/Program.cs +++ b/DysonNetwork.Sphere/Program.cs @@ -44,6 +44,6 @@ using (var scope = app.Services.CreateScope()) // Configure application middleware pipeline app.ConfigureAppMiddleware(builder.Configuration); -app.UseSwaggerManifest(); +app.UseSwaggerManifest("DysonNetwork.Sphere"); app.Run(); \ No newline at end of file diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index 7ca8903..26a0194 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -167,6 +167,9 @@ <Assembly Path="/opt/homebrew/Cellar/dotnet/9.0.6/libexec/packs/Microsoft.AspNetCore.App.Ref/9.0.6/ref/net9.0/Microsoft.AspNetCore.RateLimiting.dll" /> <Assembly Path="/Users/littlesheep/.nuget/packages/nodatime/3.2.2/lib/net8.0/NodaTime.dll" /> </AssemblyExplorer> + <SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> False False