Declare GraphQL auth in the schema and drop the Go Claude client
Authorisation: @admin and @signedIn schema directives replace the 25 hand-copied resolver checks. A test fails if a mutation has neither and is not on the public allow-list, so a new mutation cannot ship unguarded. IDs: uint model IDs bind through graphql.UintID, removing the ten int(obj.ID) resolvers. Job status is a GraphQL enum, tied to services.statusOrder by a test. Input is strict, so the mutations no longer coerce an unknown status to "applied"; output is lenient so one legacy row cannot fail the list. deleteJobApplication and deleteJobAppReference now error on a missing id like the other deletes. The rowing reader, the job extractor and now the email classifier reach the Python service through one services.CallPython helper. The email pipeline's prompt and fence stripping moved to Python, and anthropic-sdk-go is gone from go.mod. Fix the auth test fixture, whose 11-byte secret had been panicking the services test package since InitAuth began requiring 32 bytes. Add a test that keeps the python service's compose environment list in step with the env registry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -18,5 +18,5 @@ extend type Query {
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createActivity(input: CreateActivityInput!): Activity!
|
||||
createActivity(input: CreateActivityInput!): Activity! @admin
|
||||
}
|
||||
|
||||
@@ -7,10 +7,14 @@ type AuthPayload {
|
||||
user: User!
|
||||
}
|
||||
|
||||
# `me` carries no directive although it needs a session: it answers
|
||||
# "unauthorized", not @signedIn's "authentication required", and the front end
|
||||
# relies on that query failing quietly for an anonymous visitor.
|
||||
extend type Query {
|
||||
me: User
|
||||
}
|
||||
|
||||
# Deliberately public: these are how a session is obtained and given up.
|
||||
extend type Mutation {
|
||||
login(input: LoginInput!): AuthPayload!
|
||||
logout: Boolean!
|
||||
|
||||
@@ -18,6 +18,6 @@ extend type Query {
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createBookmark(input: CreateBookmarkInput!): Bookmark!
|
||||
deleteBookmark(id: ID!): Bookmark!
|
||||
createBookmark(input: CreateBookmarkInput!): Bookmark! @admin
|
||||
deleteBookmark(id: ID!): Bookmark! @admin
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ extend type Query {
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createFavorite(input: CreateFavoriteInput!): Favorite!
|
||||
createFavorite(input: CreateFavoriteInput!): Favorite! @admin
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# Reusable snippets for filling in application forms. Private, like the
|
||||
# applications themselves, so the query is @admin as well as the mutations.
|
||||
|
||||
type JobAppReference {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
@@ -23,11 +26,13 @@ input UpdateJobAppReferenceInput {
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobAppReferences: [JobAppReference!]!
|
||||
jobAppReferences: [JobAppReference!]! @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobAppReference(input: CreateJobAppReferenceInput!): JobAppReference!
|
||||
updateJobAppReference(id: ID!, input: UpdateJobAppReferenceInput!): JobAppReference!
|
||||
deleteJobAppReference(id: ID!): Boolean!
|
||||
createJobAppReference(input: CreateJobAppReferenceInput!): JobAppReference! @admin
|
||||
updateJobAppReference(id: ID!, input: UpdateJobAppReferenceInput!): JobAppReference! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true.
|
||||
deleteJobAppReference(id: ID!): Boolean! @admin
|
||||
}
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
# Job application tracker. Rows come from these mutations, automatically from
|
||||
# the email sync pipeline (backend/services/email_sync.go), or from the browser
|
||||
# capture userscript (backend/handlers/handle_job_capture.go). These are
|
||||
# private data, so the queries here are admin-only as well as the mutations.
|
||||
#
|
||||
# status is a free-form String, but only the values ranked in
|
||||
# services.statusOrder can be advanced automatically by the email pipeline:
|
||||
# saved, applied, screening, assessment, interviewing, offer, rejected,
|
||||
# withdrawn.
|
||||
# private data, so the queries here are @admin as well as the mutations.
|
||||
#
|
||||
# description is the captured posting text. It can run to tens of kilobytes,
|
||||
# so the tracker's list query leaves it out and asks for it per row.
|
||||
|
||||
# The lifecycle of an application, in the order the email pipeline and the
|
||||
# capture endpoint are allowed to advance it. The values are lowercase on
|
||||
# purpose: they are exactly the strings stored in the status column and ranked
|
||||
# in services.statusOrder (backend/services/email_sync.go), and a test there
|
||||
# fails if this list and that map ever differ. Adding a status means adding
|
||||
# it in both places, and to the tracker page and the capture userscript.
|
||||
#
|
||||
# It is bound to a custom marshaller (services/job_status.go, via gqlgen.yml)
|
||||
# rather than a generated Go type: input is strict, so a mutation carrying a
|
||||
# status outside this list is refused, while output passes a legacy stored
|
||||
# value through so one old row cannot fail the whole jobApplications query.
|
||||
#
|
||||
# On the wire it is still a JSON string ("applied"), as it was when the field
|
||||
# was a String, both in variables and in responses.
|
||||
enum JobStatus {
|
||||
saved
|
||||
applied
|
||||
screening
|
||||
assessment
|
||||
interviewing
|
||||
offer
|
||||
rejected
|
||||
withdrawn
|
||||
}
|
||||
|
||||
type JobApplication {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
@@ -19,7 +39,7 @@ type JobApplication {
|
||||
company: String!
|
||||
location: String
|
||||
url: String
|
||||
status: String!
|
||||
status: JobStatus!
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
@@ -30,7 +50,7 @@ input CreateJobApplicationInput {
|
||||
company: String!
|
||||
location: String
|
||||
url: String
|
||||
status: String!
|
||||
status: JobStatus!
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
@@ -41,19 +61,21 @@ input UpdateJobApplicationInput {
|
||||
company: String
|
||||
location: String
|
||||
url: String
|
||||
status: String
|
||||
status: JobStatus
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobApplications: [JobApplication!]!
|
||||
jobApplication(id: ID!): JobApplication
|
||||
jobApplications: [JobApplication!]! @admin
|
||||
jobApplication(id: ID!): JobApplication @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobApplication(input: CreateJobApplicationInput!): JobApplication!
|
||||
updateJobApplication(id: ID!, input: UpdateJobApplicationInput!): JobApplication!
|
||||
deleteJobApplication(id: ID!): Boolean!
|
||||
createJobApplication(input: CreateJobApplicationInput!): JobApplication! @admin
|
||||
updateJobApplication(id: ID!, input: UpdateJobApplicationInput!): JobApplication! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true.
|
||||
deleteJobApplication(id: ID!): Boolean! @admin
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#
|
||||
# Two gotchas: authorId is a per-connection counter from the chat hub, not a
|
||||
# User id, and private messages are silently filtered out for non-admins
|
||||
# rather than causing an error.
|
||||
# rather than causing an error — which is why the query has no @admin: the
|
||||
# resolver makes that decision per row.
|
||||
|
||||
type Message {
|
||||
id: ID!
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Places to go. Unlike most mutations these require only a signed-in user,
|
||||
# not an admin, and there is no per-user ownership: the list is shared.
|
||||
# Places to go. Unlike most mutations these require only a signed-in user
|
||||
# (@signedIn), not an admin, and there is no per-user ownership: the list is
|
||||
# shared. The query is guarded too — the list is not public.
|
||||
|
||||
type Place {
|
||||
id: ID!
|
||||
@@ -38,11 +39,11 @@ input UpdatePlaceInput {
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
places: [Place!]!
|
||||
places: [Place!]! @signedIn
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createPlace(input: CreatePlaceInput!): Place!
|
||||
updatePlace(id: ID!, input: UpdatePlaceInput!): Place!
|
||||
deletePlace(id: ID!): Place!
|
||||
createPlace(input: CreatePlaceInput!): Place! @signedIn
|
||||
updatePlace(id: ID!, input: UpdatePlaceInput!): Place! @signedIn
|
||||
deletePlace(id: ID!): Place! @signedIn
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ extend type Query {
|
||||
post(id: ID!): Post
|
||||
}
|
||||
|
||||
# @admin is only the first half of the rule for updatePost and deletePost:
|
||||
# the resolver also requires the caller to be the post's author.
|
||||
extend type Mutation {
|
||||
createPost(input: CreatePostInput!): Post!
|
||||
updatePost(id: ID!, input: UpdatePostInput!): Post!
|
||||
deletePost(id: ID!): Post!
|
||||
createPost(input: CreatePostInput!): Post! @admin
|
||||
updatePost(id: ID!, input: UpdatePostInput!): Post! @admin
|
||||
deletePost(id: ID!): Post! @admin
|
||||
}
|
||||
|
||||
@@ -16,5 +16,22 @@
|
||||
|
||||
scalar Time
|
||||
|
||||
# Authorisation. There is no middleware in front of /graphql, so a field is
|
||||
# PUBLIC unless it carries one of these. Each is implemented once, in
|
||||
# graph/directives.go, and runs before the field's resolver:
|
||||
#
|
||||
# @admin the request must carry an admin's access token
|
||||
# (error: "admin access required")
|
||||
# @signedIn any valid access token will do
|
||||
# (error: "authentication required")
|
||||
#
|
||||
# Every mutation needs one of them unless it is deliberately public (login,
|
||||
# logout, refreshToken); graph/directives_test.go fails otherwise, and pins
|
||||
# which queries are guarded. Rules that are not a plain gate stay in the
|
||||
# resolver: a post is only editable by its author, `me` answers for whoever is
|
||||
# signed in, and `messages` filters private rows rather than refusing.
|
||||
directive @admin on FIELD_DEFINITION
|
||||
directive @signedIn on FIELD_DEFINITION
|
||||
|
||||
type Query
|
||||
type Mutation
|
||||
|
||||
@@ -36,6 +36,7 @@ extend type Query {
|
||||
spotifyRecent: [SpotifyRecentItem!]
|
||||
# True only for an admin session while the backend lacks a Spotify client
|
||||
# (OAuth never completed or the token was revoked), used by the Listening
|
||||
# widget to offer a reconnect link. Everyone else gets false.
|
||||
# widget to offer a reconnect link. Everyone else gets false — a soft
|
||||
# check in the resolver, not @admin, so the home page query never errors.
|
||||
spotifyNeedsReauth: Boolean!
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ input CreateUserInput {
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
users: [User!]!
|
||||
user(id: ID!): User
|
||||
users: [User!]! @admin
|
||||
user(id: ID!): User @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createUser(input: CreateUserInput!): User!
|
||||
deleteUser(id: ID!): User!
|
||||
setUserAdmin(id: ID!, admin: Boolean!): User!
|
||||
createUser(input: CreateUserInput!): User! @admin
|
||||
deleteUser(id: ID!): User! @admin
|
||||
setUserAdmin(id: ID!, admin: Boolean!): User! @admin
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user