app

package
v3.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package app is glabs-web's core: the layer the GraphQL resolvers delegate to, holding the database and enforcing that every request acts only as its own user. Resolvers stay thin — auth gate plus a call into here — so the rules live in one place rather than scattered across the schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(database *db.DB, sealer *secrets.Sealer, gitlabHost string) *App

func (*App) Assignment added in v3.4.0

func (a *App) Assignment(ctx context.Context, course, name string) (*AssignmentView, error)

Assignment returns the source values and resolved preview for one assignment of one of the caller's own courses. It returns nil (no error) when the course exists but has no assignment by that name; ErrCourseNotFound propagates when the course itself is not the caller's.

func (*App) Course added in v3.2.0

func (a *App) Course(ctx context.Context, name string) (*db.StoredCourse, error)

Course returns one of the caller's own courses.

func (*App) CourseLint added in v3.2.0

func (a *App) CourseLint(ctx context.Context, name string) ([]config.Finding, error)

CourseLint returns the lint findings for one of the caller's own courses.

func (*App) CourseYAML added in v3.2.0

func (a *App) CourseYAML(ctx context.Context, name string) ([]byte, error)

CourseYAML returns the course as a downloadable YAML file: the original bytes if they are still current, otherwise a re-encoding of the stored source.

func (*App) Courses added in v3.2.0

func (a *App) Courses(ctx context.Context) ([]*db.StoredCourse, error)

Courses returns the caller's own courses.

func (*App) CreateCourse added in v3.9.0

func (a *App) CreateCourse(ctx context.Context, name, coursePath, semesterPath string, useCoursenameAsPrefix, useEmailDomainAsSuffix bool) (*db.StoredCourse, error)

CreateCourse creates a new, empty course from scratch for the caller. It fails if the caller already has a course by that name — assignments are added afterwards with SetAssignment.

func (*App) DeleteAssignment added in v3.9.0

func (a *App) DeleteAssignment(ctx context.Context, course, name string) (bool, error)

DeleteAssignment removes one assignment from one of the caller's courses and re-marshals the course YAML. It returns false when there was no such assignment (and does not touch the course).

func (*App) DeleteCourse added in v3.2.0

func (a *App) DeleteCourse(ctx context.Context, name string) error

DeleteCourse removes one of the caller's own courses.

func (*App) GetUserByEmail

func (a *App) GetUserByEmail(ctx context.Context, email string) (*model.User, error)

GetUserByEmail looks up a user for the auth middleware's allowlist check.

func (*App) GitLabTokenStatus added in v3.3.0

func (a *App) GitLabTokenStatus(ctx context.Context) (*GitLabTokenStatus, error)

GitLabTokenStatus reports whether the caller has a stored token, without decrypting or returning it.

func (*App) ImportCourseYAML added in v3.2.0

func (a *App) ImportCourseYAML(ctx context.Context, yaml string) (*db.StoredCourse, error)

ImportCourseYAML parses an uploaded course file and stores it for the caller, keeping the original bytes so a later download returns exactly what was uploaded. Importing a course whose name already exists replaces it.

An inline seeder signKey is rejected: it is a private key, and storing it would mean sealing it, hiding it in GraphQL, and excluding it from dumps — four leaks for a feature no course file uses. signKeyFile (a path) is fine.

func (*App) LocalDevUser

func (a *App) LocalDevUser() *model.User

LocalDevUser is the identity used when auth is disabled (local development). It is never consulted when auth is enabled.

func (*App) RemoveGitLabToken added in v3.3.0

func (a *App) RemoveGitLabToken(ctx context.Context) (*GitLabTokenStatus, error)

RemoveGitLabToken deletes the caller's stored GitLab PAT.

func (*App) ServerInfo

func (a *App) ServerInfo() *model.ServerInfo

ServerInfo returns the build metadata main stashed in viper (ldflags at release, VCS info otherwise), so the GUI can show which build is running.

func (*App) SetAssignment added in v3.6.0

