feat(scanner): scanner entrypoints + generic jobs carry RLS identity; SeedDB harness fallback
The full suite enumerated the remaining triage class: tests drive the scanner directly (ScanFolders(context.Background())) and read seeded media via Queries with bare contexts — every governed read raised. - MediaScanner.ScanFolders self-declares its configured admin (SetAdminID — set by main AND the test helpers): a scan is server maintenance, product-correct regardless of caller. - ScopedDB gains a Fallback identity, exposed as NewSeedDB for the TEST HARNESS ONLY: setup.DB falls back to rls.SeedIdentity when the context carries none, so direct seeding/verification helpers work uniformly instead of per-site context threading. rls.SeedIdentity is the shared constant (no library_visibility rows => full visibility). - generic job creation (jobs.go) stamps the requesting admin into the job Context, same as the scan endpoint. The sync queue processor stays identity-free: sync_queue is not an RLS-governed table.
This commit is contained in:
1 parent
385a5d9dba
commit
bb2cc26e9d
9 files changed
+72
-35
No files matched your search
@@ -175,7 +175,7 @@ func (h *ConflictHandler) GetConflict(c *echo.Context) error {
|
||||
}
|
||||
|
||||
conflictUUID := pgtype.UUID{Bytes: [16]byte(conflictID), Valid: true}
|
||||
conflict, err := h.db.GetSyncConflict(context.Background(), conflictUUID)
|
||||
conflict, err := h.db.GetSyncConflict(c.Request().Context(), conflictUUID)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "conflict not found")
|
||||
@@ -187,7 +187,7 @@ func (h *ConflictHandler) GetConflict(c *echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "access denied")
|
||||
}
|
||||
|
||||
mediaItem, err := h.db.GetMediaItem(context.Background(), conflict.MediaItemID)
|
||||
mediaItem, err := h.db.GetMediaItem(c.Request().Context(), conflict.MediaItemID)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get media item")
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func (h *ConflictHandler) ResolveConflict(c *echo.Context) error {
|
||||
}
|
||||
|
||||
conflictUUID := pgtype.UUID{Bytes: [16]byte(conflictID), Valid: true}
|
||||
conflict, err := h.db.GetSyncConflict(context.Background(), conflictUUID)
|
||||
conflict, err := h.db.GetSyncConflict(c.Request().Context(), conflictUUID)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "conflict not found")
|
||||
@@ -283,7 +283,7 @@ func (h *ConflictHandler) ResolveConflict(c *echo.Context) error {
|
||||
|
||||
resolutionDataJSON, _ := json.Marshal(resolutionData)
|
||||
|
||||
_, err = h.db.ResolveSyncConflict(context.Background(), database.ResolveSyncConflictParams{
|
||||
_, err = h.db.ResolveSyncConflict(c.Request().Context(), database.ResolveSyncConflictParams{
|
||||
ID: conflictUUID,
|
||||
ResolutionStatus: pgtype.Text{String: "user_resolved", Valid: true},
|
||||
ResolutionData: resolutionDataJSON,
|
||||
@@ -530,7 +530,7 @@ func (h *ConflictHandler) DeleteConflict(c *echo.Context) error {
|
||||
}
|
||||
|
||||
conflictUUID := pgtype.UUID{Bytes: [16]byte(conflictID), Valid: true}
|
||||
conflict, err := h.db.GetSyncConflict(context.Background(), conflictUUID)
|
||||
conflict, err := h.db.GetSyncConflict(c.Request().Context(), conflictUUID)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "conflict not found")
|
||||
@@ -542,7 +542,7 @@ func (h *ConflictHandler) DeleteConflict(c *echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "access denied")
|
||||
}
|
||||
|
||||
if err := h.db.DeleteSyncConflict(context.Background(), conflictUUID); err != nil {
|
||||
if err := h.db.DeleteSyncConflict(c.Request().Context(), conflictUUID); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete conflict")
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ func (h *ConflictHandler) DeleteConflict(c *echo.Context) error {
|
||||
func (h *ConflictHandler) DismissAllResolved(c *echo.Context) error {
|
||||
user := c.Get("user").(database.Users)
|
||||
|
||||
conflicts, err := h.db.ListConflictsByUser(context.Background(), user.ID)
|
||||
conflicts, err := h.db.ListConflictsByUser(c.Request().Context(), user.ID)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "failed to list conflicts")
|
||||
}
|
||||
@@ -560,7 +560,7 @@ func (h *ConflictHandler) DismissAllResolved(c *echo.Context) error {
|
||||
deleted := 0
|
||||
for _, conflict := range conflicts {
|
||||
if conflict.ResolutionStatus.String == "user_resolved" || conflict.ResolutionStatus.String == "bulk_resolved" {
|
||||
if err := h.db.DeleteSyncConflict(context.Background(), conflict.ID); err == nil {
|
||||
if err := h.db.DeleteSyncConflict(c.Request().Context(), conflict.ID); err == nil {
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
@@ -620,7 +620,7 @@ func (h *ConflictHandler) BulkResolveConflicts(c *echo.Context) error {
|
||||
}
|
||||
|
||||
conflictUUID := pgtype.UUID{Bytes: [16]byte(conflictID), Valid: true}
|
||||
conflict, err := h.db.GetSyncConflict(context.Background(), conflictUUID)
|
||||
conflict, err := h.db.GetSyncConflict(c.Request().Context(), conflictUUID)
|
||||
if err != nil {
|
||||
results = append(results, ConflictResult{
|
||||
ConflictID: conflictIDStr,
|
||||
@@ -719,7 +719,7 @@ func (h *ConflictHandler) BulkResolveConflicts(c *echo.Context) error {
|
||||
}
|
||||
resolutionDataJSON, _ := json.Marshal(resolutionData)
|
||||
|
||||
_, err = h.db.ResolveSyncConflict(context.Background(), database.ResolveSyncConflictParams{
|
||||
_, err = h.db.ResolveSyncConflict(c.Request().Context(), database.ResolveSyncConflictParams{
|
||||
ID: conflictUUID,
|
||||
ResolutionStatus: pgtype.Text{String: "bulk_resolved", Valid: true},
|
||||
ResolutionData: resolutionDataJSON,
|
||||
@@ -817,7 +817,7 @@ func (h *ConflictHandler) BulkDismissConflicts(c *echo.Context) error {
|
||||
}
|
||||
|
||||
conflictUUID := pgtype.UUID{Bytes: [16]byte(conflictID), Valid: true}
|
||||
conflict, err := h.db.GetSyncConflict(context.Background(), conflictUUID)
|
||||
conflict, err := h.db.GetSyncConflict(c.Request().Context(), conflictUUID)
|
||||
if err != nil {
|
||||
results = append(results, ConflictResult{
|
||||
ConflictID: conflictIDStr,
|
||||
@@ -838,7 +838,7 @@ func (h *ConflictHandler) BulkDismissConflicts(c *echo.Context) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := h.db.DeleteSyncConflict(context.Background(), conflictUUID); err != nil {
|
||||
if err := h.db.DeleteSyncConflict(c.Request().Context(), conflictUUID); err != nil {
|
||||
results = append(results, ConflictResult{
|
||||
ConflictID: conflictIDStr,
|
||||
Status: "error",
|
||||
|
||||
Reference in new issue
Block a user