Add auto-create projects on upload and API create endpoint #92

Merged
qwc merged 1 commit from feature/auto-create-projects into main 2026-03-06 11:29:51 +01:00
Owner

Summary

  • Add projects.auto_create config option (default: false) — when enabled, uploading to a non-existent project slug automatically creates the project with private visibility
  • Add POST /api/projects endpoint for explicit project creation via API (JSON body with slug, name, description, visibility)
  • Change default visibility for new projects from custom to private (admin UI form + Go fallback)
  • Add slug validation helper (^[a-z0-9]+(?:-[a-z0-9]+)*$, 1-128 chars)

Auto-create behavior

  • Requires admin or editor role
  • API auto-create uses unscoped auth (global tokens only, since no project exists for scope validation)
  • Web UI auto-create works for logged-in editors/admins
  • Race condition handling: if concurrent creates cause a unique constraint error, falls back to GetBySlug
  • Non-admin creators are auto-granted editor access

Files changed

  • internal/config/config.go — new ProjectsConfig struct
  • internal/handler/auto_create.goisValidSlug, canAutoCreate, autoCreateProject
  • internal/handler/api.go — restructured handleAPIUploadWithSlug + new handleAPICreateProject
  • internal/handler/upload.go — auto-create in web upload path
  • internal/handler/admin.go — visibility fallback customprivate
  • internal/templates/pages/admin_projects.html — default selection + label fix
  • Docs: API reference, configuration reference, CI/CD integration guide

Test plan

  • go build succeeds
  • All existing tests pass
  • New tests: TestIsValidSlug, TestAPIUploadAutoCreate*, TestWebUploadAutoCreateProject, TestAPICreateProject*
  • Manual: enable projects.auto_create: true, upload to new slug via API, verify project created
  • Manual: create project via POST /api/projects, verify 201 response
  • Manual: verify viewer token gets 403 on auto-create attempt
  • Manual: verify duplicate slug returns 409

🤖 Generated with Claude Code

## Summary - Add `projects.auto_create` config option (default: `false`) — when enabled, uploading to a non-existent project slug automatically creates the project with `private` visibility - Add `POST /api/projects` endpoint for explicit project creation via API (JSON body with `slug`, `name`, `description`, `visibility`) - Change default visibility for new projects from `custom` to `private` (admin UI form + Go fallback) - Add slug validation helper (`^[a-z0-9]+(?:-[a-z0-9]+)*$`, 1-128 chars) ### Auto-create behavior - Requires admin or editor role - API auto-create uses unscoped auth (global tokens only, since no project exists for scope validation) - Web UI auto-create works for logged-in editors/admins - Race condition handling: if concurrent creates cause a unique constraint error, falls back to `GetBySlug` - Non-admin creators are auto-granted editor access ### Files changed - `internal/config/config.go` — new `ProjectsConfig` struct - `internal/handler/auto_create.go` — `isValidSlug`, `canAutoCreate`, `autoCreateProject` - `internal/handler/api.go` — restructured `handleAPIUploadWithSlug` + new `handleAPICreateProject` - `internal/handler/upload.go` — auto-create in web upload path - `internal/handler/admin.go` — visibility fallback `custom` → `private` - `internal/templates/pages/admin_projects.html` — default selection + label fix - Docs: API reference, configuration reference, CI/CD integration guide ## Test plan - [x] `go build` succeeds - [x] All existing tests pass - [x] New tests: `TestIsValidSlug`, `TestAPIUploadAutoCreate*`, `TestWebUploadAutoCreateProject`, `TestAPICreateProject*` - [ ] Manual: enable `projects.auto_create: true`, upload to new slug via API, verify project created - [ ] Manual: create project via `POST /api/projects`, verify 201 response - [ ] Manual: verify viewer token gets 403 on auto-create attempt - [ ] Manual: verify duplicate slug returns 409 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add auto-create projects on upload and API create project endpoint
All checks were successful
CI / test (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 46s
CI / docker (pull_request) Has been skipped
613c548b7e
- Add projects.auto_create config option (default: false) to allow
  automatic project creation when uploading to a non-existent slug
- Add POST /api/projects endpoint for explicit project creation via API
- Auto-created projects get private visibility and creator gets editor access
- API auto-create requires global (unscoped) tokens since no project exists
  for scope validation; project-scoped tokens work only for existing projects
- Change default visibility for new projects from custom to private
- Add slug validation (lowercase alphanumeric with hyphens, 1-128 chars)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
qwc merged commit ccd9ef21b2 into main 2026-03-06 11:29:51 +01:00
qwc deleted branch feature/auto-create-projects 2026-03-06 11:29:51 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
qwc-open/asiakirjat!92
No description provided.