feat(photos): fix trash permanent delete and add empty trash
Permanently deleting a photo whose album was deleted failed because authorization resolved through the album. Fall back to uploader ownership when the photo is albumless. Add a bulk DELETE /trash that removes every trashed photo the caller may delete (uncapped listing) and returns the deleted count, with an «Очистить корзину» action on the trash screen.
This commit is contained in:
@@ -341,6 +341,36 @@ func (s *Store) TrashCount(ctx context.Context, userID string) (int, error) {
|
||||
return n, err
|
||||
}
|
||||
|
||||
// ListTrashIdentities returns every trashed photo accessible to the user
|
||||
// (no display cap) so a bulk purge can authorize and remove each one.
|
||||
func (s *Store) ListTrashIdentities(ctx context.Context, userID string) ([]TrashIdentity, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
`SELECT p.id, COALESCE(p.album_id, ''), p.uploader_id
|
||||
FROM photos p
|
||||
LEFT JOIN albums a ON a.id = p.album_id
|
||||
WHERE p.deleted_at IS NOT NULL
|
||||
AND (
|
||||
(a.id IS NOT NULL AND (a.owner_id = $1 OR EXISTS(
|
||||
SELECT 1 FROM album_members m WHERE m.album_id = a.id AND m.user_id = $1)))
|
||||
OR (p.album_id IS NULL AND p.uploader_id = $1)
|
||||
)
|
||||
ORDER BY p.deleted_at DESC`,
|
||||
userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []TrashIdentity{}
|
||||
for rows.Next() {
|
||||
var it TrashIdentity
|
||||
if err := rows.Scan(&it.ID, &it.AlbumID, &it.UploaderID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, it)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// RestoreToAlbum reassigns a soft-deleted photo to an album and clears the trash flag.
|
||||
func (s *Store) RestoreToAlbum(ctx context.Context, id, albumID string) error {
|
||||
tag, err := s.pool.Exec(ctx,
|
||||
|
||||
Reference in New Issue
Block a user