The applications tracker, leads inbox, email pipeline and capture userscript move here from web_server's backend, Python service and Vue app, as one Go binary that serves its own Vue SPA under /jobs/. - The Go services, resolvers and tests move over almost unchanged. - The three Claude calls are ported from Python to Go (internal/claude), with the same prompts, per-model request shaping and error messages. - There is no login: internal/auth asks the site backend's /auth/validate-admin with the visitor's cookies, and relays refreshed cookies back. - A Settings page replaces the admin-panel capture token card and adds the Microsoft sign-in link and a manual email sync. - The userscript is 2.0.0, at /jobs/, and migrates a saved API base. - Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI workflow that tests and publishes the image. Co-Authored-By: Claude Opus 5.5 <[email protected]>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package graph
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/99designs/gqlgen/graphql"
|
|
|
|
"adam-french.co.uk/job-tracker/internal/auth"
|
|
)
|
|
|
|
// The schema's authorisation directive. A field marked @admin in
|
|
// schema/*.graphql has requireAdmin run before its resolver; if it returns an
|
|
// error the resolver is never called and the error is what the client
|
|
// receives for that field.
|
|
//
|
|
// The verdict itself comes from internal/auth, which asked the site backend
|
|
// before GraphQL ran (auth.Annotate in main).
|
|
//
|
|
// The error string is part of the contract with the front end, which explains
|
|
// "admin access required" as a lapsed session and sends the browser to the
|
|
// site's login. Do not reword it.
|
|
//
|
|
// This file is hand-written and never touched by gqlgen.
|
|
const errAdminRequired = "admin access required"
|
|
|
|
// Directives is the set gqlgen needs in graph.Config. It is a function so
|
|
// that main and the tests wire exactly the same implementations.
|
|
//
|
|
// Leaving a directive nil in the Config does not open the fields that use it:
|
|
// the generated code answers "directive admin is not implemented" for each.
|
|
func Directives() DirectiveRoot {
|
|
return DirectiveRoot{Admin: requireAdmin}
|
|
}
|
|
|
|
// requireAdmin implements @admin.
|
|
func requireAdmin(ctx context.Context, _ any, next graphql.Resolver) (any, error) {
|
|
if !auth.IsAdminFromCtx(ctx) {
|
|
return nil, errors.New(errAdminRequired)
|
|
}
|
|
return next(ctx)
|
|
}
|