<commit_before>include OwnershipAuthentication

class ProjectsController < ApplicationController
  before_action :authenticate_user!,
    except: [:index, :show]
  before_action :project_owner?, only: [:edit, :update, :destroy]

  # GET /projects/new
  def new
    @project = Project.new
    @project_image = ProjectImage.new
  end

  # GET /projects
  # GET /projects.json
  def index
    @projects = Project.all
  end

  # POST /projects
  # POST /projects.json
  def create
    @project = Project.new(project_params)
    respond_to do |format|
      create_and_redir(format)
      ProjectImage.create(url: project_params[:url],project_id: @project.id )
    end
  end

  # GET /project/1
  # GET /project/1.json
  def show
    set_project
    @project_repositories = @project.repositories
    @project_image = ProjectImage.find_by_project_id(@project.id)
  end

  # GET /projects/1/edit
  # GET /projects/1/edit.json
  def edit
    set_project
    @project_image = ProjectImage.find_by_project_id(@project.id)
    #@project_image ? @project_image.check_no_image : ProjectImage.new
  end

  def update
    set_project
    @project_image = ProjectImage.find_by_project_id(@project.id)
    if @project.update(project_params) && @project_image.update(url: project_params[:image_url])
      redirect_to(project_path(@project.id))
    else
      render "edit"
    end
  end

  # DELETE /project/1<commit_msg>Removes image_url on update<commit_after>include OwnershipAuthentication

class ProjectsController < ApplicationController
  before_action :authenticate_user!,
    except: [:index, :show]
  before_action :project_owner?, only: [:edit, :update, :destroy]

  # GET /projects/new
  def new
    @project = Project.new
    @project_image = ProjectImage.new
  end

  # GET /projects
  # GET /projects.json
  def index
    @projects = Project.all
  end

  # POST /projects
  # POST /projects.json
  def create
    @project = Project.new(project_params)
    respond_to do |format|
      create_and_redir(format)
      ProjectImage.create(url: project_params[:url],project_id: @project.id )
    end
  end

  # GET /project/1
  # GET /project/1.json
  def show
    set_project
    @project_repositories = @project.repositories
    @project_image = ProjectImage.find_by_project_id(@project.id)
  end

  # GET /projects/1/edit
  # GET /projects/1/edit.json
  def edit
    set_project
    @project_image = ProjectImage.find_by_project_id(@project.id)
    #@project_image ? @project_image.check_no_image : ProjectImage.new
  end

  def update
    set_project
    @project_image = ProjectImage.find_by_project_id(@project.id)
    image_url = project_params.delete(:image_url)
    if @project.update(project_params) && @project_image.update(url: image_url)
      redirect_to(project_path(@project.id))
    else
      render "edit"
    end
  end

  # DELETE /project/1
{'fraction_non_alphanumeric': 0.09807355516637478, 'fraction_numerical': 0.0035026269702276708, 'mean_word_length': 3.562300319488818, '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': '351935', 'n_tokens_mistral': 949, 'n_tokens_neox': 920, 'n_words': 190}