Extract internal/projects.Service.Create (H-9) #104
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
qwc-open/asiakirjat!104
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/projects-service-create"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Workstream item #9. Audit finding H-9 (High) — three divergent project-create paths.
handleAdminCreateProject(admin form),handleAPICreateProject(POST /api/projects), andautoCreateProject(upload to nonexistent slug) each re-implemented the same sequence: slug validation, visibility defaulting, public-visibility-admin gate,projects.Create,EnsureProjectDir, auto-grant editor access. They had already drifted — the admin form was missing slug validation pre-#96, the API path didn't parseretention_days, auto-create skipped both visibility validation and retention. Several earlier audit findings (C-5, M-5) had to be fixed in parallel across all three.Changes
internal/projectspackage withService.Create(ctx, CreateOptions). Validation + visibility gate + persist + storage-dir + creator auto-grant all live here. Storage-dir failure is non-fatal (matches prior behavior).ErrInvalidSlugErrInvalidVisibilityErrPublicRequiresAdminErrSlugConflictservice.Create→ switch on error kind. Net 63-line reduction across them.errors.Is(err, projects.ErrSlugConflict)to fall back toGetBySlugfor the race-recovery path that was previously matched by substring on the error message.handler.Newfrom the existingDeps.main.gois unchanged.Test plan
go test ./...passes — including all the existing handler tests around create (TestEditorCanCreateProject,TestEditorCreateCustomProjectGetsAccess, the public-visibility-admin set,auto_create_test)visibility=publicvia API → 403auto_create: true→ project appears with private visibility and editor sees it on their list🤖 Generated with Claude Code