fix(photos): копия фото не наследует отредактированную версию

Clone переносил все привязки photo_objects, включая роли edit*, хотя
правка принадлежит фото, чьи правки её породили. Теперь копия делит
только обычные варианты и показывается в исходном виде.

- EditRoles() и IsEditRole() в edit_render.go — единый список ролей;
- фильтр edit-ролей в Store.Clone и SQLiteStore.Clone;
- миграции 000016 (Postgres) и 000008 (SQLite) убирают привязки у
  копий, созданных до фикса;
- контрактная проверка копирования, сервисные и e2e-тесты.
This commit is contained in:
iu
2026-10-21 21:01:33 +03:00
parent 759e78ff79
commit 8dd8cb6f0c
12 changed files with 344 additions and 6 deletions
+54
View File
@@ -74,6 +74,60 @@ func TestCopySharesStorageObjects(t *testing.T) {
}
}
func TestCopyDoesNotShareEditedVersion(t *testing.T) {
pool := testPool(t)
ctx := context.Background()
svc, cl, _ := newRecordingServiceFS(t, pool)
user := createUser(t, ctx, pool)
albumA := createAlbum(t, ctx, pool, user)
albumB := createAlbum(t, ctx, pool, user)
p, err := svc.Upload(ctx, UploadInput{
AlbumID: albumA, UserID: user, Filename: "p.png", MimeType: "image/png", Data: makePNG(t),
})
if err != nil {
t.Fatalf("upload: %v", err)
}
t.Cleanup(func() { cleanupPhoto(t, ctx, pool, cl, p.ID) })
w := NewWorker(svc, time.Second, 10, time.Minute, 2)
w.processVariantJobs(ctx)
// The edit belongs to the photo: the parameters live in its metadata and
// the background render binds the edited version to it.
if _, err := svc.EditPhoto(ctx, p.ID, user, EditParams{Light: LightParams{Exposure: 0.5}}); err != nil {
t.Fatalf("edit photo: %v", err)
}
w.processEditJobs(ctx)
src, err := svc.store.GetByID(ctx, p.ID, "")
if err != nil {
t.Fatalf("get source: %v", err)
}
if src.EditThumbKey == "" || src.EditPreviewKey == "" {
t.Fatalf("source has no edited version: %+v", src)
}
clones, err := svc.CopyBatch(ctx, []string{p.ID}, user, albumB)
if err != nil || len(clones) != 1 {
t.Fatalf("copy: %v len=%d", err, len(clones))
}
clone := clones[0]
t.Cleanup(func() { cleanupPhoto(t, ctx, pool, cl, clone.ID) })
// The copy shares the base variants with the source.
if clone.ThumbKey != src.ThumbKey || clone.MediumKey != src.MediumKey || clone.PreviewKey != src.PreviewKey {
t.Fatalf("clone does not share base variants: src=%+v clone=%+v", src, clone)
}
// But it never inherits the edited version or its parameters.
if clone.EditKey != "" || clone.EditThumbKey != "" || clone.EditMediumKey != "" || clone.EditPreviewKey != "" {
t.Fatalf("clone shares the edited version: %+v", clone)
}
if len(clone.EditParams) != 0 {
t.Fatalf("clone inherited edit params: %+v", clone.EditParams)
}
}
func sameSet(a, b []string) bool {
if len(a) != len(b) {
return false