<commit_before>class TeamsController < ApplicationController
  autocomplete :user, :name


  def action_allowed?
    ['Instructor',
     'Teaching Assistant',
     'Administrator'].include? current_role_name
  end

  def create_teams_view
    @parent = Object.const_get(session[:team_type]).find(params[:id])
  end

  def delete_all
    parent = Object.const_get(session[:team_type]).find(params[:id])
    @teams = Team.where(parent_id: parent.id)
    @teams.each do |t|
      t.destroy
    end
    undo_link("All teams have been removed successfully. ")
    redirect_to :action => 'list', :id => parent.id
  end

  def create_teams
    parent = Object.const_get(session[:team_type]).find(params[:id])
    Team.randomize_all_by_parent(parent, session[:team_type], params[:team][:size].to_i)
    undo_link("Random teams have been created successfully. ")
    redirect_to :action => 'list', :id => parent.id
  end

  def list
    if params[:type]
      session[:team_type] = params[:type]
    end

    @root_node = Object.const_get(session[:team_type] + "Node").find_by_node_object_id(params[:id])
    @child_nodes = @root_node.get_teams()
  end

  def new
    @parent = Object.const_get(session[:team_type]).find(params[:id])
  end

  def create
    parent = Object.const_get(session[:team_type]).find(params[:id])
    begin
      Team.check_for_existing(parent, params[:team][:name], session[:team_type])
      @team = Object.const_get(session[:team_type]+'Team').create(:name => params[:team][:name], :parent_id => parent.id)
      TeamNode.create(:parent_id => parent.id, :node_object_id => @team.id)
      undo_link("Team \"#{@team.name}\" has been created successfully. ")
      redirect_to :action => 'list', :id => parent.id
    rescue TeamExistsError
      flash[:error] = $!
      redirect_to :action => 'new', :id => parent.id
    end
  end

  def update
    @team = Team.find(params[:id])
    parent = Object.const_get(session[:team_type]).find(@team.parent_id)
    begin
      Team.check_for_existing(parent, params[:team][:name], session[:team_type])
      @team.name = params[:team][:name]
      @team.save
      undo_link("Team \"#{@team.name}\" has been updated successfully. ")
      redirect_to :action => 'list', :id => parent.id
    rescue TeamExistsError
      flash[:error] = $!
      redirect_to :action => 'edit', :id => @team.id
    end
  end

  def edit
    @team = Team.find(params[:id])
  end

  def delete
    @team = Team.find(params[:id])<commit_msg>Change a plain text feedback to a flashed notice.<commit_after>class TeamsController < ApplicationController
  autocomplete :user, :name


  def action_allowed?
    ['Instructor',
     'Teaching Assistant',
     'Administrator'].include? current_role_name
  end

  def create_teams_view
    @parent = Object.const_get(session[:team_type]).find(params[:id])
  end

  def delete_all
    parent = Object.const_get(session[:team_type]).find(params[:id])
    @teams = Team.where(parent_id: parent.id)
    @teams.each do |t|
      t.destroy
    end
    undo_link("All teams have been removed successfully. ")
    redirect_to :action => 'list', :id => parent.id
  end

  def create_teams
    parent = Object.const_get(session[:team_type]).find(params[:id])
    Team.randomize_all_by_parent(parent, session[:team_type], params[:team][:size].to_i)
    undo_link("Random teams have been created successfully. ")
    redirect_to :action => 'list', :id => parent.id
  end

  def list
    if params[:type]
      session[:team_type] = params[:type]
    end

    @root_node = Object.const_get(session[:team_type] + "Node").find_by_node_object_id(params[:id])
    @child_nodes = @root_node.get_teams()
  end

  def new
    @parent = Object.const_get(session[:team_type]).find(params[:id])
  end

  def create
    parent = Object.const_get(session[:team_type]).find(params[:id])
    begin
      Team.check_for_existing(parent, params[:team][:name], session[:team_type])
      @team = Object.const_get(session[:team_type]+'Team').create(:name => params[:team][:name], :parent_id => parent.id)
      TeamNode.create(:parent_id => parent.id, :node_object_id => @team.id)
      undo_link("Team \"#{@team.name}\" has been created successfully. ")
      redirect_to :action => 'list', :id => parent.id
    rescue TeamExistsError
      flash[:error] = $!
      redirect_to :action => 'new', :id => parent.id
    end
  end

  def update
    @team = Team.find(params[:id])
    parent = Object.const_get(session[:team_type]).find(@team.parent_id)
    begin
      Team.check_for_existing(parent, params[:team][:name], session[:team_type])
      @team.name = params[:team][:name]
      @team.save
      flash[:success] = "Team \"#{@team.name}\" has been updated successfully. "
      undo_link("")
      redirect_to :action => 'list', :id => parent.id
    rescue TeamExistsError
      flash[:error] = $!
      redirect_to :action => 'edit', :id => @team.id
    end
  end

  def edit
    @team = Team.find(params[:id])
  end

  def delete
    @team = Team.find(params[:id])
{'fraction_non_alphanumeric': 0.150308580529564, 'fraction_numerical': 0.0, 'mean_word_length': 3.717370892018779, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4494065', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1629, 'n_words': 331}