Refactor available_verifiables scope to reduce duplication and improve maintainability
Problem
Currently, the available_verifiables
scope is duplicated across multiple Geo verifiable models with nearly identical implementations. This creates code duplication and maintenance overhead, similar to the issue that was resolved for checksummed
and not_checksummed
scopes in #576325 (closed).
Current Issues:
- Multiple verifiable models define identical
available_verifiables
scopes - The scope logic is duplicated across models with separate verification state tables
- Each model has the same pattern:
scope :available_verifiables, -> { joins(:model_state) }
- This duplication makes the codebase harder to maintain and understand
- Changes to the scope logic require updates across multiple files
Example of Current Duplication:
Every verifiable model with a separate state table has similar scope definitions like:
scope :available_verifiables, -> { joins(:job_artifact_state) }
scope :available_verifiables, -> { joins(:container_repository_state) }
scope :available_verifiables, -> { joins(:upload_state) }
# ... and so on for each model
Proposed Solution
Move the available_verifiables
scope from individual models to VerifiableModel
where it can be implemented generically to work for both:
- Models with separate state tables (using joins with the appropriate association)
- Models with inline verification state (using the
verifiables
scope directly)
This would:
- Eliminate the need for model-specific scope definitions
- Reduce code duplication across verifiable models
- Make the abstractions clearer and more maintainable
- Ensure consistent behavior across all verifiable models
- Follow the same pattern established by the
checksummed
/not_checksummed
refactoring
Implementation Approach
The generic implementation should:
scope :available_verifiables, -> {
separate_verification_state_table? ? joins(active_record_state_association.name) : verifiables
}
This leverages the existing separate_verification_state_table?
method and active_record_state_association
helper to determine the appropriate behavior.
Context
This refactoring continues the work started in #576325 (closed) to consolidate Geo verification scopes and reduce complexity in the Geo Self-Service Framework (SSF). The available_verifiables
scope is a core part of the verification system that determines which records are eligible for verification.
Acceptance Criteria
-
Remove duplicated available_verifiables
scope definitions from individual verifiable models -
Add generic available_verifiables
scope implementation toVerifiableModel
-
Update Geo issue templates to remove the scope from examples -
Ensure all existing functionality and tests continue to work -
Verify that both separate state table and inline state models work correctly
References
- Related MR: !208630 (merged)
- Previous similar refactoring: #576325 (closed) (checksummed/not_checksummed scopes)