func (a *App) SetAssignment(ctx context.Context, course, name string, draft map[string]string) (*AssignmentView, error)

SetAssignment applies a draft to one of the caller's assignments: it validates, rejects a concrete draft that does not resolve, then persists — re-marshalling the whole course YAML (a real edit gives up the verbatim original bytes).

func (*App) SetCourse added in v3.10.0

func (a *App) SetCourse(ctx context.Context, name, coursePath, semesterPath string, useCoursenameAsPrefix, useEmailDomainAsSuffix bool) (*db.StoredCourse, error)

SetCourse updates the course-level settings of one of the caller's courses, leaving assignments, students and groups untouched, and re-marshals the course YAML.

func (*App) SetGitLabToken added in v3.3.0

func (a *App) SetGitLabToken(ctx context.Context, token string) (*GitLabTokenStatus, error)

SetGitLabToken stores the caller's GitLab PAT, AES-256-GCM encrypted. Write-only: the token is never returned by any query, and the plaintext is never persisted or logged. Fails closed if no secrets.key is configured.

func (*App) ValidateAssignmentDraft added in v3.6.0

func (a *App) ValidateAssignmentDraft(ctx context.Context, course, name string, draft map[string]string) (*ValidationResult, error)

ValidateAssignmentDraft validates a draft against the real resolver without saving.

type AssignmentView added in v3.4.0

type AssignmentView struct {
	Course   string
	Name     string
	Extends  string
	Abstract bool
	// Own holds the assignment's own (source) field values, keyed by
	// FieldMeta.key, for pre-filling the editor form.
	Own []FieldValue
	// Resolved is the Show() rendering (may contain ANSI). Empty when the
	// assignment cannot be resolved (then ResolveError explains why).
	Resolved string
	// ResolveError is set when resolution fails — e.g. an abstract base, a
	// missing parent, or an `extends` cycle. Not a fault: an abstract base is a
	// valid document that simply has no resolved form.
	ResolveError string
}

AssignmentView is one assignment in source (own) form plus its resolved preview — the same rendering `glabs show` produces. It makes the inheritance visible in the browser exactly as the CLI's confirmation gate does.

type FieldKind added in v3.4.0

type FieldKind string

FieldKind is the input shape the GUI should render for a field.

const (
	KindString     FieldKind = "STRING"
	KindBool       FieldKind = "BOOL"
	KindEnum       FieldKind = "ENUM"
	KindInt        FieldKind = "INT"
	KindStringList FieldKind = "STRINGLIST"
)

type FieldMeta added in v3.4.0

type FieldMeta struct {
	Key         string
	Label       string
	Description string
	// Group is the section the field belongs to ("" for the top-level group,
	// e.g. "Startercode" for the startercode block), so the GUI can render
	// grouped sections. Nested keys are dotted, e.g. "startercode.url".
	Group      string
	Kind       FieldKind
	Required   bool
	Deprecated bool
	Example    string
	Options    []FieldOption
}

FieldMeta describes one editable assignment field.

func AssignmentSchema added in v3.4.0

func AssignmentSchema() []FieldMeta

AssignmentSchema returns the metadata for the assignment editor's fields.

type FieldOption added in v3.4.0

type FieldOption struct {
	Value       string
	Label       string
	Description string
}

FieldOption is one choice of an ENUM field — a dropdown entry with its own short description.

type FieldValue added in v3.5.0

type FieldValue struct {
	Key   string
	Value string
}

FieldValue is one field's own (source) value, stringified and keyed by the same key as FieldMeta so the GUI can pre-fill the schema-driven form.

type GitLabTokenStatus added in v3.3.0

type GitLabTokenStatus struct {
	Set       bool
	UpdatedAt *time.Time
}

GitLabTokenStatus reports whether the caller has stored a GitLab token and when — never the token itself.

type ValidationResult added in v3.6.0

type ValidationResult struct {
	OK           bool
	Errors       []string
	Resolved     string
	ResolveError string
}

ValidationResult reports whether a draft assignment is saveable and — when it resolves — its preview.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL