fix: the avatar and logo URL fallback follows the configured public path
When the thumbnail fails, AvatarURL and OrganisationLogoURL answered "/" + the blob key, which skips storage.uploads.public_path_prefix and public_url (a 404 with the WinterCMS layout). They now answer the original's attach.File.URL.
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"git.golem15.com/golem15/sm-user-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-user-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon/attach"
|
||||
"gocloud.dev/blob/memblob"
|
||||
)
|
||||
|
||||
// uploadOrganisationFile posts an image to an organisation form's file
|
||||
@@ -51,7 +53,8 @@ func (e *adminEnv) organisationFiles(t *testing.T, id uint, field string) int64
|
||||
// fileupload right after the avatar; a logo uploaded through the admin form
|
||||
// API is stored as a system_files row with field logo; OrganisationLogoFields
|
||||
// answers has_logo, the disk name and a URL, or false and nils without a
|
||||
// logo; the avatar keeps working beside it; and deleting the organisation
|
||||
// logo, falling back to the original's public URL when the thumbnail fails;
|
||||
// the avatar keeps working beside it; and deleting the organisation
|
||||
// removes the logo attachment as it does the avatar. Postgres only: under
|
||||
// -short nothing runs.
|
||||
func TestOrganisationLogo(t *testing.T) {
|
||||
@@ -142,6 +145,22 @@ func TestOrganisationLogo(t *testing.T) {
|
||||
t.Fatalf("logo URL %q points at the avatar", url)
|
||||
}
|
||||
|
||||
// A thumbnail that cannot be made (the storage fails) falls back to
|
||||
// the original's public URL, under the public path prefix
|
||||
// (RC-IN-03).
|
||||
closed := memblob.OpenBucket(nil)
|
||||
_ = closed.Close()
|
||||
failing := sessionUserApp(t, "SUMMER_GOLEM15__USER__JWT__SECRET="+sessionSecret)
|
||||
if err := failing.Publish(env.gdb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := attach.Publish(failing, closed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, ok, err := classes.OrganisationLogoURL(ctx, failing, env.organisation(t, org.ID), 64); err != nil || !ok || got != attach.PublicURL(attach.BlobKey(logoDisk)) {
|
||||
t.Fatalf("failing logo thumbnail = %q %v %v, want %s", got, ok, err, attach.PublicURL(attach.BlobKey(logoDisk)))
|
||||
}
|
||||
|
||||
env.expect(t, http.StatusOK, http.MethodDelete, organisationPath(org.ID, ""), token, nil)
|
||||
if logos, avatars := env.organisationFiles(t, org.ID, "logo"), env.organisationFiles(t, org.ID, "avatar"); logos != 0 || avatars != 0 {
|
||||
t.Fatalf("after the delete: logo rows %d, avatar rows %d, want none", logos, avatars)
|
||||
|
||||
Reference in New Issue
Block a user