Skip to content

Fix loan auto-approval and soft-delete catalog counts - #307

Merged
fabiodalez-dev merged 3 commits into
mainfrom
fix/issues-301-306
Jul 29, 2026
Merged

Fix loan auto-approval and soft-delete catalog counts#307
fabiodalez-dev merged 3 commits into
mainfrom
fix/issues-301-306

Conversation

@fabiodalez-dev

Copy link
Copy Markdown
Owner

Summary

This pull request resolves the loan auto-approval request and the stale author book counts reported in #301 and #306.

Loan requests previously always entered the manual pendente queue. Libraries that do not need a separate availability review therefore had to approve every request before it could move to pickup. A new setting in Settings → Loans now lets administrators automatically promote immediate requests to da_ritirare. The implementation reuses the canonical approval pipeline, including eligibility, capacity, copy locking, availability recalculation, and pickup deadlines. Administrator request notifications and the patron approval email remain enabled.

The Mobile API exposes loan_approval_required through discovery and returns the resulting loan_id, auto_approved flag, and status when creating an immediate loan. Its OpenAPI contract documents the new fields.

Author list counts were derived directly from libri_autori, so associations belonging to soft-deleted books were still included even though author detail pages correctly hid those books. Both the list and bulk export now join libri and require deleted_at IS NULL. The same audit confirmed publisher counts were already correct and found one equivalent inconsistency in genre facet counts, which is fixed here as well.

The setting defaults to disabled for backward compatibility. Fresh-install seed data, an idempotent 0.7.46 migration, and all bundled translations are included.

Validation

  • PHPStan on all changed PHP controllers and repositories: no errors
  • PHP syntax checks: passed
  • Issue-specific regression suite: 14 checks passed
  • Language derived-stat and export-completeness suites: passed
  • Swagger static contract test: passed
  • Composer validation: passed
  • git diff --check: passed

Closes #301
Closes #306

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 978990a4-9c9a-415e-bbb9-ec2bf072a0e8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

version.json was still 0.7.45 while this branch ships migrate_0.7.46.sql —
version_compare('0.7.46','0.7.45','<=') is FALSE, so the updater would silently
skip the auto-approve setting migration on upgrade (and the release preflight
would reject it). Bumped to 0.7.46 so the migration runs.

Adds tests/loan-auto-approval-301.unit.php: 12 behavioural checks that seed real
libri/copie/utenti/prestiti and drive the real UserActionsController::autoApprove-
LoanRequest() (which delegates to the canonical approveLoan pipeline), asserting
state transitions rather than string-matching the source:
- setting accessor: absent/'0'/non-'1' → off, '1' → on;
- OFF leaves the request in the pendente queue;
- ON + available copy → 'da_ritirare', pickup_deadline set, a copy assigned, loan activated;
- ON + no available copy → left pending, never wrongly auto-approved.
The run restores the global auto_approve_requests setting and cleans its fixtures.
The Code Quality meta-guard (issue-237-regression.unit.php) requires the
release-version migration to have a matching tests/migration-<version>.unit.php.
migrate_0.7.46.sql shipped without one, failing CI.

Adds tests/migration-0.7.46.unit.php: runs the real migration against a sandbox
system_settings table and asserts the loans/auto_approve_requests setting is
created with the safe default '0', a re-run preserves an admin's '1' (does not
reset it — ON DUPLICATE KEY UPDATE keeps the stored value), and no duplicate row
is created.
fabiodalez-dev added a commit that referenced this pull request Jul 29, 2026
Mirrors .github/workflows/ci-quality.yml so a red Code Quality job is caught
before pushing: PHPStan, composer/npm audit, translation key+placeholder parity,
route-key integrity, Tailwind-JIT guard, plugin ensureSchema() rule, soft-delete
guard, autoloader phpstan-free, the migration-version guard, ALL standalone
tests/*.unit.php (via exit code — including the meta-guard that requires a
tests/migration-<version>.unit.php for the release migration), and the
setup-permissions shell test.

reinstall-test.sh + verify-schema.sh only cover the E2E + schema/plugin gates,
so they missed the placeholder-parity regression (v0.7.45-rc.x) and the
version-skipped migration (#307). Run this before every PR push and release.
@fabiodalez-dev
fabiodalez-dev merged commit e66bda1 into main Jul 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authors list don't get updated Auto-approve loan requests

1 participant