fix(cabana): scope mail image lookups, recompute variant URLs, and return 409 on duplicate folders
This commit is contained in:
@@ -158,6 +158,9 @@ func TestMediaUploadLifecycleAndAfterCommitDelete(t *testing.T) {
|
||||
folder := env.expect(t, http.StatusCreated, http.MethodPost, "/media/folders", managerTok, map[string]any{"name": "Heroes"})
|
||||
fid := uint(dataOf(folder)["id"].(float64))
|
||||
|
||||
// Duplicate sibling folder returns 409 Conflict (WR-03).
|
||||
env.expect(t, http.StatusConflict, http.MethodPost, "/media/folders", managerTok, map[string]any{"name": "heroes"})
|
||||
|
||||
rec := mediaMultipartUpload(t, env.h, managerTok, mediaTestPNG(t, 1000, 500), "Hero Banner.png", map[string]string{
|
||||
"folder_id": fmt.Sprintf("%d", fid),
|
||||
"alt": "Initial alt",
|
||||
@@ -275,4 +278,44 @@ func TestMailImagesUnifiedOverAlbum(t *testing.T) {
|
||||
env.expect(t, http.StatusOK, http.MethodPut, "/settings/mail_brand", layoutsTok, map[string]any{
|
||||
"logo_file_id": postResp.Data.ID,
|
||||
})
|
||||
|
||||
// CR-02 regression: mail-only admin cannot read non-mail-folder items or
|
||||
// non-image items in the mail folder via GET /mail/images/{id} or set them
|
||||
// as MailBrandSetting.LogoFileID.
|
||||
_, mediaMgrTok := env.admin(t, "mail-album-mgr", false, `{"media.manage_media":1}`)
|
||||
outsideRec := mediaMultipartUpload(t, env.h, mediaMgrTok, mediaTestPNG(t, 64, 64), "private.png", nil)
|
||||
if outsideRec.Code != http.StatusCreated {
|
||||
t.Fatalf("outside upload status = %d, body=%s", outsideRec.Code, outsideRec.Body.String())
|
||||
}
|
||||
var outsideResp struct {
|
||||
Data cabana.AdminMediaItem `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(outsideRec.Body.Bytes(), &outsideResp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var mailFolder album.Folder
|
||||
if err := env.gdb.Where("parent_id IS NULL AND slug = ?", "mail").First(&mailFolder).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pdfRec := mediaMultipartUpload(t, env.h, mediaMgrTok, []byte("%PDF-1.4\nmail-doc"), "brochure.pdf", map[string]string{
|
||||
"folder_id": fmt.Sprintf("%d", mailFolder.ID),
|
||||
})
|
||||
if pdfRec.Code != http.StatusCreated {
|
||||
t.Fatalf("mail-folder pdf upload status = %d, body=%s", pdfRec.Code, pdfRec.Body.String())
|
||||
}
|
||||
var pdfResp struct {
|
||||
Data cabana.AdminMediaItem `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(pdfRec.Body.Bytes(), &pdfResp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
env.expect(t, http.StatusNotFound, http.MethodGet, fmt.Sprintf("/mail/images/%d", outsideResp.Data.ID), layoutsTok, nil)
|
||||
env.expect(t, http.StatusNotFound, http.MethodGet, fmt.Sprintf("/mail/images/%d", pdfResp.Data.ID), layoutsTok, nil)
|
||||
env.expect(t, http.StatusUnprocessableEntity, http.MethodPut, "/settings/mail_brand", layoutsTok, map[string]any{
|
||||
"logo_file_id": outsideResp.Data.ID,
|
||||
})
|
||||
env.expect(t, http.StatusUnprocessableEntity, http.MethodPut, "/settings/mail_brand", layoutsTok, map[string]any{
|
||||
"logo_file_id": pdfResp.Data.ID,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user