<commit_before>class ChallengeGradesController < ApplicationController

  before_filter :ensure_staff?, :only=>[:new,:edit,:create,:update,:destroy]

  def index
    @title = "View All #{term_for :challenge} Grades"
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = current_course.challenge_grades
  end

  def show
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grade = @challenge.challenge_grades.find(params[:id])
    @title = @challenge_grade.name
  end

  def new
    @challenge = current_course.challenges.find(params[:challenge_id])
    @team = current_course.teams.find(params[:team_id])
    @teams = current_course.teams
    @challenge_grade = @team.challenge_grades.new
    @title = "Create a New #{term_for :challenge} Grade"
  end

  def edit
    @challenge = current_course.challenges.find(params[:challenge_id])
    @title = "Edit #{@challenge.name} Grade"
    @teams = current_course.teams
    @challenge_grade = @challenge.challenge_grades.find(params[:id])
  end

  def mass_edit
    @challenge = current_course.challenges.find(params[:challenge_id])
    @teams = current_course.teams
    @title = "Quick Grade #{@challenge.name}"
    @score_levels = @challenge.score_levels
    @students = current_course.users.students
    @challenge_grades = @teams.map do |t|
      @challenge.challenge_grades.where(:team_id => t).first || @challenge.challenge_grades.new(:team => t, :challenge => @challenge)
    end
  end

  def mass_update
    @team = find_team
    @challenge = current_course.challenges.find(params[:challenge_id])
    if @challenge.update_attributes(params[:challenge])
      redirect_to challenge_path(@challenge)
    else
      redirect_to mass_edit_challenge_challenge_grades_path(@challenge)
    end
  end


  def create
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = @challenge.challenge_grades.create(params[:challenge_grade])

    respond_to do |format|
      if @challenge_grades.save
        format.html { redirect_to @challenge, notice: 'Challenge was successfully created.' }
        format.json { render json: @challenge, status: :created, location: @challenge_grades }
      else
        format.html { render action: "new" }
        format.json { render json: @challenge_grades.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = current_course.challenge_grades.find(params[:id])

    respond_to do |format|
      if @challenge_grades.update_attributes(params[:challenge])
        format.html { redirect_to @challenge, notice: 'Challenge was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @challenge_grades.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @challenge_grades = current_course.challenge_grades.find(params[:id])
    @challenge_grades.destroy

    respond_to do |format|
      format.html { redirect_to challenges_path }
      format.json { head :ok }
    end
  end

end
<commit_msg>Added challenge grades controller scope adjustment<commit_after>class ChallengeGradesController < ApplicationController

  before_filter :ensure_staff?, :except => [:show]

  def index
    @title = "View All #{term_for :challenge} Grades"
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = current_course.challenge_grades
  end

  def show
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grade = @challenge.challenge_grades.find(params[:id])
    @title = @challenge_grade.name
  end

  def new
    @challenge = current_course.challenges.find(params[:challenge_id])
    @team = current_course.teams.find(params[:team_id])
    @teams = current_course.teams
    @challenge_grade = @team.challenge_grades.new
    @title = "Create a New #{term_for :challenge} Grade"
  end

  def edit
    @challenge = current_course.challenges.find(params[:challenge_id])
    @title = "Edit #{@challenge.name} Grade"
    @teams = current_course.teams
    @challenge_grade = @challenge.challenge_grades.find(params[:id])
  end

  def mass_edit
    @challenge = current_course.challenges.find(params[:challenge_id])
    @teams = current_course.teams
    @title = "Quick Grade #{@challenge.name}"
    @score_levels = @challenge.score_levels
    @students = current_course.users.students
    @challenge_grades = @teams.map do |t|
      @challenge.challenge_grades.where(:team_id => t).first || @challenge.challenge_grades.new(:team => t, :challenge => @challenge)
    end
  end

  def mass_update
    @team = find_team
    @challenge = current_course.challenges.find(params[:challenge_id])
    if @challenge.update_attributes(params[:challenge])
      redirect_to challenge_path(@challenge)
    else
      redirect_to mass_edit_challenge_challenge_grades_path(@challenge)
    end
  end


  def create
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = @challenge.challenge_grades.create(params[:challenge_grade])

    respond_to do |format|
      if @challenge_grades.save
        format.html { redirect_to @challenge, notice: 'Challenge was successfully created.' }
        format.json { render json: @challenge, status: :created, location: @challenge_grades }
      else
        format.html { render action: "new" }
        format.json { render json: @challenge_grades.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    @challenge = current_course.challenges.find(params[:challenge_id])
    @challenge_grades = current_course.challenge_grades.find(params[:id])

    respond_to do |format|
      if @challenge_grades.update_attributes(params[:challenge])
        format.html { redirect_to @challenge, notice: 'Challenge was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @challenge_grades.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @challenge_grades = current_course.challenge_grades.find(params[:id])
    @challenge_grades.destroy

    respond_to do |format|
      format.html { redirect_to challenges_path }
      format.json { head :ok }
    end
  end

end

{'fraction_non_alphanumeric': 0.10555641541557034, 'fraction_numerical': 0.0, 'mean_word_length': 3.9403669724770642, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951752', 'n_tokens_mistral': 2196, 'n_tokens_neox': 1874, 'n_words': 394}