<commit_before>class TeamsController < ApplicationController
  layout 'general_layout'

  def index
    not check_access(true, true) and return
    @teams = Team.order(:team_name).all
    render layout: 'admins'
  end

  def new
    not check_access(true, true) and return
    @team = Team.new
    render layout: 'admins', locals: {
                             advisers: Adviser.all,
                             mentors: Mentor.all
                           }
  end

  def create
    not check_access(true, true) and return
    @team = Team.new(get_team_params)
    if @team.save
      redirect_to teams_path
    else
      render_new_template
    end
  end

  def show
    @team = Team.find(params[:id])
    display_team_access_control_strategy = lambda {
      loggedin_user = current_user
      if @team.adviser and @team.adviser.user_id == loggedin_user.id
        return true
      end
      if @team.mentor and @team.mentor.user_id == loggedin_user.id
        return true
      end
      students = @team.students
      is_student = false
      students.each do |student|
        if student.user_id == loggedin_user.id
          is_student = true
        end
      end
      if is_student
        return true
      end
      # TODO: to think about whether to allow evaluator/evaluated teams to view
      return false
    }
    not check_access(true, false, display_team_access_control_strategy) and return
  end

  def edit
    not check_access(true, false) and return
    @team = Team.find(params[:id])
    render locals: {
             advisers: Adviser.all,
             mentors: Mentor.all
           }
  end

  def update
    not check_access(true, false) and return
    team = update_team
    if team
      redirect_to @team<commit_msg>enabled students in evaluated teams and evaluator teams to view team page<commit_after>class TeamsController < ApplicationController
  layout 'general_layout'

  def index
    not check_access(true, true) and return
    @teams = Team.order(:team_name).all
    render layout: 'admins'
  end

  def new
    not check_access(true, true) and return
    @team = Team.new
    render layout: 'admins', locals: {
                             advisers: Adviser.all,
                             mentors: Mentor.all
                           }
  end

  def create
    not check_access(true, true) and return
    @team = Team.new(get_team_params)
    if @team.save
      redirect_to teams_path
    else
      render_new_template
    end
  end

  def show
    @team = Team.find(params[:id])
    display_team_access_control_strategy = lambda {
      loggedin_user = current_user
      if @team.adviser and @team.adviser.user_id == loggedin_user.id
        return true
      end
      if @team.mentor and @team.mentor.user_id == loggedin_user.id
        return true
      end
      students = @team.students
      is_student = false
      students.each do |student|
        if student.user_id == loggedin_user.id
          is_student = true
          break
        end
      end
      if is_student
        return true
      end
      evaluateds_and_evaluators = []
      @team.evaluateds.each do |evaluated|
        evaluateds_and_evaluators.concat(evaluated.evaluated.students)
      end
      @team.evaluators.each do |evaluator|
        evaluateds_and_evaluators.concat(evaluator.evaluator.students)
      end
      has_evaluating_relation = false
      evaluateds_and_evaluators.each do |eval_er|
        if eval_er.user_id == loggedin_user.id
          has_evaluating_relation = true
          break
        end
      end
      if has_evaluating_relation
        return true
      end
      return false
    }
    not check_access(true, false, display_team_access_control_strategy) and return
  end

  def edit
    not check_access(true, false) and return
    @team = Team.find(params[:id])
    render locals: {
             advisers: Adviser.all,
             mentors: Mentor.all
           }
  end

  def update
    not check_access(true, false) and return
    team = update_team
    if team
      redirect_to @team
{'fraction_non_alphanumeric': 0.06523879862136879, 'fraction_numerical': 0.0, 'mean_word_length': 2.0897338403041825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '346932', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1223, 'n_words': 319}