app/controllers/questionnaires_controller.rb
def submission
    if current_user.is_admin_or_respondent_admin? && params[:respondent_id]
      @respondent = User.find(params[:respondent_id])
      @authorization = @respondent ? @respondent.authorization_for(@questionnaire, nil, @respondent.id) : false
    else
      @authorization = current_user ? current_user.authorization_for(@questionnaire) : false
    end
    raise CanCan::AccessDenied.new(t("flash_messages.#{@authorization ? @authorization[:error_message] : "not_authorized"}"), :submission, Questionnaire) if !@authorization || @authorization[:error_message]
    if current_user.is_delegate?
      @delegation = current_user.delegated_tasks.find_by_questionnaire_id(@questionnaire.id)
    end
    @sections_to_display_in_tab = @questionnaire.sections_to_display_in_tab.
      includes(
        {loop_item_type: {loop_items: {loop_item_name: :loop_item_name_fields}}},
        :submission_states
      )
    @sections_to_display_in_tab_loops_expanded = []
    @sections_to_display_in_tab.each do |section|
      if section.looping? && section.loop_item_type
        section.loop_item_type.loop_items.each do |loop_item|
          if section.available_for?(@respondent || current_user, loop_item)
            submission_state = section.submission_states.find do |s|
              s.user_id == @authorization[:user].id && s.loop_item_id == loop_item.id
            end
            @sections_to_display_in_tab_loops_expanded << [section, loop_item, submission_state.try(:section_state) || SubmissionStatus::DEFAULT]
          end
        end
      else
        submission_state = section.submission_states.find do |s|
          s.user_id == @authorization[:user].id
        end
        @sections_to_display_in_tab_loops_expanded << [section, nil, submission_state.try(:section_state) || SubmissionStatus::DEFAULT]
      end
    end
    respond_to do |format|
      format.html
      format.js
    end
  end
#Access questionnaire to fill in answers as a respondent
Access questionnaire to fill in answers as a respondent
Access questionnaire to fill in answers as a respondent
def submission
    if current_user.is_admin_or_respondent_admin? && params[:respondent_id]
      @respondent = User.find(params[:respondent_id])
      @authorization = @respondent ? @respondent.authorization_for(@questionnaire, nil, @respondent.id) : false
    else
      @authorization = current_user ? current_user.authorization_for(@questionnaire) : false
    end
    raise CanCan::AccessDenied.new(t("flash_messages.#{@authorization ? @authorization[:error_message] : "not_authorized"}"), :submission, Questionnaire) if !@authorization || @authorization[:error_message]
    if current_user.is_delegate?
      @delegation = current_user.delegated_tasks.find_by_questionnaire_id(@questionnaire.id)
    end
    @sections_to_display_in_tab = @questionnaire.sections_to_display_in_tab.
      includes(
        {loop_item_type: {loop_items: {loop_item_name: :loop_item_name_fields}}},
        :submission_states
      )
    @sections_to_display_in_tab_loops_expanded = []
    @sections_to_display_in_tab.each do |section|
      if section.looping? && section.loop_item_type
        section.loop_item_type.loop_items.each do |loop_item|
          if section.available_for?(@respondent || current_user, loop_item)
            submission_state = section.submission_states.find do |s|
              s.user_id == @authorization[:user].id && s.loop_item_id == loop_item.id
            end
            @sections_to_display_in_tab_loops_expanded << [section, loop_item, submission_state.try(:section_state) || SubmissionStatus::DEFAULT]
          end
        end
      else
        submission_state = section.submission_states.find do |s|
          s.user_id == @authorization[:user].id
        end
        @sections_to_display_in_tab_loops_expanded << [section, nil, submission_state.try(:section_state) || SubmissionStatus::DEFAULT]
      end
    end
    respond_to do |format|
      format.html
      format.js
    end
  end
def submission if current_user . is_admin_or_respondent_admin? && params [ :respondent_id ] @respondent = User . find ( params [ :respondent_id ] ) @authorization = @respondent ? @respondent . authorization_for ( @questionnaire , nil , @respondent . id ) : false else @authorization = current_user ? current_user . authorization_for ( @questionnaire ) : false end raise CanCan :: AccessDenied . new ( t ( "flash_messages.#{@authorization ? @authorization[:error_message] : "not_authorized"}" ) , :submission , Questionnaire ) if ! @authorization || @authorization [ :error_message ] if current_user . is_delegate? @delegation = current_user . delegated_tasks . find_by_questionnaire_id ( @questionnaire . id ) end @sections_to_display_in_tab = @questionnaire . sections_to_display_in_tab . includes ( { loop_item_type : { loop_items : { loop_item_name : :loop_item_name_fields } } } , :submission_states ) @sections_to_display_in_tab_loops_expanded = [ ] @sections_to_display_in_tab . each do | section | if section . looping? && section . loop_item_type section . loop_item_type . loop_items . each do | loop_item | if section . available_for? ( @respondent || current_user , loop_item ) submission_state = section . submission_states . find do | s | s . user_id == @authorization [ :user ] . id && s . loop_item_id == loop_item . id end @sections_to_display_in_tab_loops_expanded << [ section , loop_item , submission_state . try ( :section_state ) || SubmissionStatus :: DEFAULT ] end end else submission_state = section . submission_states . find do | s | s . user_id == @authorization [ :user ] . id end @sections_to_display_in_tab_loops_expanded << [ section , nil , submission_state . try ( :section_state ) || SubmissionStatus :: DEFAULT ] end end respond_to do | format | format . html format . js end end
Access questionnaire to fill in answers as a respondent
Access questionnaire to fill in answers as a respondent