diff --git a/src/Bifrost.Web/Features/Motions/MotionEveSurfaceService.cs b/src/Bifrost.Web/Features/Motions/MotionEveSurfaceService.cs deleted file mode 100644 index dbe5d96..0000000 --- a/src/Bifrost.Web/Features/Motions/MotionEveSurfaceService.cs +++ /dev/null @@ -1,203 +0,0 @@ -using Bifrost.Web.Domain; - -namespace Bifrost.Web.Features.Motions; - -public sealed class MotionEveSurfaceService -{ - private const string MotionCommandTarget = "cultmesh://asgard.starfire.bifrost/commands/motion"; - - public EveSurfaceDocument BuildSurface(MotionGovernanceState state) - { - var motionNodes = state.Motions.Count > 0 - ? state.Motions.Select(BuildMotionCard).ToArray() - : [TextNode("motion-empty", "No motions yet.")]; - - return new EveSurfaceDocument( - "gamecult.eve.surface.v1", - "bifrost-motion-verse", - "Bifrost Motion Verse", - new EveNode( - "bifrost-motion-root", - "workspace", - new Dictionary - { - ["title"] = "Bifrost Governance", - ["subtitle"] = "Motions, weighted votes, thresholds, and receipts", - ["actor"] = state.ActorName, - ["effectiveVotingWeight"] = state.EffectiveVotingWeight, - ["canonicalCommandTarget"] = MotionCommandTarget, - ["commandTransport"] = "cultmesh-command-document", - ["commandSchema"] = "bifrost.motion_command.v0" - }, - [ - new EveNode( - "motion-create", - "form", - new Dictionary - { - ["title"] = "Open Motion", - ["command"] = "motion.create", - ["target"] = MotionCommandTarget, - ["transport"] = "cultmesh-command-document" - }, - [ - SelectNode("scope", "Scope", EnumNames()), - SelectNode("projectId", "Project", state.Projects.Select(x => new EveOption(x.Id.ToString(), x.Name)).Prepend(new EveOption("", "No project scope"))), - SelectNode("category", "Category", EnumNames()), - InputNode("title", "Title", "text"), - InputNode("summary", "Summary", "multiline"), - InputNode("closesAtUtc", "Close at UTC", "datetime") - ]), - new EveNode( - "vote-ledger", - "panel", - new Dictionary - { - ["title"] = "Vote Ledger", - ["effectiveVotingWeight"] = state.EffectiveVotingWeight - }, - state.CategoryPolicies - .Select(x => TextNode($"threshold-{Slug(x.Label)}", $"{x.Label}: {x.Threshold:P0} threshold")) - .ToArray()), - new EveNode( - "motions", - "collection", - new Dictionary { ["title"] = "Motions" }, - motionNodes) - ])); - } - - private static EveNode BuildMotionCard(MotionListItem motion) - { - var commandNodes = new List(); - foreach (var choice in Enum.GetValues()) - { - commandNodes.Add(CommandNode( - $"vote-{motion.Id}-{choice}", - $"Vote {choice}", - "motion.vote", - new Dictionary - { - ["motionId"] = motion.Id, - ["choice"] = choice.ToString(), - ["comment"] = string.Empty - }, - motion.CurrentUserVote == choice ? "selected" : "default")); - } - - if (motion.StatusLabel == "Expired") - { - commandNodes.Add(CommandNode( - $"close-{motion.Id}", - "Close motion", - "motion.close", - new Dictionary { ["motionId"] = motion.Id }, - "secondary")); - } - - return new EveNode( - $"motion-{motion.Id}", - "card", - new Dictionary - { - ["title"] = motion.Title, - ["summary"] = motion.Summary, - ["scope"] = motion.Scope, - ["category"] = motion.Category, - ["status"] = motion.StatusLabel, - ["tone"] = motion.StatusTone, - ["project"] = motion.ProjectName, - ["threshold"] = motion.Threshold, - ["closesAtUtc"] = motion.ClosesAtUtc, - ["resolutionNote"] = motion.ResolutionNote - }, - [ - new EveNode( - $"motion-votes-{motion.Id}", - "metrics", - new Dictionary - { - ["for"] = motion.VotesFor, - ["against"] = motion.VotesAgainst, - ["abstain"] = motion.VotesAbstain, - ["currentUserVote"] = motion.CurrentUserVote?.ToString() ?? string.Empty - }), - new EveNode( - $"motion-commands-{motion.Id}", - "commands", - new Dictionary - { - ["target"] = MotionCommandTarget, - ["transport"] = "cultmesh-command-document" - }, - commandNodes) - ]); - } - - private static EveNode CommandNode( - string id, - string label, - string command, - IReadOnlyDictionary payload, - string tone) => - new( - id, - "command", - new Dictionary - { - ["label"] = label, - ["command"] = command, - ["target"] = MotionCommandTarget, - ["transport"] = "cultmesh-command-document", - ["payload"] = payload, - ["tone"] = tone - }); - - private static EveNode InputNode(string id, string label, string inputKind) => - new( - $"input-{id}", - "input", - new Dictionary - { - ["name"] = id, - ["label"] = label, - ["inputKind"] = inputKind - }); - - private static EveNode SelectNode(string id, string label, IEnumerable options) => - SelectNode(id, label, options.Select(x => new EveOption(x, x))); - - private static EveNode SelectNode(string id, string label, IEnumerable options) => - new( - $"input-{id}", - "select", - new Dictionary - { - ["name"] = id, - ["label"] = label, - ["options"] = options.ToArray() - }); - - private static EveNode TextNode(string id, string text) => - new(id, "text", new Dictionary { ["text"] = text }); - - private static IReadOnlyList EnumNames() where TEnum : struct, Enum => - Enum.GetNames(); - - private static string Slug(string value) => - value.ToLowerInvariant().Replace(" ", "-", StringComparison.Ordinal); -} - -public sealed record EveSurfaceDocument( - string Schema, - string Id, - string Title, - EveNode Root); - -public sealed record EveNode( - string Id, - string Kind, - IReadOnlyDictionary Props, - IReadOnlyList? Children = null); - -public sealed record EveOption(string Value, string Label); diff --git a/src/Bifrost.Web/Program.cs b/src/Bifrost.Web/Program.cs index 5a84602..98f4de0 100644 --- a/src/Bifrost.Web/Program.cs +++ b/src/Bifrost.Web/Program.cs @@ -138,7 +138,6 @@ builder.Services.AddScoped(); builder.Services.AddOptions().BindConfiguration(ChatNoticesOptions.SectionName); builder.Services.AddSingleton(); builder.Services.AddHostedService(); -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -787,23 +786,6 @@ app.MapPost("/patronage/stripe/webhook", async ( }; }).AllowAnonymous(); -var eveGovernance = app.MapGroup("/eve/governance") - .RequireAuthorization(ActiveMemberRequirement.PolicyName); - -eveGovernance.MapGet("/surface", async ( - ICurrentBifrostActorAccessor actorAccessor, - MotionGovernanceService motionGovernanceService, - MotionEveSurfaceService motionEveSurfaceService, - CancellationToken cancellationToken) => -{ - var actor = await actorAccessor.GetAsync(cancellationToken); - var state = await motionGovernanceService.GetStateAsync(actor, cancellationToken); - var surface = motionEveSurfaceService.BuildSurface(state); - return Results.Text( - JsonSerializer.Serialize(surface, appJsonSerializerOptions), - "application/json"); -}); - // Sealed-ballot intake. Typed JSON documents posted directly by the voter; no ballot content ever rides in a room message, // and no response before close carries another member's ballot. var sealedMotions = app.MapGroup("/api/sealed-motions") diff --git a/tests/Bifrost.Web.Tests/OidcIssuerTests.cs b/tests/Bifrost.Web.Tests/OidcIssuerTests.cs index 201e436..053561f 100644 --- a/tests/Bifrost.Web.Tests/OidcIssuerTests.cs +++ b/tests/Bifrost.Web.Tests/OidcIssuerTests.cs @@ -169,7 +169,7 @@ public sealed class OidcIssuerTests : IClassFixture Assert.Equal(0, (await _factory.RowCountsAsync()).Votes); // Neither the session that signed in to chat nor its token opens a member or governance surface. - foreach (var path in new[] { "/eve/governance/surface", "/api/sealed-motions", "/App" }) + foreach (var path in new[] { "/api/sealed-motions", "/App" }) { using var viaSession = await client.GetAsync(path); Assert.NotEqual(HttpStatusCode.OK, viaSession.StatusCode); diff --git a/tests/Bifrost.Web.Tests/PlatformEndpointsTests.cs b/tests/Bifrost.Web.Tests/PlatformEndpointsTests.cs index 83e2a38..e1de7c3 100644 --- a/tests/Bifrost.Web.Tests/PlatformEndpointsTests.cs +++ b/tests/Bifrost.Web.Tests/PlatformEndpointsTests.cs @@ -482,19 +482,13 @@ public sealed class PlatformEndpointsTests : IClassFixture