<commit_before>class ProjectsController < ApplicationController
  before_action :set_project, only: %i[show edit update destroy]

  def index
    @projects = Project.all
  end

  def show() end

  def new
    @project = Project.new
  end

  def edit
  end

  def create
    @project = Project.new(project_params)
    @project.project_members << current_user
    notice = 'Project was successfully created.'
    @project.save ? (redirect_to @project, notice: notice) : (render :new)
  end

  def update
    @project.assign_attributes(project_params)
    notice = 'Project was successfully updated.'
    @project.save ? (redirect_to @project, notice: notice) : (render :edit)
  end

  def destroy
    if check_if_team_member
      @project.destroy
      redirect_to projects_url, notice: 'Project was successfully destroyed.'
    else
      flash[:error] = 'Only a project member can delete a project'
      redirect_to projects_path
    end
  end

  private

  def set_project
    @project = Project.find(params[:id])
  end

  def project_params
    params.require(:project).permit(:title,
                                    :description,
                                    :due_date,
                                    :completed,
                                    tasks_attributes:
                                    %i[id title content due_date completed])
  end

  def check_if_team_member
    @project.team_members.include?(current_user)
  end
end<commit_msg>refactored projects controller to use check_if_team_member<commit_after>class ProjectsController < ApplicationController
  before_action :set_project, except: %i[index new]
  before_action :check_if_team_member, except: %i[index new]

  def index
    @projects = Project.all
  end

  def show() end

  def new
    @project = Project.new
  end

  def edit() end

  def create
    @project = Project.new(project_params)
    @project.project_members << current_user
    notice = 'Project was successfully created.'
    @project.save ? (redirect_to @project, notice: notice) : (render :new)
  end

  def update
    @project.assign_attributes(project_params)
    notice = 'Project was successfully updated.'
    @project.save ? (redirect_to @project, notice: notice) : (render :edit)
  end

  def destroy
    @project.destroy
    redirect_to projects_url, notice: 'Project was successfully destroyed.'
  end

  private

  def set_project
    @project = Project.find(params[:id])
  end

  def project_params
    params.require(:project).permit(:title,
                                    :description,
                                    :due_date,
                                    :completed,
                                    tasks_attributes:
                                    %i[id title content due_date completed])
  end
end
{'fraction_non_alphanumeric': 0.07642857142857143, 'fraction_numerical': 0.0, 'mean_word_length': 2.2494199535962878, 'pattern_counts': {'":': 0, '<': 9, '<?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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7043498', 'n_tokens_mistral': 771, 'n_tokens_neox': 736, 'n_words': 210}