Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Use current_conference instead of set_conference and conference (1/3) #2303

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Commits on May 5, 2024

  1. Avoid overriding set_speaker method in SpeakerDashboardsController

    ApplicationController has `set_speaker` method.
    
    ```ruby
    def set_speaker
      if current_user
        @speaker = Speaker.find_by(email: current_user[:info][:email], conference_id: set_conference.id)
      end
    end
    ```
    
    SpeakerDashboardsController's method is
    
    ```ruby
    def set_speaker
      @conference ||= Conference.find_by(abbr: params[:event])
      if current_user
        @speaker = Speaker.find_by(conference_id: @conference.id, email: current_user[:info][:email])
        @talks = @speaker ? @speaker.talks.not_sponsor : []
      end
    end
    ```
    
    Only differences are related to setting @talks, so setting of `@talks` into the action.
    
    Note: `set_conference` implementation is here.
    
    https://github.com/cloudnativedaysjp/dreamkast/blob/6c4b9071bf895dea2f8006184382ed39e1ef885a/app/controllers/application_controller.rb#L128-L130
    https://github.com/cloudnativedaysjp/dreamkast/blob/6c4b9071bf895dea2f8006184382ed39e1ef885a/app/controllers/application_controller.rb#L39-L41
    
    ```ruby
    def set_conference
      @conference ||= Conference.find_by(abbr: event_name)
    end
    
    def event_name
      params[:event]
    end
    ```
    onk committed May 5, 2024
    Configuration menu
    Copy the full SHA
    85dc770 View commit details
    Browse the repository at this point in the history
  2. Avoid using return value of set_conference

    Use ivar `@conference` which is set by `set_conference` instead of `set_conference`'s return value.
    onk committed May 5, 2024
    Configuration menu
    Copy the full SHA
    5e4876a View commit details
    Browse the repository at this point in the history
  3. Invoke set_conference via before_action in Secured, SecuredAdmin co…

    …ncerns
    
    `set_conference` is now invoked automatically via `before_action` in the `Secured` and `SecuredAdmin` concerns.
    This change removes the need for explicit calls to `set_conference` in individual controller actions.
    onk committed May 5, 2024
    Configuration menu
    Copy the full SHA
    01e8a69 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ea1f453 View commit details
    Browse the repository at this point in the history
  5. Use @conference ivar directly in Secured and SecuredAdmin

    Since `Secured` and `SecuredAdmin` modules already include the `set_conference` method as a `before_action`, the ivar `@conference` is consistently available.
    Remove redundant method calls to `conference`.
    onk committed May 5, 2024
    Configuration menu
    Copy the full SHA
    ec52c1b View commit details
    Browse the repository at this point in the history
  6. Ensure set_conference is called before set_profile

    Enforce the calling `set_conference` before `set_profile` across controllers to access `@conference` ivar.
    `Secure` or `SecureAdmin` concerns already called `set_conference` by `before_action`.
    For api/v1 routes, explicitly call `set_conference` in each controller.
    onk committed May 5, 2024
    Configuration menu
    Copy the full SHA
    5f44693 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e0cfd64 View commit details
    Browse the repository at this point in the history