feat: tags, unpublish and image upload for the author

- GET /_bm/api/v1/tags: the jz_bm_tags dictionary, to material managers
- POST /materials/{id}/unpublish: back to drafts, no revision bump, the
  search document resynced
- POST /materials/{id}/images: one JPEG/PNG/GIF/WebP per request through
  storeMaterialUpload, refusals with reason type, size or count
- storeMaterialUpload/fileRefusalFor: attach.ErrNotImage is a type
  refusal, not a 500; storeMaterialFile keeps its texts
- the author's routes get their own per-user buckets (the inline
  throttle form shares one counter per user)
- README: the author routes and revision on the student detail
This commit is contained in:
Jakub Zych
2026-11-09 01:05:54 +01:00
parent 7bf18de987
commit 40e4a2438b
9 changed files with 499 additions and 27 deletions

View File

@@ -503,6 +503,9 @@ var authorRoutes = []string{
"GET /materials/{id}/access",
"PUT /materials/{id}/access",
"PUT /materials/{id}",
"GET /tags",
"POST /materials/{id}/unpublish",
"POST /materials/{id}/images",
}
// TestTokenMirrorRoutes is the invariant of the two student surfaces: every
@@ -733,3 +736,34 @@ func TestManageBucketKey(t *testing.T) {
t.Errorf("token twin key = %q, want jz.bm.token|u:7", got)
}
}
// TestAuthorBucketKeys: the author's material routes are throttled per user,
// each under its own name, so an editor's saves and uploads never use up
// the unpublish budget.
func TestAuthorBucketKeys(t *testing.T) {
buckets := (&bm.Plugin{}).Buckets()
req := httptest.NewRequest(http.MethodPut, "/", nil)
req = req.WithContext(bouncer.WithUser(req.Context(), &bouncer.Principal{ID: 7}))
keys := map[string]bool{}
for name, max := range map[string]int{"jz.bm.material-edit": 30, "jz.bm.material-images": 30, "jz.bm.material-unpublish": 10} {
b, ok := buckets[name]
if !ok {
t.Errorf("%s is not declared", name)
continue
}
if b.Max != max {
t.Errorf("%s Max = %d, want %d", name, b.Max, max)
}
key := b.Key(req)
if key != name+"|u:7" {
t.Errorf("%s key = %q, want %s|u:7", name, key, name)
}
keys[key] = true
if got := b.Key(httptest.NewRequest(http.MethodPut, "/", nil)); !strings.HasPrefix(got, name+"|ip:") {
t.Errorf("%s bare key = %q, want the IP", name, got)
}
}
if len(keys) != 3 {
t.Errorf("keys = %v, want three distinct counters", keys)
}
}