Skip to content

Migrate remaining controller consumers away from ValidateHelper #8353

Description

@vitormattos

ValidateHelper was split into focused validators in #8334. Several consumers have already been migrated in follow-up PRs, including #8336, #8337, #8343, #8345 and #8355.

This issue covers the remaining controller consumers of ValidateHelper.

The goal is to replace calls through the compatibility façade with direct calls to the focused validators that already own each validation rule.

Do not change validation behavior.

What needs to change

Update these consumers:

FileController

Replace the ValidateHelper dependency with:

  • FileInputValidator
  • SigningRequestValidator

Use them as follows:

  • ValidateHelper::validateNewFile()FileInputValidator::validateNewFile()
  • ValidateHelper::canRequestSign()SigningRequestValidator::canRequestSign()
  • ValidateHelper::iRequestedSignThisFile()SigningRequestValidator::iRequestedSignThisFile()

Migrate all current calls in FileController. After this change, FileController must no longer import, inject or call ValidateHelper.

PageController

Replace the ValidateHelper dependency with SigningRequestValidator.

Use:

  • ValidateHelper::canRequestSign()SigningRequestValidator::canRequestSign()

After this change, PageController must no longer import, inject or call ValidateHelper.

AccountController

ValidateHelper is injected but is not used.

Remove the ValidateHelper constructor dependency and import.

Do not replace it with another validator.

Focused validators

The validation rules are currently split into:

  • FileInputValidator: file input, MIME type and LibreSign file ID validation.
  • VisibleElementValidator: visible signature element validation.
  • SigningRequestValidator: signing-request state, permissions and file-signing workflow validation.
  • SignerValidator: signer identity, UUID and credential validation.
  • IdentityDocumentValidator: identification-document validation and approval rules.

Do not introduce another façade, wrapper or validation interface.

Each controller should inject only the focused validators required by its current validation calls.

Tests

Update every affected unit test that creates one of these controllers directly.

For the affected tests:

  • replace ValidateHelper mocks with FileInputValidator and/or SigningRequestValidator mocks as required;
  • remove obsolete ValidateHelper mocks where the dependency is removed;
  • update constructor arguments;
  • move existing method expectations to the corresponding focused validator mock;
  • keep the existing assertions and behavior coverage;
  • do not remove or weaken tests to make the migration pass.

The change must not modify validation behavior or any public API.

Scope

This issue is limited to:

  • FileController
  • PageController
  • AccountController
  • their affected tests

The service and middleware consumers were handled separately in #8355.

Do not remove ValidateHelper itself in this issue. Its final removal is tracked by #8357 and should happen only after this migration is complete.

Do not:

  • change validation rules;
  • move validation logic between focused validators;
  • rename validator methods or constants;
  • change controller public APIs;
  • change exception or HTTP response behavior;
  • introduce another validation façade or wrapper;
  • include unrelated cleanup or refactoring.

Before submitting the PR

Search the three affected production controllers for:

ValidateHelper

There should be no remaining imports, constructor dependencies or calls.

Also search their affected tests and make sure no obsolete ValidateHelper mocks remain.

A repository-wide search may still find the compatibility façade itself and its dedicated test. Those are handled by #8357.

Done when

  • FileController uses FileInputValidator and SigningRequestValidator directly.
  • FileController no longer imports, injects or calls ValidateHelper.
  • PageController uses SigningRequestValidator directly.
  • PageController no longer imports, injects or calls ValidateHelper.
  • AccountController no longer imports or injects ValidateHelper.
  • Affected unit tests use the focused validator mocks or remove obsolete mocks.
  • Constructor arguments in affected tests are updated.
  • Existing test coverage and assertions are preserved.
  • PHPUnit passes.
  • Static analysis passes.
  • Coding style checks pass.
  • Other relevant CI checks pass.
  • No unrelated cleanup is included.

Good first issue

You do not need to understand the complete LibreSign codebase to work on this issue.

The validation architecture has already been split into focused validators. This task only migrates the remaining controller consumers away from the compatibility façade.

A good way to start is:

  1. Read one affected controller and its unit tests.
  2. Find every ValidateHelper call in that controller.
  3. Replace each call with the focused validator that already owns that method.
  4. Update the related mocks and constructor arguments.
  5. Run the related PHPUnit tests.
  6. Repeat for the other controllers.
  7. Search the affected files for ValidateHelper before submitting the PR.

This is a good way to learn dependency injection, PHPUnit mocks and the LibreSign validation architecture while working on a focused change.

If anything in the expected change is unclear, feel free to ask in this issue before starting.

Additional context

  • If you have questions, feel free to ask in this issue.
  • Give a ⭐️ star to this repository if you find LibreSign useful and would like to support the project.
  • You can also join our community: https://t.me/LibreSign

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

backendBackend taskgood first issueGood for newcomersphpPull requests that update Php code

Type

Projects

  • Status
    4. to release

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions