diff --git a/CLAUDE.md b/CLAUDE.md index a892669..6bc15da 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -73,7 +73,7 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi. - `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout) - `graph/generated.go` — auto-generated by gqlgen, do not edit - `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit -- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box) +- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page) - `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns) - `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), the `.env` registry (`env_manager.go`), DB seeding. There is no Claude client in Go any more @@ -81,8 +81,8 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi. - `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`) - `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status -- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes. `createCrudStore.js` is the factory behind places and boxes; `createMirrorStore.js` is the one behind the home-page slices -- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. See "The /stp canvas" in `vue/README.md` +- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices +- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. The canvas (`views/home3/BoxCanvas.vue`) is reusable per page key: the landing page overlays one for notes, and admin-created `Page`s (e.g. shrines) are served at `/` by the router's catch-all, `views/canvas/CanvasPage.vue`. Boxes and pages can be admin-only, filtered server-side. See "The /stp canvas" in `vue/README.md` - `src/components/` — reusable UI components - `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`. diff --git a/backend/gqlgen.yml b/backend/gqlgen.yml index fc358d1..e0291f7 100644 --- a/backend/gqlgen.yml +++ b/backend/gqlgen.yml @@ -82,3 +82,9 @@ models: fields: deletedAt: resolver: false + Page: + model: + - adam-french.co.uk/backend/models.Page + fields: + deletedAt: + resolver: false diff --git a/backend/graph/box.resolvers.go b/backend/graph/box.resolvers.go index 1bafbef..9e88e03 100644 --- a/backend/graph/box.resolvers.go +++ b/backend/graph/box.resolvers.go @@ -18,6 +18,7 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI // comment on models.Box.Framed. Sizes not supplied fall back to the // same 300x200 the column defaults use. box := models.Box{ + Page: input.Page, Kind: input.Kind, Widget: input.Widget, HTML: input.HTML, @@ -37,6 +38,9 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI if input.HideOnMobile != nil { box.HideOnMobile = *input.HideOnMobile } + if input.AdminOnly != nil { + box.AdminOnly = *input.AdminOnly + } if err := validateBox(&box); err != nil { return nil, err } @@ -76,6 +80,9 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up if input.HideOnMobile != nil { box.HideOnMobile = *input.HideOnMobile } + if input.AdminOnly != nil { + box.AdminOnly = *input.AdminOnly + } if err := validateBox(&box); err != nil { return nil, err } @@ -98,13 +105,27 @@ func (r *mutationResolver) DeleteBox(ctx context.Context, id int) (*models.Box, } // Boxes is the resolver for the boxes field. -func (r *queryResolver) Boxes(ctx context.Context) ([]*models.Box, error) { +func (r *queryResolver) Boxes(ctx context.Context, page string) ([]*models.Box, error) { // Public: this is the page layout every visitor loads. Ordered by z so // DOM order matches stacking order, which keeps tab order sensible. + // + // What is admin-only is filtered here rather than hidden in the browser, + // so a private note never reaches anyone else: an adminOnly page answers + // with no boxes at all, and adminOnly boxes are left out of the rest. + hidden, err := pageHiddenFrom(ctx, r.Store.DB, page) + if err != nil { + return nil, err + } + if hidden { + return []*models.Box{}, nil + } + query := r.Store.DB.Where("page = ?", page) + if !IsAdminFromCtx(ctx) { + query = query.Where("admin_only = ?", false) + } var boxes []models.Box - if err := r.Store.DB.Order("z ASC, id ASC").Find(&boxes).Error; err != nil { + if err := query.Order("z ASC, id ASC").Find(&boxes).Error; err != nil { return nil, err } return ptrs(boxes), nil } - diff --git a/backend/graph/box_helpers.go b/backend/graph/box_helpers.go index 4114f30..d70d9e8 100644 --- a/backend/graph/box_helpers.go +++ b/backend/graph/box_helpers.go @@ -24,6 +24,9 @@ func setInt(dst *int, src *int) { // rather than rejecting it, because a drag that overshoots the canvas edge // should land at the edge, not fail. func validateBox(box *models.Box) error { + if !validPageKey(box.Page) { + return errors.New("a box needs a valid page") + } switch box.Kind { case "widget": if box.Widget == nil || *box.Widget == "" { diff --git a/backend/graph/box_helpers_test.go b/backend/graph/box_helpers_test.go index c41c517..b74e7a3 100644 --- a/backend/graph/box_helpers_test.go +++ b/backend/graph/box_helpers_test.go @@ -14,13 +14,15 @@ func TestValidateBox(t *testing.T) { box models.Box wantErr bool }{ - {"widget with a name", models.Box{Kind: "widget", Widget: str("Chat")}, false}, - {"widget without a name", models.Box{Kind: "widget"}, true}, - {"widget with an empty name", models.Box{Kind: "widget", Widget: str("")}, true}, - {"html with html", models.Box{Kind: "html", HTML: str("

hi

")}, false}, - {"html with empty html", models.Box{Kind: "html", HTML: str("")}, false}, - {"html without html", models.Box{Kind: "html"}, true}, - {"unknown kind", models.Box{Kind: "iframe", HTML: str("x")}, true}, + {"widget with a name", models.Box{Page: "stp", Kind: "widget", Widget: str("Chat")}, false}, + {"widget without a name", models.Box{Page: "stp", Kind: "widget"}, true}, + {"widget with an empty name", models.Box{Page: "stp", Kind: "widget", Widget: str("")}, true}, + {"html with html", models.Box{Page: "stp", Kind: "html", HTML: str("

hi

")}, false}, + {"html with empty html", models.Box{Page: "stp", Kind: "html", HTML: str("")}, false}, + {"html without html", models.Box{Page: "stp", Kind: "html"}, true}, + {"no page", models.Box{Kind: "widget", Widget: str("Chat")}, true}, + {"bad page", models.Box{Page: "Shrines/GTO", Kind: "widget", Widget: str("Chat")}, true}, + {"unknown kind", models.Box{Page: "stp", Kind: "iframe", HTML: str("x")}, true}, } { t.Run(c.name, func(t *testing.T) { err := validateBox(&c.box) @@ -32,7 +34,7 @@ func TestValidateBox(t *testing.T) { // Geometry is clamped, not rejected: a drag past the canvas edge lands // at the edge, and a box can never shrink below a grabbable size. - box := models.Box{Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0} + box := models.Box{Page: "stp", Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0} if err := validateBox(&box); err != nil { t.Fatal(err) } diff --git a/backend/graph/generated.go b/backend/graph/generated.go index 3b52c60..27b9963 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -66,6 +66,7 @@ type ComplexityRoot struct { } Box struct { + AdminOnly func(childComplexity int) int CreatedAt func(childComplexity int) int Framed func(childComplexity int) int H func(childComplexity int) int @@ -73,6 +74,7 @@ type ComplexityRoot struct { HideOnMobile func(childComplexity int) int ID func(childComplexity int) int Kind func(childComplexity int) int + Page func(childComplexity int) int Title func(childComplexity int) int UpdatedAt func(childComplexity int) int W func(childComplexity int) int @@ -114,11 +116,13 @@ type ComplexityRoot struct { CreateBookmark func(childComplexity int, input model.CreateBookmarkInput) int CreateBox func(childComplexity int, input model.CreateBoxInput) int CreateFavorite func(childComplexity int, input model.CreateFavoriteInput) int + CreatePage func(childComplexity int, input model.CreatePageInput) int CreatePlace func(childComplexity int, input model.CreatePlaceInput) int CreatePost func(childComplexity int, input model.CreatePostInput) int CreateUser func(childComplexity int, input model.CreateUserInput) int DeleteBookmark func(childComplexity int, id int) int DeleteBox func(childComplexity int, id int) int + DeletePage func(childComplexity int, id int) int DeletePlace func(childComplexity int, id int) int DeletePost func(childComplexity int, id int) int DeleteUser func(childComplexity int, id int) int @@ -127,10 +131,20 @@ type ComplexityRoot struct { RefreshToken func(childComplexity int) int SetUserAdmin func(childComplexity int, id int, admin bool) int UpdateBox func(childComplexity int, id int, input model.UpdateBoxInput) int + UpdatePage func(childComplexity int, id int, input model.UpdatePageInput) int UpdatePlace func(childComplexity int, id int, input model.UpdatePlaceInput) int UpdatePost func(childComplexity int, id int, input model.UpdatePostInput) int } + Page struct { + AdminOnly func(childComplexity int) int + CreatedAt func(childComplexity int) int + ID func(childComplexity int) int + Slug func(childComplexity int) int + Title func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + Place struct { Category func(childComplexity int) int Cost func(childComplexity int) int @@ -157,11 +171,13 @@ type ComplexityRoot struct { Query struct { Activities func(childComplexity int) int Bookmarks func(childComplexity int) int - Boxes func(childComplexity int) int + Boxes func(childComplexity int, page string) int Favorites func(childComplexity int) int GiteaFeed func(childComplexity int) int Me func(childComplexity int) int Messages func(childComplexity int) int + Page func(childComplexity int, slug string) int + Pages func(childComplexity int) int Places func(childComplexity int) int Post func(childComplexity int, id int) int Posts func(childComplexity int) int @@ -253,6 +269,9 @@ type MutationResolver interface { UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) DeleteBox(ctx context.Context, id int) (*models.Box, error) CreateFavorite(ctx context.Context, input model.CreateFavoriteInput) (*models.Favorite, error) + CreatePage(ctx context.Context, input model.CreatePageInput) (*models.Page, error) + UpdatePage(ctx context.Context, id int, input model.UpdatePageInput) (*models.Page, error) + DeletePage(ctx context.Context, id int) (*models.Page, error) CreatePlace(ctx context.Context, input model.CreatePlaceInput) (*models.Place, error) UpdatePlace(ctx context.Context, id int, input model.UpdatePlaceInput) (*models.Place, error) DeletePlace(ctx context.Context, id int) (*models.Place, error) @@ -267,10 +286,12 @@ type QueryResolver interface { Activities(ctx context.Context) ([]*models.Activity, error) Me(ctx context.Context) (*models.User, error) Bookmarks(ctx context.Context) ([]*models.Bookmark, error) - Boxes(ctx context.Context) ([]*models.Box, error) + Boxes(ctx context.Context, page string) ([]*models.Box, error) Favorites(ctx context.Context) ([]*models.Favorite, error) GiteaFeed(ctx context.Context) (*model.GiteaFeedItem, error) Messages(ctx context.Context) ([]*models.Message, error) + Pages(ctx context.Context) ([]*models.Page, error) + Page(ctx context.Context, slug string) (*models.Page, error) Places(ctx context.Context) ([]*models.Place, error) Posts(ctx context.Context) ([]*models.Post, error) Post(ctx context.Context, id int) (*models.Post, error) @@ -386,6 +407,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Bookmark.UpdatedAt(childComplexity), true + case "Box.adminOnly": + if e.ComplexityRoot.Box.AdminOnly == nil { + break + } + + return e.ComplexityRoot.Box.AdminOnly(childComplexity), true case "Box.createdAt": if e.ComplexityRoot.Box.CreatedAt == nil { break @@ -428,6 +455,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Box.Kind(childComplexity), true + case "Box.page": + if e.ComplexityRoot.Box.Page == nil { + break + } + + return e.ComplexityRoot.Box.Page(childComplexity), true case "Box.title": if e.ComplexityRoot.Box.Title == nil { break @@ -626,6 +659,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.CreateFavorite(childComplexity, args["input"].(model.CreateFavoriteInput)), true + case "Mutation.createPage": + if e.ComplexityRoot.Mutation.CreatePage == nil { + break + } + + args, err := ec.field_Mutation_createPage_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreatePage(childComplexity, args["input"].(model.CreatePageInput)), true case "Mutation.createPlace": if e.ComplexityRoot.Mutation.CreatePlace == nil { break @@ -681,6 +725,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteBox(childComplexity, args["id"].(int)), true + case "Mutation.deletePage": + if e.ComplexityRoot.Mutation.DeletePage == nil { + break + } + + args, err := ec.field_Mutation_deletePage_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeletePage(childComplexity, args["id"].(int)), true case "Mutation.deletePlace": if e.ComplexityRoot.Mutation.DeletePlace == nil { break @@ -759,6 +814,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.UpdateBox(childComplexity, args["id"].(int), args["input"].(model.UpdateBoxInput)), true + case "Mutation.updatePage": + if e.ComplexityRoot.Mutation.UpdatePage == nil { + break + } + + args, err := ec.field_Mutation_updatePage_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdatePage(childComplexity, args["id"].(int), args["input"].(model.UpdatePageInput)), true case "Mutation.updatePlace": if e.ComplexityRoot.Mutation.UpdatePlace == nil { break @@ -782,6 +848,43 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Mutation.UpdatePost(childComplexity, args["id"].(int), args["input"].(model.UpdatePostInput)), true + case "Page.adminOnly": + if e.ComplexityRoot.Page.AdminOnly == nil { + break + } + + return e.ComplexityRoot.Page.AdminOnly(childComplexity), true + case "Page.createdAt": + if e.ComplexityRoot.Page.CreatedAt == nil { + break + } + + return e.ComplexityRoot.Page.CreatedAt(childComplexity), true + case "Page.id": + if e.ComplexityRoot.Page.ID == nil { + break + } + + return e.ComplexityRoot.Page.ID(childComplexity), true + case "Page.slug": + if e.ComplexityRoot.Page.Slug == nil { + break + } + + return e.ComplexityRoot.Page.Slug(childComplexity), true + case "Page.title": + if e.ComplexityRoot.Page.Title == nil { + break + } + + return e.ComplexityRoot.Page.Title(childComplexity), true + case "Page.updatedAt": + if e.ComplexityRoot.Page.UpdatedAt == nil { + break + } + + return e.ComplexityRoot.Page.UpdatedAt(childComplexity), true + case "Place.category": if e.ComplexityRoot.Place.Category == nil { break @@ -903,7 +1006,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin break } - return e.ComplexityRoot.Query.Boxes(childComplexity), true + args, err := ec.field_Query_boxes_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Query.Boxes(childComplexity, args["page"].(string)), true case "Query.favorites": if e.ComplexityRoot.Query.Favorites == nil { break @@ -929,6 +1037,23 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Query.Messages(childComplexity), true + case "Query.page": + if e.ComplexityRoot.Query.Page == nil { + break + } + + args, err := ec.field_Query_page_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Query.Page(childComplexity, args["slug"].(string)), true + case "Query.pages": + if e.ComplexityRoot.Query.Pages == nil { + break + } + + return e.ComplexityRoot.Query.Pages(childComplexity), true case "Query.places": if e.ComplexityRoot.Query.Places == nil { break @@ -1202,11 +1327,13 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCreateBookmarkInput, ec.unmarshalInputCreateBoxInput, ec.unmarshalInputCreateFavoriteInput, + ec.unmarshalInputCreatePageInput, ec.unmarshalInputCreatePlaceInput, ec.unmarshalInputCreatePostInput, ec.unmarshalInputCreateUserInput, ec.unmarshalInputLoginInput, ec.unmarshalInputUpdateBoxInput, + ec.unmarshalInputUpdatePageInput, ec.unmarshalInputUpdatePlaceInput, ec.unmarshalInputUpdatePostInput, ) @@ -1283,7 +1410,7 @@ func newExecutionContext( } } -//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/message.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" +//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/message.graphql" "schema/page.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" var sourcesFS embed.FS func sourceData(filename string) string { @@ -1302,6 +1429,7 @@ var sources = []*ast.Source{ {Name: "schema/favorite.graphql", Input: sourceData("schema/favorite.graphql"), BuiltIn: false}, {Name: "schema/gitea.graphql", Input: sourceData("schema/gitea.graphql"), BuiltIn: false}, {Name: "schema/message.graphql", Input: sourceData("schema/message.graphql"), BuiltIn: false}, + {Name: "schema/page.graphql", Input: sourceData("schema/page.graphql"), BuiltIn: false}, {Name: "schema/place.graphql", Input: sourceData("schema/place.graphql"), BuiltIn: false}, {Name: "schema/post.graphql", Input: sourceData("schema/post.graphql"), BuiltIn: false}, {Name: "schema/rowing.graphql", Input: sourceData("schema/rowing.graphql"), BuiltIn: false}, @@ -1368,6 +1496,8 @@ func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.C return ec.fieldContext_Box_createdAt(ctx, field) case "updatedAt": return ec.fieldContext_Box_updatedAt(ctx, field) + case "page": + return ec.fieldContext_Box_page(ctx, field) case "kind": return ec.fieldContext_Box_kind(ctx, field) case "widget": @@ -1390,6 +1520,8 @@ func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.C return ec.fieldContext_Box_framed(ctx, field) case "hideOnMobile": return ec.fieldContext_Box_hideOnMobile(ctx, field) + case "adminOnly": + return ec.fieldContext_Box_adminOnly(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Box", field.Name) } @@ -1448,6 +1580,24 @@ func (ec *executionContext) childFields_Message(ctx context.Context, field graph return nil, fmt.Errorf("no field named %q was found under type Message", field.Name) } +func (ec *executionContext) childFields_Page(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Page_id(ctx, field) + case "createdAt": + return ec.fieldContext_Page_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Page_updatedAt(ctx, field) + case "slug": + return ec.fieldContext_Page_slug(ctx, field) + case "title": + return ec.fieldContext_Page_title(ctx, field) + case "adminOnly": + return ec.fieldContext_Page_adminOnly(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Page", field.Name) +} + func (ec *executionContext) childFields_Place(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": @@ -1786,6 +1936,20 @@ func (ec *executionContext) field_Mutation_createFavorite_args(ctx context.Conte return args, nil } +func (ec *executionContext) field_Mutation_createPage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.CreatePageInput, error) { + return ec.unmarshalNCreatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreatePageInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createPlace_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -1856,6 +2020,20 @@ func (ec *executionContext) field_Mutation_deleteBox_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_deletePage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_deletePlace_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -1956,6 +2134,28 @@ func (ec *executionContext) field_Mutation_updateBox_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_updatePage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + arg1, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.UpdatePageInput, error) { + return ec.unmarshalNUpdatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdatePageInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updatePlace_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2014,6 +2214,34 @@ func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Query_boxes_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "page", + func(ctx context.Context, v any) (string, error) { + return ec.unmarshalNString2string(ctx, v) + }) + if err != nil { + return nil, err + } + args["page"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_page_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "slug", + func(ctx context.Context, v any) (string, error) { + return ec.unmarshalNString2string(ctx, v) + }) + if err != nil { + return nil, err + } + args["slug"] = arg0 + return args, nil +} + func (ec *executionContext) field_Query_post_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2479,6 +2707,29 @@ func (ec *executionContext) fieldContext_Box_updatedAt(_ context.Context, field return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Time does not have child fields")) } +func (ec *executionContext) _Box_page(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_page(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Page, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_page(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields")) +} + func (ec *executionContext) _Box_kind(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -2732,6 +2983,29 @@ func (ec *executionContext) fieldContext_Box_hideOnMobile(_ context.Context, fie return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields")) } +func (ec *executionContext) _Box_adminOnly(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_adminOnly(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.AdminOnly, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_adminOnly(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields")) +} + func (ec *executionContext) _Favorite_id(ctx context.Context, field graphql.CollectedField, obj *models.Favorite) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -3644,6 +3918,177 @@ func (ec *executionContext) fieldContext_Mutation_createFavorite(ctx context.Con return fc, nil } +func (ec *executionContext) _Mutation_createPage(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_createPage(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreatePage(ctx, fc.Args["input"].(model.CreatePageInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Page + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Page) graphql.Marshaler { + return ec.marshalNPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createPage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Page(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createPage_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updatePage(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_updatePage(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdatePage(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdatePageInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Page + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Page) graphql.Marshaler { + return ec.marshalNPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updatePage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Page(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updatePage_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deletePage(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_deletePage(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeletePage(ctx, fc.Args["id"].(int)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Page + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Page) graphql.Marshaler { + return ec.marshalNPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deletePage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Page(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deletePage_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_createPlace(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -4157,6 +4602,144 @@ func (ec *executionContext) fieldContext_Mutation_setUserAdmin(ctx context.Conte return fc, nil } +func (ec *executionContext) _Page_id(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_id(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.ID, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v uint) graphql.Marshaler { + return ec.marshalNID2uint(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _Page_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_createdAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.CreatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Page_updatedAt(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_updatedAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.UpdatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Page_slug(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_slug(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Slug, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_slug(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Page_title(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_title(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Title, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Page_adminOnly(ctx context.Context, field graphql.CollectedField, obj *models.Page) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Page_adminOnly(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.AdminOnly, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Page_adminOnly(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Page", field, false, false, errors.New("field of type Boolean does not have child fields")) +} + func (ec *executionContext) _Place_id(ctx context.Context, field graphql.CollectedField, obj *models.Place) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -4662,7 +5245,8 @@ func (ec *executionContext) _Query_boxes(ctx context.Context, field graphql.Coll return ec.fieldContext_Query_boxes(ctx, field) }, func(ctx context.Context) (any, error) { - return ec.Resolvers.Query().Boxes(ctx) + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Query().Boxes(ctx, fc.Args["page"].(string)) }, nil, func(ctx context.Context, selections ast.SelectionSet, v []*models.Box) graphql.Marshaler { @@ -4672,7 +5256,7 @@ func (ec *executionContext) _Query_boxes(ctx context.Context, field graphql.Coll true, ) } -func (ec *executionContext) fieldContext_Query_boxes(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_boxes(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Query", Field: field, @@ -4682,6 +5266,17 @@ func (ec *executionContext) fieldContext_Query_boxes(_ context.Context, field gr return ec.childFields_Box(ctx, field) }, } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_boxes_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } @@ -4781,6 +5376,82 @@ func (ec *executionContext) fieldContext_Query_messages(_ context.Context, field return fc, nil } +func (ec *executionContext) _Query_pages(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Query_pages(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().Pages(ctx) + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v []*models.Page) graphql.Marshaler { + return ec.marshalNPage2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPageᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_pages(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Page(ctx, field) + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_page(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Query_page(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Query().Page(ctx, fc.Args["slug"].(string)) + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *models.Page) graphql.Marshaler { + return ec.marshalOPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Query_page(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Page(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_page_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query_places(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -7133,13 +7804,20 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile"} + fieldsInOrder := [...]string{"page", "kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { continue } switch k { + case "page": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Page = data case "kind": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("kind")) data, err := ec.unmarshalNString2string(ctx, v) @@ -7217,6 +7895,13 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob return it, err } it.HideOnMobile = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data } } return it, nil @@ -7266,6 +7951,50 @@ func (ec *executionContext) unmarshalInputCreateFavoriteInput(ctx context.Contex return it, nil } +func (ec *executionContext) unmarshalInputCreatePageInput(ctx context.Context, obj any) (model.CreatePageInput, error) { + var it model.CreatePageInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"slug", "title", "adminOnly"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "slug": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("slug")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Slug = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputCreatePlaceInput(ctx context.Context, obj any) (model.CreatePlaceInput, error) { var it model.CreatePlaceInput if obj == nil { @@ -7467,7 +8196,7 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile"} + fieldsInOrder := [...]string{"widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -7544,6 +8273,57 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob return it, err } it.HideOnMobile = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data + } + } + return it, nil +} + +func (ec *executionContext) unmarshalInputUpdatePageInput(ctx context.Context, obj any) (model.UpdatePageInput, error) { + var it model.UpdatePageInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"slug", "title", "adminOnly"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "slug": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("slug")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Slug = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data } } return it, nil @@ -7864,6 +8644,11 @@ func (ec *executionContext) _Box(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { out.Invalids++ } + case "page": + out.Values[i] = ec._Box_page(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "kind": out.Values[i] = ec._Box_kind(ctx, field, obj) if out.Values[i] == graphql.Null { @@ -7919,6 +8704,11 @@ func (ec *executionContext) _Box(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { out.Invalids++ } + case "adminOnly": + out.Values[i] = ec._Box_adminOnly(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -8252,6 +9042,27 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createPage": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createPage(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updatePage": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updatePage(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deletePage": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deletePage(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "createPlace": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_createPlace(ctx, field) @@ -8336,6 +9147,69 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) return out } +var pageImplementors = []string{"Page"} + +func (ec *executionContext) _Page(ctx context.Context, sel ast.SelectionSet, obj *models.Page) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, pageImplementors) + + out := graphql.NewFieldSet(fields) + deferredFieldSet := graphql.NewFieldSet(nil) + deferLabelToView := make(map[string]*graphql.FieldSetView) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Page") + case "id": + out.Values[i] = ec._Page_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createdAt": + out.Values[i] = ec._Page_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updatedAt": + out.Values[i] = ec._Page_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "slug": + out.Values[i] = ec._Page_slug(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "title": + out.Values[i] = ec._Page_title(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "adminOnly": + out.Values[i] = ec._Page_adminOnly(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.Deferred, int32(min(len(deferLabelToView), math.MaxInt32))) + + ec.ProcessDeferredGroup(graphql.DeferredGroup{ + Defers: deferLabelToView, + Path: graphql.GetPath(ctx), + FieldSet: deferredFieldSet, + Context: ctx, + }) + + return out +} + var placeImplementors = []string{"Place"} func (ec *executionContext) _Place(ctx context.Context, sel ast.SelectionSet, obj *models.Place) graphql.Marshaler { @@ -8660,6 +9534,50 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "pages": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_pages(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "page": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_page(ctx, field) + if res == graphql.RequiredNull { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "places": field := field @@ -9978,6 +10896,11 @@ func (ec *executionContext) unmarshalNCreateFavoriteInput2adamᚑfrenchᚗcoᚗu return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreatePageInput(ctx context.Context, v any) (model.CreatePageInput, error) { + res, err := ec.unmarshalInputCreatePageInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreatePlaceInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreatePlaceInput(ctx context.Context, v any) (model.CreatePlaceInput, error) { res, err := ec.unmarshalInputCreatePlaceInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -10114,6 +11037,32 @@ func (ec *executionContext) marshalNMessage2ᚖadamᚑfrenchᚗcoᚗukᚋbackend return ec._Message(ctx, sel, v) } +func (ec *executionContext) marshalNPage2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPageᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Page) graphql.Marshaler { + ret := graphql.MarshalSliceConcurrently(ctx, len(v), 0, false, func(ctx context.Context, i int) graphql.Marshaler { + fc := graphql.GetFieldContext(ctx) + fc.Result = &v[i] + return ec.marshalNPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx context.Context, sel ast.SelectionSet, v *models.Page) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + graphql.AddErrorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Page(ctx, sel, v) +} + func (ec *executionContext) marshalNPlace2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPlaceᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Place) graphql.Marshaler { ret := graphql.MarshalSliceConcurrently(ctx, len(v), 0, false, func(ctx context.Context, i int) graphql.Marshaler { fc := graphql.GetFieldContext(ctx) @@ -10337,6 +11286,11 @@ func (ec *executionContext) unmarshalNUpdateBoxInput2adamᚑfrenchᚗcoᚗukᚋb return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNUpdatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdatePageInput(ctx context.Context, v any) (model.UpdatePageInput, error) { + res, err := ec.unmarshalInputUpdatePageInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNUpdatePlaceInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdatePlaceInput(ctx context.Context, v any) (model.UpdatePlaceInput, error) { res, err := ec.unmarshalInputUpdatePlaceInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -10568,6 +11522,13 @@ func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.Sele return res } +func (ec *executionContext) marshalOPage2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPage(ctx context.Context, sel ast.SelectionSet, v *models.Page) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Page(ctx, sel, v) +} + func (ec *executionContext) marshalOPost2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐPost(ctx context.Context, sel ast.SelectionSet, v *models.Post) graphql.Marshaler { if v == nil { return graphql.Null diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index 199418f..44998b9 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -25,6 +25,7 @@ type CreateBookmarkInput struct { } type CreateBoxInput struct { + Page string `json:"page"` Kind string `json:"kind"` Widget *string `json:"widget,omitempty"` HTML *string `json:"html,omitempty"` @@ -36,6 +37,7 @@ type CreateBoxInput struct { Z *int `json:"z,omitempty"` Framed *bool `json:"framed,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"` + AdminOnly *bool `json:"adminOnly,omitempty"` } type CreateFavoriteInput struct { @@ -44,6 +46,12 @@ type CreateFavoriteInput struct { Link *string `json:"link,omitempty"` } +type CreatePageInput struct { + Slug string `json:"slug"` + Title string `json:"title"` + AdminOnly *bool `json:"adminOnly,omitempty"` +} + type CreatePlaceInput struct { Title string `json:"title"` Location *string `json:"location,omitempty"` @@ -138,6 +146,13 @@ type UpdateBoxInput struct { Z *int `json:"z,omitempty"` Framed *bool `json:"framed,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"` + AdminOnly *bool `json:"adminOnly,omitempty"` +} + +type UpdatePageInput struct { + Slug *string `json:"slug,omitempty"` + Title *string `json:"title,omitempty"` + AdminOnly *bool `json:"adminOnly,omitempty"` } type UpdatePlaceInput struct { diff --git a/backend/graph/page.resolvers.go b/backend/graph/page.resolvers.go new file mode 100644 index 0000000..296b554 --- /dev/null +++ b/backend/graph/page.resolvers.go @@ -0,0 +1,145 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver +// implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.95 + +import ( + "context" + "errors" + "strings" + + "adam-french.co.uk/backend/graph/model" + "adam-french.co.uk/backend/models" + "gorm.io/gorm" +) + +// CreatePage is the resolver for the createPage field. +func (r *mutationResolver) CreatePage(ctx context.Context, input model.CreatePageInput) (*models.Page, error) { + page := models.Page{ + Slug: input.Slug, + Title: strings.TrimSpace(input.Title), + } + if input.AdminOnly != nil { + page.AdminOnly = *input.AdminOnly + } + if err := validateSlug(page.Slug); err != nil { + return nil, err + } + if page.Title == "" { + return nil, errors.New("a page needs a title") + } + taken, err := slugTaken(r.Store.DB, page.Slug, 0) + if err != nil { + return nil, err + } + if taken { + return nil, errors.New("there is already a page at that address") + } + if err := r.Store.DB.Create(&page).Error; err != nil { + return nil, err + } + return &page, nil +} + +// UpdatePage is the resolver for the updatePage field. +func (r *mutationResolver) UpdatePage(ctx context.Context, id int, input model.UpdatePageInput) (*models.Page, error) { + // Partial update, like updateBox. A new slug moves the page's boxes with + // it in the same transaction, since boxes find their page by slug. + var page models.Page + if err := r.Store.DB.First(&page, id).Error; err != nil { + return nil, err + } + oldSlug := page.Slug + if input.Slug != nil { + page.Slug = *input.Slug + } + if input.Title != nil { + page.Title = strings.TrimSpace(*input.Title) + } + if input.AdminOnly != nil { + page.AdminOnly = *input.AdminOnly + } + if page.Title == "" { + return nil, errors.New("a page needs a title") + } + if page.Slug != oldSlug { + if err := validateSlug(page.Slug); err != nil { + return nil, err + } + taken, err := slugTaken(r.Store.DB, page.Slug, page.ID) + if err != nil { + return nil, err + } + if taken { + return nil, errors.New("there is already a page at that address") + } + } + err := r.Store.DB.Transaction(func(tx *gorm.DB) error { + if page.Slug != oldSlug { + if err := tx.Model(&models.Box{}).Where("page = ?", oldSlug).Update("page", page.Slug).Error; err != nil { + return err + } + } + return tx.Save(&page).Error + }) + if err != nil { + return nil, err + } + return &page, nil +} + +// DeletePage is the resolver for the deletePage field. +func (r *mutationResolver) DeletePage(ctx context.Context, id int) (*models.Page, error) { + // The boxes go too: left behind, they would reappear on any page later + // created at the same address. + var page models.Page + if err := r.Store.DB.First(&page, id).Error; err != nil { + return nil, err + } + err := r.Store.DB.Transaction(func(tx *gorm.DB) error { + if err := tx.Where("page = ?", page.Slug).Delete(&models.Box{}).Error; err != nil { + return err + } + return tx.Delete(&page).Error + }) + if err != nil { + return nil, err + } + return &page, nil +} + +// Pages is the resolver for the pages field. +func (r *queryResolver) Pages(ctx context.Context) ([]*models.Page, error) { + // Public, for page indexes such as /shrines; adminOnly pages are only + // listed for an admin. + query := r.Store.DB.Order("slug ASC") + if !IsAdminFromCtx(ctx) { + query = query.Where("admin_only = ?", false) + } + var pages []models.Page + if err := query.Find(&pages).Error; err != nil { + return nil, err + } + return ptrs(pages), nil +} + +// Page is the resolver for the page field. +func (r *queryResolver) Page(ctx context.Context, slug string) (*models.Page, error) { + // Null, not an error, for a missing page: the SPA's catch-all route asks + // this for every unknown path and shows its 404 on null. An adminOnly + // page reads as missing to everyone else, so its existence isn't leaked. + var page models.Page + err := r.Store.DB.Where("slug = ?", slug).First(&page).Error + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, nil + } + if err != nil { + return nil, err + } + if page.AdminOnly && !IsAdminFromCtx(ctx) { + return nil, nil + } + return &page, nil +} diff --git a/backend/graph/page_helpers.go b/backend/graph/page_helpers.go new file mode 100644 index 0000000..70f265f --- /dev/null +++ b/backend/graph/page_helpers.go @@ -0,0 +1,78 @@ +package graph + +// Hand-written helpers for page.resolvers.go and box.resolvers.go, kept out +// of the resolver files for the same reason as box_helpers.go. + +import ( + "context" + "errors" + "regexp" + "strings" + + "adam-french.co.uk/backend/models" + "gorm.io/gorm" +) + +// pageKeyPattern is the shape of a box's page key and of a page slug: lower +// case words joined by hyphens, in one or more /-separated segments. It is +// URL-safe as it stands, so the front end can use a slug as a path without +// escaping it. +var pageKeyPattern = regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*(/[a-z0-9]+(-[a-z0-9]+)*)*$`) + +const maxSlugLen = 100 + +// reservedFirstSegments are paths a page could never be reached at, because +// nginx or one of the SPA's own routes answers them first (see +// nginx/nginx_routes.conf.template and vue/src/router/index.js), plus the +// built-in canvases' page keys, whose boxes a page of the same slug would +// share. "shrines" is deliberately absent: shrine pages live under it. +var reservedFirstSegments = map[string]bool{ + "stp": true, "stp2": true, "index": true, "admin": true, "cv": true, + "automata": true, "hotels": true, "api": true, "py": true, "radio": true, + "gitea": true, "notes": true, "sb": true, "jobs": true, "tracker": true, + "usaco": true, "uploads": true, "img": true, "fonts": true, "pdf": true, + "sound": true, "assets": true, "internal": true, +} + +// reservedSlugs are individual paths the SPA routes itself. +var reservedSlugs = map[string]bool{ + "shrines": true, + "shrines/demoman": true, +} + +func validPageKey(key string) bool { + return len(key) <= maxSlugLen && pageKeyPattern.MatchString(key) +} + +// validateSlug reports why slug can't be a page's address, or nil. +func validateSlug(slug string) error { + if !validPageKey(slug) { + return errors.New("a page address is lower-case letters, digits and hyphens, in /-separated parts, e.g. shrines/evangelion") + } + first, _, _ := strings.Cut(slug, "/") + if reservedFirstSegments[first] || reservedSlugs[slug] { + return errors.New("that address is already used by the site") + } + return nil +} + +// pageHiddenFrom reports whether the page with this key is an adminOnly page +// and the caller is not an admin. A key with no Page row (a built-in canvas, +// or a page that doesn't exist) is not hidden. +func pageHiddenFrom(ctx context.Context, db *gorm.DB, key string) (bool, error) { + if IsAdminFromCtx(ctx) { + return false, nil + } + var count int64 + err := db.Model(&models.Page{}).Where("slug = ? AND admin_only = ?", key, true).Count(&count).Error + return count > 0, err +} + +// slugTaken reports whether a live page other than exceptID has this slug. +// Checked up front so the admin gets a sentence rather than a constraint +// violation; the partial unique index still backs it up. +func slugTaken(db *gorm.DB, slug string, exceptID uint) (bool, error) { + var count int64 + err := db.Model(&models.Page{}).Where("slug = ? AND id <> ?", slug, exceptID).Count(&count).Error + return count > 0, err +} diff --git a/backend/graph/page_helpers_test.go b/backend/graph/page_helpers_test.go new file mode 100644 index 0000000..5b34d75 --- /dev/null +++ b/backend/graph/page_helpers_test.go @@ -0,0 +1,33 @@ +package graph + +import "testing" + +func TestValidateSlug(t *testing.T) { + for _, c := range []struct { + slug string + ok bool + }{ + {"notes-to-self", true}, + {"shrines/evangelion", true}, + {"shrines/neon-genesis/rei2", true}, + {"", false}, + {"Shrines/GTO", false}, // upper case + {"shrines/", false}, // empty segment + {"/shrines/gto", false}, // leading slash + {"shrines//gto", false}, // empty segment + {"shrines/gto-", false}, // trailing hyphen + {"shrines/../admin", false}, // dots + {"shrines", false}, // the SPA's own index + {"shrines/demoman", false}, // an existing SPA route + {"admin/pages", false}, // under an SPA route + {"jobs/x", false}, // under an nginx route + {"stp", false}, // a built-in canvas's key + {"index", false}, // likewise + {"stp-fan-page", true}, // only whole segments are reserved + } { + err := validateSlug(c.slug) + if (err == nil) != c.ok { + t.Errorf("validateSlug(%q) = %v, want ok=%v", c.slug, err, c.ok) + } + } +} diff --git a/backend/graph/schema/box.graphql b/backend/graph/schema/box.graphql index 360493c..ce8a569 100644 --- a/backend/graph/schema/box.graphql +++ b/backend/graph/schema/box.graphql @@ -1,6 +1,8 @@ -# Boxes on the home page canvas (/stp). Anyone may read the layout — it is -# the page — but only an admin may change it. x/y/w/h are px on a fixed -# 1400px-wide design canvas; see models.Box. +# Boxes on a canvas page: the home page (/stp, page "stp"), the landing +# page's overlay (page "index") or an admin-created Page (page = its slug). +# Anyone may read a page's layout — it is the page — but only an admin may +# change it, and adminOnly boxes are only ever returned to an admin. x/y/w/h +# are px on a fixed 1400px-wide design canvas; see models.Box. # # kind is "widget" (a built-in Vue component named by `widget`) or "html" # (`html` rendered in a sandboxed iframe on the front end). @@ -9,6 +11,7 @@ type Box { id: ID! createdAt: Time! updatedAt: Time! + page: String! kind: String! widget: String html: String @@ -20,9 +23,11 @@ type Box { z: Int! framed: Boolean! hideOnMobile: Boolean! + adminOnly: Boolean! } input CreateBoxInput { + page: String! kind: String! widget: String html: String @@ -34,6 +39,7 @@ input CreateBoxInput { z: Int framed: Boolean hideOnMobile: Boolean + adminOnly: Boolean } input UpdateBoxInput { @@ -47,10 +53,11 @@ input UpdateBoxInput { z: Int framed: Boolean hideOnMobile: Boolean + adminOnly: Boolean } extend type Query { - boxes: [Box!]! + boxes(page: String!): [Box!]! } extend type Mutation { diff --git a/backend/graph/schema/page.graphql b/backend/graph/schema/page.graphql new file mode 100644 index 0000000..37d1808 --- /dev/null +++ b/backend/graph/schema/page.graphql @@ -0,0 +1,41 @@ +# Admin-created canvas pages. A page is just a slug and a title; its content +# is the boxes whose `page` is the slug (see box.graphql). The SPA serves it +# at / through its catch-all route, so a slug may not start with a path +# the site already uses — see validateSlug in page_helpers.go. +# +# adminOnly pages, and their boxes, are invisible to everyone but an admin: +# `page` answers null and `pages` leaves them out. + +type Page { + id: ID! + createdAt: Time! + updatedAt: Time! + slug: String! + title: String! + adminOnly: Boolean! +} + +input CreatePageInput { + slug: String! + title: String! + adminOnly: Boolean +} + +input UpdatePageInput { + slug: String + title: String + adminOnly: Boolean +} + +extend type Query { + pages: [Page!]! + page(slug: String!): Page +} + +extend type Mutation { + createPage(input: CreatePageInput!): Page! @admin + # Renaming a page moves its boxes with it. + updatePage(id: ID!, input: UpdatePageInput!): Page! @admin + # Deletes the page's boxes too. + deletePage(id: ID!): Page! @admin +} diff --git a/backend/models/models.go b/backend/models/models.go index 84bc302..3377c07 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -156,29 +156,52 @@ type Place struct { Done bool `gorm:"default:false" json:"done"` } -// Box is one panel on the home page canvas (/stp). Its position and size are -// in px on a fixed 1400px-wide design canvas, which the page scales down on -// narrower screens — so the stored numbers mean the same thing for every -// visitor. Kind "widget" renders a built-in Vue component named by Widget; +// Box is one panel on a canvas page. Page names the canvas it belongs to: +// "stp" for the home page, "index" for the landing page's overlay, or a +// Page.Slug for an admin-created page — it is a key, not a foreign key, so the +// built-in canvases need no Page row. Its position and size are in px on a +// fixed 1400px-wide design canvas, which the page scales down on narrower +// screens — so the stored numbers mean the same thing for every visitor. Kind "widget" renders a built-in Vue component named by Widget; // kind "html" renders HTML in a sandboxed iframe on the front end, which is // what makes storing admin-authored script here acceptable. type Box struct { - ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` - Kind string `gorm:"not null" json:"kind"` - Widget *string `json:"widget"` - HTML *string `json:"html"` - Title *string `json:"title"` - X int `gorm:"not null;default:0" json:"x"` - Y int `gorm:"not null;default:0" json:"y"` - W int `gorm:"not null;default:300" json:"w"` - H int `gorm:"not null;default:200" json:"h"` - Z int `gorm:"not null;default:0" json:"z"` + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` + // default:stp is what the boxes that predate pages are migrated to. + Page string `gorm:"not null;default:stp;index" json:"page"` + Kind string `gorm:"not null" json:"kind"` + Widget *string `json:"widget"` + HTML *string `json:"html"` + Title *string `json:"title"` + X int `gorm:"not null;default:0" json:"x"` + Y int `gorm:"not null;default:0" json:"y"` + W int `gorm:"not null;default:300" json:"w"` + H int `gorm:"not null;default:200" json:"h"` + Z int `gorm:"not null;default:0" json:"z"` // No gorm default on Framed: GORM omits zero values for defaulted columns // on insert, so default:true would turn an explicit false into true. // CreateBox applies the true default itself. - Framed bool `gorm:"not null" json:"framed"` - HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"` + Framed bool `gorm:"not null" json:"framed"` + HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"` + // AdminOnly boxes are never sent to anyone but an admin (the boxes + // resolver filters them out), so they suit private notes. + AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` +} + +// Page is an admin-created canvas page, served by the SPA's catch-all route +// at / (e.g. "shrines/evangelion"). Its content is the Boxes whose Page +// equals Slug. The unique index is partial so that a deleted page's slug can +// be reused — a plain uniqueIndex would still collide with the soft-deleted +// row. +type Page struct { + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` + Slug string `gorm:"not null;index:idx_pages_slug,unique,where:deleted_at IS NULL" json:"slug"` + Title string `gorm:"not null" json:"title"` + // AdminOnly hides the whole page, boxes included, from everyone else. + AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` } diff --git a/backend/services/database.go b/backend/services/database.go index 250558e..3eef1ae 100644 --- a/backend/services/database.go +++ b/backend/services/database.go @@ -52,6 +52,7 @@ func migrateDatabase(db *gorm.DB) error { &models.Bookmark{}, &models.Place{}, &models.Box{}, + &models.Page{}, ) if err != nil { return err diff --git a/vue/README.md b/vue/README.md index 2aad099..6d5e780 100644 --- a/vue/README.md +++ b/vue/README.md @@ -65,13 +65,13 @@ Two layout shells, defined in `src/router/index.js`: | Path | Layout | Notes | | --- | --- | --- | -| `/` | DefaultLayout | Landing page (statically imported — it's the first paint) | +| `/` | DefaultLayout | Landing page (statically imported — it's the first paint), with a canvas overlay for pinned notes (page key `index`) | | `/stp` | DefaultLayout | The personal home page: an admin-editable canvas of boxes (`views/home3/`, see "The /stp canvas" below) | | `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` | -| `/automata`, `/hotels`, `/shrines/*` | DefaultLayout | | +| `/automata`, `/hotels`, `/shrines`, `/shrines/demoman` | DefaultLayout | Every other shrine is a canvas page | | `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); nginx redirects the old `/cv/jobs` and `/cv/leads` there | | `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts | -| `:pathMatch(.*)*` | DefaultLayout | 404 | +| `:pathMatch(.*)*` | DefaultLayout | `views/canvas/CanvasPage.vue`: an admin-created canvas page if one exists at the path, else the 404 (with a "create a page here" form for admins) | Everything except the landing page is a dynamic `import()`, so Vite gives each view its own chunk. @@ -169,7 +169,8 @@ true only once a fetch has succeeded, meaning the data is real. Waiting on | `auth` | current user (`ensureLoaded()`, see Routing), plus login/logout mutations | | `posts`, `favorites`, `activity`, `songs`, `steam` | mirror one slice of `homeData` via an `immediate` watch, and keep a placeholder value until real data arrives | | `places` | CRUD via `createCrudStore`; sign-in only, so it is fetched lazily | -| `boxes` | CRUD via `createCrudStore`; the `/stp` canvas layout. Public read, admin write | +| `boxes` | CRUD via `createCrudStore`, one store per canvas page: `useBoxesStore(page)`. Public read (admin-only boxes excepted), admin write | +| `pages` | CRUD via `createCrudStore`; the admin-created canvas pages. Public read (admin-only pages excepted), admin write | | `messages` | the chat WebSocket — not GraphQL at all | | `models` | dormant; not imported anywhere | @@ -188,7 +189,9 @@ Two factories keep the repeated shapes in one place: differences between types: `itemsKey` (the name the array is exposed under), `insert` (`"prepend"` or `"append"`), `deleteReturns` (`"object"` for `deletePlace`, `"boolean"` for a delete that returns a - scalar — a scalar must not be given a selection set) and `extend` for extra actions. + scalar — a scalar must not be given a selection set), `args` (fixed + arguments for the list query, e.g. the boxes store's `page`) and `extend` + for extra actions. The error contract is deliberate: `fetch()` never throws and records the failure on `error`; the mutations throw, so the form that called them can @@ -198,10 +201,29 @@ Two factories keep the repeated shapes in one place: `/stp` is a set of **boxes** (`Box` in GraphQL, `stores/boxes.js`) that an admin creates, drags, resizes and edits in the browser. Changes save to the database, -so every visitor sees the saved layout. All of it lives in `views/home3/`: +so every visitor sees the saved layout. The canvas is `views/home3/BoxCanvas.vue`, +and it is not only `/stp`: every box has a `page` key, and the same component +renders any page's boxes. +- **Pages.** `"stp"` is `/stp` (`Home3.vue`). `"index"` is the landing page, + where the canvas is an `overlay` over the page's own content: it takes no + room when empty, lets clicks through except on boxes, and reports its height + so the page grows to fit. Any other key is the slug of a **`Page`** (GraphQL + type, `stores/pages.js`), an admin-created page served at `/` by the + router's catch-all (`views/canvas/CanvasPage.vue`). Pages are created from + the admin panel's Pages tab, from `/shrines`, or from the 404 of the address + you want; each can start from a layout in `views/canvas/pageStarters.js` + (Blank, Shrine, Notes board). Title, address and visibility are under "Page + settings" on the page; renaming moves its boxes, deleting takes them too. + The server refuses slugs that an SPA or nginx route would answer first + (`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when + adding a route. +- **Admin only.** A box or a page can be marked admin-only. The server never + sends those to anyone else, so they are fit for private notes; admins see + such boxes outlined, with a 🔒 in edit mode. The "Note" template starts + admin-only. - **Coordinates.** `x`/`y`/`w`/`h` are px on a fixed 1400px-wide design canvas. - `Home3.vue` draws the canvas at that width and shrinks it with + `BoxCanvas.vue` draws the canvas at that width and shrinks it with `transform: scale()` to fit the window, so the arrangement is identical at every desktop width. `BoxFrame.vue` divides pointer deltas by that scale. `z` is the CSS z-index. @@ -221,9 +243,11 @@ so every visitor sees the saved layout. All of it lives in `views/home3/`: saves on pointer release, and the box is moved locally first and put back if the save fails. `BoxEditor.vue` is the side panel. Settings save on change; HTML is a draft that previews live and saves with Save or Ctrl/Cmd+S. - CodeMirror is loaded only when that panel opens. Starter HTML is in - `templates.js`. "Import current layout" (shown only on an empty canvas) - recreates the old `Home.vue` grid from `defaultLayout.js`. + CodeMirror is loaded only when that panel opens. "Insert upload" stores a + file through the chat's public upload endpoint and puts an ``/`