app/controllers/meeting_reservations_controller.rb
# Verifies that a meeting id is provided as parameter and that the current user
# is either associated to a swimmer or is the team_manager of a team.
# Else, returns an invalid action request.
#
# Sets/assigns:
# - @meeting, a valid Meeting instance
# - @is_valid_team_manager, either +true+ or +false+
# - @swimmer, +nil+ only when no associated swimmer was found (allegedly, in this case @is_valid_team_manager should result true)
# - @team_affiliation, a valid TeamAffiliation instance
# - @team, a valid Team instance
#
# == Params:
# id: the meeting id to be processed
#
# == Implied parameters:
# current_user:  user must be logged-in and either be a team-manager or have an
#                associated swimmer (must be a "goggler").
#
Verifies that a meeting id is provided as parameter and that the current user
is either associated to a swimmer or is the team_manager of a team.
Else, returns an invalid action request.



the meeting id to be processed

Implied parameters:
current_user:  user must be logged-in and either be a team-manager or have an
associated swimmer (must be a "goggler").
Verifies that a meeting id is provided as parameter and that the current user is either associated to a swimmer or is the team_manager of a team . Else returns an invalid action request . the meeting id to be processed Implied parameters : current_user : user must be logged - in and either be a team - manager or have an associated swimmer ( must be a " goggler " ) .
def verify_meeting_and_association
    set_meeting_from_id
    unless ( @meeting )
      flash[:error] = I18n.t(:invalid_action_request) + ' - ' + I18n.t('meeting.errors.missing_meeting_id')
      redirect_to( meetings_current_path() ) and return
    end
    @is_valid_team_manager = TeamManagerValidator.can_manage?( current_user, @meeting ) &&
                             TeamManagerValidator.is_reservation_manageable?( @meeting )
    set_swimmer_from_current_user
    unless ( @is_valid_team_manager ||
             ( @swimmer && TeamManagerValidator.any_reservations_for?(current_user, @meeting) )
           )
      flash[:error] = I18n.t(:invalid_action_request) + ' - ' + I18n.t('meeting.errors.invalid_team_manager_or_no_swimmer')
      redirect_to( meetings_current_path() ) and return
    end
           This is possibile because Team Managers are defined freely according
           to user requests.
           THIS MUSt BE HANDLED BY THE QUERY BELOW AND ALL THE SWIMMERS FOR
           ALL INVOLVED TEAMAFFILIATIONS SHOULD BE COLLECTED!
    if @is_valid_team_manager
      enabled_manager = current_user.team_managers.includes(:team_affiliation)
        .find{|tm| tm.team_affiliation.season_id == @meeting.season_id }
      @team_affiliation = enabled_manager.team_affiliation
    else
 DEBUG
      puts "\r\n=> verify_meeting_and_association()\r\n--- @swimmer: { @swimmer.inspect }"
      puts "--- @meeting: { @meeting.inspect }"
      enabled_badge = @swimmer.badges.includes(:team_affiliation)
        .find{|b| b.team_affiliation.season_id == @meeting.season_id }
      @team_affiliation = enabled_badge.team_affiliation
    end
    @team = @team_affiliation.team
  end
def verify_meeting_and_association set_meeting_from_id unless ( @meeting ) flash [ :error ] = I18n . t ( :invalid_action_request ) + ' - ' + I18n . t ( 'meeting.errors.missing_meeting_id' ) redirect_to ( meetings_current_path ( ) ) and return end @is_valid_team_manager = TeamManagerValidator . can_manage? ( current_user , @meeting ) && TeamManagerValidator . is_reservation_manageable? ( @meeting ) set_swimmer_from_current_user unless ( @is_valid_team_manager || ( @swimmer && TeamManagerValidator . any_reservations_for? ( current_user , @meeting ) ) ) flash [ :error ] = I18n . t ( :invalid_action_request ) + ' - ' + I18n . t ( 'meeting.errors.invalid_team_manager_or_no_swimmer' ) redirect_to ( meetings_current_path ( ) ) and return end if @is_valid_team_manager enabled_manager = current_user . team_managers . includes ( :team_affiliation ) . find { | tm | tm . team_affiliation . season_id == @meeting . season_id } @team_affiliation = enabled_manager . team_affiliation else enabled_badge = @swimmer . badges . includes ( :team_affiliation ) . find { | b | b . team_affiliation . season_id == @meeting . season_id } @team_affiliation = enabled_badge . team_affiliation end @team = @team_affiliation . team end
Verifies that a meeting id is provided as parameter and that the current user
is either associated to a swimmer or is the team_manager of a team.
Verifies that a meeting id is provided as parameter and that the current user is either associated to a swimmer or is the team_manager of a team .
# To be a valid team manager (precisely, for editing & adding reservations), # a user must be: # - enabled to manage the season of the selected Meeting (...AND...) # - the meeting must still be 'reservation-manageable' # (If the meeting is no more 'reservation-manageable', each view page widget #  should be set as read-only, even if the page is still accessible because #  of existing reservations.) # Detect if there's a swimmer associated: # Bail out unless the user is a valid team manager, or if a swimmer is checking # a meeting w/ reservations that do not belong to him/her: # FIXME [Steve, 20161213] It could be possible to have a user that is defined as TeamManager #       (for example, for ease of passages editing) for a couple of TeamAffiliations #       both registered to the same season and thus eligible to manage the registrations #       of different teams for the same meeting, while (for referential integrity) the #       badge associated to the swimmer of the TeamManager allows him/her to take #       part in the same meeting with only one affiliation. # #       This is possibile because Team Managers are defined freely according #       to user requests. # #       THIS MUSt BE HANDLED BY THE QUERY BELOW AND ALL THE SWIMMERS FOR #       ALL INVOLVED TEAMAFFILIATIONS SHOULD BE COLLECTED! # DEBUG #      puts "\r\n=> verify_meeting_and_association()\r\n--- @swimmer: #{ @swimmer.inspect }" #      puts "--- @meeting: #{ @meeting.inspect }"