Skip to content

Phase 2: Split names_controller into smaller controllers#258

Open
lmrodriguezr wants to merge 11 commits into
mainfrom
split-names-controller
Open

Phase 2: Split names_controller into smaller controllers#258
lmrodriguezr wants to merge 11 commits into
mainfrom
split-names-controller

Conversation

@lmrodriguezr
Copy link
Copy Markdown
Member

This PR implements Phase 2 of the code reorganization plan for the SeqCode Registry. It splits the large names_controller.rb into smaller, focused controllers under the Names:: namespace, improving maintainability and readability.


📌 Changes Made

1. New Base Controller

  • app/controllers/names/base_controller.rb: Contains shared logic, before_actions, and private methods used by all Names:: controllers. This includes:
    • Authentication methods (e.g., authenticate_can_edit!, authenticate_owner_or_curator!).
    • Setup methods (e.g., set_name, set_tutorial).
    • Helper methods (e.g., name_params, change_status, add_automatic_correspondence).

2. New Split Controllers

All new controllers inherit from Names::BaseController and handle specific groups of actions:

Controller Actions Purpose
Names::MainController index, show, new, create, update, destroy, autocomplete Core CRUD operations for names.
Names::FilteringController user, submitted, endorsed, draft, unranked, unknown_proposal, type_genomes Filtering and listing names by status, user, or type.
Names::PublicationsController proposed_in, not_validly_proposed_in, emended_in, assigned_in, corrigendum_in, corrigendum Publication-related actions.
Names::StatusController return, validate, endorse, claim, unclaim, demote, temporary_editable Status-related actions.
Names::UserActionsController transfer_user, transfer_user_commit, observe, unobserve, new_correspondence User-related actions (e.g., transferring, observing).
Names::NetworkController network Network visualization.
Names::WikiController wiki Wiki-related actions.
Names::UtilityController autocomplete, linkout, etymology_sandbox, syllabify, quality_checks Utility actions.
Names::EditingController edit, edit_description, edit_notes, edit_rank, edit_links, edit_type, edit_redirect, autofill_etymology, edit_etymology, edit_parent Editing actions.

3. Updated Routes

  • The config/routes.rb file has been updated to explicitly map actions to their respective controllers using the controller: option.
  • Standard REST actions (e.g., index, show, new, create) are mapped to Names::MainController via controller: 'names/main'.
  • Custom actions (e.g., submitted, validate) are explicitly mapped to their respective controllers (e.g., controller: 'names/filtering').
  • No breaking changes: All existing URLs remain the same.

🎯 Goals Achieved

  1. Improved Maintainability: The large names_controller.rb (500+ lines) is now split into smaller, focused controllers (~50-100 lines each).
  2. Better Readability: Each controller handles a specific group of actions, making the code easier to understand and navigate.
  3. Shared Logic: Common logic (e.g., authentication, setup) is centralized in Names::BaseController.
  4. No Breaking Changes: The existing route structure and URLs are preserved.

🔜 Next Steps

  • Phase 3: Replace JBuilder with serializers (e.g., FastJSONAPI) for consistency.
  • Phase 3: Version API routes (e.g., /v1/names) and add request specs for all endpoints.
  • Testing: Ensure all actions work as expected in the new structure.

📚 Related Issues/PRs

  • Follows up on PR #255 (Phase 1: Reorganize code with concerns, services, and docs).
  • Improves maintainability and scalability of the names_controller.rb file.

Reviewers: Please focus on the new controller structure and route mappings. The changes are backward-compatible and do not break existing functionality.

This controller contains shared logic, before_actions, and private methods
used by all Names-related controllers. It centralizes authentication, setup,
and helper methods to avoid repetition.
This controller handles the core CRUD operations for Names:
- index, show, new, create, update, destroy
- autocomplete

It inherits from Names::BaseController to reuse shared logic.
This controller handles filtering and listing names by status, user, or type:
- user, observing, submitted, endorsed, draft, unranked, unknown_proposal, type_genomes

It inherits from Names::BaseController and reuses the index logic.
This controller handles actions related to publication associations:
- proposed_in, not_validly_proposed_in, emended_in, assigned_in, corrigendum_in, corrigendum

It inherits from Names::BaseController.
This controller handles actions related to changing the status of a name:
- return, validate, endorse, claim, unclaim, demote, temporary_editable

It inherits from Names::BaseController.
This controller handles actions related to user interactions:
- transfer_user, transfer_user_commit, observe, unobserve, new_correspondence

It inherits from Names::BaseController.
This controller handles the network visualization action:
- network

It inherits from Names::BaseController.
This controller handles the wiki action:
- wiki

It inherits from Names::BaseController.
This controller handles utility actions:
- autocomplete, linkout, etymology_sandbox, syllabify, quality_checks

It inherits from Names::BaseController.
This controller handles actions related to editing name attributes:
- edit, edit_description, edit_notes, edit_rank, edit_links, edit_type,
  edit_redirect, autofill_etymology, edit_etymology, edit_parent

It inherits from Names::BaseController.
This change updates the routes to use the new Names:: namespace for controllers.
- Standard REST actions (index, show, new, create, update, destroy) are mapped to Names::MainController.
- Custom actions are explicitly mapped to their respective controllers (e.g., filtering, publications, status).
- The existing route structure and URLs remain unchanged.
def observe
@name.add_observer(current_user)
if params[:from] && RedirectSafely.safe?(params[:from])
redirect_to(params[:from])
def unobserve
@name.observers.delete(current_user)
if params[:from] && RedirectSafely.safe?(params[:from])
redirect_to(params[:from])
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.

2 participants